1 | /* |
2 | * Copyright (c) 2009 The JOMC Project |
3 | * Copyright (c) 2005 Christian Schulte <cs@jomc.org> |
4 | * All rights reserved. |
5 | * |
6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions |
8 | * are met: |
9 | * |
10 | * o Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. |
12 | * |
13 | * o Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in |
15 | * the documentation and/or other materials provided with the |
16 | * distribution. |
17 | * |
18 | * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS" |
19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
20 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
21 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR |
22 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
23 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * |
30 | * $Id: DefaultModelValidator.java 1336 2010-01-19 04:00:00Z schulte2005 $ |
31 | * |
32 | */ |
33 | package org.jomc.model; |
34 | |
35 | import java.text.MessageFormat; |
36 | import java.util.HashMap; |
37 | import java.util.LinkedList; |
38 | import java.util.List; |
39 | import java.util.Locale; |
40 | import java.util.Map; |
41 | import java.util.ResourceBundle; |
42 | import java.util.logging.Level; |
43 | import javax.xml.bind.JAXBElement; |
44 | import javax.xml.bind.JAXBException; |
45 | import javax.xml.bind.util.JAXBSource; |
46 | import org.jomc.util.ParseException; |
47 | import org.jomc.util.TokenMgrError; |
48 | import org.jomc.util.VersionParser; |
49 | |
50 | /** |
51 | * Default {@code ModelValidator} implementation. |
52 | * |
53 | * @author <a href="mailto:cs@jomc.org">Christian Schulte</a> |
54 | * @version $Id: DefaultModelValidator.java 1336 2010-01-19 04:00:00Z schulte2005 $ |
55 | * @see ModelContext#validateModel(org.jomc.model.Modules) |
56 | */ |
57 | public class DefaultModelValidator implements ModelValidator |
58 | { |
59 | |
60 | /** Creates a new {@code DefaultModelValidator} instance. */ |
61 | public DefaultModelValidator() |
62 | { |
63 | super(); |
64 | } |
65 | |
66 | public ModelValidationReport validateModel( |
67 | final ModelContext context, final Modules modules ) throws ModelException |
68 | { |
69 | if ( context == null ) |
70 | { |
71 | throw new NullPointerException( "context" ); |
72 | } |
73 | if ( modules == null ) |
74 | { |
75 | throw new NullPointerException( "modules" ); |
76 | } |
77 | |
78 | try |
79 | { |
80 | final ModelValidationReport report = context.validateModel( |
81 | new JAXBSource( context.createContext(), new ObjectFactory().createModules( modules ) ) ); |
82 | |
83 | this.assertClassDeclarationUniqueness( modules, report ); |
84 | |
85 | for ( Module m : modules.getModule() ) |
86 | { |
87 | this.assertNoSpecificationReferenceDeclarations( m, report ); |
88 | this.assertNoImplementationReferenceDeclarations( m, report ); |
89 | this.assertNoMessageReferenceDeclarations( m, report ); |
90 | this.assertNoFinalMessageDeclarations( m, report ); |
91 | this.assertNoOverrideMessageDeclarations( m, report ); |
92 | this.assertNoPropertyReferenceDeclarations( m, report ); |
93 | this.assertNoFinalPropertyDeclarations( m, report ); |
94 | this.assertNoOverridePropertyDeclarations( m, report ); |
95 | this.assertNoPropertyValueAndAnyObject( m, report ); |
96 | this.assertPropertyTypeWithAnyObject( m, report ); |
97 | this.assertValidPropertyJavaValues( context, m, report ); |
98 | |
99 | if ( m.getImplementations() != null ) |
100 | { |
101 | for ( Implementation i : m.getImplementations().getImplementation() ) |
102 | { |
103 | this.assertNoDependencyPropertyReferenceDeclarations( i, report ); |
104 | this.assertNoImplementationDeclarations( i, report ); |
105 | this.assertNoLocationWhenAbstract( i, report ); |
106 | this.assertNoSpecificationDeclarations( i, report ); |
107 | this.assertImplementationMessagesUniqueness( i, report ); |
108 | this.assertImplementationPropertiesUniqueness( i, report ); |
109 | this.assertImplementationDependencyCompatibility( modules, i, report ); |
110 | this.assertImplementationInheritanceCompatibility( modules, i, report ); |
111 | this.assertImplementationSpecificationCompatibility( modules, i, report ); |
112 | this.assertNoMissingMandatoryDependencies( modules, i, report ); |
113 | this.assertNoDependenciesWithoutSpecificationClass( modules, i, report ); |
114 | this.assertNoInheritanceCycle( modules, i, report ); |
115 | this.assertNoInheritanceClashes( modules, i, report ); |
116 | this.assertNoOverridenDependencyPropertiesWhenNotMultiton( modules, i, report ); |
117 | this.assertImplementationOverrideConstraints( modules, i, report ); |
118 | this.assertSpecificationOverrideConstraints( modules, i, report ); |
119 | this.assertDependencyOverrideConstraints( modules, i, report ); |
120 | this.assertMessageOverrideConstraints( modules, i, report ); |
121 | this.assertPropertyOverrideConstraints( modules, i, report ); |
122 | this.assertDependencyPropertiesOverrideConstraints( modules, i, report ); |
123 | this.assertValidMessageTemplates( modules, i, report ); |
124 | this.assertNoPropertyValueAndAnyObject( i, report ); |
125 | this.assertPropertyTypeWithAnyObject( i, report ); |
126 | this.assertValidPropertyJavaValues( context, i, report ); |
127 | } |
128 | } |
129 | |
130 | if ( m.getSpecifications() != null ) |
131 | { |
132 | for ( Specification s : m.getSpecifications().getSpecification() ) |
133 | { |
134 | this.assertNoSpecificationPropertyReferenceDeclarations( s, report ); |
135 | this.assertSpecificationImplementationNameUniqueness( modules, s, report ); |
136 | this.assertSpecificationMultiplicityConstraint( modules, s, report ); |
137 | this.assertNoPropertyValueAndAnyObject( s, report ); |
138 | this.assertPropertyTypeWithAnyObject( s, report ); |
139 | this.assertValidPropertyJavaValues( context, s, report ); |
140 | } |
141 | } |
142 | } |
143 | |
144 | return report; |
145 | } |
146 | catch ( final JAXBException e ) |
147 | { |
148 | throw new ModelException( e ); |
149 | } |
150 | } |
151 | |
152 | private void assertValidPropertyJavaValues( final ModelContext context, final Module module, |
153 | final ModelValidationReport report ) |
154 | { |
155 | if ( module.getProperties() != null ) |
156 | { |
157 | for ( Property p : module.getProperties().getProperty() ) |
158 | { |
159 | try |
160 | { |
161 | p.getJavaValue( context.getClassLoader() ); |
162 | } |
163 | catch ( final ModelException e ) |
164 | { |
165 | report.getDetails().add( this.createDetail( |
166 | "MODULE_PROPERTY_JAVA_VALUE_CONSTRAINT", Level.SEVERE, |
167 | "modulePropertyJavaValueConstraint", new Object[] |
168 | { |
169 | module.getName(), p.getName(), e.getMessage() |
170 | }, new ObjectFactory().createModule( module ) ) ); |
171 | |
172 | } |
173 | } |
174 | } |
175 | } |
176 | |
177 | private void assertValidPropertyJavaValues( final ModelContext context, final Specification specification, |
178 | final ModelValidationReport report ) |
179 | { |
180 | if ( specification.getProperties() != null ) |
181 | { |
182 | for ( Property p : specification.getProperties().getProperty() ) |
183 | { |
184 | try |
185 | { |
186 | p.getJavaValue( context.getClassLoader() ); |
187 | } |
188 | catch ( final ModelException e ) |
189 | { |
190 | report.getDetails().add( this.createDetail( |
191 | "SPECIFICATION_PROPERTY_JAVA_VALUE_CONSTRAINT", Level.SEVERE, |
192 | "specificationPropertyJavaValueConstraint", new Object[] |
193 | { |
194 | specification.getIdentifier(), p.getName(), e.getMessage() |
195 | }, new ObjectFactory().createSpecification( specification ) ) ); |
196 | |
197 | } |
198 | } |
199 | } |
200 | } |
201 | |
202 | private void assertValidPropertyJavaValues( final ModelContext context, final Implementation implementation, |
203 | final ModelValidationReport report ) |
204 | { |
205 | if ( implementation.getProperties() != null ) |
206 | { |
207 | for ( Property p : implementation.getProperties().getProperty() ) |
208 | { |
209 | try |
210 | { |
211 | p.getJavaValue( context.getClassLoader() ); |
212 | } |
213 | catch ( final ModelException e ) |
214 | { |
215 | report.getDetails().add( this.createDetail( |
216 | "IMPLEMENTATION_PROPERTY_JAVA_VALUE_CONSTRAINT", Level.SEVERE, |
217 | "implementationPropertyJavaValueConstraint", new Object[] |
218 | { |
219 | implementation.getIdentifier(), p.getName(), e.getMessage() |
220 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
221 | |
222 | } |
223 | } |
224 | } |
225 | } |
226 | |
227 | private void assertValidMessageTemplates( final Modules modules, final Implementation implementation, |
228 | final ModelValidationReport report ) |
229 | { |
230 | final Messages messages = modules.getMessages( implementation.getIdentifier() ); |
231 | if ( messages != null ) |
232 | { |
233 | for ( Message message : messages.getMessage() ) |
234 | { |
235 | if ( message.getTemplate() != null ) |
236 | { |
237 | for ( Text t : message.getTemplate().getText() ) |
238 | { |
239 | try |
240 | { |
241 | new MessageFormat( t.getValue(), new Locale( t.getLanguage() ) ); |
242 | } |
243 | catch ( final IllegalArgumentException e ) |
244 | { |
245 | report.getDetails().add( this.createDetail( |
246 | "IMPLEMENTATION_MESSAGE_TEMPLATE_CONSTRAINT", Level.SEVERE, |
247 | "implementationMessageTemplateConstraint", new Object[] |
248 | { |
249 | implementation.getIdentifier(), message.getName(), t.getValue(), e.getMessage() |
250 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
251 | |
252 | } |
253 | } |
254 | } |
255 | } |
256 | } |
257 | } |
258 | |
259 | private void assertClassDeclarationUniqueness( final Modules modules, final ModelValidationReport report ) |
260 | { |
261 | final Map<String, Specification> specificationClassDeclarations = new HashMap<String, Specification>(); |
262 | final Map<String, Implementation> implementationClassDeclarations = new HashMap<String, Implementation>(); |
263 | |
264 | for ( Module m : modules.getModule() ) |
265 | { |
266 | if ( m.getSpecifications() != null ) |
267 | { |
268 | for ( Specification s : m.getSpecifications().getSpecification() ) |
269 | { |
270 | if ( s.isClassDeclaration() ) |
271 | { |
272 | if ( s.getClazz() == null ) |
273 | { |
274 | report.getDetails().add( this.createDetail( |
275 | "SPECIFICATION_CLASS_CONSTRAINT", Level.SEVERE, "specificationClassConstraint", |
276 | new Object[] |
277 | { |
278 | s.getIdentifier() |
279 | }, new ObjectFactory().createSpecification( s ) ) ); |
280 | |
281 | } |
282 | else |
283 | { |
284 | final Specification prev = specificationClassDeclarations.get( s.getClazz() ); |
285 | if ( prev != null ) |
286 | { |
287 | report.getDetails().add( this.createDetail( |
288 | "SPECIFICATION_CLASS_DECLARATION_CONSTRAINT", Level.SEVERE, |
289 | "specificationClassDeclarationConstraint", new Object[] |
290 | { |
291 | s.getIdentifier(), s.getClazz(), prev.getIdentifier() |
292 | }, new ObjectFactory().createSpecification( s ) ) ); |
293 | |
294 | } |
295 | else |
296 | { |
297 | specificationClassDeclarations.put( s.getClazz(), s ); |
298 | } |
299 | } |
300 | } |
301 | } |
302 | } |
303 | |
304 | if ( m.getImplementations() != null ) |
305 | { |
306 | for ( Implementation i : m.getImplementations().getImplementation() ) |
307 | { |
308 | if ( i.isClassDeclaration() ) |
309 | { |
310 | if ( i.getClazz() == null ) |
311 | { |
312 | report.getDetails().add( this.createDetail( |
313 | "IMPLEMENTATION_CLASS_CONSTRAINT", Level.SEVERE, |
314 | "implementationClassConstraint", new Object[] |
315 | { |
316 | i.getIdentifier() |
317 | }, new ObjectFactory().createImplementation( i ) ) ); |
318 | |
319 | } |
320 | else |
321 | { |
322 | final Implementation prev = implementationClassDeclarations.get( i.getClazz() ); |
323 | if ( prev != null ) |
324 | { |
325 | report.getDetails().add( this.createDetail( |
326 | "IMPLEMENTATION_CLASS_DECLARATION_CONSTRAINT", |
327 | Level.SEVERE, "implementationClassDeclarationConstraint", new Object[] |
328 | { |
329 | i.getIdentifier(), i.getClazz(), prev.getIdentifier() |
330 | }, new ObjectFactory().createImplementation( i ) ) ); |
331 | |
332 | } |
333 | else |
334 | { |
335 | implementationClassDeclarations.put( i.getClazz(), i ); |
336 | } |
337 | } |
338 | } |
339 | } |
340 | } |
341 | } |
342 | } |
343 | |
344 | private void assertNoPropertyValueAndAnyObject( final Module module, final ModelValidationReport report ) |
345 | { |
346 | if ( module.getProperties() != null ) |
347 | { |
348 | for ( Property p : module.getProperties().getProperty() ) |
349 | { |
350 | if ( p.getValue() != null && p.getAny() != null ) |
351 | { |
352 | report.getDetails().add( this.createDetail( |
353 | "MODULE_PROPERTY_VALUE_CONSTRAINT", Level.SEVERE, "modulePropertyValueConstraint", new Object[] |
354 | { |
355 | module.getName(), p.getName() |
356 | }, new ObjectFactory().createModule( module ) ) ); |
357 | |
358 | } |
359 | } |
360 | } |
361 | } |
362 | |
363 | private void assertNoPropertyValueAndAnyObject( final Implementation implementation, |
364 | final ModelValidationReport report ) |
365 | { |
366 | if ( implementation.getProperties() != null ) |
367 | { |
368 | for ( Property p : implementation.getProperties().getProperty() ) |
369 | { |
370 | if ( p.getValue() != null && p.getAny() != null ) |
371 | { |
372 | report.getDetails().add( this.createDetail( |
373 | "IMPLEMENTATION_PROPERTY_VALUE_CONSTRAINT", Level.SEVERE, |
374 | "implementationPropertyValueConstraint", new Object[] |
375 | { |
376 | implementation.getIdentifier(), p.getName() |
377 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
378 | |
379 | } |
380 | } |
381 | } |
382 | } |
383 | |
384 | private void assertNoPropertyValueAndAnyObject( final Specification specification, |
385 | final ModelValidationReport report ) |
386 | { |
387 | if ( specification.getProperties() != null ) |
388 | { |
389 | for ( Property p : specification.getProperties().getProperty() ) |
390 | { |
391 | if ( p.getValue() != null && p.getAny() != null ) |
392 | { |
393 | report.getDetails().add( this.createDetail( |
394 | "SPECIFICATION_PROPERTY_VALUE_CONSTRAINT", Level.SEVERE, |
395 | "specificationPropertyValueConstraint", new Object[] |
396 | { |
397 | specification.getIdentifier(), p.getName() |
398 | }, new ObjectFactory().createSpecification( specification ) ) ); |
399 | |
400 | } |
401 | } |
402 | } |
403 | } |
404 | |
405 | private void assertPropertyTypeWithAnyObject( final Module module, final ModelValidationReport report ) |
406 | { |
407 | if ( module.getProperties() != null ) |
408 | { |
409 | for ( Property p : module.getProperties().getProperty() ) |
410 | { |
411 | if ( p.getAny() != null && p.getType() == null ) |
412 | { |
413 | report.getDetails().add( this.createDetail( |
414 | "MODULE_PROPERTY_TYPE_CONSTRAINT", Level.SEVERE, |
415 | "modulePropertyTypeConstraint", new Object[] |
416 | { |
417 | module.getName(), p.getName() |
418 | }, new ObjectFactory().createModule( module ) ) ); |
419 | |
420 | } |
421 | } |
422 | } |
423 | } |
424 | |
425 | private void assertPropertyTypeWithAnyObject( final Implementation implementation, |
426 | final ModelValidationReport report ) |
427 | { |
428 | if ( implementation.getProperties() != null ) |
429 | { |
430 | for ( Property p : implementation.getProperties().getProperty() ) |
431 | { |
432 | if ( p.getAny() != null && p.getType() == null ) |
433 | { |
434 | report.getDetails().add( this.createDetail( |
435 | "IMPLEMENTATION_PROPERTY_TYPE_CONSTRAINT", Level.SEVERE, |
436 | "implementationPropertyTypeConstraint", new Object[] |
437 | { |
438 | implementation.getIdentifier(), p.getName() |
439 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
440 | |
441 | } |
442 | } |
443 | } |
444 | } |
445 | |
446 | private void assertPropertyTypeWithAnyObject( final Specification specification, |
447 | final ModelValidationReport report ) |
448 | { |
449 | if ( specification.getProperties() != null ) |
450 | { |
451 | for ( Property p : specification.getProperties().getProperty() ) |
452 | { |
453 | if ( p.getAny() != null && p.getType() == null ) |
454 | { |
455 | report.getDetails().add( this.createDetail( |
456 | "SPECIFICATION_PROPERTY_TYPE_CONSTRAINT", Level.SEVERE, |
457 | "specificationPropertyTypeConstraint", new Object[] |
458 | { |
459 | specification.getIdentifier(), p.getName() |
460 | }, new ObjectFactory().createSpecification( specification ) ) ); |
461 | |
462 | } |
463 | } |
464 | } |
465 | } |
466 | |
467 | private void assertNoSpecificationReferenceDeclarations( final Module module, |
468 | final ModelValidationReport report ) |
469 | { |
470 | if ( module.getSpecifications() != null ) |
471 | { |
472 | for ( SpecificationReference r : module.getSpecifications().getReference() ) |
473 | { |
474 | report.getDetails().add( this.createDetail( |
475 | "MODULE_SPECIFICATION_REFERENCE_DECLARATION_CONSTRAINT", Level.SEVERE, |
476 | "moduleSpecificationReferenceDeclarationConstraint", new Object[] |
477 | { |
478 | module.getName(), r.getIdentifier() |
479 | }, new ObjectFactory().createModule( module ) ) ); |
480 | |
481 | } |
482 | } |
483 | } |
484 | |
485 | private void assertNoImplementationReferenceDeclarations( final Module module, |
486 | final ModelValidationReport report ) |
487 | { |
488 | if ( module.getImplementations() != null ) |
489 | { |
490 | for ( ImplementationReference r : module.getImplementations().getReference() ) |
491 | { |
492 | report.getDetails().add( this.createDetail( |
493 | "MODULE_IMPLEMENTATION_REFERENCE_DECLARATION_CONSTRAINT", Level.SEVERE, |
494 | "moduleImplementationReferenceDeclarationConstraint", new Object[] |
495 | { |
496 | module.getName(), r.getIdentifier() |
497 | }, new ObjectFactory().createModule( module ) ) ); |
498 | |
499 | } |
500 | } |
501 | } |
502 | |
503 | private void assertNoMessageReferenceDeclarations( final Module module, |
504 | final ModelValidationReport report ) |
505 | { |
506 | if ( module.getMessages() != null ) |
507 | { |
508 | for ( MessageReference r : module.getMessages().getReference() ) |
509 | { |
510 | report.getDetails().add( this.createDetail( |
511 | "MODULE_MESSAGE_REFERENCE_DECLARATION_CONSTRAINT", Level.SEVERE, |
512 | "moduleMessageReferenceDeclarationConstraint", new Object[] |
513 | { |
514 | module.getName(), r.getName() |
515 | }, new ObjectFactory().createModule( module ) ) ); |
516 | |
517 | } |
518 | } |
519 | } |
520 | |
521 | private void assertNoFinalMessageDeclarations( final Module module, |
522 | final ModelValidationReport report ) |
523 | { |
524 | if ( module.getMessages() != null ) |
525 | { |
526 | for ( Message m : module.getMessages().getMessage() ) |
527 | { |
528 | if ( m.isFinal() ) |
529 | { |
530 | report.getDetails().add( this.createDetail( |
531 | "MODULE_FINAL_MESSAGE_DECLARATION_CONSTRAINT", Level.SEVERE, |
532 | "moduleFinalMessageConstraint", new Object[] |
533 | { |
534 | module.getName(), m.getName() |
535 | }, new ObjectFactory().createModule( module ) ) ); |
536 | |
537 | } |
538 | } |
539 | } |
540 | } |
541 | |
542 | private void assertNoOverrideMessageDeclarations( final Module module, |
543 | final ModelValidationReport report ) |
544 | { |
545 | if ( module.getMessages() != null ) |
546 | { |
547 | for ( Message m : module.getMessages().getMessage() ) |
548 | { |
549 | if ( m.isOverride() ) |
550 | { |
551 | report.getDetails().add( this.createDetail( |
552 | "MODULE_OVERRIDE_MESSAGE_DECLARATION_CONSTRAINT", Level.SEVERE, |
553 | "moduleOverrideMessageConstraint", new Object[] |
554 | { |
555 | module.getName(), m.getName() |
556 | }, new ObjectFactory().createModule( module ) ) ); |
557 | |
558 | } |
559 | } |
560 | } |
561 | } |
562 | |
563 | private void assertNoPropertyReferenceDeclarations( final Module module, |
564 | final ModelValidationReport report ) |
565 | { |
566 | if ( module.getProperties() != null ) |
567 | { |
568 | for ( PropertyReference r : module.getProperties().getReference() ) |
569 | { |
570 | report.getDetails().add( this.createDetail( |
571 | "MODULE_PROPERTY_REFERENCE_DECLARATION_CONSTRAINT", Level.SEVERE, |
572 | "modulePropertyReferenceDeclarationConstraint", new Object[] |
573 | { |
574 | module.getName(), r.getName() |
575 | }, new ObjectFactory().createModule( module ) ) ); |
576 | |
577 | } |
578 | } |
579 | } |
580 | |
581 | private void assertNoFinalPropertyDeclarations( final Module module, |
582 | final ModelValidationReport report ) |
583 | { |
584 | if ( module.getProperties() != null ) |
585 | { |
586 | for ( Property p : module.getProperties().getProperty() ) |
587 | { |
588 | if ( p.isFinal() ) |
589 | { |
590 | report.getDetails().add( this.createDetail( |
591 | "MODULE_FINAL_PROPERTY_DECLARATION_CONSTRAINT", Level.SEVERE, |
592 | "moduleFinalPropertyConstraint", new Object[] |
593 | { |
594 | module.getName(), p.getName() |
595 | }, new ObjectFactory().createModule( module ) ) ); |
596 | |
597 | } |
598 | } |
599 | } |
600 | } |
601 | |
602 | private void assertNoOverridePropertyDeclarations( final Module module, |
603 | final ModelValidationReport report ) |
604 | { |
605 | if ( module.getProperties() != null ) |
606 | { |
607 | for ( Property p : module.getProperties().getProperty() ) |
608 | { |
609 | if ( p.isOverride() ) |
610 | { |
611 | report.getDetails().add( this.createDetail( |
612 | "MODULE_OVERRIDE_PROPERTY_DECLARATION_CONSTRAINT", Level.SEVERE, |
613 | "moduleOverridePropertyConstraint", new Object[] |
614 | { |
615 | module.getName(), p.getName() |
616 | }, new ObjectFactory().createModule( module ) ) ); |
617 | |
618 | } |
619 | } |
620 | } |
621 | } |
622 | |
623 | private void assertNoSpecificationDeclarations( final Implementation implementation, |
624 | final ModelValidationReport report ) |
625 | { |
626 | if ( implementation.getSpecifications() != null ) |
627 | { |
628 | for ( Specification s : implementation.getSpecifications().getSpecification() ) |
629 | { |
630 | report.getDetails().add( this.createDetail( |
631 | "IMPLEMENTATION_SPECIFICATION_DECLARATION_CONSTRAINT", Level.SEVERE, |
632 | "implementationSpecificationDeclarationConstraint", new Object[] |
633 | { |
634 | implementation.getIdentifier(), s.getIdentifier() |
635 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
636 | |
637 | } |
638 | } |
639 | } |
640 | |
641 | private void assertNoImplementationDeclarations( final Implementation implementation, |
642 | final ModelValidationReport report ) |
643 | { |
644 | if ( implementation.getImplementations() != null ) |
645 | { |
646 | for ( Implementation i : implementation.getImplementations().getImplementation() ) |
647 | { |
648 | report.getDetails().add( this.createDetail( |
649 | "IMPLEMENTATION_IMPLEMENTATION_DECLARATION_CONSTRAINT", Level.SEVERE, |
650 | "implementationImplementationDeclarationConstraint", new Object[] |
651 | { |
652 | implementation.getIdentifier(), i.getIdentifier() |
653 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
654 | |
655 | } |
656 | } |
657 | } |
658 | |
659 | private void assertNoLocationWhenAbstract( final Implementation implementation, |
660 | final ModelValidationReport report ) |
661 | { |
662 | if ( implementation.isAbstract() && implementation.getLocation() != null ) |
663 | { |
664 | report.getDetails().add( this.createDetail( |
665 | "IMPLEMENTATION_ABSTRACT_LOCATION_DECLARATION_CONSTRAINT", Level.SEVERE, |
666 | "implementationAbstractLocationDeclarationConstraint", new Object[] |
667 | { |
668 | implementation.getIdentifier(), implementation.getLocation() |
669 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
670 | |
671 | } |
672 | } |
673 | |
674 | private void assertNoInheritanceCycle( final Modules modules, |
675 | final Implementation implementation, |
676 | final ModelValidationReport report ) |
677 | { |
678 | final Implementation cycle = |
679 | this.findInheritanceCycle( modules, implementation, implementation, new Implementations() ); |
680 | |
681 | if ( cycle != null ) |
682 | { |
683 | report.getDetails().add( this.createDetail( |
684 | "IMPLEMENTATION_INHERITANCE_CYCLE_CONSTRAINT", Level.SEVERE, |
685 | "implementationInheritanceCycleConstraint", new Object[] |
686 | { |
687 | implementation.getIdentifier(), cycle.getIdentifier() |
688 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
689 | |
690 | } |
691 | } |
692 | |
693 | private void assertImplementationSpecificationCompatibility( final Modules modules, |
694 | final Implementation implementation, |
695 | final ModelValidationReport report ) |
696 | { |
697 | final Specifications specs = modules.getSpecifications( implementation.getIdentifier() ); |
698 | |
699 | if ( specs != null ) |
700 | { |
701 | for ( SpecificationReference r : specs.getReference() ) |
702 | { |
703 | final Specification s = specs.getSpecification( r.getIdentifier() ); |
704 | |
705 | if ( s != null && r.getVersion() != null ) |
706 | { |
707 | if ( s.getVersion() == null ) |
708 | { |
709 | report.getDetails().add( this.createDetail( |
710 | "IMPLEMENTATION_SPECIFICATION_VERSIONING_CONSTRAINT", Level.SEVERE, |
711 | "implementationSpecificationVersioningConstraint", new Object[] |
712 | { |
713 | implementation.getIdentifier(), s.getIdentifier() |
714 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
715 | |
716 | } |
717 | else |
718 | { |
719 | try |
720 | { |
721 | if ( VersionParser.compare( r.getVersion(), s.getVersion() ) != 0 ) |
722 | { |
723 | final Module moduleOfImplementation = |
724 | modules.getModuleOfImplementation( implementation.getIdentifier() ); |
725 | |
726 | final Module moduleOfSpecification = |
727 | modules.getModuleOfSpecification( s.getIdentifier() ); |
728 | |
729 | report.getDetails().add( this.createDetail( |
730 | "IMPLEMENTATION_SPECIFICATION_COMPATIBILITY_CONSTRAINT", Level.SEVERE, |
731 | "implementationSpecificationCompatibilityConstraint", new Object[] |
732 | { |
733 | implementation.getIdentifier(), |
734 | moduleOfImplementation != null ? moduleOfImplementation.getName() : "<>", |
735 | s.getIdentifier(), |
736 | moduleOfSpecification != null ? moduleOfSpecification.getName() : "<>", |
737 | r.getVersion(), s.getVersion() |
738 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
739 | |
740 | } |
741 | } |
742 | catch ( final ParseException e ) |
743 | { |
744 | final ModelValidationReport.Detail d = new ModelValidationReport.Detail( |
745 | "IMPLEMENTATION_SPECIFICATION_COMPATIBILITY_VERSIONING_PARSE_EXCEPTION", |
746 | Level.SEVERE, e.getMessage(), |
747 | new ObjectFactory().createImplementation( implementation ) ); |
748 | |
749 | report.getDetails().add( d ); |
750 | } |
751 | catch ( final TokenMgrError e ) |
752 | { |
753 | final ModelValidationReport.Detail d = new ModelValidationReport.Detail( |
754 | "IMPLEMENTATION_SPECIFICATION_COMPATIBILITY_VERSIONING_TOKEN_MANAGER_ERROR", |
755 | Level.SEVERE, e.getMessage(), |
756 | new ObjectFactory().createImplementation( implementation ) ); |
757 | |
758 | report.getDetails().add( d ); |
759 | } |
760 | } |
761 | } |
762 | } |
763 | } |
764 | } |
765 | |
766 | private void assertImplementationDependencyCompatibility( final Modules modules, |
767 | final Implementation implementation, |
768 | final ModelValidationReport report ) |
769 | { |
770 | final Dependencies dependencies = modules.getDependencies( implementation.getIdentifier() ); |
771 | if ( dependencies != null ) |
772 | { |
773 | for ( Dependency d : dependencies.getDependency() ) |
774 | { |
775 | final Specification s = modules.getSpecification( d.getIdentifier() ); |
776 | if ( s != null && d.getVersion() != null ) |
777 | { |
778 | if ( s.getVersion() == null ) |
779 | { |
780 | report.getDetails().add( this.createDetail( |
781 | "IMPLEMENTATION_DEPENDENCY_SPECIFICATION_VERSIONING_CONSTRAINT", Level.SEVERE, |
782 | "implementationDependencySpecificationVersioningConstraint", new Object[] |
783 | { |
784 | implementation.getIdentifier(), d.getName(), s.getIdentifier() |
785 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
786 | |
787 | } |
788 | else |
789 | { |
790 | try |
791 | { |
792 | if ( VersionParser.compare( d.getVersion(), s.getVersion() ) > 0 ) |
793 | { |
794 | final Module moduleOfImplementation = |
795 | modules.getModuleOfImplementation( implementation.getIdentifier() ); |
796 | |
797 | final Module moduleOfSpecification = |
798 | modules.getModuleOfSpecification( s.getIdentifier() ); |
799 | |
800 | report.getDetails().add( this.createDetail( |
801 | "IMPLEMENTATION_DEPENDENCY_SPECIFICATION_COMPATIBILITY_CONSTRAINT", Level.SEVERE, |
802 | "implementationDependencySpecificationCompatibilityConstraint", new Object[] |
803 | { |
804 | implementation.getIdentifier(), |
805 | moduleOfImplementation != null ? moduleOfImplementation.getName() : "<>", |
806 | s.getIdentifier(), |
807 | moduleOfSpecification != null ? moduleOfSpecification.getName() : "<>", |
808 | d.getVersion(), s.getVersion() |
809 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
810 | |
811 | } |
812 | } |
813 | catch ( final ParseException e ) |
814 | { |
815 | final ModelValidationReport.Detail detail = new ModelValidationReport.Detail( |
816 | "IMPLEMENTATION_DEPENDENCY_SPECIFICATION_COMPATIBILITY_VERSIONING_PARSE_EXCEPTION", |
817 | Level.SEVERE, e.getMessage(), |
818 | new ObjectFactory().createImplementation( implementation ) ); |
819 | |
820 | report.getDetails().add( detail ); |
821 | } |
822 | catch ( final TokenMgrError e ) |
823 | { |
824 | final ModelValidationReport.Detail detail = new ModelValidationReport.Detail( |
825 | "IMPLEMENTATION_DEPENDENCY_SPECIFICATION_COMPATIBILITY_VERSIONING_TOKEN_MANAGER_ERROR", |
826 | Level.SEVERE, e.getMessage(), |
827 | new ObjectFactory().createImplementation( implementation ) ); |
828 | |
829 | report.getDetails().add( detail ); |
830 | } |
831 | } |
832 | } |
833 | } |
834 | } |
835 | } |
836 | |
837 | private void assertNoDependencyPropertyReferenceDeclarations( final Implementation implementation, |
838 | final ModelValidationReport report ) |
839 | { |
840 | if ( implementation.getDependencies() != null ) |
841 | { |
842 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
843 | { |
844 | if ( d.getProperties() != null ) |
845 | { |
846 | for ( PropertyReference r : d.getProperties().getReference() ) |
847 | { |
848 | report.getDetails().add( this.createDetail( |
849 | "IMPLEMENTATION_DEPENDENCY_PROPERTY_REFERENCE_DECLARATION_CONSTRAINT", Level.SEVERE, |
850 | "implementationDependencyPropertyReferenceDeclarationConstraint", new Object[] |
851 | { |
852 | implementation.getIdentifier(), d.getName(), r.getName() |
853 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
854 | |
855 | } |
856 | } |
857 | } |
858 | } |
859 | } |
860 | |
861 | private void assertNoOverridenDependencyPropertiesWhenNotMultiton( final Modules modules, |
862 | final Implementation implementation, |
863 | final ModelValidationReport report ) |
864 | { |
865 | if ( implementation.getDependencies() != null ) |
866 | { |
867 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
868 | { |
869 | final Specification s = modules.getSpecification( d.getIdentifier() ); |
870 | |
871 | if ( s != null && s.getScope() != null && d.getProperties() != null ) |
872 | { |
873 | for ( Property p : d.getProperties().getProperty() ) |
874 | { |
875 | report.getDetails().add( this.createDetail( |
876 | "IMPLEMENTATION_DEPENDENCY_PROPERTIES_OVERRIDE_CONSTRAINT", Level.SEVERE, |
877 | "implementationDependencyPropertiesOverrideConstraint", new Object[] |
878 | { |
879 | implementation.getIdentifier(), d.getName(), s.getIdentifier(), s.getScope(), |
880 | p.getName() |
881 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
882 | |
883 | } |
884 | } |
885 | } |
886 | } |
887 | } |
888 | |
889 | private void assertDependencyPropertiesOverrideConstraints( final Modules modules, |
890 | final Implementation implementation, |
891 | final ModelValidationReport report ) |
892 | { |
893 | if ( implementation.getDependencies() != null ) |
894 | { |
895 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
896 | { |
897 | final Implementations available = modules.getImplementations( d.getIdentifier() ); |
898 | if ( available != null ) |
899 | { |
900 | if ( d.getImplementationName() != null ) |
901 | { |
902 | final Implementation i = available.getImplementationByName( d.getImplementationName() ); |
903 | if ( i != null ) |
904 | { |
905 | this.assertDependencyDoesNotOverrideFinalPropertyAndDoesNotFlagNonOverridenPropertyOverride( |
906 | modules, implementation, d, i, report ); |
907 | |
908 | } |
909 | } |
910 | else |
911 | { |
912 | for ( Implementation i : available.getImplementation() ) |
913 | { |
914 | this.assertDependencyDoesNotOverrideFinalPropertyAndDoesNotFlagNonOverridenPropertyOverride( |
915 | modules, implementation, d, i, report ); |
916 | |
917 | } |
918 | } |
919 | } |
920 | } |
921 | } |
922 | } |
923 | |
924 | private void assertDependencyDoesNotOverrideFinalPropertyAndDoesNotFlagNonOverridenPropertyOverride( |
925 | final Modules modules, final Implementation implementation, final Dependency dependency, |
926 | final Implementation dependencyImplementation, final ModelValidationReport report ) |
927 | { |
928 | if ( dependency.getProperties() != null ) |
929 | { |
930 | final Properties properties = modules.getProperties( dependencyImplementation.getIdentifier() ); |
931 | |
932 | if ( properties != null ) |
933 | { |
934 | for ( Property override : dependency.getProperties().getProperty() ) |
935 | { |
936 | final Property overriden = properties.getProperty( override.getName() ); |
937 | if ( overriden != null && overriden.isFinal() ) |
938 | { |
939 | report.getDetails().add( this.createDetail( |
940 | "IMPLEMENTATION_DEPENDENCY_FINAL_PROPERTY_CONSTRAINT", Level.SEVERE, |
941 | "implementationDependencyFinalPropertyConstraint", new Object[] |
942 | { |
943 | implementation.getIdentifier(), dependency.getName(), |
944 | dependencyImplementation.getIdentifier(), override.getName() |
945 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
946 | |
947 | } |
948 | if ( overriden == null && override.isOverride() ) |
949 | { |
950 | report.getDetails().add( this.createDetail( |
951 | "IMPLEMENTATION_DEPENDENCY_OVERRIDE_PROPERTY_CONSTRAINT", Level.SEVERE, |
952 | "implementationDependencyOverridePropertyConstraint", new Object[] |
953 | { |
954 | implementation.getIdentifier(), dependency.getName(), |
955 | dependencyImplementation.getIdentifier(), override.getName() |
956 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
957 | |
958 | } |
959 | } |
960 | } |
961 | } |
962 | } |
963 | |
964 | private void assertNoMissingMandatoryDependencies( final Modules modules, final Implementation implementation, |
965 | final ModelValidationReport report ) |
966 | { |
967 | if ( implementation.getDependencies() != null ) |
968 | { |
969 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
970 | { |
971 | final Implementations available = modules.getImplementations( d.getIdentifier() ); |
972 | |
973 | if ( !d.isOptional() ) |
974 | { |
975 | boolean missing = false; |
976 | |
977 | if ( available == null ) |
978 | { |
979 | missing = true; |
980 | } |
981 | else if ( available.getImplementation().isEmpty() ) |
982 | { |
983 | missing = true; |
984 | } |
985 | else if ( d.getImplementationName() != null && |
986 | available.getImplementationByName( d.getImplementationName() ) == null ) |
987 | { |
988 | missing = true; |
989 | } |
990 | |
991 | if ( missing ) |
992 | { |
993 | report.getDetails().add( this.createDetail( |
994 | "IMPLEMENTATION_MANDATORY_DEPENDENCY_CONSTRAINT", Level.SEVERE, |
995 | "implementationMandatoryDependencyConstraint", new Object[] |
996 | { |
997 | implementation.getIdentifier(), d.getName() |
998 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
999 | |
1000 | } |
1001 | } |
1002 | } |
1003 | } |
1004 | } |
1005 | |
1006 | private void assertNoDependenciesWithoutSpecificationClass( final Modules modules, |
1007 | final Implementation implementation, |
1008 | final ModelValidationReport report ) |
1009 | { |
1010 | if ( implementation.getDependencies() != null ) |
1011 | { |
1012 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
1013 | { |
1014 | final Specification s = modules.getSpecification( d.getIdentifier() ); |
1015 | |
1016 | if ( s != null && s.getClazz() == null ) |
1017 | { |
1018 | report.getDetails().add( this.createDetail( |
1019 | "IMPLEMENTATION_DEPENDENCY_SPECIFICATION_CLASS_CONSTRAINT", Level.SEVERE, |
1020 | "implementationDependencySpecificationClassConstraint", new Object[] |
1021 | { |
1022 | implementation.getIdentifier(), d.getName(), d.getIdentifier() |
1023 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1024 | |
1025 | } |
1026 | } |
1027 | } |
1028 | } |
1029 | |
1030 | private void assertImplementationInheritanceCompatibility( final Modules modules, |
1031 | final Implementation implementation, |
1032 | final ModelValidationReport report ) |
1033 | { |
1034 | if ( implementation.getImplementations() != null ) |
1035 | { |
1036 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1037 | { |
1038 | final Implementation referenced = modules.getImplementation( r.getIdentifier() ); |
1039 | if ( referenced != null && r.getVersion() != null ) |
1040 | { |
1041 | if ( referenced.getVersion() == null ) |
1042 | { |
1043 | report.getDetails().add( this.createDetail( |
1044 | "IMPLEMENTATION_IMPLEMENTATION_VERSIONING_CONSTRAINT", Level.SEVERE, |
1045 | "implementationImplementationVersioningConstraint", new Object[] |
1046 | { |
1047 | implementation.getIdentifier(), referenced.getIdentifier() |
1048 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1049 | |
1050 | } |
1051 | else |
1052 | { |
1053 | try |
1054 | { |
1055 | if ( VersionParser.compare( r.getVersion(), referenced.getVersion() ) > 0 ) |
1056 | { |
1057 | report.getDetails().add( this.createDetail( |
1058 | "IMPLEMENTATION_INHERITANCE_COMPATIBILITY_CONSTRAINT", Level.SEVERE, |
1059 | "implementationInheritanceCompatibilityConstraint", new Object[] |
1060 | { |
1061 | implementation.getIdentifier(), referenced.getIdentifier(), |
1062 | r.getVersion(), referenced.getVersion() |
1063 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1064 | |
1065 | } |
1066 | } |
1067 | catch ( final ParseException e ) |
1068 | { |
1069 | final ModelValidationReport.Detail detail = new ModelValidationReport.Detail( |
1070 | "IMPLEMENTATION_INHERITANCE_COMPATIBILITY_VERSIONING_PARSE_EXCEPTION", |
1071 | Level.SEVERE, e.getMessage(), |
1072 | new ObjectFactory().createImplementation( implementation ) ); |
1073 | |
1074 | report.getDetails().add( detail ); |
1075 | } |
1076 | catch ( final TokenMgrError e ) |
1077 | { |
1078 | final ModelValidationReport.Detail detail = new ModelValidationReport.Detail( |
1079 | "IMPLEMENTATION_INHERITANCE_COMPATIBILITY_VERSIONING_TOKEN_MANAGER_ERROR", |
1080 | Level.SEVERE, e.getMessage(), |
1081 | new ObjectFactory().createImplementation( implementation ) ); |
1082 | |
1083 | report.getDetails().add( detail ); |
1084 | } |
1085 | } |
1086 | } |
1087 | } |
1088 | } |
1089 | } |
1090 | |
1091 | private void assertImplementationOverrideConstraints( final Modules modules, |
1092 | final Implementation implementation, |
1093 | final ModelValidationReport report ) |
1094 | { |
1095 | final Implementations parentImplementations = new Implementations(); |
1096 | this.collectParentImplementations( |
1097 | modules, implementation, parentImplementations, new Implementations(), false ); |
1098 | |
1099 | if ( implementation.getImplementations() != null ) |
1100 | { |
1101 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1102 | { |
1103 | final Implementation referenced = modules.getImplementation( r.getIdentifier() ); |
1104 | final ImplementationReference parentReference = parentImplementations.getReference( r.getIdentifier() ); |
1105 | |
1106 | if ( referenced.isFinal() ) |
1107 | { |
1108 | report.getDetails().add( this.createDetail( |
1109 | "IMPLEMENTATION_IMPLEMENTATION_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1110 | "implementationFinalImplementationConstraint", new Object[] |
1111 | { |
1112 | implementation.getIdentifier(), referenced.getIdentifier(), |
1113 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1114 | |
1115 | } |
1116 | if ( parentReference != null && parentReference.isFinal() ) |
1117 | { |
1118 | report.getDetails().add( this.createDetail( |
1119 | "IMPLEMENTATION_IMPLEMENTATION_REFERENCE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1120 | "implementationFinalImplementatioReferenceConstraint", new Object[] |
1121 | { |
1122 | implementation.getIdentifier(), parentReference.getIdentifier(), |
1123 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1124 | |
1125 | } |
1126 | if ( r.isOverride() && parentReference == null ) |
1127 | { |
1128 | report.getDetails().add( this.createDetail( |
1129 | "IMPLEMENTATION_IMPLEMENTATION_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1130 | "implementationImplementationOverrideConstraint", new Object[] |
1131 | { |
1132 | implementation.getIdentifier(), r.getIdentifier(), |
1133 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1134 | |
1135 | } |
1136 | } |
1137 | } |
1138 | } |
1139 | |
1140 | private void assertSpecificationOverrideConstraints( final Modules modules, |
1141 | final Implementation implementation, |
1142 | final ModelValidationReport report ) |
1143 | { |
1144 | final Specifications parentSpecifications = new Specifications(); |
1145 | this.collectParentSpecifications( modules, implementation, parentSpecifications, new Implementations(), false ); |
1146 | |
1147 | if ( implementation.getSpecifications() != null ) |
1148 | { |
1149 | for ( SpecificationReference r : implementation.getSpecifications().getReference() ) |
1150 | { |
1151 | final SpecificationReference parent = parentSpecifications.getReference( r.getIdentifier() ); |
1152 | |
1153 | if ( r.isOverride() && parent == null ) |
1154 | { |
1155 | report.getDetails().add( this.createDetail( |
1156 | "IMPLEMENTATION_SPECIFICATION_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1157 | "implementationSpecificationOverrideConstraint", new Object[] |
1158 | { |
1159 | implementation.getIdentifier(), r.getIdentifier(), |
1160 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1161 | |
1162 | } |
1163 | if ( parent != null && parent.isFinal() ) |
1164 | { |
1165 | report.getDetails().add( this.createDetail( |
1166 | "IMPLEMENTATION_SPECIFICATION_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1167 | "implementationSpecificationFinalConstraint", new Object[] |
1168 | { |
1169 | implementation.getIdentifier(), r.getIdentifier(), |
1170 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1171 | |
1172 | } |
1173 | } |
1174 | } |
1175 | } |
1176 | |
1177 | private void assertDependencyOverrideConstraints( final Modules modules, |
1178 | final Implementation implementation, |
1179 | final ModelValidationReport report ) |
1180 | { |
1181 | final Dependencies parentDependencies = new Dependencies(); |
1182 | this.collectParentDependencies( modules, implementation, parentDependencies, new Implementations(), false ); |
1183 | |
1184 | if ( implementation.getDependencies() != null ) |
1185 | { |
1186 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
1187 | { |
1188 | final Dependency parent = parentDependencies.getDependency( d.getName() ); |
1189 | if ( d.isOverride() && parent == null ) |
1190 | { |
1191 | report.getDetails().add( this.createDetail( |
1192 | "IMPLEMENTATION_DEPENDENCY_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1193 | "implementationDependencyOverrideConstraint", new Object[] |
1194 | { |
1195 | implementation.getIdentifier(), d.getName(), |
1196 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1197 | |
1198 | } |
1199 | if ( parent != null && parent.isFinal() ) |
1200 | { |
1201 | report.getDetails().add( this.createDetail( |
1202 | "IMPLEMENTATION_DEPENDENCY_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1203 | "implementationDependencyFinalConstraint", new Object[] |
1204 | { |
1205 | implementation.getIdentifier(), d.getName(), |
1206 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1207 | |
1208 | } |
1209 | } |
1210 | } |
1211 | } |
1212 | |
1213 | private void assertMessageOverrideConstraints( final Modules modules, |
1214 | final Implementation implementation, |
1215 | final ModelValidationReport report ) |
1216 | { |
1217 | final Messages parentMessages = new Messages(); |
1218 | this.collectParentMessages( modules, implementation, parentMessages, new Implementations(), false ); |
1219 | |
1220 | if ( implementation.getMessages() != null ) |
1221 | { |
1222 | for ( Message m : implementation.getMessages().getMessage() ) |
1223 | { |
1224 | final Message parentMessage = parentMessages.getMessage( m.getName() ); |
1225 | final MessageReference parentReference = parentMessages.getReference( m.getName() ); |
1226 | |
1227 | if ( m.isOverride() && parentMessage == null && parentReference == null ) |
1228 | { |
1229 | report.getDetails().add( this.createDetail( |
1230 | "IMPLEMENTATION_MESSAGE_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1231 | "implementationMessageOverrideConstraint", new Object[] |
1232 | { |
1233 | implementation.getIdentifier(), m.getName(), |
1234 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1235 | |
1236 | } |
1237 | if ( ( parentMessage != null && parentMessage.isFinal() ) || |
1238 | ( parentReference != null && parentReference.isFinal() ) ) |
1239 | { |
1240 | report.getDetails().add( this.createDetail( |
1241 | "IMPLEMENTATION_MESSAGE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1242 | "implementationMessageFinalConstraint", new Object[] |
1243 | { |
1244 | implementation.getIdentifier(), m.getName(), |
1245 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1246 | |
1247 | } |
1248 | } |
1249 | for ( MessageReference r : implementation.getMessages().getReference() ) |
1250 | { |
1251 | final Message parentMessage = parentMessages.getMessage( r.getName() ); |
1252 | final MessageReference parentReference = parentMessages.getReference( r.getName() ); |
1253 | |
1254 | if ( r.isOverride() && parentMessage == null && parentReference == null ) |
1255 | { |
1256 | report.getDetails().add( this.createDetail( |
1257 | "IMPLEMENTATION_MESSAGE_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1258 | "implementationMessageOverrideConstraint", new Object[] |
1259 | { |
1260 | implementation.getIdentifier(), r.getName(), |
1261 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1262 | |
1263 | } |
1264 | if ( ( parentMessage != null && parentMessage.isFinal() ) || |
1265 | ( parentReference != null && parentReference.isFinal() ) ) |
1266 | { |
1267 | report.getDetails().add( this.createDetail( |
1268 | "IMPLEMENTATION_MESSAGE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1269 | "implementationMessageFinalConstraint", new Object[] |
1270 | { |
1271 | implementation.getIdentifier(), r.getName(), |
1272 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1273 | |
1274 | } |
1275 | } |
1276 | } |
1277 | } |
1278 | |
1279 | private void assertPropertyOverrideConstraints( final Modules modules, |
1280 | final Implementation implementation, |
1281 | final ModelValidationReport report ) |
1282 | { |
1283 | final Properties parentProperties = new Properties(); |
1284 | this.collectParentProperties( modules, implementation, parentProperties, new Implementations(), false ); |
1285 | |
1286 | if ( implementation.getProperties() != null ) |
1287 | { |
1288 | for ( Property p : implementation.getProperties().getProperty() ) |
1289 | { |
1290 | final Property parentProperty = parentProperties.getProperty( p.getName() ); |
1291 | final PropertyReference parentReference = parentProperties.getReference( p.getName() ); |
1292 | |
1293 | if ( p.isOverride() && parentProperty == null && parentReference == null ) |
1294 | { |
1295 | report.getDetails().add( this.createDetail( |
1296 | "IMPLEMENTATION_PROPERTY_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1297 | "implementationPropertyOverrideConstraint", new Object[] |
1298 | { |
1299 | implementation.getIdentifier(), p.getName(), |
1300 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1301 | |
1302 | } |
1303 | if ( ( parentProperty != null && parentProperty.isFinal() ) || |
1304 | ( parentReference != null && parentReference.isFinal() ) ) |
1305 | { |
1306 | report.getDetails().add( this.createDetail( |
1307 | "IMPLEMENTATION_PROPERTY_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1308 | "implementationPropertyFinalConstraint", new Object[] |
1309 | { |
1310 | implementation.getIdentifier(), p.getName(), |
1311 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1312 | |
1313 | } |
1314 | } |
1315 | for ( PropertyReference r : implementation.getProperties().getReference() ) |
1316 | { |
1317 | final Property parentProperty = parentProperties.getProperty( r.getName() ); |
1318 | final PropertyReference parentReference = parentProperties.getReference( r.getName() ); |
1319 | |
1320 | if ( r.isOverride() && parentProperty == null && parentReference == null ) |
1321 | { |
1322 | report.getDetails().add( this.createDetail( |
1323 | "IMPLEMENTATION_PROPERTY_OVERRIDE_CONSTRAINT", Level.SEVERE, |
1324 | "implementationPropertyOverrideConstraint", new Object[] |
1325 | { |
1326 | implementation.getIdentifier(), r.getName(), |
1327 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1328 | |
1329 | } |
1330 | if ( ( parentProperty != null && parentProperty.isFinal() ) || |
1331 | ( parentReference != null && parentReference.isFinal() ) ) |
1332 | { |
1333 | report.getDetails().add( this.createDetail( |
1334 | "IMPLEMENTATION_PROPERTY_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1335 | "implementationPropertyFinalConstraint", new Object[] |
1336 | { |
1337 | implementation.getIdentifier(), r.getName(), |
1338 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1339 | |
1340 | } |
1341 | } |
1342 | } |
1343 | } |
1344 | |
1345 | private void assertImplementationMessagesUniqueness( |
1346 | final Implementation implementation, final ModelValidationReport report ) |
1347 | { |
1348 | if ( implementation.getMessages() != null ) |
1349 | { |
1350 | for ( Message m : implementation.getMessages().getMessage() ) |
1351 | { |
1352 | if ( implementation.getMessages().getReference( m.getName() ) != null ) |
1353 | { |
1354 | report.getDetails().add( this.createDetail( |
1355 | "IMPLEMENTATION_MESSAGES_UNIQUENESS_CONSTRAINT", Level.SEVERE, |
1356 | "implementationMessagesUniquenessConstraint", new Object[] |
1357 | { |
1358 | implementation.getIdentifier(), m.getName(), |
1359 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1360 | |
1361 | } |
1362 | } |
1363 | } |
1364 | } |
1365 | |
1366 | private void assertImplementationPropertiesUniqueness( |
1367 | final Implementation implementation, final ModelValidationReport report ) |
1368 | { |
1369 | if ( implementation.getProperties() != null ) |
1370 | { |
1371 | for ( Property p : implementation.getProperties().getProperty() ) |
1372 | { |
1373 | if ( implementation.getProperties().getReference( p.getName() ) != null ) |
1374 | { |
1375 | report.getDetails().add( this.createDetail( |
1376 | "IMPLEMENTATION_PROPERTIES_UNIQUENESS_CONSTRAINT", Level.SEVERE, |
1377 | "implementationPropertiesUniquenessConstraint", new Object[] |
1378 | { |
1379 | implementation.getIdentifier(), p.getName(), |
1380 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1381 | |
1382 | } |
1383 | } |
1384 | } |
1385 | } |
1386 | |
1387 | private void assertNoInheritanceClashes( final Modules modules, |
1388 | final Implementation implementation, |
1389 | final ModelValidationReport report ) |
1390 | { |
1391 | if ( implementation.getImplementations() != null ) |
1392 | { |
1393 | final Map<String, List<Dependency>> dependencyMap = new HashMap<String, List<Dependency>>(); |
1394 | final Map<String, List<Message>> messageMap = new HashMap<String, List<Message>>(); |
1395 | final Map<String, List<Property>> propertyMap = new HashMap<String, List<Property>>(); |
1396 | final Map<String, List<SpecificationReference>> specMap = |
1397 | new HashMap<String, List<SpecificationReference>>(); |
1398 | |
1399 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1400 | { |
1401 | final Specifications currentSpecs = new Specifications(); |
1402 | final Dependencies currentDependencies = new Dependencies(); |
1403 | final Properties currentProperties = new Properties(); |
1404 | final Messages currentMessages = new Messages(); |
1405 | final Implementation current = modules.getImplementation( r.getIdentifier() ); |
1406 | |
1407 | modules.collectSpecifications( current, currentSpecs, new Implementations(), true ); |
1408 | modules.collectDependencies( current, currentDependencies, new Implementations(), true ); |
1409 | modules.collectMessages( current, currentMessages, new Implementations(), true ); |
1410 | modules.collectProperties( current, currentProperties, new Implementations(), true ); |
1411 | |
1412 | for ( SpecificationReference ref : currentSpecs.getReference() ) |
1413 | { |
1414 | List<SpecificationReference> list = specMap.get( ref.getIdentifier() ); |
1415 | if ( list == null ) |
1416 | { |
1417 | list = new LinkedList<SpecificationReference>(); |
1418 | specMap.put( ref.getIdentifier(), list ); |
1419 | } |
1420 | |
1421 | list.add( ref ); |
1422 | } |
1423 | |
1424 | for ( Dependency d : currentDependencies.getDependency() ) |
1425 | { |
1426 | List<Dependency> list = dependencyMap.get( d.getName() ); |
1427 | if ( list == null ) |
1428 | { |
1429 | list = new LinkedList<Dependency>(); |
1430 | dependencyMap.put( d.getName(), list ); |
1431 | } |
1432 | |
1433 | list.add( d ); |
1434 | } |
1435 | |
1436 | for ( Message msg : currentMessages.getMessage() ) |
1437 | { |
1438 | List<Message> list = messageMap.get( msg.getName() ); |
1439 | if ( list == null ) |
1440 | { |
1441 | list = new LinkedList<Message>(); |
1442 | messageMap.put( msg.getName(), list ); |
1443 | } |
1444 | |
1445 | list.add( msg ); |
1446 | } |
1447 | |
1448 | for ( Property p : currentProperties.getProperty() ) |
1449 | { |
1450 | List<Property> list = propertyMap.get( p.getName() ); |
1451 | if ( list == null ) |
1452 | { |
1453 | list = new LinkedList<Property>(); |
1454 | propertyMap.put( p.getName(), list ); |
1455 | } |
1456 | |
1457 | list.add( p ); |
1458 | } |
1459 | } |
1460 | |
1461 | for ( Map.Entry<String, List<SpecificationReference>> e : specMap.entrySet() ) |
1462 | { |
1463 | if ( e.getValue().size() > 1 && |
1464 | ( implementation.getSpecifications() == null || |
1465 | implementation.getSpecifications().getReference( e.getKey() ) == null ) ) |
1466 | { |
1467 | report.getDetails().add( this.createDetail( |
1468 | "IMPLEMENTATION_SPECIFICATION_MULTIPLE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1469 | "implementationMultipleInheritanceSpecificationConstraint", new Object[] |
1470 | { |
1471 | implementation.getIdentifier(), e.getKey() |
1472 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1473 | |
1474 | } |
1475 | } |
1476 | |
1477 | for ( Map.Entry<String, List<Dependency>> e : dependencyMap.entrySet() ) |
1478 | { |
1479 | if ( e.getValue().size() > 1 && |
1480 | ( implementation.getDependencies() == null || |
1481 | implementation.getDependencies().getDependency( e.getKey() ) == null ) ) |
1482 | { |
1483 | report.getDetails().add( this.createDetail( |
1484 | "IMPLEMENTATION_DEPENDENCY_MULTIPLE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1485 | "implementationMultipleInheritanceDependencyConstraint", new Object[] |
1486 | { |
1487 | implementation.getIdentifier(), e.getKey() |
1488 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1489 | |
1490 | } |
1491 | } |
1492 | |
1493 | for ( Map.Entry<String, List<Message>> e : messageMap.entrySet() ) |
1494 | { |
1495 | if ( e.getValue().size() > 1 && |
1496 | ( implementation.getMessages() == null || |
1497 | ( implementation.getMessages().getMessage( e.getKey() ) == null && |
1498 | implementation.getMessages().getReference( e.getKey() ) == null ) ) ) |
1499 | { |
1500 | report.getDetails().add( this.createDetail( |
1501 | "IMPLEMENTATION_MESSAGE_MULTIPLE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1502 | "implementationMultipleInheritanceMessageConstraint", new Object[] |
1503 | { |
1504 | implementation.getIdentifier(), e.getKey() |
1505 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1506 | |
1507 | } |
1508 | } |
1509 | |
1510 | for ( Map.Entry<String, List<Property>> e : propertyMap.entrySet() ) |
1511 | { |
1512 | if ( e.getValue().size() > 1 && |
1513 | ( implementation.getProperties() == null || |
1514 | ( implementation.getProperties().getProperty( e.getKey() ) == null && |
1515 | implementation.getProperties().getReference( e.getKey() ) == null ) ) ) |
1516 | { |
1517 | report.getDetails().add( this.createDetail( |
1518 | "IMPLEMENTATION_PROPERTY_MULTIPLE_INHERITANCE_CONSTRAINT", Level.SEVERE, |
1519 | "implementationMultipleInheritancePropertyConstraint", new Object[] |
1520 | { |
1521 | implementation.getIdentifier(), e.getKey() |
1522 | }, new ObjectFactory().createImplementation( implementation ) ) ); |
1523 | |
1524 | } |
1525 | } |
1526 | } |
1527 | } |
1528 | |
1529 | private void assertSpecificationImplementationNameUniqueness( final Modules modules, |
1530 | final Specification specification, |
1531 | final ModelValidationReport report ) |
1532 | { |
1533 | final Implementations impls = modules.getImplementations( specification.getIdentifier() ); |
1534 | |
1535 | if ( impls != null ) |
1536 | { |
1537 | final Map<String, Implementations> map = new HashMap<String, Implementations>(); |
1538 | |
1539 | for ( Implementation i : impls.getImplementation() ) |
1540 | { |
1541 | Implementations implementations = map.get( i.getName() ); |
1542 | if ( implementations == null ) |
1543 | { |
1544 | implementations = new Implementations(); |
1545 | map.put( i.getName(), implementations ); |
1546 | } |
1547 | |
1548 | implementations.getImplementation().add( i ); |
1549 | } |
1550 | |
1551 | for ( Map.Entry<String, Implementations> e : map.entrySet() ) |
1552 | { |
1553 | if ( e.getValue().getImplementation().size() > 1 ) |
1554 | { |
1555 | for ( Implementation i : e.getValue().getImplementation() ) |
1556 | { |
1557 | report.getDetails().add( this.createDetail( |
1558 | "SPECIFICATION_IMPLEMENTATION_NAME_UNIQUENESS_CONSTRAINT", Level.SEVERE, |
1559 | "specificationImplementationNameConstraint", new Object[] |
1560 | { |
1561 | i.getIdentifier(), specification.getIdentifier(), i.getName() |
1562 | }, new ObjectFactory().createImplementation( i ) ) ); |
1563 | |
1564 | } |
1565 | } |
1566 | } |
1567 | } |
1568 | } |
1569 | |
1570 | private void assertSpecificationMultiplicityConstraint( final Modules modules, final Specification specification, |
1571 | final ModelValidationReport report ) |
1572 | { |
1573 | final Implementations impls = modules.getImplementations( specification.getIdentifier() ); |
1574 | |
1575 | if ( specification.getMultiplicity() == Multiplicity.ONE && impls != null && |
1576 | impls.getImplementation().size() > 1 ) |
1577 | { |
1578 | for ( Implementation i : impls.getImplementation() ) |
1579 | { |
1580 | report.getDetails().add( this.createDetail( |
1581 | "SPECIFICATION_IMPLEMENTATION_MULTIPLICITY_CONSTRAINT", Level.SEVERE, |
1582 | "specificationMultiplicityConstraint", new Object[] |
1583 | { |
1584 | i.getIdentifier(), specification.getIdentifier(), specification.getMultiplicity() |
1585 | }, new ObjectFactory().createImplementation( i ) ) ); |
1586 | |
1587 | } |
1588 | } |
1589 | } |
1590 | |
1591 | private void assertNoSpecificationPropertyReferenceDeclarations( final Specification specification, |
1592 | final ModelValidationReport report ) |
1593 | { |
1594 | if ( specification.getProperties() != null ) |
1595 | { |
1596 | for ( PropertyReference r : specification.getProperties().getReference() ) |
1597 | { |
1598 | report.getDetails().add( this.createDetail( |
1599 | "SPECIFICATION_PROPERTY_REFERENCE_DECLARATION_CONSTRAINT", Level.SEVERE, |
1600 | "specificationPropertyReferenceDeclarationConstraint", new Object[] |
1601 | { |
1602 | specification.getIdentifier(), r.getName() |
1603 | }, new ObjectFactory().createSpecification( specification ) ) ); |
1604 | |
1605 | } |
1606 | } |
1607 | } |
1608 | |
1609 | private Implementation findInheritanceCycle( final Modules modules, final Implementation current, |
1610 | final Implementation report, final Implementations implementations ) |
1611 | { |
1612 | if ( current != null ) |
1613 | { |
1614 | if ( implementations.getImplementation( current.getIdentifier() ) != null ) |
1615 | { |
1616 | return report; |
1617 | } |
1618 | |
1619 | implementations.getImplementation().add( current ); |
1620 | |
1621 | if ( current.getImplementations() != null ) |
1622 | { |
1623 | for ( ImplementationReference r : current.getImplementations().getReference() ) |
1624 | { |
1625 | return this.findInheritanceCycle( modules, modules.getImplementation( r.getIdentifier() ), |
1626 | current, implementations ); |
1627 | |
1628 | } |
1629 | |
1630 | } |
1631 | } |
1632 | |
1633 | return null; |
1634 | } |
1635 | |
1636 | private void collectParentImplementations( final Modules modules, final Implementation implementation, |
1637 | final Implementations implementations, final Implementations seen, |
1638 | final boolean includeImplementation ) |
1639 | { |
1640 | if ( implementation != null && seen.getImplementation( implementation.getIdentifier() ) == null ) |
1641 | { |
1642 | seen.getImplementation().add( implementation ); |
1643 | |
1644 | if ( includeImplementation && implementations.getImplementation( implementation.getIdentifier() ) == null ) |
1645 | { |
1646 | implementations.getImplementation().add( implementation ); |
1647 | } |
1648 | |
1649 | if ( implementation.getImplementations() != null ) |
1650 | { |
1651 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1652 | { |
1653 | if ( includeImplementation && implementations.getReference( r.getIdentifier() ) == null ) |
1654 | { |
1655 | implementations.getReference().add( r ); |
1656 | } |
1657 | |
1658 | this.collectParentImplementations( modules, modules.getImplementation( r.getIdentifier() ), |
1659 | implementations, seen, true ); |
1660 | |
1661 | } |
1662 | } |
1663 | } |
1664 | } |
1665 | |
1666 | private void collectParentSpecifications( final Modules modules, final Implementation implementation, |
1667 | final Specifications specifications, final Implementations seen, |
1668 | final boolean includeImplementation ) |
1669 | { |
1670 | if ( implementation != null && seen.getImplementation( implementation.getIdentifier() ) == null ) |
1671 | { |
1672 | seen.getImplementation().add( implementation ); |
1673 | |
1674 | if ( includeImplementation && implementation.getSpecifications() != null ) |
1675 | { |
1676 | for ( SpecificationReference r : implementation.getSpecifications().getReference() ) |
1677 | { |
1678 | if ( specifications.getReference( r.getIdentifier() ) == null ) |
1679 | { |
1680 | specifications.getReference().add( r ); |
1681 | } |
1682 | } |
1683 | } |
1684 | |
1685 | if ( implementation.getImplementations() != null ) |
1686 | { |
1687 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1688 | { |
1689 | this.collectParentSpecifications( modules, modules.getImplementation( r.getIdentifier() ), |
1690 | specifications, seen, true ); |
1691 | |
1692 | } |
1693 | } |
1694 | } |
1695 | } |
1696 | |
1697 | private void collectParentDependencies( final Modules modules, final Implementation implementation, |
1698 | final Dependencies dependencies, final Implementations seen, |
1699 | final boolean includeImplementation ) |
1700 | { |
1701 | if ( implementation != null && seen.getImplementation( implementation.getIdentifier() ) == null ) |
1702 | { |
1703 | seen.getImplementation().add( implementation ); |
1704 | |
1705 | if ( includeImplementation && implementation.getDependencies() != null ) |
1706 | { |
1707 | for ( Dependency d : implementation.getDependencies().getDependency() ) |
1708 | { |
1709 | if ( dependencies.getDependency( d.getName() ) == null ) |
1710 | { |
1711 | dependencies.getDependency().add( d ); |
1712 | } |
1713 | } |
1714 | } |
1715 | |
1716 | if ( implementation.getImplementations() != null ) |
1717 | { |
1718 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1719 | { |
1720 | this.collectParentDependencies( modules, modules.getImplementation( r.getIdentifier() ), |
1721 | dependencies, seen, true ); |
1722 | |
1723 | } |
1724 | } |
1725 | } |
1726 | } |
1727 | |
1728 | private void collectParentMessages( final Modules modules, final Implementation implementation, |
1729 | final Messages messages, final Implementations seen, |
1730 | final boolean includeImplementation ) |
1731 | { |
1732 | if ( implementation != null && seen.getImplementation( implementation.getIdentifier() ) == null ) |
1733 | { |
1734 | seen.getImplementation().add( implementation ); |
1735 | |
1736 | if ( includeImplementation && implementation.getMessages() != null ) |
1737 | { |
1738 | for ( Message m : implementation.getMessages().getMessage() ) |
1739 | { |
1740 | if ( messages.getMessage( m.getName() ) == null ) |
1741 | { |
1742 | messages.getMessage().add( m ); |
1743 | } |
1744 | } |
1745 | for ( MessageReference r : implementation.getMessages().getReference() ) |
1746 | { |
1747 | if ( messages.getReference( r.getName() ) == null ) |
1748 | { |
1749 | messages.getReference().add( r ); |
1750 | } |
1751 | } |
1752 | } |
1753 | |
1754 | if ( implementation.getImplementations() != null ) |
1755 | { |
1756 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1757 | { |
1758 | this.collectParentMessages( modules, modules.getImplementation( r.getIdentifier() ), |
1759 | messages, seen, true ); |
1760 | |
1761 | } |
1762 | } |
1763 | } |
1764 | } |
1765 | |
1766 | private void collectParentProperties( final Modules modules, final Implementation implementation, |
1767 | final Properties properties, final Implementations seen, |
1768 | final boolean includeImplementation ) |
1769 | { |
1770 | if ( implementation != null && seen.getImplementation( implementation.getIdentifier() ) == null ) |
1771 | { |
1772 | seen.getImplementation().add( implementation ); |
1773 | |
1774 | if ( includeImplementation && implementation.getProperties() != null ) |
1775 | { |
1776 | for ( Property p : implementation.getProperties().getProperty() ) |
1777 | { |
1778 | if ( properties.getProperty( p.getName() ) == null ) |
1779 | { |
1780 | properties.getProperty().add( p ); |
1781 | } |
1782 | } |
1783 | for ( PropertyReference r : implementation.getProperties().getReference() ) |
1784 | { |
1785 | if ( properties.getReference( r.getName() ) == null ) |
1786 | { |
1787 | properties.getReference().add( r ); |
1788 | } |
1789 | } |
1790 | } |
1791 | |
1792 | if ( implementation.getImplementations() != null ) |
1793 | { |
1794 | for ( ImplementationReference r : implementation.getImplementations().getReference() ) |
1795 | { |
1796 | this.collectParentProperties( modules, modules.getImplementation( r.getIdentifier() ), |
1797 | properties, seen, true ); |
1798 | |
1799 | } |
1800 | } |
1801 | } |
1802 | } |
1803 | |
1804 | private ModelValidationReport.Detail createDetail( final String identifier, final Level level, |
1805 | final String messageKey, final Object messageArguments, |
1806 | final JAXBElement<? extends ModelObject> element ) |
1807 | { |
1808 | return new ModelValidationReport.Detail( |
1809 | identifier, level, this.getMessage( messageKey, messageArguments ), element ); |
1810 | |
1811 | } |
1812 | |
1813 | private String getMessage( final String key, final Object args ) |
1814 | { |
1815 | return new MessageFormat( ResourceBundle.getBundle( |
1816 | DefaultModelValidator.class.getName().replace( '.', '/' ), |
1817 | Locale.getDefault() ).getString( key ) ).format( args ); |
1818 | |
1819 | } |
1820 | |
1821 | } |