001    /*
002     *   Copyright (C) Christian Schulte, 2005-206
003     *   All rights reserved.
004     *
005     *   Redistribution and use in source and binary forms, with or without
006     *   modification, are permitted provided that the following conditions
007     *   are met:
008     *
009     *     o Redistributions of source code must retain the above copyright
010     *       notice, this list of conditions and the following disclaimer.
011     *
012     *     o Redistributions in binary form must reproduce the above copyright
013     *       notice, this list of conditions and the following disclaimer in
014     *       the documentation and/or other materials provided with the
015     *       distribution.
016     *
017     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027     *
028     *   $JOMC: ToolsModelValidator.java 3838 2011-10-08 20:15:41Z schulte2005 $
029     *
030     */
031    package org.jomc.tools.modlet;
032    
033    import java.text.MessageFormat;
034    import java.util.List;
035    import java.util.Locale;
036    import java.util.ResourceBundle;
037    import java.util.logging.Level;
038    import org.jomc.model.Dependencies;
039    import org.jomc.model.Dependency;
040    import org.jomc.model.Implementation;
041    import org.jomc.model.Message;
042    import org.jomc.model.Messages;
043    import org.jomc.model.Module;
044    import org.jomc.model.Modules;
045    import org.jomc.model.Specification;
046    import org.jomc.model.modlet.ModelHelper;
047    import org.jomc.modlet.Model;
048    import org.jomc.modlet.ModelContext;
049    import org.jomc.modlet.ModelException;
050    import org.jomc.modlet.ModelValidationReport;
051    import org.jomc.modlet.ModelValidator;
052    import org.jomc.tools.model.ObjectFactory;
053    import org.jomc.tools.model.SourceFileType;
054    import org.jomc.tools.model.SourceFilesType;
055    import org.jomc.tools.model.SourceSectionType;
056    import org.jomc.tools.model.SourceSectionsType;
057    
058    /**
059     * Object management and configuration tools {@code ModelValidator} implementation.
060     *
061     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
062     * @version $JOMC: ToolsModelValidator.java 3838 2011-10-08 20:15:41Z schulte2005 $
063     * @see ModelContext#validateModel(org.jomc.modlet.Model)
064     * @since 1.2
065     */
066    public class ToolsModelValidator implements ModelValidator
067    {
068    
069        /** Creates a new {@code ToolsModelValidator} instance. */
070        public ToolsModelValidator()
071        {
072            super();
073        }
074    
075        public ModelValidationReport validateModel( final ModelContext context, final Model model ) throws ModelException
076        {
077            if ( context == null )
078            {
079                throw new NullPointerException( "context" );
080            }
081            if ( model == null )
082            {
083                throw new NullPointerException( "model" );
084            }
085    
086            final ModelValidationReport report = new ModelValidationReport();
087            this.assertValidToolsTypes( model, report );
088            return report;
089        }
090    
091        private void assertValidToolsTypes( final Model model, final ModelValidationReport report )
092        {
093            final List<SourceFileType> sourceFileType = model.getAnyObjects( SourceFileType.class );
094            final List<SourceFilesType> sourceFilesType = model.getAnyObjects( SourceFilesType.class );
095            final List<SourceSectionType> sourceSectionType = model.getAnyObjects( SourceSectionType.class );
096            final List<SourceSectionsType> sourceSectionsType = model.getAnyObjects( SourceSectionsType.class );
097    
098            if ( sourceFileType != null )
099            {
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    }