1 | package de.uka.ipd.sdq.workflow.pcm.jobs; |
2 | |
3 | import org.apache.log4j.Logger; |
4 | import org.eclipse.core.runtime.IProgressMonitor; |
5 | |
6 | import de.uka.ipd.sdq.workflow.IBlackboardInteractingJob; |
7 | import de.uka.ipd.sdq.workflow.IJob; |
8 | import de.uka.ipd.sdq.workflow.exceptions.JobFailedException; |
9 | import de.uka.ipd.sdq.workflow.exceptions.RollbackFailedException; |
10 | import de.uka.ipd.sdq.workflow.exceptions.UserCanceledException; |
11 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.MDSDBlackboard; |
12 | import de.uka.ipd.sdq.workflow.mdsd.blackboard.ResourceSetPartition; |
13 | import de.uka.ipd.sdq.workflow.pcm.configurations.AbstractCodeGenerationWorkflowRunConfiguration; |
14 | import de.uka.ipd.sdq.workflow.pcm.configurations.AbstractPCMWorkflowRunConfiguration; |
15 | |
16 | public class LoadMiddlewareConfigurationIntoBlackboardJob |
17 | implements IJob, IBlackboardInteractingJob<MDSDBlackboard> { |
18 | |
19 | private Logger logger = Logger.getLogger(LoadPCMModelsIntoBlackboardJob.class); |
20 | |
21 | public static final String MIDDLEWARE_PARTITION_ID = "de.uka.ipd.sdq.pcmmodels.partition.middleware"; |
22 | public static final String EVENT_MIDDLEWARE_PARTITION_ID = "de.uka.ipd.sdq.pcmmodels.partition.eventmiddleware"; |
23 | |
24 | private MDSDBlackboard blackboard = null; |
25 | private AbstractPCMWorkflowRunConfiguration configuration = null; |
26 | |
27 | public LoadMiddlewareConfigurationIntoBlackboardJob(AbstractCodeGenerationWorkflowRunConfiguration config) { |
28 | super(); |
29 | |
30 | this.configuration = config; |
31 | } |
32 | |
33 | public void execute(IProgressMonitor monitor) throws JobFailedException, |
34 | UserCanceledException { |
35 | ResourceSetPartition middlewareRepositoryPartition = null; |
36 | if (!this.blackboard.hasPartition(MIDDLEWARE_PARTITION_ID)) { |
37 | logger.debug("Creating Middleware Repository Partition"); |
38 | |
39 | middlewareRepositoryPartition = new ResourceSetPartition(); |
40 | this.blackboard.addPartition(MIDDLEWARE_PARTITION_ID, middlewareRepositoryPartition); |
41 | |
42 | logger.debug("Initialising Middleware EPackages"); |
43 | middlewareRepositoryPartition.initialiseResourceSetEPackages(AbstractPCMWorkflowRunConfiguration.PCM_EPACKAGES); |
44 | } else { |
45 | middlewareRepositoryPartition = this.blackboard.getPartition(MIDDLEWARE_PARTITION_ID); |
46 | } |
47 | middlewareRepositoryPartition.loadModel(configuration.getMiddlewareFile()); |
48 | |
49 | // load event middleware |
50 | ResourceSetPartition eventMiddlewareRepositoryPartition = null; |
51 | if (!this.blackboard.hasPartition(EVENT_MIDDLEWARE_PARTITION_ID)) { |
52 | logger.debug("Creating Event Middleware Repository Partition"); |
53 | |
54 | eventMiddlewareRepositoryPartition = new ResourceSetPartition(); |
55 | this.blackboard.addPartition(EVENT_MIDDLEWARE_PARTITION_ID, eventMiddlewareRepositoryPartition); |
56 | |
57 | logger.debug("Initialising Event Middleware EPackages"); |
58 | eventMiddlewareRepositoryPartition.initialiseResourceSetEPackages(AbstractPCMWorkflowRunConfiguration.PCM_EPACKAGES); |
59 | } else { |
60 | eventMiddlewareRepositoryPartition = this.blackboard.getPartition(EVENT_MIDDLEWARE_PARTITION_ID); |
61 | } |
62 | if (configuration.getEventMiddlewareFile() != null) { |
63 | eventMiddlewareRepositoryPartition.loadModel(configuration.getEventMiddlewareFile()); |
64 | } |
65 | } |
66 | |
67 | public String getName() { |
68 | return "Load Middleware Configuration into Blackboard"; |
69 | } |
70 | |
71 | public void rollback(IProgressMonitor monitor) |
72 | throws RollbackFailedException { |
73 | this.blackboard.removePartition(MIDDLEWARE_PARTITION_ID); |
74 | } |
75 | |
76 | public void setBlackboard(MDSDBlackboard blackboard) { |
77 | this.blackboard = blackboard; |
78 | } |
79 | |
80 | } |