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