View Javadoc

1   /*
2    *   Copyright (C) Christian Schulte, 2005-206
3    *   All rights reserved.
4    *
5    *   Redistribution and use in source and binary forms, with or without
6    *   modification, are permitted provided that the following conditions
7    *   are met:
8    *
9    *     o Redistributions of source code must retain the above copyright
10   *       notice, this list of conditions and the following disclaimer.
11   *
12   *     o Redistributions in binary form must reproduce the above copyright
13   *       notice, this list of conditions and the following disclaimer in
14   *       the documentation and/or other materials provided with the
15   *       distribution.
16   *
17   *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18   *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19   *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20   *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
21   *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22   *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23   *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24   *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25   *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26   *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27   *
28   *   $JOMC: ToolsModelValidator.java 4613 2012-09-22 10:07:08Z schulte $
29   *
30   */
31  package org.jomc.tools.modlet;
32  
33  import java.text.MessageFormat;
34  import java.util.List;
35  import java.util.Locale;
36  import java.util.ResourceBundle;
37  import java.util.logging.Level;
38  import org.jomc.model.Dependencies;
39  import org.jomc.model.Dependency;
40  import org.jomc.model.Implementation;
41  import org.jomc.model.Message;
42  import org.jomc.model.Messages;
43  import org.jomc.model.Module;
44  import org.jomc.model.Modules;
45  import org.jomc.model.Specification;
46  import org.jomc.model.modlet.ModelHelper;
47  import org.jomc.modlet.Model;
48  import org.jomc.modlet.ModelContext;
49  import org.jomc.modlet.ModelException;
50  import org.jomc.modlet.ModelValidationReport;
51  import org.jomc.modlet.ModelValidator;
52  import org.jomc.tools.model.ObjectFactory;
53  import org.jomc.tools.model.SourceFileType;
54  import org.jomc.tools.model.SourceFilesType;
55  import org.jomc.tools.model.SourceSectionType;
56  import org.jomc.tools.model.SourceSectionsType;
57  
58  /**
59   * Object management and configuration tools {@code ModelValidator} implementation.
60   *
61   * @author <a href="mailto:cs@schulte.it">Christian Schulte</a>
62   * @version $JOMC: ToolsModelValidator.java 4613 2012-09-22 10:07:08Z schulte $
63   * @see ModelContext#validateModel(org.jomc.modlet.Model)
64   * @since 1.2
65   */
66  public class ToolsModelValidator implements ModelValidator
67  {
68  
69      /** Creates a new {@code ToolsModelValidator} instance. */
70      public ToolsModelValidator()
71      {
72          super();
73      }
74  
75      public ModelValidationReport validateModel( final ModelContext context, final Model model ) throws ModelException
76      {
77          if ( context == null )
78          {
79              throw new NullPointerException( "context" );
80          }
81          if ( model == null )
82          {
83              throw new NullPointerException( "model" );
84          }
85  
86          final ModelValidationReport report = new ModelValidationReport();
87          this.assertValidToolsTypes( model, report );
88          return report;
89      }
90  
91      private void assertValidToolsTypes( final Model model, final ModelValidationReport report )
92      {
93          final List<SourceFileType> sourceFileType = model.getAnyObjects( SourceFileType.class );
94          final List<SourceFilesType> sourceFilesType = model.getAnyObjects( SourceFilesType.class );
95          final List<SourceSectionType> sourceSectionType = model.getAnyObjects( SourceSectionType.class );
96          final List<SourceSectionsType> sourceSectionsType = model.getAnyObjects( SourceSectionsType.class );
97  
98          if ( sourceFileType != null )
99          {
100             for ( SourceFileType s : sourceFileType )
101             {
102                 report.getDetails().add( new ModelValidationReport.Detail(
103                     "MODEL_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
104                     "modelSourceFileConstraint", model.getIdentifier(), s.getIdentifier() ),
105                     new ObjectFactory().createSourceFile( s ) ) );
106 
107 
108             }
109         }
110 
111         if ( sourceFilesType != null )
112         {
113             for ( SourceFilesType files : sourceFilesType )
114             {
115                 for ( SourceFileType s : files.getSourceFile() )
116                 {
117                     report.getDetails().add( new ModelValidationReport.Detail(
118                         "MODEL_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
119                         "modelSourceFileConstraint", model.getIdentifier(), s.getIdentifier() ),
120                         new ObjectFactory().createSourceFile( s ) ) );
121 
122                 }
123 
124                 if ( files.getSourceFile().isEmpty() )
125                 {
126                     report.getDetails().add( new ModelValidationReport.Detail(
127                         "MODEL_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
128                         "modelSourceFilesConstraint", model.getIdentifier() ),
129                         new ObjectFactory().createSourceFiles( files ) ) );
130 
131                 }
132             }
133         }
134 
135         if ( sourceSectionType != null )
136         {
137             for ( SourceSectionType s : sourceSectionType )
138             {
139                 report.getDetails().add( new ModelValidationReport.Detail(
140                     "MODEL_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
141                     "modelSourceSectionConstraint", model.getIdentifier(), s.getName() ),
142                     new ObjectFactory().createSourceSection( s ) ) );
143 
144             }
145         }
146 
147         if ( sourceSectionsType != null )
148         {
149             for ( SourceSectionsType sections : sourceSectionsType )
150             {
151                 for ( SourceSectionType s : sections.getSourceSection() )
152                 {
153                     report.getDetails().add( new ModelValidationReport.Detail(
154                         "MODEL_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
155                         "modelSourceSectionConstraint", model.getIdentifier(), s.getName() ),
156                         new ObjectFactory().createSourceSection( s ) ) );
157 
158                 }
159 
160                 if ( sections.getSourceSection().isEmpty() )
161                 {
162                     report.getDetails().add( new ModelValidationReport.Detail(
163                         "MODEL_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
164                         "modelSourceSectionsConstraint", model.getIdentifier() ),
165                         new ObjectFactory().createSourceSections( sections ) ) );
166 
167                 }
168             }
169         }
170 
171         final Modules modules = ModelHelper.getModules( model );
172 
173         if ( modules != null )
174         {
175             this.assertValidToolsTypes( modules, report );
176         }
177     }
178 
179     private void assertValidToolsTypes( final Modules modules, final ModelValidationReport report )
180     {
181         for ( int i = 0, s0 = modules.getModule().size(); i < s0; i++ )
182         {
183             this.assertValidToolsTypes( modules.getModule().get( i ), report );
184         }
185     }
186 
187     private void assertValidToolsTypes( final Module module, final ModelValidationReport report )
188     {
189         final List<SourceFileType> sourceFileType = module.getAnyObjects( SourceFileType.class );
190         final List<SourceFilesType> sourceFilesType = module.getAnyObjects( SourceFilesType.class );
191         final List<SourceSectionType> sourceSectionType = module.getAnyObjects( SourceSectionType.class );
192         final List<SourceSectionsType> sourceSectionsType = module.getAnyObjects( SourceSectionsType.class );
193 
194         if ( sourceFileType != null )
195         {
196             for ( SourceFileType s : sourceFileType )
197             {
198                 report.getDetails().add( new ModelValidationReport.Detail(
199                     "MODULE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
200                     "moduleSourceFileConstraint", module.getName(), s.getIdentifier() ),
201                     new ObjectFactory().createSourceFile( s ) ) );
202 
203 
204             }
205         }
206 
207         if ( sourceFilesType != null )
208         {
209             for ( SourceFilesType files : sourceFilesType )
210             {
211                 for ( SourceFileType s : files.getSourceFile() )
212                 {
213                     report.getDetails().add( new ModelValidationReport.Detail(
214                         "MODULE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
215                         "moduleSourceFileConstraint", module.getName(), s.getIdentifier() ),
216                         new ObjectFactory().createSourceFile( s ) ) );
217 
218                 }
219 
220                 if ( files.getSourceFile().isEmpty() )
221                 {
222                     report.getDetails().add( new ModelValidationReport.Detail(
223                         "MODULE_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
224                         "moduleSourceFilesConstraint", module.getName() ),
225                         new ObjectFactory().createSourceFiles( files ) ) );
226 
227                 }
228             }
229         }
230 
231         if ( sourceSectionType != null )
232         {
233             for ( SourceSectionType s : sourceSectionType )
234             {
235                 report.getDetails().add( new ModelValidationReport.Detail(
236                     "MODULE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
237                     "moduleSourceSectionConstraint", module.getName(), s.getName() ),
238                     new ObjectFactory().createSourceSection( s ) ) );
239 
240             }
241         }
242 
243         if ( sourceSectionsType != null )
244         {
245             for ( SourceSectionsType sections : sourceSectionsType )
246             {
247                 for ( SourceSectionType s : sections.getSourceSection() )
248                 {
249                     report.getDetails().add( new ModelValidationReport.Detail(
250                         "MODULE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
251                         "moduleSourceSectionConstraint", module.getName(), s.getName() ),
252                         new ObjectFactory().createSourceSection( s ) ) );
253 
254                 }
255 
256                 if ( sections.getSourceSection().isEmpty() )
257                 {
258                     report.getDetails().add( new ModelValidationReport.Detail(
259                         "MODULE_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
260                         "moduleSourceSectionsConstraint", module.getName() ),
261                         new ObjectFactory().createSourceSections( sections ) ) );
262 
263                 }
264             }
265         }
266 
267         if ( module.getImplementations() != null )
268         {
269             for ( int i = 0, s0 = module.getImplementations().getImplementation().size(); i < s0; i++ )
270             {
271                 this.assertValidToolsTypes( module.getImplementations().getImplementation().get( i ), report );
272             }
273         }
274 
275         if ( module.getSpecifications() != null )
276         {
277             for ( int i = 0, s0 = module.getSpecifications().getSpecification().size(); i < s0; i++ )
278             {
279                 this.assertValidToolsTypes( module.getSpecifications().getSpecification().get( i ), report );
280             }
281         }
282     }
283 
284     private void assertValidToolsTypes( final Implementation implementation, final ModelValidationReport report )
285     {
286         final List<SourceFileType> sourceFileType = implementation.getAnyObjects( SourceFileType.class );
287         final List<SourceFilesType> sourceFilesType = implementation.getAnyObjects( SourceFilesType.class );
288         final List<SourceSectionType> sourceSectionType = implementation.getAnyObjects( SourceSectionType.class );
289         final List<SourceSectionsType> sourceSectionsType = implementation.getAnyObjects( SourceSectionsType.class );
290 
291         if ( sourceFileType != null )
292         {
293             if ( sourceFileType.size() > 1 )
294             {
295                 report.getDetails().add( new ModelValidationReport.Detail(
296                     "IMPLEMENTATION_SOURCE_FILE_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
297                     "implementationSourceFileMultiplicityConstraint", implementation.getIdentifier(),
298                     sourceFileType.size() ),
299                     new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
300 
301             }
302             else if ( sourceFileType.size() == 1 )
303             {
304                 report.getDetails().add( new ModelValidationReport.Detail(
305                     "IMPLEMENTATION_SOURCE_FILE_INFORMATION", Level.INFO, getMessage(
306                     "implementationSourceFileInfo", implementation.getIdentifier(),
307                     sourceFileType.get( 0 ).getIdentifier() ),
308                     new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
309 
310             }
311         }
312 
313         if ( sourceFilesType != null )
314         {
315             if ( sourceFilesType.size() > 1 )
316             {
317                 report.getDetails().add( new ModelValidationReport.Detail(
318                     "IMPLEMENTATION_SOURCE_FILES_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
319                     "implementationSourceFilesMultiplicityConstraint", implementation.getIdentifier(),
320                     sourceFilesType.size() ),
321                     new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
322 
323             }
324         }
325 
326         if ( sourceSectionType != null )
327         {
328             for ( SourceSectionType s : sourceSectionType )
329             {
330                 report.getDetails().add( new ModelValidationReport.Detail(
331                     "IMPLEMENTATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
332                     "implementationSourceSectionConstraint", implementation.getIdentifier(), s.getName() ),
333                     new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
334 
335             }
336         }
337 
338         if ( sourceSectionsType != null )
339         {
340             for ( SourceSectionsType sections : sourceSectionsType )
341             {
342                 for ( SourceSectionType s : sections.getSourceSection() )
343                 {
344                     report.getDetails().add( new ModelValidationReport.Detail(
345                         "IMPLEMENTATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
346                         "implementationSourceSectionConstraint", implementation.getIdentifier(), s.getName() ),
347                         new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
348 
349                 }
350 
351                 if ( sections.getSourceSection().isEmpty() )
352                 {
353                     report.getDetails().add( new ModelValidationReport.Detail(
354                         "IMPLEMENTATION_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
355                         "implementationSourceSectionsConstraint", implementation.getIdentifier() ),
356                         new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
357 
358                 }
359             }
360         }
361 
362         if ( implementation.getDependencies() != null )
363         {
364             this.assertValidToolsTypes( implementation, implementation.getDependencies(), report );
365         }
366 
367         if ( implementation.getMessages() != null )
368         {
369             this.assertValidToolsTypes( implementation, implementation.getMessages(), report );
370         }
371     }
372 
373     private void assertValidToolsTypes( final Implementation implementation, final Dependencies dependencies,
374                                         final ModelValidationReport report )
375     {
376         for ( Dependency d : dependencies.getDependency() )
377         {
378             final List<SourceFileType> sourceFileType = d.getAnyObjects( SourceFileType.class );
379             final List<SourceFilesType> sourceFilesType = d.getAnyObjects( SourceFilesType.class );
380             final List<SourceSectionType> sourceSectionType = d.getAnyObjects( SourceSectionType.class );
381             final List<SourceSectionsType> sourceSectionsType = d.getAnyObjects( SourceSectionsType.class );
382 
383             if ( sourceFileType != null )
384             {
385                 for ( SourceFileType s : sourceFileType )
386                 {
387                     report.getDetails().add( new ModelValidationReport.Detail(
388                         "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
389                         "dependencySourceFileConstraint", implementation.getIdentifier(), d.getName(),
390                         s.getIdentifier() ),
391                         new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
392 
393 
394                 }
395             }
396 
397             if ( sourceFilesType != null )
398             {
399                 for ( SourceFilesType files : sourceFilesType )
400                 {
401                     for ( SourceFileType s : files.getSourceFile() )
402                     {
403                         report.getDetails().add( new ModelValidationReport.Detail(
404                             "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
405                             "dependencySourceFileConstraint", implementation.getIdentifier(), d.getName(),
406                             s.getIdentifier() ),
407                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
408 
409                     }
410 
411                     if ( files.getSourceFile().isEmpty() )
412                     {
413                         report.getDetails().add( new ModelValidationReport.Detail(
414                             "IMPLEMENTATION_DEPENDENCY_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
415                             "dependencySourceFilesConstraint", implementation.getIdentifier(), d.getName() ),
416                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
417 
418                     }
419                 }
420             }
421 
422             if ( sourceSectionType != null )
423             {
424                 for ( SourceSectionType s : sourceSectionType )
425                 {
426                     report.getDetails().add( new ModelValidationReport.Detail(
427                         "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
428                         "dependencySourceSectionConstraint", implementation.getIdentifier(), d.getName(), s.getName() ),
429                         new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
430 
431                 }
432             }
433 
434             if ( sourceSectionsType != null )
435             {
436                 for ( SourceSectionsType sections : sourceSectionsType )
437                 {
438                     for ( SourceSectionType s : sections.getSourceSection() )
439                     {
440                         report.getDetails().add( new ModelValidationReport.Detail(
441                             "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
442                             "dependencySourceSectionConstraint", implementation.getIdentifier(), d.getName(),
443                             s.getName() ),
444                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
445 
446                     }
447 
448                     if ( sections.getSourceSection().isEmpty() )
449                     {
450                         report.getDetails().add( new ModelValidationReport.Detail(
451                             "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
452                             "dependencySourceSectionsConstraint", implementation.getIdentifier(), d.getName() ),
453                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
454 
455                     }
456                 }
457             }
458         }
459     }
460 
461     private void assertValidToolsTypes( final Implementation implementation, final Messages messages,
462                                         final ModelValidationReport report )
463     {
464         for ( Message m : messages.getMessage() )
465         {
466             final List<SourceFileType> sourceFileType = m.getAnyObjects( SourceFileType.class );
467             final List<SourceFilesType> sourceFilesType = m.getAnyObjects( SourceFilesType.class );
468             final List<SourceSectionType> sourceSectionType = m.getAnyObjects( SourceSectionType.class );
469             final List<SourceSectionsType> sourceSectionsType = m.getAnyObjects( SourceSectionsType.class );
470 
471             if ( sourceFileType != null )
472             {
473                 for ( SourceFileType s : sourceFileType )
474                 {
475                     report.getDetails().add( new ModelValidationReport.Detail(
476                         "IMPLEMENTATION_MESSAGE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
477                         "messageSourceFileConstraint", implementation.getIdentifier(), m.getName(),
478                         s.getIdentifier() ),
479                         new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
480 
481 
482                 }
483             }
484 
485             if ( sourceFilesType != null )
486             {
487                 for ( SourceFilesType files : sourceFilesType )
488                 {
489                     for ( SourceFileType s : files.getSourceFile() )
490                     {
491                         report.getDetails().add( new ModelValidationReport.Detail(
492                             "IMPLEMENTATION_MESSAGE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
493                             "messageSourceFileConstraint", implementation.getIdentifier(), m.getName(),
494                             s.getIdentifier() ),
495                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
496 
497                     }
498 
499                     if ( files.getSourceFile().isEmpty() )
500                     {
501                         report.getDetails().add( new ModelValidationReport.Detail(
502                             "IMPLEMENTATION_MESSAGE_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
503                             "messageSourceFilesConstraint", implementation.getIdentifier(), m.getName() ),
504                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
505 
506                     }
507                 }
508             }
509 
510             if ( sourceSectionType != null )
511             {
512                 for ( SourceSectionType s : sourceSectionType )
513                 {
514                     report.getDetails().add( new ModelValidationReport.Detail(
515                         "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
516                         "messageSourceSectionConstraint", implementation.getIdentifier(), m.getName(), s.getName() ),
517                         new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
518 
519                 }
520             }
521 
522             if ( sourceSectionsType != null )
523             {
524                 for ( SourceSectionsType sections : sourceSectionsType )
525                 {
526                     for ( SourceSectionType s : sections.getSourceSection() )
527                     {
528                         report.getDetails().add( new ModelValidationReport.Detail(
529                             "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
530                             "messageSourceSectionConstraint", implementation.getIdentifier(), m.getName(),
531                             s.getName() ),
532                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
533 
534                     }
535 
536                     if ( sections.getSourceSection().isEmpty() )
537                     {
538                         report.getDetails().add( new ModelValidationReport.Detail(
539                             "IMPLEMENTATION_MESSAGE_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
540                             "messageSourceSectionsConstraint", implementation.getIdentifier(), m.getName() ),
541                             new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
542 
543                     }
544                 }
545             }
546         }
547     }
548 
549     private void assertValidToolsTypes( final Specification specification, final ModelValidationReport report )
550     {
551         final List<SourceFileType> sourceFileType = specification.getAnyObjects( SourceFileType.class );
552         final List<SourceFilesType> sourceFilesType = specification.getAnyObjects( SourceFilesType.class );
553         final List<SourceSectionType> sourceSectionType = specification.getAnyObjects( SourceSectionType.class );
554         final List<SourceSectionsType> sourceSectionsType = specification.getAnyObjects( SourceSectionsType.class );
555 
556         if ( sourceFileType != null )
557         {
558             if ( sourceFileType.size() > 1 )
559             {
560                 report.getDetails().add( new ModelValidationReport.Detail(
561                     "SPECIFICATION_SOURCE_FILE_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
562                     "specificationSourceFileMultiplicityConstraint", specification.getIdentifier(),
563                     sourceFileType.size() ),
564                     new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
565 
566             }
567             else if ( sourceFileType.size() == 1 )
568             {
569                 report.getDetails().add( new ModelValidationReport.Detail(
570                     "SPECIFICATION_SOURCE_FILE_INFORMATION", Level.INFO, getMessage(
571                     "specificationSourceFileInfo", specification.getIdentifier(),
572                     sourceFileType.get( 0 ).getIdentifier() ),
573                     new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
574 
575             }
576         }
577 
578         if ( sourceFilesType != null )
579         {
580             if ( sourceFilesType.size() > 1 )
581             {
582                 report.getDetails().add( new ModelValidationReport.Detail(
583                     "SPECIFICATION_SOURCE_FILES_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
584                     "specificationSourceFilesMultiplicityConstraint", specification.getIdentifier(),
585                     sourceFilesType.size() ),
586                     new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
587 
588             }
589         }
590 
591         if ( sourceSectionType != null )
592         {
593             for ( SourceSectionType s : sourceSectionType )
594             {
595                 report.getDetails().add( new ModelValidationReport.Detail(
596                     "SPECIFICATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
597                     "specificationSourceSectionConstraint", specification.getIdentifier(), s.getName() ),
598                     new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
599 
600             }
601         }
602 
603         if ( sourceSectionsType != null )
604         {
605             for ( SourceSectionsType sections : sourceSectionsType )
606             {
607                 for ( SourceSectionType s : sections.getSourceSection() )
608                 {
609                     report.getDetails().add( new ModelValidationReport.Detail(
610                         "SPECIFICATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
611                         "specificationSourceSectionConstraint", specification.getIdentifier(), s.getName() ),
612                         new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
613 
614                 }
615 
616                 if ( sections.getSourceSection().isEmpty() )
617                 {
618                     report.getDetails().add( new ModelValidationReport.Detail(
619                         "SPECIFICATION_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
620                         "specificationSourceSectionsConstraint", specification.getIdentifier() ),
621                         new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
622 
623                 }
624             }
625         }
626     }
627 
628     private static String getMessage( final String key, final Object... args )
629     {
630         return MessageFormat.format( ResourceBundle.getBundle(
631             ToolsModelValidator.class.getName().replace( '.', '/' ), Locale.getDefault() ).getString( key ), args );
632 
633     }
634 
635 }