Child: [b3cf88] (diff)

Download this file

EPCManager.java    175 lines (133 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package converter;
import bpcf.BPCtrlFlowModel;
import bpcf.BPElement;
import bpcf.BpcfFactory;
import bpcf.Start;
import epc.*;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.UUID;
/**
* Created by miguel on 06-05-2014.
*/
public class EPCManager implements Manager {
private EpcFactory epcFactory;
private EPCModel epcModel;
private HashMap<String, Object> elements;
int n = 0;
public EPCManager() {
epcFactory = EpcFactory.eINSTANCE;
epcModel = epcFactory.createEPCModel();
elements = new HashMap<String, Object>();
}
public void addActivity(String id, String name) {
System.out.println(".. Adding Activity " + name);
Function function = epcFactory.createFunction();
function.setUuid(id);
function.setName(name);
epcModel.getElements().add(function);
elements.put(id, function);
}
@Override
public void addFlow(String idFrom, String idTo) {
System.out.println("Adding flow from " + ((EPCFlowNode)elements.get(idFrom)).getName() + " to " + ((EPCFlowNode)elements.get(idTo)).getName() + "...");
if (n < 4) {
n++;
}
FlowConnection connection = epcFactory.createFlowConnection();
connection.setUuid(UUID.randomUUID().toString());
connection.setSource((EPCFlowNode) elements.get(idFrom));
connection.setTarget((EPCFlowNode) elements.get(idTo));
epcModel.getConnections().add(connection);
((EPCFlowNode) elements.get(idFrom)).getOutgoing().add(connection);
((EPCFlowNode) elements.get(idTo)).getIncoming().add(connection);
}
public void addMerge(String id, String name) {
System.out.println(".. Adding Merge Element " + name);
JoinLogicGate merge = epcFactory.createJoinLogicGate();
merge.setUuid(id);
merge.setName(name);
epcModel.getElements().add(merge);
elements.put(id, merge);
}
public void addFork(String id, String name) {
System.out.println(".. Adding Fork Element " + name);
SplitLogicGate fork = epcFactory.createSplitLogicGate();
fork.setUuid(id);
fork.setName(name);
epcModel.getElements().add(fork);
elements.put(id, fork);
}
public void addJoin(String id, String name) {
System.out.println(".. Adding Join Element " + name);
JoinLogicGate join = epcFactory.createJoinLogicGate();
join.setUuid(id);
join.setName(name);
epcModel.getElements().add(join);
elements.put(id, join);
}
public void addDecision(String id, String name) {
System.out.println(".. Adding Decision Element " + name);
SplitLogicGate decision = epcFactory.createSplitLogicGate();
decision.setUuid(id);
decision.setGateType(LogicGateType.XOR);
decision.setName(name);
epcModel.getElements().add(decision);
elements.put(id, decision);
}
public void addStart(String id, String name) {
System.out.println(".. Adding Start Element " + name);
Event start = epcFactory.createEvent();
start.setName(name);
start.setUuid(id);
elements.put(id, start);
epcModel.getElements().add(start);
}
@Override
public void addArtificialStart(String flowToId) {
}
public void addFinish(String id, String name) {
System.out.println(".. Adding Finish Element " + name);
Event end = epcFactory.createEvent();
end.setUuid(id);
end.setName(name);
elements.put(id, end);
epcModel.getElements().add(end);
}
@Override
public void addArtificialFinish(String flowFromId) {
}
public void saveModel(String path) {
System.out.println("Saving model in " + path + "...");
ResourceSet resSet = new ResourceSetImpl();
resSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
Resource.Factory.Registry.DEFAULT_EXTENSION, new org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl());
String newFileString = new File(path).getAbsolutePath();
URI fileURI = URI.createFileURI(newFileString);
Resource resource = resSet.createResource(fileURI);
resource.getContents().add(epcModel);
try {
resource.save(Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
}
public HashMap<String, Object> getElements() {
return elements;
}
public static void main(String[] args) {
BpcfFactory factory = BpcfFactory.eINSTANCE;
BPCtrlFlowModel bpCtrlFlowModel = factory.createBPCtrlFlowModel();
// bpCtrlFlowModel.getBpElements().add(start);
BPElement start = factory.createStart();
Start start1 = factory.createStart();
// System.out.println(StartImpl.class);
// bpCtrlFlowModel.getStartEvents().add(start);
}
}