1 | package de.uka.ipd.sdq.pcm.transformations.builder.abstractbuilder; |
2 | |
3 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
4 | import de.uka.ipd.sdq.pcm.repository.OperationInterface; |
5 | import de.uka.ipd.sdq.pcm.repository.OperationProvidedRole; |
6 | import de.uka.ipd.sdq.pcm.repository.OperationRequiredRole; |
7 | import de.uka.ipd.sdq.pcm.repository.ProvidedRole; |
8 | import de.uka.ipd.sdq.pcm.repository.RepositoryComponent; |
9 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
10 | import de.uka.ipd.sdq.pcm.repository.RequiredRole; |
11 | import de.uka.ipd.sdq.pcm.resourcetype.ProcessingResourceType; |
12 | import de.uka.ipd.sdq.pcm.resourcetype.ResourceType; |
13 | import de.uka.ipd.sdq.pcm.transformations.builder.IComponentBuilder; |
14 | import de.uka.ipd.sdq.pcm.transformations.builder.util.PCMAndCompletionModelHolder; |
15 | |
16 | /** |
17 | * Replaces the passed AssemblyConnector with a completion |
18 | * @author Snowball |
19 | */ |
20 | public abstract class AbstractComponentBuilder |
21 | implements IComponentBuilder { |
22 | |
23 | /** |
24 | */ |
25 | protected RepositoryComponent myComponent; |
26 | protected OperationProvidedRole myOperationProvidedRole; |
27 | protected OperationRequiredRole myOperationRequiredRole; |
28 | protected AssemblyContext myAssemblyContext; |
29 | protected PCMAndCompletionModelHolder myModels; |
30 | |
31 | private static int counter = 0; |
32 | |
33 | public AbstractComponentBuilder(PCMAndCompletionModelHolder models, String componentName) { |
34 | this.myComponent = createComponent(componentName); |
35 | this.myModels = models; |
36 | } |
37 | |
38 | protected abstract RepositoryComponent createComponent(String componentName); |
39 | |
40 | public AssemblyContext getAssemblyContext() { |
41 | return myAssemblyContext; |
42 | } |
43 | |
44 | protected OperationProvidedRole addOperationProvidedRole(OperationInterface interf, String roleName) { |
45 | OperationProvidedRole result = RepositoryFactory.eINSTANCE.createOperationProvidedRole(); |
46 | result.setProvidedInterface__OperationProvidedRole(interf); |
47 | result.setEntityName(roleName); |
48 | myComponent.getProvidedRoles_InterfaceProvidingEntity().add(result); |
49 | return result; |
50 | } |
51 | |
52 | protected OperationRequiredRole addOperationRequiredRole(OperationInterface interf, String roleName) { |
53 | OperationRequiredRole result = RepositoryFactory.eINSTANCE.createOperationRequiredRole(); |
54 | result.setRequiredInterface__OperationRequiredRole(interf); |
55 | result.setEntityName(roleName); |
56 | myComponent.getRequiredRoles_InterfaceRequiringEntity().add(result); |
57 | return result; |
58 | } |
59 | |
60 | public OperationProvidedRole getOperationProvidedRole() { |
61 | return myOperationProvidedRole; |
62 | } |
63 | |
64 | public OperationRequiredRole getOperationRequiredRole() { |
65 | return myOperationRequiredRole; |
66 | } |
67 | |
68 | protected int getNextCounter(){ |
69 | counter++; |
70 | return counter; |
71 | } |
72 | |
73 | public RepositoryComponent getComponent() { |
74 | return myComponent; |
75 | } |
76 | |
77 | public void build() { |
78 | myModels.getCompletionRepository().getComponents__Repository().add(myComponent); |
79 | } |
80 | |
81 | protected ProcessingResourceType findResourceType(String nameFragment) { |
82 | for (ResourceType type : myModels.getResourceRepository().getAvailableResourceTypes_ResourceRepository()){ |
83 | if (type instanceof ProcessingResourceType && type.getEntityName().toLowerCase().contains(nameFragment.toLowerCase())) |
84 | return (ProcessingResourceType) type; |
85 | } |
86 | throw new RuntimeException("Neccessary resourcetype "+nameFragment+" not found"); |
87 | } |
88 | } |