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