EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.workflow.pcm.jobs]

COVERAGE SUMMARY FOR SOURCE FILE [EventsTransformationJob.java]

nameclass, %method, %block, %line, %
EventsTransformationJob.java0%   (0/1)0%   (0/8)0%   (0/215)0%   (0/56)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class EventsTransformationJob0%   (0/1)0%   (0/8)0%   (0/215)0%   (0/56)
EventsTransformationJob (AbstractPCMWorkflowRunConfiguration): void 0%   (0/1)0%   (0/6)0%   (0/3)
execute (IProgressMonitor): void 0%   (0/1)0%   (0/77)0%   (0/20)
getEventMiddlewareModel (MDSDBlackboard): ModelLocation 0%   (0/1)0%   (0/21)0%   (0/4)
getName (): String 0%   (0/1)0%   (0/2)0%   (0/1)
getProject (String): IProject 0%   (0/1)0%   (0/5)0%   (0/2)
getRequiredModels (MDSDBlackboard): ModelLocation [] 0%   (0/1)0%   (0/99)0%   (0/23)
rollback (IProgressMonitor): void 0%   (0/1)0%   (0/1)0%   (0/1)
setBlackboard (MDSDBlackboard): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package de.uka.ipd.sdq.workflow.pcm.jobs;
2 
3import java.util.ArrayList;
4import java.util.HashMap;
5 
6import org.eclipse.core.resources.IProject;
7import org.eclipse.core.resources.ResourcesPlugin;
8import org.eclipse.core.runtime.IProgressMonitor;
9import org.eclipse.emf.common.util.URI;
10import org.eclipse.emf.ecore.resource.Resource;
11 
12import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob;
13import de.uka.ipd.sdq.workflow.exceptions.JobFailedException;
14import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException;
15import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException;
16import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard;
17import de.uka.ipd.sdq.workflow.mdsd.blackboard.ModelLocation;
18import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition;
19import de.uka.ipd.sdq.workflow.mdsd.blackboard.SavePartitionToDiskJob;
20import de.uka.ipd.sdq.workflow.mdsd.emf.qvto.QVTOTransformationJob;
21import de.uka.ipd.sdq.workflow.mdsd.emf.qvto.QVTOTransformationJobConfiguration;
22import de.uka.ipd.sdq.workflow.pcm.configurations.AbstractPCMWorkflowRunConfiguration;
23 
24/**
25 * Workflow job to transform the event related model elements to classic 
26 * pcm model elements
27 * 
28 * @author Benjamin Klatt <klatt@fzi.de>
29 */
30public class EventsTransformationJob 
31        implements IBlackboardInteractingJob<MDSDBlackboard> {
32        
33        /** Path to the qvto transformation script */
34        protected static final String TRANSFORMATION_SCRIPT = "platform:/plugin/de.uka.ipd.sdq.pcm.resources/transformations/events/transformation-psm.qvto";
35 
36        private static final String TRACESFOLDER = "traces";
37        
38        /** Reference to the blackboard to access it in the complete job */
39        private MDSDBlackboard blackboard;
40        
41        /** SimuCom configuration to be used in this job */
42        private AbstractPCMWorkflowRunConfiguration configuration;
43                
44        /**
45         * Constructor providing access to the SimuCom workflow specific configuration.. 
46         * 
47         * @param configuration The configuration object to work with.
48         */
49        public EventsTransformationJob(AbstractPCMWorkflowRunConfiguration configuration) {
50                super();
51                this.configuration = configuration;
52        }
53 
54        public void execute(IProgressMonitor monitor) throws JobFailedException,
55                        UserCanceledException {
56                
57                // get the models to work with
58                ModelLocation[] modelLocations = getRequiredModels(blackboard);
59                
60                configuration.getEventMiddlewareFile();
61                
62                // build file paths
63                URI traceFileURI = URI.createURI(getProject(configuration.getStoragePluginID())
64                                .getFolder(TRACESFOLDER)
65                                .getFullPath().toOSString());
66                URI scriptFileURI = URI.createURI(TRANSFORMATION_SCRIPT);
67                
68                // configure the QVTO Job
69                QVTOTransformationJobConfiguration qvtoConfig = new QVTOTransformationJobConfiguration();
70                qvtoConfig.setInoutModels(modelLocations);
71                qvtoConfig.setTraceFileURI(traceFileURI);
72                qvtoConfig.setScriptFileURI(scriptFileURI);
73                qvtoConfig.setOptions(new HashMap<String,Object>());
74                
75                // create and add the qvto job
76                QVTOTransformationJob job = new QVTOTransformationJob(qvtoConfig);
77                job.setBlackboard(blackboard);
78                job.execute(monitor);
79                
80                // add the event middleware model to the blackboard
81                ResourceSetPartition partition = blackboard.getPartition(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID);
82                partition.loadModel(configuration.getEventMiddlewareFile());
83                
84                // save the modified model
85                SavePartitionToDiskJob savePartitionJob = new SavePartitionToDiskJob(LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID);
86                savePartitionJob.setBlackboard(blackboard);
87                savePartitionJob.execute(monitor);
88                
89        }
90 
91        /**
92         * Build the location objects out of the blackboards PCM model partition.
93         * 
94         * @param blackboard        The blackboard to work with.
95         * @return        The prepared model locations for the PCM models.
96         */
97        private ModelLocation[] getRequiredModels(MDSDBlackboard blackboard) {
98                
99                // prepare the models required for the transformation
100                ModelLocation allocationModelLocation = null;
101                ModelLocation systemModelLocation = null;
102                ModelLocation repositoryModelLocation = null;
103                
104                // find the models in the blackboard
105                String pcmModelPartitionId = LoadPCMModelsIntoBlackboardJob.PCM_MODELS_PARTITION_ID;
106                ResourceSetPartition partition = blackboard.getPartition(pcmModelPartitionId);
107                partition.resolveAllProxies();
108                for (Resource r : partition.getResourceSet().getResources()) {
109                        URI modelURI = r.getURI();
110                        String fileExtension = modelURI.fileExtension();
111                        
112                        if(fileExtension.equals("allocation")){
113                                allocationModelLocation = new ModelLocation(pcmModelPartitionId, modelURI);
114                        }
115                        
116                        if(fileExtension.equals("system")){
117                                systemModelLocation = new ModelLocation(pcmModelPartitionId, modelURI);
118                        }
119                        
120                        if(fileExtension.equals("repository") 
121                                        && repositoryModelLocation == null
122                                        && !modelURI.toString().startsWith("pathmap://")){
123                                repositoryModelLocation = new ModelLocation(pcmModelPartitionId, modelURI);
124                        }
125                }
126                
127                // Build the model location list
128                ArrayList<ModelLocation> modelLocations = new ArrayList<ModelLocation>();
129                modelLocations.add(allocationModelLocation);
130                modelLocations.add(systemModelLocation);
131                modelLocations.add(repositoryModelLocation);
132 
133                // add the additional event middleware model
134                modelLocations.add(getEventMiddlewareModel(blackboard));
135                
136                
137                return modelLocations.toArray(new ModelLocation[]{});
138        }
139 
140        /**
141         * Get the middleware repository from the appropriate blackboard partition
142         * 
143         * @param blackboard The blackboard to get the model from
144         * @return The event middleware model
145         */
146        private ModelLocation getEventMiddlewareModel(MDSDBlackboard blackboard) {
147                
148                ResourceSetPartition eventMiddlewarePartition = blackboard.getPartition(LoadPCMModelsIntoBlackboardJob.EVENT_MIDDLEWARE_PARTITION_ID);
149                eventMiddlewarePartition.resolveAllProxies();
150                
151                // Only the first resource is necessary. 
152                // All the others are eventually referenced models like the PrimitiveTypes repository we do not need here
153                Resource r = eventMiddlewarePartition.getResourceSet().getResources().get(0);
154                return new ModelLocation(LoadPCMModelsIntoBlackboardJob.EVENT_MIDDLEWARE_PARTITION_ID, r.getURI());
155        }
156 
157        public void setBlackboard(MDSDBlackboard blackboard) {
158                this.blackboard = blackboard;
159        }
160 
161        public String getName() {
162                return "Add event transformation job";
163        }
164 
165        public void rollback(IProgressMonitor monitor)
166                        throws RollbackFailedException {
167                // Nothing to do for the roll back
168        }        
169        
170        /**
171         * returns a new project to be used for the simulation
172         * 
173         * @return a handle to the project to be used for the simulation
174         */
175        public static IProject getProject(String projectId) {
176                return ResourcesPlugin.getWorkspace().getRoot().getProject(
177                                projectId);
178        }
179 
180}

[all classes][de.uka.ipd.sdq.workflow.pcm.jobs]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov