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