1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.jomc.tools.modlet;
32
33 import java.text.MessageFormat;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 import java.util.Locale;
38 import java.util.ResourceBundle;
39 import java.util.logging.Level;
40 import javax.xml.bind.JAXBElement;
41 import org.jomc.model.Dependencies;
42 import org.jomc.model.Dependency;
43 import org.jomc.model.Implementation;
44 import org.jomc.model.Message;
45 import org.jomc.model.Messages;
46 import org.jomc.model.ModelObjectException;
47 import org.jomc.model.Module;
48 import org.jomc.model.Modules;
49 import org.jomc.model.Specification;
50 import org.jomc.model.modlet.ModelHelper;
51 import org.jomc.modlet.Model;
52 import org.jomc.modlet.ModelContext;
53 import org.jomc.modlet.ModelException;
54 import org.jomc.modlet.ModelValidationReport;
55 import org.jomc.modlet.ModelValidator;
56 import org.jomc.tools.model.ObjectFactory;
57 import org.jomc.tools.model.SourceFileType;
58 import org.jomc.tools.model.SourceFilesType;
59 import org.jomc.tools.model.SourceSectionType;
60 import org.jomc.tools.model.SourceSectionsType;
61 import org.jomc.tools.model.TemplateParameterType;
62
63
64
65
66
67
68
69
70
71 public class ToolsModelValidator implements ModelValidator
72 {
73
74
75
76
77
78
79
80 public static final String VALIDATE_JAVA_ATTRIBUTE_NAME =
81 "org.jomc.tools.modlet.ToolsModelValidator.validateJavaAttribute";
82
83
84
85
86
87
88
89 private static final String DEFAULT_VALIDATE_JAVA_PROPERTY_NAME =
90 "org.jomc.tools.modlet.ToolsModelValidator.defaultValidateJava";
91
92
93
94
95
96
97
98 private static final Boolean DEFAULT_VALIDATE_JAVA = Boolean.TRUE;
99
100
101
102
103
104
105 private static volatile Boolean defaultValidateJava;
106
107
108
109
110
111
112 private Boolean validateJava;
113
114
115
116
117 public ToolsModelValidator()
118 {
119 super();
120 }
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 public static boolean isDefaultValidateJava()
139 {
140 if ( defaultValidateJava == null )
141 {
142 defaultValidateJava = Boolean.valueOf( System.getProperty( DEFAULT_VALIDATE_JAVA_PROPERTY_NAME,
143 Boolean.toString( DEFAULT_VALIDATE_JAVA ) ) );
144
145 }
146
147 return defaultValidateJava;
148 }
149
150
151
152
153
154
155
156
157
158
159
160 public static void setDefaultValidateJava( final Boolean value )
161 {
162 defaultValidateJava = value;
163 }
164
165
166
167
168
169
170
171
172
173
174
175
176 public final boolean isValidateJava()
177 {
178 if ( this.validateJava == null )
179 {
180 this.validateJava = isDefaultValidateJava();
181 }
182
183 return this.validateJava;
184 }
185
186
187
188
189
190
191
192
193
194
195
196 public final void setValidateJava( final Boolean value )
197 {
198 this.validateJava = value;
199 }
200
201 public ModelValidationReport validateModel( final ModelContext context, final Model model ) throws ModelException
202 {
203 if ( context == null )
204 {
205 throw new NullPointerException( "context" );
206 }
207 if ( model == null )
208 {
209 throw new NullPointerException( "model" );
210 }
211
212 final ModelValidationReport report = new ModelValidationReport();
213 this.assertValidToolsTypes( context, model, report );
214 return report;
215 }
216
217 private void assertValidToolsTypes( final ModelContext context, final Model model,
218 final ModelValidationReport report )
219 {
220 final List<SourceFileType> sourceFileType = model.getAnyObjects( SourceFileType.class );
221 final List<SourceFilesType> sourceFilesType = model.getAnyObjects( SourceFilesType.class );
222 final List<SourceSectionType> sourceSectionType = model.getAnyObjects( SourceSectionType.class );
223 final List<SourceSectionsType> sourceSectionsType = model.getAnyObjects( SourceSectionsType.class );
224
225 if ( sourceFileType != null )
226 {
227 for ( final SourceFileType s : sourceFileType )
228 {
229 report.getDetails().add( new ModelValidationReport.Detail(
230 "MODEL_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
231 "modelSourceFileConstraint", model.getIdentifier(), s.getIdentifier() ),
232 new ObjectFactory().createSourceFile( s ) ) );
233
234 if ( this.isValidateJava() )
235 {
236 for ( final TemplateParameterType p : s.getTemplateParameter() )
237 {
238 try
239 {
240 p.getJavaValue( context.getClassLoader() );
241 }
242 catch ( final ModelObjectException e )
243 {
244 final String message = getMessage( e );
245
246 if ( context.isLoggable( Level.FINE ) )
247 {
248 context.log( Level.FINE, message, e );
249 }
250
251 report.getDetails().add( new ModelValidationReport.Detail(
252 "MODEL_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE, getMessage(
253 "modelSourceFileTemplateParameterJavaValueConstraint", model.getIdentifier(),
254 s.getIdentifier(), p.getName(),
255 message != null && message.length() > 0 ? " " + message : "" ),
256 new ObjectFactory().createSourceFile( s ) ) );
257
258 }
259 }
260 }
261
262 this.validateTemplateParameters( report, context, s.getSourceSections(),
263 "MODEL_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
264 new ObjectFactory().createSourceFile( s ),
265 "modelSourceFileSectionTemplateParameterJavaValueConstraint",
266 model.getIdentifier(), s.getIdentifier() );
267
268 }
269 }
270
271 if ( sourceFilesType != null )
272 {
273 for ( final SourceFilesType files : sourceFilesType )
274 {
275 for ( final SourceFileType s : files.getSourceFile() )
276 {
277 report.getDetails().add( new ModelValidationReport.Detail(
278 "MODEL_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
279 "modelSourceFileConstraint", model.getIdentifier(), s.getIdentifier() ),
280 new ObjectFactory().createSourceFile( s ) ) );
281
282 if ( this.isValidateJava() )
283 {
284 for ( final TemplateParameterType p : s.getTemplateParameter() )
285 {
286 try
287 {
288 p.getJavaValue( context.getClassLoader() );
289 }
290 catch ( final ModelObjectException e )
291 {
292 final String message = getMessage( e );
293
294 if ( context.isLoggable( Level.FINE ) )
295 {
296 context.log( Level.FINE, message, e );
297 }
298
299 report.getDetails().add( new ModelValidationReport.Detail(
300 "MODEL_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
301 getMessage( "modelSourceFileTemplateParameterJavaValueConstraint",
302 model.getIdentifier(), s.getIdentifier(), p.getName(),
303 message != null && message.length() > 0 ? " " + message : "" ),
304 new ObjectFactory().createSourceFile( s ) ) );
305
306 }
307 }
308 }
309
310 this.validateTemplateParameters(
311 report, context, s.getSourceSections(),
312 "MODEL_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
313 new ObjectFactory().createSourceFile( s ),
314 "modelSourceFileSectionTemplateParameterJavaValueConstraint",
315 model.getIdentifier(), s.getIdentifier() );
316
317 }
318
319 if ( files.getSourceFile().isEmpty() )
320 {
321 report.getDetails().add( new ModelValidationReport.Detail(
322 "MODEL_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
323 "modelSourceFilesConstraint", model.getIdentifier() ),
324 new ObjectFactory().createSourceFiles( files ) ) );
325
326 }
327 }
328 }
329
330 if ( sourceSectionType != null )
331 {
332 for ( final SourceSectionType s : sourceSectionType )
333 {
334 report.getDetails().add( new ModelValidationReport.Detail(
335 "MODEL_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
336 "modelSourceSectionConstraint", model.getIdentifier(), s.getName() ),
337 new ObjectFactory().createSourceSection( s ) ) );
338
339 if ( this.isValidateJava() )
340 {
341 for ( final TemplateParameterType p : s.getTemplateParameter() )
342 {
343 try
344 {
345 p.getJavaValue( context.getClassLoader() );
346 }
347 catch ( final ModelObjectException e )
348 {
349 final String message = getMessage( e );
350
351 if ( context.isLoggable( Level.FINE ) )
352 {
353 context.log( Level.FINE, message, e );
354 }
355
356 report.getDetails().add( new ModelValidationReport.Detail(
357 "MODEL_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
358 getMessage( "modelSourceSectionTemplateParameterJavaValueConstraint",
359 model.getIdentifier(), s.getName(), p.getName(),
360 message != null && message.length() > 0 ? " " + message : "" ),
361 new ObjectFactory().createSourceSection( s ) ) );
362
363 }
364 }
365 }
366
367 this.validateTemplateParameters( report, context, s.getSourceSections(),
368 "MODEL_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
369 new ObjectFactory().createSourceSection( s ),
370 "modelSourceSectionTemplateParameterJavaValueConstraint",
371 model.getIdentifier() );
372
373 }
374 }
375
376 if ( sourceSectionsType != null )
377 {
378 for ( final SourceSectionsType sections : sourceSectionsType )
379 {
380 for ( final SourceSectionType s : sections.getSourceSection() )
381 {
382 report.getDetails().add( new ModelValidationReport.Detail(
383 "MODEL_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
384 "modelSourceSectionConstraint", model.getIdentifier(), s.getName() ),
385 new ObjectFactory().createSourceSection( s ) ) );
386
387 }
388
389 if ( sections.getSourceSection().isEmpty() )
390 {
391 report.getDetails().add( new ModelValidationReport.Detail(
392 "MODEL_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
393 "modelSourceSectionsConstraint", model.getIdentifier() ),
394 new ObjectFactory().createSourceSections( sections ) ) );
395
396 }
397
398 this.validateTemplateParameters( report, context, sections,
399 "MODEL_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
400 new ObjectFactory().createSourceSections( sections ),
401 "modelSourceSectionTemplateParameterJavaValueConstraint",
402 model.getIdentifier() );
403
404 }
405 }
406
407 final Modules modules = ModelHelper.getModules( model );
408
409 if ( modules != null )
410 {
411 this.assertValidToolsTypes( context, modules, report );
412 }
413 }
414
415 private void assertValidToolsTypes( final ModelContext context, final Modules modules,
416 final ModelValidationReport report )
417 {
418 for ( int i = 0, s0 = modules.getModule().size(); i < s0; i++ )
419 {
420 this.assertValidToolsTypes( context, modules.getModule().get( i ), report );
421 }
422 }
423
424 private void assertValidToolsTypes( final ModelContext context, final Module module,
425 final ModelValidationReport report )
426 {
427 final List<SourceFileType> sourceFileType = module.getAnyObjects( SourceFileType.class );
428 final List<SourceFilesType> sourceFilesType = module.getAnyObjects( SourceFilesType.class );
429 final List<SourceSectionType> sourceSectionType = module.getAnyObjects( SourceSectionType.class );
430 final List<SourceSectionsType> sourceSectionsType = module.getAnyObjects( SourceSectionsType.class );
431
432 if ( sourceFileType != null )
433 {
434 for ( final SourceFileType s : sourceFileType )
435 {
436 report.getDetails().add( new ModelValidationReport.Detail(
437 "MODULE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
438 "moduleSourceFileConstraint", module.getName(), s.getIdentifier() ),
439 new ObjectFactory().createSourceFile( s ) ) );
440
441 if ( this.isValidateJava() )
442 {
443 for ( final TemplateParameterType p : s.getTemplateParameter() )
444 {
445 try
446 {
447 p.getJavaValue( context.getClassLoader() );
448 }
449 catch ( final ModelObjectException e )
450 {
451 final String message = getMessage( e );
452
453 if ( context.isLoggable( Level.FINE ) )
454 {
455 context.log( Level.FINE, message, e );
456 }
457
458 report.getDetails().add( new ModelValidationReport.Detail(
459 "MODULE_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE, getMessage(
460 "moduleSourceFileTemplateParameterJavaValueConstraint", module.getName(),
461 s.getIdentifier(), p.getName(),
462 message != null && message.length() > 0 ? " " + message : "" ),
463 new ObjectFactory().createSourceFile( s ) ) );
464
465 }
466 }
467 }
468
469 this.validateTemplateParameters(
470 report, context, s.getSourceSections(),
471 "MODULE_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
472 new ObjectFactory().createSourceFile( s ),
473 "moduleSourceFileSectionTemplateParameterJavaValueConstraint",
474 module.getName(), s.getIdentifier() );
475
476 }
477 }
478
479 if ( sourceFilesType != null )
480 {
481 for ( final SourceFilesType files : sourceFilesType )
482 {
483 for ( final SourceFileType s : files.getSourceFile() )
484 {
485 report.getDetails().add( new ModelValidationReport.Detail(
486 "MODULE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
487 "moduleSourceFileConstraint", module.getName(), s.getIdentifier() ),
488 new ObjectFactory().createSourceFile( s ) ) );
489
490 if ( this.isValidateJava() )
491 {
492 for ( final TemplateParameterType p : s.getTemplateParameter() )
493 {
494 try
495 {
496 p.getJavaValue( context.getClassLoader() );
497 }
498 catch ( final ModelObjectException e )
499 {
500 final String message = getMessage( e );
501
502 if ( context.isLoggable( Level.FINE ) )
503 {
504 context.log( Level.FINE, message, e );
505 }
506
507 report.getDetails().add( new ModelValidationReport.Detail(
508 "MODULE_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
509 getMessage( "moduleSourceFileTemplateParameterJavaValueConstraint",
510 module.getName(), s.getIdentifier(), p.getName(),
511 message != null && message.length() > 0 ? " " + message : "" ),
512 new ObjectFactory().createSourceFile( s ) ) );
513
514 }
515 }
516 }
517
518 this.validateTemplateParameters(
519 report, context, s.getSourceSections(),
520 "MODULE_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
521 new ObjectFactory().createSourceFile( s ),
522 "moduleSourceFileSectionTemplateParameterJavaValueConstraint",
523 module.getName(), s.getIdentifier() );
524
525 }
526
527 if ( files.getSourceFile().isEmpty() )
528 {
529 report.getDetails().add( new ModelValidationReport.Detail(
530 "MODULE_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
531 "moduleSourceFilesConstraint", module.getName() ),
532 new ObjectFactory().createSourceFiles( files ) ) );
533
534 }
535 }
536 }
537
538 if ( sourceSectionType != null )
539 {
540 for ( final SourceSectionType s : sourceSectionType )
541 {
542 report.getDetails().add( new ModelValidationReport.Detail(
543 "MODULE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
544 "moduleSourceSectionConstraint", module.getName(), s.getName() ),
545 new ObjectFactory().createSourceSection( s ) ) );
546
547 if ( this.isValidateJava() )
548 {
549 for ( final TemplateParameterType p : s.getTemplateParameter() )
550 {
551 try
552 {
553 p.getJavaValue( context.getClassLoader() );
554 }
555 catch ( final ModelObjectException e )
556 {
557 final String message = getMessage( e );
558
559 if ( context.isLoggable( Level.FINE ) )
560 {
561 context.log( Level.FINE, message, e );
562 }
563
564 report.getDetails().add( new ModelValidationReport.Detail(
565 "MODULE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
566 getMessage( "moduleSourceSectionTemplateParameterJavaValueConstraint",
567 module.getName(), s.getName(), p.getName(),
568 message != null && message.length() > 0 ? " " + message : "" ),
569 new ObjectFactory().createSourceSection( s ) ) );
570
571 }
572 }
573 }
574
575 this.validateTemplateParameters(
576 report, context, s.getSourceSections(),
577 "MODULE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
578 new ObjectFactory().createSourceSection( s ),
579 "moduleSourceSectionTemplateParameterJavaValueConstraint",
580 module.getName(), s.getName() );
581
582 }
583 }
584
585 if ( sourceSectionsType != null )
586 {
587 for ( final SourceSectionsType sections : sourceSectionsType )
588 {
589 for ( final SourceSectionType s : sections.getSourceSection() )
590 {
591 report.getDetails().add( new ModelValidationReport.Detail(
592 "MODULE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
593 "moduleSourceSectionConstraint", module.getName(), s.getName() ),
594 new ObjectFactory().createSourceSection( s ) ) );
595
596 if ( this.isValidateJava() )
597 {
598 for ( final TemplateParameterType p : s.getTemplateParameter() )
599 {
600 try
601 {
602 p.getJavaValue( context.getClassLoader() );
603 }
604 catch ( final ModelObjectException e )
605 {
606 final String message = getMessage( e );
607
608 if ( context.isLoggable( Level.FINE ) )
609 {
610 context.log( Level.FINE, message, e );
611 }
612
613 report.getDetails().add( new ModelValidationReport.Detail(
614 "MODULE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
615 getMessage( "moduleSourceSectionTemplateParameterJavaValueConstraint",
616 module.getName(), s.getName(), p.getName(),
617 message != null && message.length() > 0 ? " " + message : "" ),
618 new ObjectFactory().createSourceSection( s ) ) );
619
620 }
621 }
622 }
623
624 this.validateTemplateParameters( report, context, s.getSourceSections(),
625 "MODULE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
626 new ObjectFactory().createSourceSection( s ),
627 "moduleSourceSectionTemplateParameterJavaValueConstraint",
628 module.getName(), s.getName() );
629
630 }
631
632 if ( sections.getSourceSection().isEmpty() )
633 {
634 report.getDetails().add( new ModelValidationReport.Detail(
635 "MODULE_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
636 "moduleSourceSectionsConstraint", module.getName() ),
637 new ObjectFactory().createSourceSections( sections ) ) );
638
639 }
640 }
641 }
642
643 if ( module.getImplementations() != null )
644 {
645 for ( int i = 0, s0 = module.getImplementations().getImplementation().size(); i < s0; i++ )
646 {
647 this.assertValidToolsTypes( context, module, module.getImplementations().getImplementation().get( i ),
648 report );
649
650 }
651 }
652
653 if ( module.getSpecifications() != null )
654 {
655 for ( int i = 0, s0 = module.getSpecifications().getSpecification().size(); i < s0; i++ )
656 {
657 this.assertValidToolsTypes( context, module, module.getSpecifications().getSpecification().get( i ),
658 report );
659
660 }
661 }
662 }
663
664 private void assertValidToolsTypes( final ModelContext context, final Module module,
665 final Implementation implementation, final ModelValidationReport report )
666 {
667 final List<SourceFileType> sourceFileType = implementation.getAnyObjects( SourceFileType.class );
668 final List<SourceFilesType> sourceFilesType = implementation.getAnyObjects( SourceFilesType.class );
669 final List<SourceSectionType> sourceSectionType = implementation.getAnyObjects( SourceSectionType.class );
670 final List<SourceSectionsType> sourceSectionsType = implementation.getAnyObjects( SourceSectionsType.class );
671
672 if ( sourceFileType != null )
673 {
674 for ( final SourceFileType s : sourceFileType )
675 {
676 if ( this.isValidateJava() )
677 {
678 for ( final TemplateParameterType p : s.getTemplateParameter() )
679 {
680 try
681 {
682 p.getJavaValue( context.getClassLoader() );
683 }
684 catch ( final ModelObjectException e )
685 {
686 final String message = getMessage( e );
687
688 if ( context.isLoggable( Level.FINE ) )
689 {
690 context.log( Level.FINE, message, e );
691 }
692
693 report.getDetails().add( new ModelValidationReport.Detail(
694 "IMPLEMENTATION_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
695 getMessage( "implementationSourceFileTemplateParameterJavaValueConstraint",
696 module.getName(), implementation.getIdentifier(),
697 s.getIdentifier(), p.getName(),
698 message != null && message.length() > 0 ? " " + message : "" ),
699 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
700
701 }
702 }
703 }
704
705 this.validateTemplateParameters(
706 report, context, s.getSourceSections(),
707 "IMPLEMENTATION_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
708 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
709 "implementationSourceFileSectionTemplateParameterJavaValueConstraint",
710 module.getName(), implementation.getIdentifier(), s.getIdentifier() );
711
712 }
713
714 if ( sourceFileType.size() > 1 )
715 {
716 report.getDetails().add( new ModelValidationReport.Detail(
717 "IMPLEMENTATION_SOURCE_FILE_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
718 "implementationSourceFileMultiplicityConstraint", module.getName(),
719 implementation.getIdentifier(), sourceFileType.size() ),
720 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
721
722 }
723 else if ( sourceFileType.size() == 1 )
724 {
725 report.getDetails().add( new ModelValidationReport.Detail(
726 "IMPLEMENTATION_SOURCE_FILE_INFORMATION", Level.INFO, getMessage(
727 "implementationSourceFileInfo", module.getName(), implementation.getIdentifier(),
728 sourceFileType.get( 0 ).getIdentifier() ),
729 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
730
731 }
732 }
733
734 if ( sourceFilesType != null )
735 {
736 if ( sourceFilesType.size() > 1 )
737 {
738 report.getDetails().add( new ModelValidationReport.Detail(
739 "IMPLEMENTATION_SOURCE_FILES_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
740 "implementationSourceFilesMultiplicityConstraint", module.getName(),
741 implementation.getIdentifier(), sourceFilesType.size() ),
742 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
743
744 }
745
746 for ( final SourceFilesType l : sourceFilesType )
747 {
748 for ( final SourceFileType s : l.getSourceFile() )
749 {
750 if ( this.isValidateJava() )
751 {
752 for ( final TemplateParameterType p : s.getTemplateParameter() )
753 {
754 try
755 {
756 p.getJavaValue( context.getClassLoader() );
757 }
758 catch ( final ModelObjectException e )
759 {
760 final String message = getMessage( e );
761
762 if ( context.isLoggable( Level.FINE ) )
763 {
764 context.log( Level.FINE, message, e );
765 }
766
767 report.getDetails().add( new ModelValidationReport.Detail(
768 "IMPLEMENTATION_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
769 getMessage( "implementationSourceFileTemplateParameterJavaValueConstraint",
770 module.getName(), implementation.getIdentifier(),
771 s.getIdentifier(), p.getName(),
772 message != null && message.length() > 0 ? " " + message : "" ),
773 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
774
775 }
776 }
777 }
778
779 this.validateTemplateParameters(
780 report, context, s.getSourceSections(),
781 "IMPLEMENTATION_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
782 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
783 "implementationSourceFileSectionTemplateParameterJavaValueConstraint",
784 module.getName(), implementation.getIdentifier(), s.getIdentifier() );
785
786 }
787 }
788 }
789
790 if ( sourceSectionType != null )
791 {
792 for ( final SourceSectionType s : sourceSectionType )
793 {
794 report.getDetails().add( new ModelValidationReport.Detail(
795 "IMPLEMENTATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
796 "implementationSourceSectionConstraint", module.getName(), implementation.getIdentifier(),
797 s.getName() ), new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
798
799 if ( this.isValidateJava() )
800 {
801 for ( final TemplateParameterType p : s.getTemplateParameter() )
802 {
803 try
804 {
805 p.getJavaValue( context.getClassLoader() );
806 }
807 catch ( final ModelObjectException e )
808 {
809 final String message = getMessage( e );
810
811 if ( context.isLoggable( Level.FINE ) )
812 {
813 context.log( Level.FINE, message, e );
814 }
815
816 report.getDetails().add( new ModelValidationReport.Detail(
817 "IMPLEMENTATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT", Level.SEVERE,
818 getMessage( "implementationSourceSectionTemplateParameterJavaValueConstraint",
819 module.getName(), implementation.getIdentifier(),
820 s.getName(), p.getName(),
821 message != null && message.length() > 0 ? " " + message : "" ),
822 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
823
824 }
825 }
826 }
827
828 this.validateTemplateParameters(
829 report, context, s.getSourceSections(),
830 "IMPLEMENTATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
831 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
832 "implementationSourceSectionTemplateParameterJavaValueConstraint",
833 module.getName(), implementation.getIdentifier() );
834
835 }
836 }
837
838 if ( sourceSectionsType != null )
839 {
840 for ( final SourceSectionsType sections : sourceSectionsType )
841 {
842 for ( final SourceSectionType s : sections.getSourceSection() )
843 {
844 report.getDetails().add( new ModelValidationReport.Detail(
845 "IMPLEMENTATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
846 "implementationSourceSectionConstraint", module.getName(), implementation.getIdentifier(),
847 s.getName() ),
848 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
849
850 if ( this.isValidateJava() )
851 {
852 for ( final TemplateParameterType p : s.getTemplateParameter() )
853 {
854 try
855 {
856 p.getJavaValue( context.getClassLoader() );
857 }
858 catch ( final ModelObjectException e )
859 {
860 final String message = getMessage( e );
861
862 if ( context.isLoggable( Level.FINE ) )
863 {
864 context.log( Level.FINE, message, e );
865 }
866
867 report.getDetails().add( new ModelValidationReport.Detail(
868 "IMPLEMENTATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
869 Level.SEVERE, getMessage(
870 "implementationSourceSectionTemplateParameterJavaValueConstraint",
871 module.getName(), implementation.getIdentifier(), s.getName(), p.getName(),
872 message != null && message.length() > 0 ? " " + message : "" ),
873 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
874
875 }
876 }
877 }
878
879 this.validateTemplateParameters(
880 report, context, s.getSourceSections(),
881 "IMPLEMENTATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
882 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
883 "implementationSourceSectionTemplateParameterJavaValueConstraint",
884 module.getName(), implementation.getIdentifier() );
885
886 }
887
888 if ( sections.getSourceSection().isEmpty() )
889 {
890 report.getDetails().add( new ModelValidationReport.Detail(
891 "IMPLEMENTATION_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
892 "implementationSourceSectionsConstraint", module.getName(),
893 implementation.getIdentifier() ),
894 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
895
896 }
897 }
898 }
899
900 if ( implementation.getDependencies() != null )
901 {
902 this.assertValidToolsTypes( context, module, implementation, implementation.getDependencies(), report );
903 }
904
905 if ( implementation.getMessages() != null )
906 {
907 this.assertValidToolsTypes( context, module, implementation, implementation.getMessages(), report );
908 }
909 }
910
911 private void assertValidToolsTypes( final ModelContext context, final Module module,
912 final Implementation implementation, final Dependencies dependencies,
913 final ModelValidationReport report )
914 {
915 for ( final Dependency d : dependencies.getDependency() )
916 {
917 final List<SourceFileType> sourceFileType = d.getAnyObjects( SourceFileType.class );
918 final List<SourceFilesType> sourceFilesType = d.getAnyObjects( SourceFilesType.class );
919 final List<SourceSectionType> sourceSectionType = d.getAnyObjects( SourceSectionType.class );
920 final List<SourceSectionsType> sourceSectionsType = d.getAnyObjects( SourceSectionsType.class );
921
922 if ( sourceFileType != null )
923 {
924 for ( final SourceFileType s : sourceFileType )
925 {
926 report.getDetails().add( new ModelValidationReport.Detail(
927 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
928 "dependencySourceFileConstraint", module.getName(), implementation.getIdentifier(),
929 d.getName(), s.getIdentifier() ),
930 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
931
932 if ( this.isValidateJava() )
933 {
934 for ( final TemplateParameterType p : s.getTemplateParameter() )
935 {
936 try
937 {
938 p.getJavaValue( context.getClassLoader() );
939 }
940 catch ( final ModelObjectException e )
941 {
942 final String message = getMessage( e );
943
944 if ( context.isLoggable( Level.FINE ) )
945 {
946 context.log( Level.FINE, message, e );
947 }
948
949 report.getDetails().add( new ModelValidationReport.Detail(
950 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
951 Level.SEVERE, getMessage(
952 "dependencySourceFileTemplateParameterJavaValueConstraint",
953 module.getName(), implementation.getIdentifier(), d.getName(),
954 s.getIdentifier(), p.getName(),
955 message != null && message.length() > 0 ? " " + message : "" ),
956 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
957
958 }
959 }
960 }
961
962 this.validateTemplateParameters(
963 report, context, s.getSourceSections(),
964 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
965 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
966 "dependencySourceFileSectionTemplateParameterJavaValueConstraint",
967 module.getName(), implementation.getIdentifier(), d.getName(), s.getIdentifier() );
968
969 }
970 }
971
972 if ( sourceFilesType != null )
973 {
974 for ( final SourceFilesType files : sourceFilesType )
975 {
976 for ( final SourceFileType s : files.getSourceFile() )
977 {
978 report.getDetails().add( new ModelValidationReport.Detail(
979 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
980 "dependencySourceFileConstraint", module.getName(), implementation.getIdentifier(),
981 d.getName(), s.getIdentifier() ),
982 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
983
984 if ( this.isValidateJava() )
985 {
986 for ( final TemplateParameterType p : s.getTemplateParameter() )
987 {
988 try
989 {
990 p.getJavaValue( context.getClassLoader() );
991 }
992 catch ( final ModelObjectException e )
993 {
994 final String message = getMessage( e );
995
996 if ( context.isLoggable( Level.FINE ) )
997 {
998 context.log( Level.FINE, message, e );
999 }
1000
1001 report.getDetails().add( new ModelValidationReport.Detail(
1002 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1003 Level.SEVERE, getMessage(
1004 "dependencySourceFileTemplateParameterJavaValueConstraint",
1005 module.getName(), implementation.getIdentifier(), d.getName(),
1006 s.getIdentifier(), p.getName(),
1007 message != null && message.length() > 0 ? " " + message : "" ),
1008 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1009
1010 }
1011 }
1012 }
1013
1014 this.validateTemplateParameters(
1015 report, context, s.getSourceSections(),
1016 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1017 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1018 "dependencySourceFileSectionTemplateParameterJavaValueConstraint",
1019 module.getName(), implementation.getIdentifier(), d.getName(), s.getIdentifier() );
1020
1021 }
1022
1023 if ( files.getSourceFile().isEmpty() )
1024 {
1025 report.getDetails().add( new ModelValidationReport.Detail(
1026 "IMPLEMENTATION_DEPENDENCY_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
1027 "dependencySourceFilesConstraint", module.getName(), implementation.getIdentifier(),
1028 d.getName() ),
1029 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1030
1031 }
1032 }
1033 }
1034
1035 if ( sourceSectionType != null )
1036 {
1037 for ( final SourceSectionType s : sourceSectionType )
1038 {
1039 report.getDetails().add( new ModelValidationReport.Detail(
1040 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
1041 "dependencySourceSectionConstraint", module.getName(), implementation.getIdentifier(),
1042 d.getName(), s.getName() ),
1043 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1044
1045 if ( this.isValidateJava() )
1046 {
1047 for ( final TemplateParameterType p : s.getTemplateParameter() )
1048 {
1049 try
1050 {
1051 p.getJavaValue( context.getClassLoader() );
1052 }
1053 catch ( final ModelObjectException e )
1054 {
1055 final String message = getMessage( e );
1056
1057 if ( context.isLoggable( Level.FINE ) )
1058 {
1059 context.log( Level.FINE, message, e );
1060 }
1061
1062 report.getDetails().add( new ModelValidationReport.Detail(
1063 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1064 Level.SEVERE, getMessage(
1065 "dependencySourceSectionTemplateParameterJavaValueConstraint",
1066 module.getName(), implementation.getIdentifier(), d.getName(),
1067 s.getName(), p.getName(),
1068 message != null && message.length() > 0 ? " " + message : "" ),
1069 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1070
1071 }
1072 }
1073 }
1074
1075 this.validateTemplateParameters(
1076 report, context, s.getSourceSections(),
1077 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1078 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1079 "dependencySourceSectionTemplateParameterJavaValueConstraint",
1080 module.getName(), implementation.getIdentifier(), d.getName() );
1081
1082 }
1083 }
1084
1085 if ( sourceSectionsType != null )
1086 {
1087 for ( final SourceSectionsType sections : sourceSectionsType )
1088 {
1089 for ( final SourceSectionType s : sections.getSourceSection() )
1090 {
1091 report.getDetails().add( new ModelValidationReport.Detail(
1092 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
1093 "dependencySourceSectionConstraint", module.getName(), implementation.getIdentifier(),
1094 d.getName(), s.getName() ),
1095 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1096
1097 if ( this.isValidateJava() )
1098 {
1099 for ( final TemplateParameterType p : s.getTemplateParameter() )
1100 {
1101 try
1102 {
1103 p.getJavaValue( context.getClassLoader() );
1104 }
1105 catch ( final ModelObjectException e )
1106 {
1107 final String message = getMessage( e );
1108
1109 if ( context.isLoggable( Level.FINE ) )
1110 {
1111 context.log( Level.FINE, message, e );
1112 }
1113
1114 report.getDetails().add( new ModelValidationReport.Detail(
1115 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1116 Level.SEVERE, getMessage(
1117 "dependencySourceSectionTemplateParameterJavaValueConstraint",
1118 module.getName(), implementation.getIdentifier(), d.getName(),
1119 s.getName(), p.getName(),
1120 message != null && message.length() > 0 ? " " + message : "" ),
1121 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1122
1123 }
1124 }
1125 }
1126
1127 this.validateTemplateParameters(
1128 report, context, s.getSourceSections(),
1129 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1130 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1131 "dependencySourceSectionTemplateParameterJavaValueConstraint",
1132 module.getName(), implementation.getIdentifier(), d.getName() );
1133
1134 }
1135
1136 if ( sections.getSourceSection().isEmpty() )
1137 {
1138 report.getDetails().add( new ModelValidationReport.Detail(
1139 "IMPLEMENTATION_DEPENDENCY_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
1140 "dependencySourceSectionsConstraint", module.getName(), implementation.getIdentifier(),
1141 d.getName() ),
1142 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1143
1144 }
1145 }
1146 }
1147 }
1148 }
1149
1150 private void assertValidToolsTypes( final ModelContext context, final Module module,
1151 final Implementation implementation, final Messages messages,
1152 final ModelValidationReport report )
1153 {
1154 for ( final Message m : messages.getMessage() )
1155 {
1156 final List<SourceFileType> sourceFileType = m.getAnyObjects( SourceFileType.class );
1157 final List<SourceFilesType> sourceFilesType = m.getAnyObjects( SourceFilesType.class );
1158 final List<SourceSectionType> sourceSectionType = m.getAnyObjects( SourceSectionType.class );
1159 final List<SourceSectionsType> sourceSectionsType = m.getAnyObjects( SourceSectionsType.class );
1160
1161 if ( sourceFileType != null )
1162 {
1163 for ( final SourceFileType s : sourceFileType )
1164 {
1165 report.getDetails().add( new ModelValidationReport.Detail(
1166 "IMPLEMENTATION_MESSAGE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
1167 "messageSourceFileConstraint", module.getName(), implementation.getIdentifier(),
1168 m.getName(), s.getIdentifier() ),
1169 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1170
1171 if ( this.isValidateJava() )
1172 {
1173 for ( final TemplateParameterType p : s.getTemplateParameter() )
1174 {
1175 try
1176 {
1177 p.getJavaValue( context.getClassLoader() );
1178 }
1179 catch ( final ModelObjectException e )
1180 {
1181 final String message = getMessage( e );
1182
1183 if ( context.isLoggable( Level.FINE ) )
1184 {
1185 context.log( Level.FINE, message, e );
1186 }
1187
1188 report.getDetails().add( new ModelValidationReport.Detail(
1189 "IMPLEMENTATION_MESSAGE_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1190 Level.SEVERE, getMessage(
1191 "messageSourceFileTemplateParameterJavaValueConstraint",
1192 module.getName(), implementation.getIdentifier(), m.getName(),
1193 s.getIdentifier(), p.getName(),
1194 message != null && message.length() > 0 ? " " + message : "" ),
1195 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1196
1197 }
1198 }
1199 }
1200
1201 this.validateTemplateParameters(
1202 report, context, s.getSourceSections(),
1203 "IMPLEMENTATION_MESSAGE_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1204 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1205 "messageSourceFileSectionTemplateParameterJavaValueConstraint",
1206 module.getName(), implementation.getIdentifier(), m.getName(), s.getIdentifier() );
1207
1208 }
1209 }
1210
1211 if ( sourceFilesType != null )
1212 {
1213 for ( final SourceFilesType files : sourceFilesType )
1214 {
1215 for ( final SourceFileType s : files.getSourceFile() )
1216 {
1217 report.getDetails().add( new ModelValidationReport.Detail(
1218 "IMPLEMENTATION_MESSAGE_SOURCE_FILE_CONSTRAINT", Level.SEVERE, getMessage(
1219 "messageSourceFileConstraint", module.getName(), implementation.getIdentifier(),
1220 m.getName(), s.getIdentifier() ),
1221 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1222
1223 if ( this.isValidateJava() )
1224 {
1225 for ( final TemplateParameterType p : s.getTemplateParameter() )
1226 {
1227 try
1228 {
1229 p.getJavaValue( context.getClassLoader() );
1230 }
1231 catch ( final ModelObjectException e )
1232 {
1233 final String message = getMessage( e );
1234
1235 if ( context.isLoggable( Level.FINE ) )
1236 {
1237 context.log( Level.FINE, message, e );
1238 }
1239
1240 report.getDetails().add( new ModelValidationReport.Detail(
1241 "IMPLEMENTATION_MESSAGE_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1242 Level.SEVERE, getMessage(
1243 "messageSourceFileTemplateParameterJavaValueConstraint",
1244 module.getName(), implementation.getIdentifier(), m.getName(),
1245 s.getIdentifier(), p.getName(),
1246 message != null && message.length() > 0 ? " " + message : "" ),
1247 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1248
1249 }
1250 }
1251 }
1252
1253 this.validateTemplateParameters(
1254 report, context, s.getSourceSections(),
1255 "IMPLEMENTATION_MESSAGE_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1256 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1257 "messageSourceFileSectionTemplateParameterJavaValueConstraint",
1258 module.getName(), implementation.getIdentifier(), m.getName(), s.getIdentifier() );
1259
1260 }
1261
1262 if ( files.getSourceFile().isEmpty() )
1263 {
1264 report.getDetails().add( new ModelValidationReport.Detail(
1265 "IMPLEMENTATION_MESSAGE_SOURCE_FILES_CONSTRAINT", Level.SEVERE, getMessage(
1266 "messageSourceFilesConstraint", module.getName(), implementation.getIdentifier(),
1267 m.getName() ),
1268 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1269
1270 }
1271 }
1272 }
1273
1274 if ( sourceSectionType != null )
1275 {
1276 for ( final SourceSectionType s : sourceSectionType )
1277 {
1278 report.getDetails().add( new ModelValidationReport.Detail(
1279 "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
1280 "messageSourceSectionConstraint", module.getName(), implementation.getIdentifier(),
1281 m.getName(), s.getName() ),
1282 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1283
1284 if ( this.isValidateJava() )
1285 {
1286 for ( final TemplateParameterType p : s.getTemplateParameter() )
1287 {
1288 try
1289 {
1290 p.getJavaValue( context.getClassLoader() );
1291 }
1292 catch ( final ModelObjectException e )
1293 {
1294 final String message = getMessage( e );
1295
1296 if ( context.isLoggable( Level.FINE ) )
1297 {
1298 context.log( Level.FINE, message, e );
1299 }
1300
1301 report.getDetails().add( new ModelValidationReport.Detail(
1302 "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1303 Level.SEVERE, getMessage(
1304 "messageSourceSectionTemplateParameterJavaValueConstraint",
1305 module.getName(), implementation.getIdentifier(), m.getName(),
1306 s.getName(), p.getName(),
1307 message != null && message.length() > 0 ? " " + message : "" ),
1308 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1309
1310 }
1311 }
1312 }
1313
1314 this.validateTemplateParameters(
1315 report, context, s.getSourceSections(),
1316 "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1317 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1318 "messageSourceSectionTemplateParameterJavaValueConstraint",
1319 module.getName(), implementation.getIdentifier(), m.getName() );
1320
1321 }
1322 }
1323
1324 if ( sourceSectionsType != null )
1325 {
1326 for ( final SourceSectionsType sections : sourceSectionsType )
1327 {
1328 for ( final SourceSectionType s : sections.getSourceSection() )
1329 {
1330 report.getDetails().add( new ModelValidationReport.Detail(
1331 "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
1332 "messageSourceSectionConstraint", module.getName(), implementation.getIdentifier(),
1333 m.getName(), s.getName() ),
1334 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1335
1336 if ( this.isValidateJava() )
1337 {
1338 for ( final TemplateParameterType p : s.getTemplateParameter() )
1339 {
1340 try
1341 {
1342 p.getJavaValue( context.getClassLoader() );
1343 }
1344 catch ( final ModelObjectException e )
1345 {
1346 final String message = getMessage( e );
1347
1348 if ( context.isLoggable( Level.FINE ) )
1349 {
1350 context.log( Level.FINE, message, e );
1351 }
1352
1353 report.getDetails().add( new ModelValidationReport.Detail(
1354 "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1355 Level.SEVERE, getMessage(
1356 "messageSourceSectionTemplateParameterJavaValueConstraint",
1357 module.getName(), implementation.getIdentifier(), m.getName(),
1358 s.getName(), p.getName(),
1359 message != null && message.length() > 0 ? " " + message : "" ),
1360 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1361
1362 }
1363 }
1364 }
1365
1366 this.validateTemplateParameters(
1367 report, context, s.getSourceSections(),
1368 "IMPLEMENTATION_MESSAGE_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1369 new org.jomc.model.ObjectFactory().createImplementation( implementation ),
1370 "messageSourceSectionTemplateParameterJavaValueConstraint",
1371 module.getName(), implementation.getIdentifier(), m.getName() );
1372
1373 }
1374
1375 if ( sections.getSourceSection().isEmpty() )
1376 {
1377 report.getDetails().add( new ModelValidationReport.Detail(
1378 "IMPLEMENTATION_MESSAGE_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
1379 "messageSourceSectionsConstraint", module.getName(), implementation.getIdentifier(),
1380 m.getName() ),
1381 new org.jomc.model.ObjectFactory().createImplementation( implementation ) ) );
1382
1383 }
1384 }
1385 }
1386 }
1387 }
1388
1389 private void assertValidToolsTypes( final ModelContext context, final Module module,
1390 final Specification specification, final ModelValidationReport report )
1391 {
1392 final List<SourceFileType> sourceFileType = specification.getAnyObjects( SourceFileType.class );
1393 final List<SourceFilesType> sourceFilesType = specification.getAnyObjects( SourceFilesType.class );
1394 final List<SourceSectionType> sourceSectionType = specification.getAnyObjects( SourceSectionType.class );
1395 final List<SourceSectionsType> sourceSectionsType = specification.getAnyObjects( SourceSectionsType.class );
1396
1397 if ( sourceFileType != null )
1398 {
1399 for ( final SourceFileType s : sourceFileType )
1400 {
1401 if ( this.isValidateJava() )
1402 {
1403 for ( final TemplateParameterType p : s.getTemplateParameter() )
1404 {
1405 try
1406 {
1407 p.getJavaValue( context.getClassLoader() );
1408 }
1409 catch ( final ModelObjectException e )
1410 {
1411 final String message = getMessage( e );
1412
1413 if ( context.isLoggable( Level.FINE ) )
1414 {
1415 context.log( Level.FINE, message, e );
1416 }
1417
1418 report.getDetails().add( new ModelValidationReport.Detail(
1419 "SPECIFICATION_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1420 Level.SEVERE, getMessage(
1421 "specificationSourceFileTemplateParameterJavaValueConstraint",
1422 module.getName(), specification.getIdentifier(), s.getIdentifier(), p.getName(),
1423 message != null && message.length() > 0 ? " " + message : "" ),
1424 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1425
1426 }
1427 }
1428 }
1429
1430 this.validateTemplateParameters(
1431 report, context, s.getSourceSections(),
1432 "SPECIFICATION_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1433 new org.jomc.model.ObjectFactory().createSpecification( specification ),
1434 "specificationSourceFileSectionTemplateParameterJavaValueConstraint",
1435 module.getName(), specification.getIdentifier(), s.getIdentifier() );
1436
1437 }
1438
1439 if ( sourceFileType.size() > 1 )
1440 {
1441 report.getDetails().add( new ModelValidationReport.Detail(
1442 "SPECIFICATION_SOURCE_FILE_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
1443 "specificationSourceFileMultiplicityConstraint", module.getName(),
1444 specification.getIdentifier(), sourceFileType.size() ),
1445 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1446
1447 }
1448 else if ( sourceFileType.size() == 1 )
1449 {
1450 report.getDetails().add( new ModelValidationReport.Detail(
1451 "SPECIFICATION_SOURCE_FILE_INFORMATION", Level.INFO, getMessage(
1452 "specificationSourceFileInfo", module.getName(), specification.getIdentifier(),
1453 sourceFileType.get( 0 ).getIdentifier() ),
1454 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1455
1456 }
1457 }
1458
1459 if ( sourceFilesType != null )
1460 {
1461 for ( final SourceFilesType l : sourceFilesType )
1462 {
1463 for ( final SourceFileType s : l.getSourceFile() )
1464 {
1465 if ( this.isValidateJava() )
1466 {
1467 for ( final TemplateParameterType p : s.getTemplateParameter() )
1468 {
1469 try
1470 {
1471 p.getJavaValue( context.getClassLoader() );
1472 }
1473 catch ( final ModelObjectException e )
1474 {
1475 final String message = getMessage( e );
1476
1477 if ( context.isLoggable( Level.FINE ) )
1478 {
1479 context.log( Level.FINE, message, e );
1480 }
1481
1482 report.getDetails().add( new ModelValidationReport.Detail(
1483 "SPECIFICATION_SOURCE_FILE_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1484 Level.SEVERE, getMessage(
1485 "specificationSourceFileTemplateParameterJavaValueConstraint",
1486 module.getName(), specification.getIdentifier(), s.getIdentifier(), p.getName(),
1487 message != null && message.length() > 0 ? " " + message : "" ),
1488 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1489
1490 }
1491 }
1492 }
1493
1494 this.validateTemplateParameters(
1495 report, context, s.getSourceSections(),
1496 "SPECIFICATION_SOURCE_FILE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1497 new org.jomc.model.ObjectFactory().createSpecification( specification ),
1498 "specificationSourceFileSectionTemplateParameterJavaValueConstraint",
1499 module.getName(), specification.getIdentifier(), s.getIdentifier() );
1500
1501 }
1502 }
1503
1504 if ( sourceFilesType.size() > 1 )
1505 {
1506 report.getDetails().add( new ModelValidationReport.Detail(
1507 "SPECIFICATION_SOURCE_FILES_MULTIPLICITY_CONSTRAINT", Level.SEVERE, getMessage(
1508 "specificationSourceFilesMultiplicityConstraint", module.getName(),
1509 specification.getIdentifier(), sourceFilesType.size() ),
1510 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1511
1512 }
1513 }
1514
1515 if ( sourceSectionType != null )
1516 {
1517 for ( final SourceSectionType s : sourceSectionType )
1518 {
1519 report.getDetails().add( new ModelValidationReport.Detail(
1520 "SPECIFICATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
1521 "specificationSourceSectionConstraint", specification.getIdentifier(), s.getName() ),
1522 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1523
1524 if ( this.isValidateJava() )
1525 {
1526 for ( final TemplateParameterType p : s.getTemplateParameter() )
1527 {
1528 try
1529 {
1530 p.getJavaValue( context.getClassLoader() );
1531 }
1532 catch ( final ModelObjectException e )
1533 {
1534 final String message = getMessage( e );
1535
1536 if ( context.isLoggable( Level.FINE ) )
1537 {
1538 context.log( Level.FINE, message, e );
1539 }
1540
1541 report.getDetails().add( new ModelValidationReport.Detail(
1542 "SPECIFICATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1543 Level.SEVERE, getMessage(
1544 "specificationSourceSectionTemplateParameterJavaValueConstraint",
1545 module.getName(), specification.getIdentifier(), s.getName(), p.getName(),
1546 message != null && message.length() > 0 ? " " + message : "" ),
1547 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1548
1549 }
1550 }
1551 }
1552
1553 this.validateTemplateParameters(
1554 report, context, s.getSourceSections(),
1555 "SPECIFICATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1556 new org.jomc.model.ObjectFactory().createSpecification( specification ),
1557 "specificationSourceSectionTemplateParameterJavaValueConstraint",
1558 module.getName(), specification.getIdentifier() );
1559
1560 }
1561 }
1562
1563 if ( sourceSectionsType != null )
1564 {
1565 for ( final SourceSectionsType sections : sourceSectionsType )
1566 {
1567 for ( final SourceSectionType s : sections.getSourceSection() )
1568 {
1569 report.getDetails().add( new ModelValidationReport.Detail(
1570 "SPECIFICATION_SOURCE_SECTION_CONSTRAINT", Level.SEVERE, getMessage(
1571 "specificationSourceSectionConstraint", specification.getIdentifier(), s.getName() ),
1572 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1573
1574 if ( this.isValidateJava() )
1575 {
1576 for ( final TemplateParameterType p : s.getTemplateParameter() )
1577 {
1578 try
1579 {
1580 p.getJavaValue( context.getClassLoader() );
1581 }
1582 catch ( final ModelObjectException e )
1583 {
1584 final String message = getMessage( e );
1585
1586 if ( context.isLoggable( Level.FINE ) )
1587 {
1588 context.log( Level.FINE, message, e );
1589 }
1590
1591 report.getDetails().add( new ModelValidationReport.Detail(
1592 "SPECIFICATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1593 Level.SEVERE, getMessage(
1594 "specificationSourceSectionTemplateParameterJavaValueConstraint",
1595 module.getName(), specification.getIdentifier(), s.getName(), p.getName(),
1596 message != null && message.length() > 0 ? " " + message : "" ),
1597 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1598
1599 }
1600 }
1601 }
1602
1603 this.validateTemplateParameters(
1604 report, context, s.getSourceSections(),
1605 "SPECIFICATION_SOURCE_SECTION_TEMPLATE_PARAMETER_JAVA_VALUE_CONSTRAINT",
1606 new org.jomc.model.ObjectFactory().createSpecification( specification ),
1607 "specificationSourceSectionTemplateParameterJavaValueConstraint",
1608 module.getName(), specification.getIdentifier() );
1609
1610 }
1611
1612 if ( sections.getSourceSection().isEmpty() )
1613 {
1614 report.getDetails().add( new ModelValidationReport.Detail(
1615 "SPECIFICATION_SOURCE_SECTIONS_CONSTRAINT", Level.SEVERE, getMessage(
1616 "specificationSourceSectionsConstraint", specification.getIdentifier() ),
1617 new org.jomc.model.ObjectFactory().createSpecification( specification ) ) );
1618
1619 }
1620 }
1621 }
1622 }
1623
1624 private void validateTemplateParameters( final ModelValidationReport report, final ModelContext context,
1625 final SourceSectionsType sourceSectionsType,
1626 final String detailIdentifier,
1627 final JAXBElement<?> detailElement,
1628 final String messageKey, final Object... messageArguments )
1629 {
1630 if ( sourceSectionsType != null )
1631 {
1632 if ( this.isValidateJava() )
1633 {
1634 for ( final SourceSectionType s : sourceSectionsType.getSourceSection() )
1635 {
1636 for ( final TemplateParameterType p : s.getTemplateParameter() )
1637 {
1638 try
1639 {
1640 p.getJavaValue( context.getClassLoader() );
1641 }
1642 catch ( final ModelObjectException e )
1643 {
1644 final String message = getMessage( e );
1645
1646 if ( context.isLoggable( Level.FINE ) )
1647 {
1648 context.log( Level.FINE, message, e );
1649 }
1650
1651 final List<Object> arguments = new ArrayList<Object>( Arrays.asList( messageArguments ) );
1652 arguments.add( s.getName() );
1653 arguments.add( p.getName() );
1654 arguments.add( message != null && message.length() > 0 ? " " + message : "" );
1655
1656 report.getDetails().add( new ModelValidationReport.Detail(
1657 detailIdentifier, Level.SEVERE, getMessage(
1658 messageKey, arguments.toArray( new Object[ arguments.size() ] ) ),
1659 detailElement ) );
1660
1661 }
1662 }
1663
1664 this.validateTemplateParameters( report, context, s.getSourceSections(), detailIdentifier,
1665 detailElement, messageKey, messageArguments );
1666
1667 }
1668 }
1669 }
1670 }
1671
1672 private static String getMessage( final String key, final Object... args )
1673 {
1674 return MessageFormat.format( ResourceBundle.getBundle(
1675 ToolsModelValidator.class.getName().replace( '.', '/' ), Locale.getDefault() ).getString( key ), args );
1676
1677 }
1678
1679 private static String getMessage( final Throwable t )
1680 {
1681 return t != null
1682 ? t.getMessage() != null && t.getMessage().trim().length() > 0
1683 ? t.getMessage()
1684 : getMessage( t.getCause() )
1685 : null;
1686
1687 }
1688
1689 }