1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.jdtaus.core.container.ri.jomc;
26
27 import java.util.HashSet;
28 import java.util.Locale;
29 import java.util.Set;
30 import org.jomc.model.Argument;
31 import org.jomc.model.ArgumentType;
32 import org.jomc.model.Arguments;
33 import org.jomc.model.Dependencies;
34 import org.jomc.model.Dependency;
35 import org.jomc.model.Implementation;
36 import org.jomc.model.ImplementationReference;
37 import org.jomc.model.Implementations;
38 import org.jomc.model.InheritanceModel;
39 import org.jomc.model.Message;
40 import org.jomc.model.MessageReference;
41 import org.jomc.model.Messages;
42 import org.jomc.model.Module;
43 import org.jomc.model.Modules;
44 import org.jomc.model.Multiplicity;
45 import org.jomc.model.Properties;
46 import org.jomc.model.Property;
47 import org.jomc.model.Specification;
48 import org.jomc.model.SpecificationReference;
49 import org.jomc.model.Specifications;
50 import org.jomc.model.Text;
51 import org.jomc.model.Texts;
52 import org.jomc.model.modlet.ModelHelper;
53 import org.jomc.modlet.Model;
54 import org.jomc.modlet.ModelContext;
55 import org.jomc.modlet.ModelException;
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.3", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.3" )
80
81
82 public class ModelModelProvider
83 implements
84 org.jomc.modlet.ModelProvider
85 {
86
87
88
89 private static final String CONTEXT_CLASSLOADER_PROPERTY_NAME =
90 "org.jdtaus.core.container.ClassLoaderFactory.enableContextClassloader";
91
92 @Override
93 public Model findModel( final ModelContext context, final Model model ) throws NullPointerException, ModelException
94 {
95 Model provided = null;
96 final String sys = System.getProperty( CONTEXT_CLASSLOADER_PROPERTY_NAME );
97 final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
98
99 try
100 {
101 System.setProperty( CONTEXT_CLASSLOADER_PROPERTY_NAME, Boolean.TRUE.toString() );
102 Thread.currentThread().setContextClassLoader( context.getClassLoader() );
103
104 final Modules modules = transformModules( org.jdtaus.core.container.ModelFactory.getModel().getModules() );
105
106 if ( modules != null )
107 {
108 applyInheritanceAttributes( modules );
109 provided = model.clone();
110 ModelHelper.addModules( provided, modules );
111 }
112
113 return provided;
114 }
115 finally
116 {
117 Thread.currentThread().setContextClassLoader( classLoader );
118
119 if ( sys != null )
120 {
121 System.setProperty( CONTEXT_CLASSLOADER_PROPERTY_NAME, sys );
122 }
123 else
124 {
125 System.clearProperty( CONTEXT_CLASSLOADER_PROPERTY_NAME );
126 }
127 }
128 }
129
130
131
132 private static Modules transformModules( final org.jdtaus.core.container.Modules jdtausModules )
133 {
134 Modules modules = null;
135
136 if ( jdtausModules != null )
137 {
138 modules = new Modules();
139
140 for ( int i = 0, s0 = jdtausModules.size(); i < s0; i++ )
141 {
142 final org.jdtaus.core.container.Module jdtausModule = jdtausModules.getModule( i );
143
144 if ( !org.jdtaus.core.container.Model.class.getName().equals( jdtausModule.getName() ) )
145 {
146 modules.getModule().add( transformModule( jdtausModule ) );
147 }
148 }
149 }
150
151 return modules;
152 }
153
154 private static Module transformModule( final org.jdtaus.core.container.Module jdtausModule )
155 {
156 Module module = null;
157
158 if ( jdtausModule != null )
159 {
160 module = new Module();
161 module.setDocumentation( transformText( jdtausModule.getDocumentation() ) );
162 module.setName( jdtausModule.getName() );
163 module.setVersion( jdtausModule.getVersion() );
164 module.setSpecifications( transformSpecifications( jdtausModule.getSpecifications() ) );
165 module.setImplementations( transformImplementations( jdtausModule.getImplementations() ) );
166 }
167
168 return module;
169 }
170
171 private static Implementations transformImplementations(
172 final org.jdtaus.core.container.Implementations jdtausImplementations )
173 {
174 Implementations implementations = null;
175
176 if ( jdtausImplementations != null )
177 {
178 implementations = new Implementations();
179 implementations.setDocumentation( transformText( jdtausImplementations.getDocumentation() ) );
180
181 for ( int i = 0, s0 = jdtausImplementations.size(); i < s0; i++ )
182 {
183 implementations.getImplementation().add( transformImplementation(
184 jdtausImplementations.getImplementation( i ) ) );
185
186 }
187 }
188
189 return implementations;
190 }
191
192 private static Implementation transformImplementation(
193 final org.jdtaus.core.container.Implementation jdtausImplementation )
194 {
195 final Implementation implementation = new Implementation();
196 implementation.setIdentifier( jdtausImplementation.getIdentifier() );
197 implementation.setClazz( jdtausImplementation.getIdentifier() );
198 implementation.setClassDeclaration( Boolean.TRUE );
199 implementation.setFinal( jdtausImplementation.isFinal() );
200 implementation.setName( jdtausImplementation.getName() );
201 implementation.setVendor( jdtausImplementation.getVendor() );
202 implementation.setVersion( jdtausImplementation.getVersion() );
203 implementation.setDocumentation( transformText( jdtausImplementation.getDocumentation() ) );
204 implementation.setProperties( transformProperties( jdtausImplementation.getDeclaredProperties() ) );
205 implementation.setMessages( transformMessages( jdtausImplementation.getDeclaredMessages() ) );
206 implementation.setDependencies( transformDependencies( jdtausImplementation.getDeclaredDependencies() ) );
207 implementation.setSpecifications( transformSpecificationReferences(
208 jdtausImplementation.getImplementedSpecifications() ) );
209
210
211
212 implementation.setStateless( Boolean.FALSE );
213
214 if ( jdtausImplementation.getParent() != null )
215 {
216 final Implementations references = new Implementations();
217 implementation.setImplementations( references );
218
219 final ImplementationReference reference = new ImplementationReference();
220 references.getReference().add( reference );
221
222 reference.setIdentifier( jdtausImplementation.getParent().getIdentifier() );
223 reference.setVersion( jdtausImplementation.getParent().getVersion() );
224 }
225
226 return implementation;
227 }
228
229 private static Specifications transformSpecifications(
230 final org.jdtaus.core.container.Specifications jdtausSpecifications )
231 {
232 Specifications specifications = null;
233
234 if ( jdtausSpecifications != null )
235 {
236 specifications = new Specifications();
237 specifications.setDocumentation( transformText( jdtausSpecifications.getDocumentation() ) );
238
239 for ( int i = 0, s0 = jdtausSpecifications.size(); i < s0; i++ )
240 {
241 specifications.getSpecification().add( transformSpecification(
242 jdtausSpecifications.getSpecification( i ) ) );
243
244 }
245 }
246
247 return specifications;
248 }
249
250 private static Specifications transformSpecificationReferences(
251 final org.jdtaus.core.container.Specifications jdtausSpecifications )
252 {
253 Specifications specifications = null;
254
255 if ( jdtausSpecifications != null )
256 {
257 specifications = new Specifications();
258 specifications.setDocumentation( transformText( jdtausSpecifications.getDocumentation() ) );
259
260 for ( int i = 0, s0 = jdtausSpecifications.size(); i < s0; i++ )
261 {
262 final SpecificationReference specificationReference = new SpecificationReference();
263 specificationReference.setIdentifier( jdtausSpecifications.getSpecification( i ).getIdentifier() );
264 specificationReference.setVersion( jdtausSpecifications.getSpecification( i ).getVersion() );
265 specifications.getReference().add( specificationReference );
266 }
267 }
268
269 return specifications;
270 }
271
272 private static Specification transformSpecification(
273 final org.jdtaus.core.container.Specification jdtausSpecification )
274 {
275 final Specification specification = new Specification();
276 specification.setClassDeclaration( Boolean.TRUE );
277 specification.setClazz( jdtausSpecification.getIdentifier() );
278 specification.setIdentifier( jdtausSpecification.getIdentifier() );
279 specification.setVendor( jdtausSpecification.getVendor() );
280 specification.setVersion( jdtausSpecification.getVersion() );
281 specification.setDocumentation( transformText( jdtausSpecification.getDocumentation() ) );
282
283 switch ( jdtausSpecification.getMultiplicity() )
284 {
285 case org.jdtaus.core.container.Specification.MULTIPLICITY_MANY:
286 specification.setMultiplicity( Multiplicity.MANY );
287 break;
288 case org.jdtaus.core.container.Specification.MULTIPLICITY_ONE:
289 specification.setMultiplicity( Multiplicity.ONE );
290 break;
291 default:
292
293 }
294
295 switch ( jdtausSpecification.getScope() )
296 {
297 case org.jdtaus.core.container.Specification.SCOPE_CONTEXT:
298 specification.setScope( "jDTAUS Context" );
299 break;
300
301 case org.jdtaus.core.container.Specification.SCOPE_SINGLETON:
302 specification.setScope( "Singleton" );
303 break;
304 default:
305
306 }
307
308 specification.setProperties( transformProperties( jdtausSpecification.getProperties() ) );
309 return specification;
310 }
311
312 private static Texts transformText( final org.jdtaus.core.container.Text jdtausText )
313 {
314 Texts texts = null;
315
316 if ( jdtausText != null )
317 {
318 texts = new Texts();
319
320 for ( final Locale locale : jdtausText.getLocales() )
321 {
322 final Text text = new Text();
323 text.setLanguage( locale.getLanguage() );
324 text.setValue( jdtausText.getValue( locale ) );
325 texts.getText().add( text );
326
327 if ( text.getValue().equals( jdtausText.getValue() ) )
328 {
329 texts.setDefaultLanguage( locale.getLanguage() );
330 }
331 }
332
333 if ( texts.getText().isEmpty() )
334 {
335 texts = null;
336 }
337 }
338
339 return texts;
340 }
341
342 private static Properties transformProperties( final org.jdtaus.core.container.Properties jdtausProperties )
343 {
344 Properties properties = null;
345
346 if ( jdtausProperties != null )
347 {
348 properties = new Properties();
349 properties.setDocumentation( transformText( jdtausProperties.getDocumentation() ) );
350
351 for ( int i = 0, s0 = jdtausProperties.size(); i < s0; i++ )
352 {
353 properties.getProperty().add( transformProperty( jdtausProperties.getProperty( i ) ) );
354 }
355 }
356
357 return properties;
358 }
359
360 private static Property transformProperty( final org.jdtaus.core.container.Property jdtausProperty )
361 {
362 Property property = null;
363
364 if ( jdtausProperty != null )
365 {
366 property = new Property();
367 property.setDocumentation( transformText( jdtausProperty.getDocumentation() ) );
368 property.setName( jdtausProperty.getName() );
369 property.setFinal( Boolean.FALSE );
370 property.setOverride( Boolean.FALSE );
371 property.setType( jdtausProperty.getType().getName() );
372
373 if ( jdtausProperty.getValue() != null )
374 {
375 property.setValue( jdtausProperty.getValue().toString() );
376 }
377 else if ( jdtausProperty.isApi() )
378 {
379 if ( Byte.TYPE.equals( jdtausProperty.getType() )
380 || Short.TYPE.equals( jdtausProperty.getType() )
381 || Integer.TYPE.equals( jdtausProperty.getType() )
382 || Long.TYPE.equals( jdtausProperty.getType() )
383 || Float.TYPE.equals( jdtausProperty.getType() )
384 || Double.TYPE.equals( jdtausProperty.getType() ) )
385 {
386 property.setValue( "0" );
387 }
388 else
389 {
390 property.setValue( "" );
391 }
392 }
393 }
394
395 return property;
396 }
397
398 private static Messages transformMessages( final org.jdtaus.core.container.Messages jdtausMessages )
399 {
400 Messages messages = null;
401
402 if ( jdtausMessages != null )
403 {
404 messages = new Messages();
405 messages.setDocumentation( transformText( jdtausMessages.getDocumentation() ) );
406
407 for ( int i = 0, s0 = jdtausMessages.size(); i < s0; i++ )
408 {
409 messages.getMessage().add( transformMessage( jdtausMessages.getMessage( i ) ) );
410 }
411 }
412
413 return messages;
414 }
415
416 private static Message transformMessage( final org.jdtaus.core.container.Message jdtausMessage )
417 {
418 Message message = null;
419
420 if ( jdtausMessage != null )
421 {
422 message = new Message();
423 message.setDocumentation( transformText( jdtausMessage.getDocumentation() ) );
424 message.setName( jdtausMessage.getName() );
425 message.setFinal( Boolean.FALSE );
426 message.setOverride( Boolean.FALSE );
427 message.setTemplate( transformText( jdtausMessage.getTemplate() ) );
428 message.setArguments( transformArguments( jdtausMessage.getArguments() ) );
429 }
430
431 return message;
432 }
433
434 private static Arguments transformArguments( final org.jdtaus.core.container.Arguments jdtausArguments )
435 {
436 Arguments arguments = null;
437
438 if ( jdtausArguments != null )
439 {
440 arguments = new Arguments();
441 arguments.setDocumentation( transformText( jdtausArguments.getDocumentation() ) );
442
443 for ( int i = 0, s0 = jdtausArguments.size(); i < s0; i++ )
444 {
445 arguments.getArgument().add( transformArgument( jdtausArguments.getArgument( i ) ) );
446 }
447 }
448
449 return arguments;
450 }
451
452 private static Argument transformArgument( final org.jdtaus.core.container.Argument jdtausArgument )
453 {
454 Argument argument = null;
455
456 if ( jdtausArgument != null )
457 {
458 argument = new Argument();
459 argument.setDocumentation( transformText( jdtausArgument.getDocumentation() ) );
460 argument.setIndex( jdtausArgument.getIndex() );
461 argument.setName( jdtausArgument.getName() );
462
463 switch ( jdtausArgument.getType() )
464 {
465 case org.jdtaus.core.container.Argument.TYPE_DATE:
466 argument.setType( ArgumentType.DATE );
467 break;
468
469 case org.jdtaus.core.container.Argument.TYPE_NUMBER:
470 argument.setType( ArgumentType.NUMBER );
471 break;
472
473 case org.jdtaus.core.container.Argument.TYPE_TEXT:
474 argument.setType( ArgumentType.TEXT );
475 break;
476 case org.jdtaus.core.container.Argument.TYPE_TIME:
477 argument.setType( ArgumentType.TIME );
478 break;
479 default:
480
481 }
482 }
483
484 return argument;
485 }
486
487 private static Dependencies transformDependencies( final org.jdtaus.core.container.Dependencies jdtausDependencies )
488 {
489 Dependencies dependencies = null;
490
491 if ( jdtausDependencies != null )
492 {
493 dependencies = new Dependencies();
494 dependencies.setDocumentation( transformText( jdtausDependencies.getDocumentation() ) );
495
496 for ( int i = 0, s0 = jdtausDependencies.size(); i < s0; i++ )
497 {
498 dependencies.getDependency().add( transformDependency( jdtausDependencies.getDependency( i ) ) );
499 }
500 }
501
502 return dependencies;
503 }
504
505 private static Dependency transformDependency( final org.jdtaus.core.container.Dependency jdtausDependency )
506 {
507 Dependency dependency = null;
508
509 if ( jdtausDependency != null )
510 {
511 dependency = new Dependency();
512 dependency.setDocumentation( transformText( jdtausDependency.getDocumentation() ) );
513 dependency.setName( jdtausDependency.getName() );
514 dependency.setFinal( Boolean.FALSE );
515 dependency.setOverride( Boolean.FALSE );
516 dependency.setBound( jdtausDependency.isBound() );
517 dependency.setIdentifier( jdtausDependency.getSpecification().getIdentifier() );
518 dependency.setVersion( jdtausDependency.getSpecification().getVersion() );
519
520 if ( jdtausDependency.getImplementation() != null )
521 {
522 dependency.setImplementationName( jdtausDependency.getImplementation().getName() );
523 }
524
525
526
527 dependency.setOptional( Boolean.FALSE );
528 dependency.setProperties( transformProperties( jdtausDependency.getDeclaredProperties() ) );
529 }
530
531 return dependency;
532 }
533
534 private static void applyInheritanceAttributes( final Modules modules )
535 {
536 final InheritanceModel imodel = new InheritanceModel( modules );
537
538 if ( modules.getImplementations() != null )
539 {
540 for ( int i = 0, s0 = modules.getImplementations().getImplementation().size(); i < s0; i++ )
541 {
542 applyInheritanceAttributes(
543 modules, imodel, modules.getImplementations().getImplementation().get( i ) );
544
545 }
546 }
547 }
548
549 private static void applyInheritanceAttributes( final Modules modules, final InheritanceModel imodel,
550 final Implementation implementation )
551 {
552 final Set<String> dependencyNames = imodel.getDependencyNames( implementation.getIdentifier() );
553 final Set<String> messageNames = imodel.getMessageNames( implementation.getIdentifier() );
554 final Set<String> propertyNames = imodel.getPropertyNames( implementation.getIdentifier() );
555
556 for ( final String dependencyName : dependencyNames )
557 {
558 final Set<InheritanceModel.Node<Dependency>> effDependency =
559 imodel.getDependencyNodes( implementation.getIdentifier(), dependencyName );
560
561 for ( final InheritanceModel.Node<Dependency> d : effDependency )
562 {
563 if ( d.getImplementation().getIdentifier().equals( implementation.getIdentifier() )
564 && !d.getOverriddenNodes().isEmpty() )
565 {
566 implementation.getDependencies().getDependency( dependencyName ).setOverride( true );
567 }
568 }
569 }
570
571 for ( final String messageName : messageNames )
572 {
573 final Set<InheritanceModel.Node<Message>> effMessage =
574 imodel.getMessageNodes( implementation.getIdentifier(), messageName );
575
576 for ( final InheritanceModel.Node<Message> m : effMessage )
577 {
578 if ( m.getImplementation().getIdentifier().equals( implementation.getIdentifier() )
579 && !m.getOverriddenNodes().isEmpty() )
580 {
581 final Message msg = implementation.getMessages().getMessage( messageName );
582 final MessageReference ref = implementation.getMessages().getReference( messageName );
583
584 if ( msg != null )
585 {
586 msg.setOverride( true );
587 }
588 if ( ref != null )
589 {
590 ref.setOverride( true );
591 }
592 }
593 }
594 }
595
596 for ( final String propertyName : propertyNames )
597 {
598 final Set<InheritanceModel.Node<Property>> effProperty =
599 imodel.getPropertyNodes( implementation.getIdentifier(), propertyName );
600
601 for ( final InheritanceModel.Node<Property> p : effProperty )
602 {
603 if ( p.getImplementation().getIdentifier().equals( implementation.getIdentifier() )
604 && !p.getOverriddenNodes().isEmpty() )
605 {
606 implementation.getProperties().getProperty( propertyName ).setOverride( true );
607 }
608 }
609 }
610
611 if ( implementation.getDependencies() != null )
612 {
613 for ( int i = 0, s0 = implementation.getDependencies().getDependency().size(); i < s0; i++ )
614 {
615 applyInheritanceAttributes(
616 modules, imodel, implementation.getDependencies().getDependency().get( i ) );
617
618 }
619 }
620 }
621
622 private static void applyInheritanceAttributes( final Modules modules, final InheritanceModel imodel,
623 final Dependency dependency )
624 {
625 final Set<Implementation> implementations = new HashSet<Implementation>();
626
627 if ( dependency.getImplementationName() != null )
628 {
629 final Implementation i = modules.getImplementation( dependency.getIdentifier(),
630 dependency.getImplementationName() );
631
632 if ( i != null )
633 {
634 implementations.add( i );
635 }
636 }
637 else
638 {
639 final Implementations i = modules.getImplementations( dependency.getIdentifier() );
640 if ( i != null )
641 {
642 implementations.addAll( i.getImplementation() );
643 }
644 }
645
646 if ( dependency.getDependencies() != null )
647 {
648 for ( int i = 0, s0 = dependency.getDependencies().getDependency().size(); i < s0; i++ )
649 {
650 final Dependency d = dependency.getDependencies().getDependency().get( i );
651
652 for ( final Implementation impl : implementations )
653 {
654 final Set<InheritanceModel.Node<Dependency>> effDependencies =
655 imodel.getDependencyNodes( impl.getIdentifier(), d.getName() );
656
657 if ( !d.isOverride() && !effDependencies.isEmpty() )
658 {
659 d.setOverride( true );
660 }
661 }
662
663 applyInheritanceAttributes( modules, imodel, d );
664 }
665 }
666 if ( dependency.getMessages() != null )
667 {
668 for ( int i = 0, s0 = dependency.getMessages().getMessage().size(); i < s0; i++ )
669 {
670 final Message m = dependency.getMessages().getMessage().get( i );
671
672 for ( final Implementation impl : implementations )
673 {
674 final Set<InheritanceModel.Node<Message>> effMessages =
675 imodel.getMessageNodes( impl.getIdentifier(), m.getName() );
676
677 if ( !m.isOverride() && !effMessages.isEmpty() )
678 {
679 m.setOverride( true );
680 }
681 }
682 }
683 }
684 if ( dependency.getProperties() != null )
685 {
686 for ( int i = 0, s0 = dependency.getProperties().getProperty().size(); i < s0; i++ )
687 {
688 final Property p = dependency.getProperties().getProperty().get( i );
689
690 for ( final Implementation impl : implementations )
691 {
692 final Set<InheritanceModel.Node<Property>> effProperties =
693 imodel.getPropertyNodes( impl.getIdentifier(), p.getName() );
694
695 if ( !p.isOverride() && !effProperties.isEmpty() )
696 {
697 p.setOverride( true );
698 }
699 }
700 }
701 }
702 }
703
704
705
706
707
708 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.3", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.3" )
709 public ModelModelProvider()
710 {
711
712 super();
713
714 }
715
716
717
718
719
720
721
722
723 }