1 | package de.uka.ipd.sdq.pcm.transformations.builder.abstractbuilder; |
2 | |
3 | import de.uka.ipd.sdq.pcm.allocation.AllocationContext; |
4 | import de.uka.ipd.sdq.pcm.allocation.AllocationFactory; |
5 | import de.uka.ipd.sdq.pcm.core.composition.CompositionFactory; |
6 | import de.uka.ipd.sdq.pcm.repository.BasicComponent; |
7 | import de.uka.ipd.sdq.pcm.repository.Interface; |
8 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
9 | import de.uka.ipd.sdq.pcm.repository.RepositoryComponent; |
10 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
11 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceContainer; |
12 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.DelegatorComponentSeffBuilder; |
13 | import de.uka.ipd.sdq.pcm.transformations.builder.seff.ISeffBuilder; |
14 | import de.uka.ipd.sdq.pcm.transformations.builder.util.PCMAndCompletionModelHolder; |
15 | |
16 | /** |
17 | * A builder for creating basic components and their assembly and allocation context. The component has a single provided and required interface which |
18 | * can be optionally the same (usefull if used with a delegating seff builder). |
19 | * @author Snowball |
20 | */ |
21 | public abstract class BasicComponentBuilder |
22 | extends AbstractComponentBuilder { |
23 | |
24 | protected DelegatorComponentSeffBuilder seffBuilder; |
25 | private OperationInterface providedOperationInterface; |
26 | private OperationInterface requiredOperationInterface; |
27 | private AllocationContext myAllocationContext; |
28 | protected ResourceContainer container; |
29 | |
30 | public BasicComponentBuilder( |
31 | PCMAndCompletionModelHolder models, |
32 | OperationInterface interf, |
33 | ResourceContainer container, |
34 | String componentName) { |
35 | this(models,interf,interf,container,componentName); |
36 | } |
37 | |
38 | public BasicComponentBuilder( |
39 | PCMAndCompletionModelHolder models, |
40 | OperationInterface providedIf, |
41 | OperationInterface requiredIf, |
42 | ResourceContainer container, |
43 | String componentName) { |
44 | super(models, componentName); |
45 | this.providedOperationInterface = providedIf; |
46 | this.requiredOperationInterface = requiredIf; |
47 | this.container = container; |
48 | } |
49 | |
50 | protected abstract ISeffBuilder getSeffBuilder(); |
51 | |
52 | @Override |
53 | public void build() { |
54 | super.build(); |
55 | |
56 | myOperationProvidedRole = addOperationProvidedRole(providedOperationInterface,"ProvidedRole"); |
57 | myOperationRequiredRole = addOperationRequiredRole(requiredOperationInterface,"RequiredRole"); |
58 | |
59 | ISeffBuilder seffBuilder = this.getSeffBuilder(); |
60 | seffBuilder.build(); |
61 | getBasicComponent().getServiceEffectSpecifications__BasicComponent().addAll(seffBuilder.getSeffs()); |
62 | |
63 | this.myAssemblyContext = CompositionFactory.eINSTANCE.createAssemblyContext(); |
64 | this.myAssemblyContext.setEntityName("BCAssembly "+myComponent.getEntityName()); |
65 | this.myAssemblyContext.setEncapsulatedComponent__AssemblyContext(myComponent); |
66 | |
67 | this.myAllocationContext = AllocationFactory.eINSTANCE.createAllocationContext(); |
68 | myAllocationContext.setAssemblyContext_AllocationContext(myAssemblyContext); |
69 | myAllocationContext.setResourceContainer_AllocationContext(this.container); |
70 | |
71 | myModels.getAllocation().getAllocationContexts_Allocation().add(myAllocationContext); |
72 | } |
73 | |
74 | protected BasicComponent getBasicComponent() { |
75 | return (BasicComponent)myComponent; |
76 | } |
77 | |
78 | @Override |
79 | protected RepositoryComponent createComponent(String componentName) { |
80 | BasicComponent bc = RepositoryFactory.eINSTANCE.createBasicComponent(); |
81 | bc.setEntityName("InnerBasicComponent_"+componentName+getNextCounter()); |
82 | return bc; |
83 | } |
84 | |
85 | } |