1 | package de.uka.ipd.sdq.workflow.pcm.blackboard; |
2 | |
3 | import java.util.ArrayList; |
4 | import java.util.Iterator; |
5 | import java.util.List; |
6 | |
7 | import org.eclipse.emf.ecore.EObject; |
8 | import org.eclipse.emf.ecore.resource.Resource; |
9 | |
10 | import de.uka.ipd.sdq.featureconfig.Configuration; |
11 | import de.uka.ipd.sdq.featureconfig.featureconfigFactory; |
12 | import de.uka.ipd.sdq.pcm.allocation.Allocation; |
13 | import de.uka.ipd.sdq.pcm.allocation.AllocationFactory; |
14 | import de.uka.ipd.sdq.pcm.repository.Repository; |
15 | import de.uka.ipd.sdq.pcm.repository.RepositoryFactory; |
16 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceEnvironment; |
17 | import de.uka.ipd.sdq.pcm.resourceenvironment.ResourceenvironmentFactory; |
18 | import de.uka.ipd.sdq.pcm.resourcetype.ResourceRepository; |
19 | import de.uka.ipd.sdq.pcm.resourcetype.ResourcetypeFactory; |
20 | import de.uka.ipd.sdq.pcm.system.System; |
21 | import de.uka.ipd.sdq.pcm.system.SystemFactory; |
22 | import de.uka.ipd.sdq.pcm.usagemodel.UsageModel; |
23 | import de.uka.ipd.sdq.pcm.usagemodel.UsagemodelFactory; |
24 | import de.uka.ipd.sdq.workflow.Blackboard; |
25 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition; |
26 | |
27 | /** |
28 | * This class is a specialised MDSDBlackboard partition which is specialised to load and hold PCM model |
29 | * instances. Currently, the PCM instance is loaded as a list of files, each file containing a part of the PCM |
30 | * model. It is sufficient to specify a PCM Allocation and a PCM UsageModel. All |
31 | * other model parts can then be derived automatically. |
32 | * |
33 | * Note that there is no specialised {@link Blackboard} for PCMResourceSetPartitions, because |
34 | * usually, the Blackboard containing the PCM might contain other models, for example SAAM models |
35 | * when transforming one into the other. |
36 | * |
37 | * |
38 | * @author Steffen Becker |
39 | * |
40 | */ |
41 | public class PCMResourceSetPartition extends ResourceSetPartition { |
42 | |
43 | /** |
44 | * @return Returns the PCM repository instance of the PCM model |
45 | */ |
46 | public List<Repository> getRepositories() { |
47 | // TODO: Allow using multiple Repositories, derive the list of repositories automatically |
48 | List<Repository> allRepositories = getElement(RepositoryFactory.eINSTANCE.createRepository()); |
49 | Iterator<Repository> iterator = allRepositories.iterator(); |
50 | List<Repository> resultList = new ArrayList<Repository>(); |
51 | while(iterator.hasNext()) { |
52 | resultList.add((Repository)iterator.next()); |
53 | } |
54 | return resultList; |
55 | } |
56 | |
57 | /** |
58 | * @return Returns a PCM Repository which contains components of Steffen's and Jens' middleware completions |
59 | */ |
60 | public Repository getMiddlewareRepository() { |
61 | return (Repository) getElement(RepositoryFactory.eINSTANCE.createRepository()).get(0); |
62 | } |
63 | |
64 | /** |
65 | * @return Returns the feature configuration which annotates connectors with their technical realisation |
66 | */ |
67 | public Configuration getFeatureConfig() { |
68 | return (Configuration) getElement(featureconfigFactory.eINSTANCE.createConfiguration()).get(0); |
69 | } |
70 | |
71 | /** |
72 | * @return Returns the PCM system instance of the stored PCM model |
73 | */ |
74 | public System getSystem() { |
75 | return (System) getElement(SystemFactory.eINSTANCE.createSystem()).get(0); |
76 | } |
77 | |
78 | /** |
79 | * @return Returns the PCM system's allocation model |
80 | */ |
81 | public Allocation getAllocation() { |
82 | return (Allocation) getElement(AllocationFactory.eINSTANCE.createAllocation()).get(0); |
83 | } |
84 | |
85 | /** |
86 | * @return Returns the PCM usage model of the PCM model in this blackboard partition |
87 | */ |
88 | public UsageModel getUsageModel() { |
89 | return (UsageModel) getElement(UsagemodelFactory.eINSTANCE.createUsageModel()).get(0); |
90 | } |
91 | |
92 | /** |
93 | * @return Returns the PCM Resource Type Repository used by the stored PCM model instance |
94 | */ |
95 | public ResourceRepository getResourceTypeRepository() { |
96 | return (ResourceRepository) getElement(ResourcetypeFactory.eINSTANCE.createResourceRepository()).get(0); |
97 | } |
98 | |
99 | /** |
100 | * @return Returns the PCM Resource Environment used by the stored PCM model instance |
101 | */ |
102 | public ResourceEnvironment getResourceEnvironment() { |
103 | return (ResourceEnvironment) getElement(ResourceenvironmentFactory.eINSTANCE.createResourceEnvironment()).get(0); |
104 | } |
105 | |
106 | /** |
107 | * Helper to find root objects of a specified class. |
108 | * |
109 | * @param clazz The class to get elements for. |
110 | * @return The list of found root elements. Empty list if none have been found. |
111 | */ |
112 | @SuppressWarnings("unchecked") |
113 | public <T extends EObject> List<T> getElement(final T targetType) { |
114 | ArrayList<T> result = new ArrayList<T>(); |
115 | for (Resource r : rs.getResources()) { |
116 | if (r != null && r.getContents().size() > 0 && r.getContents().get(0).eClass() == targetType.eClass() ) { |
117 | result.add((T) r.getContents().get(0)); |
118 | } |
119 | } |
120 | if (result.size() == 0) |
121 | throw new RuntimeException("Failed to retrieve PCM model element "+targetType.eClass().getName()); |
122 | else |
123 | return result; |
124 | } |
125 | |
126 | } |