本文整理汇总了Java中org.jbpt.throwable.SerializationException类的典型用法代码示例。如果您正苦于以下问题:Java SerializationException类的具体用法?Java SerializationException怎么用?Java SerializationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerializationException类属于org.jbpt.throwable包,在下文中一共展示了SerializationException类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyzeSoundness
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
/**
* Uses the LoLA service to check the soundness of the given {@link PetriNet}.
* @param petrinet to check
* @return true if Petri net is sound
* @throws IOException
* @throws TimeoutException
* @throws SerializationException
* @throws IOException
*/
public static LolaSoundnessCheckerResult analyzeSoundness(NetSystem net) throws SerializationException, IOException {
String pnml = PNMLSerializer.serializePetriNet(net, PNMLSerializer.LOLA);
LolaSoundnessCheckerResult result = new LolaSoundnessCheckerResult();
for (int i=0; i<LolaSoundnessChecker.N; i++) {
String response = callLola(pnml, LOLA_URI);
try { result.parseResult(response, net); }
catch (IllegalArgumentException e) {
if (i==LolaSoundnessChecker.N-1) throw new IOException("Lola service failure!");
continue;
}
return result;
}
return result;
}
示例2: serializePetriNet
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
/**
* Creates a PNML XML string from the given {@link PetriNet}.
* @param net {@link PetriNet} to transform into PNML-String
* @param tool integer indicating the tool
* @return PNML string
* @throws SerializationException
*/
public static String serializePetriNet(NetSystem net, int tool) throws SerializationException {
Document doc = PNMLSerializer.serialize(net, tool);
if (doc == null) {
return null;
}
DOMSource domSource = new DOMSource(doc);
StreamResult streamResult = new StreamResult(new StringWriter());
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer;
try {
serializer = tf.newTransformer();
//serializer.setOutputProperty(OutputKeys.INDENT,"yes");
serializer.transform(domSource, streamResult);
} catch (TransformerException e) {
e.printStackTrace();
throw new SerializationException(e.getMessage());
}
return ((StringWriter) streamResult.getWriter()).getBuffer().toString();
}
示例3: storeNetSystem
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
@Override
public int storeNetSystem(INetSystem<F,N,P,T,M> sys, String externalID) throws SQLException {
// TODO: check why PNMLSerializer.serializePetriNet throws SerializationException
// TODO: implement SerializationException for interfaces
try {
String pnmlContent = PNMLSerializer.serializePetriNet((NetSystem) sys);
return this.storeNetSystem(pnmlContent,sys,externalID);
} catch (SerializationException e) {
return 0;
}
}
示例4: loadProcess
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
protected ProcessModel loadProcess(String filename) throws SerializationException, IOException {
String line;
StringBuilder sb = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(filename));
while ((line = reader.readLine()) != null) {
sb.append(line);
}
reader.close();
return JSON2Process.convert(sb.toString());
}
示例5: testJSON2Process
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
public void testJSON2Process() {
String json = "{'name' : 'test case', " +
"'tasks' : [{'id' : 'task1', 'label' : 'Task 1'}, " +
"{'id' : 'task2', 'label' : 'Task 2'}," +
"{'id' : 'task3', 'label' : 'Task 3'}], " +
"'gateways' : [{'id' : 'gate1', type : 'XOR'}], " +
"'flows' : [{'src' : 'task1', 'tgt' : 'gate1', 'label' : null}," +
"{'src' : 'gate1', 'tgt' : 'task2', 'label' : 'x > 3'}," +
"{'src' : 'gate1', 'tgt' : 'task3', 'label' : 'x <= 3'}]}";
ProcessModel process = null;
try {
process = JSON2Process.convert(json);
} catch(SerializationException e) {}
assertNotNull(process);
assertEquals(process.getName(), "test case");
ArrayList<Activity> tasks = (ArrayList<Activity>) process.getActivities();
assertEquals(tasks.size(), 3);
for (Activity task:tasks) {
assertTrue(task.getId().matches("task[123]"));
assertTrue(task.getName().matches("Task [123]"));
}
assertEquals(process.getGateways().size(), 1);
Gateway gate = (Gateway) process.getGateways().toArray()[0];
assertTrue(gate instanceof XorGateway);
assertEquals(gate.getId(), "gate1");
assertEquals(process.getControlFlow().size(), 3);
ArrayList<ControlFlow<FlowNode>> flows = (ArrayList<ControlFlow<FlowNode>>) process.getControlFlow();
for (ControlFlow<FlowNode> flow:flows) {
assertTrue(flow.getSource().getId().matches("(task1|gate1)"));
assertTrue(flow.getTarget().getId().matches("(task[23]|gate1)"));
}
}
示例6: testProcess2JSON
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
public void testProcess2JSON() {
ProcessModel process = new ProcessModel("test case");
Activity task1 = new Activity("Task 1");
task1.setId("task1");
process.addVertex(task1);
Activity task2 = new Activity("Task 2");
task2.setId("task2");
process.addVertex(task2);
Activity task3 = new Activity("Task 3");
task3.setId("task3");
process.addVertex(task3);
Gateway gate1 = new XorGateway();
gate1.setId("gate1");
process.addVertex(gate1);
ControlFlow<FlowNode> flow1 = process.addControlFlow(task1, gate1);
flow1.setLabel(null);
ControlFlow<FlowNode> flow2 = process.addControlFlow(gate1, task2);
flow2.setLabel("x > 3");
ControlFlow<FlowNode> flow3 = process.addControlFlow(gate1, task3);
flow3.setLabel("x <= 3");
String json = null;
try {
json = Process2JSON.convert(process);
} catch(SerializationException e) {}
assertNotNull(json);
assertTrue(json.matches("^\\{.*?\"name\":\"test case\".*?\\}$"));
assertTrue(json.matches(".*?\"tasks\":\\[\\{.*?\\},\\{.*?\\},\\{.*?\\}\\].*?"));
assertTrue(json.matches(".*?\\{(\"id\":\"task1\"|,|\"label\":\"Task 1\"){3}\\}.*?"));
assertTrue(json.matches(".*?\\{(\"id\":\"task2\"|,|\"label\":\"Task 2\"){3}\\}.*?"));
assertTrue(json.matches(".*?\\{(\"id\":\"task3\"|,|\"label\":\"Task 3\"){3}\\}.*?"));
assertTrue(json.matches(".*?\"gateways\":\\[\\{(\"id\":\"gate1\"|,|\"type\":\"XOR\"){3}\\}\\].*?"));
assertTrue(json.matches(".*?\"flows\":\\[\\{.*?\\},\\{.*?\\},\\{.*?\\}\\].*?"));
assertTrue(json.matches(".*?\\{(\"src\":\"task1\"|\"tgt\":\"gate1\"|,|\"label\":null){5}\\}.*?"));
assertTrue(json.matches(".*?\\{(\"src\":\"gate1\"|\"tgt\":\"task2\"|,|\"label\":\"x > 3\"){5}\\}.*?"));
assertTrue(json.matches(".*?\\{(\"src\":\"gate1\"|\"tgt\":\"task3\"|,|\"label\":\"x <= 3\"){5}\\}.*?"));
}
示例7: testSerializationException
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
public void testSerializationException() {
String json = "{'name' : 'test case', 'tasks' : [], 'gateways' : []}";
try {
JSON2Process.convert(json);
assertTrue("Should throw exception.", false);
} catch (Exception e) {
assertEquals(SerializationException.class, e.getClass());
}
}
示例8: testWrongGatewayType
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
public void testWrongGatewayType() {
String json = "{'name' : 'test case', 'tasks' : [], 'gateways' : [{'id' : 'gate1', type : 'FOR'}], 'flows' : []}";
try {
JSON2Process.convert(json);
assertTrue("Should throw exception.", false);
} catch (Exception e) {
assertEquals(SerializationException.class, e.getClass());
assertEquals("Couldn't determine GatewayType.", e.getMessage());
}
}
示例9: determineGatewayType
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
private static String determineGatewayType(Gateway gateway) throws SerializationException {
if (gateway instanceof XorGateway)
return IGatewayType.XOR;
if (gateway instanceof AndGateway)
return IGatewayType.AND;
if (gateway instanceof OrGateway)
return IGatewayType.OR;
throw new SerializationException("GatewayType is UNDEFINED.");
}
示例10: convert
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
public static ProcessModel convert(String json) throws SerializationException {
try {
return convert(new JSONObject(json));
} catch (JSONException e) {
throw new SerializationException(e.getMessage());
}
}
示例11: convert
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
public static String convert(ProcessModel process) throws SerializationException {
try {
JSONObject json = new JSONObject();
json.put("name", process.getName());
JSONArray tasks = new JSONArray();
for (Activity task:process.getActivities()) {
JSONObject jTask = new JSONObject();
jTask.put("id", task.getId());
jTask.put("label", task.getName());
tasks.put(jTask);
}
json.put("tasks", tasks);
JSONArray events = new JSONArray();
for (Event event:process.getEvents()) {
JSONObject jEvent = new JSONObject();
jEvent.put("id", event.getId());
jEvent.put("label", event.getName());
events.put(jEvent);
}
json.put("events", events);
JSONArray gateways = new JSONArray();
for (Gateway gate:process.getGateways()) {
JSONObject jGate = new JSONObject();
jGate.put("id", gate.getId());
if (!gate.getName().equals(""))
jGate.put("label", gate.getName());
jGate.put("type", determineGatewayType(gate));
gateways.put(jGate);
}
json.put("gateways", gateways);
JSONArray flows = new JSONArray();
for (ControlFlow<FlowNode> flow:process.getControlFlow()) {
JSONObject jFlow = new JSONObject();
jFlow.put("src", flow.getSource().getId());
jFlow.put("tgt", flow.getTarget().getId());
if (flow.getLabel() == null)
jFlow.put("label", JSONObject.NULL);
else
jFlow.put("label", flow.getLabel());
flows.put(jFlow);
}
json.put("flows", flows);
return json.toString();
} catch(JSONException e) {
throw new SerializationException(e.getMessage());
}
}
示例12: serialize
import org.jbpt.throwable.SerializationException; //导入依赖的package包/类
/**
* Serializes the given PetriNet to PNML and returns the according Document object.
*
* @param the PetriNet
* @param tool integer indicating the tool
* @return Document object
*/
public static Document serialize(NetSystem net, int tool) throws SerializationException {
if (net == null) {
return null;
}
DocumentBuilderFactory docBFac = DocumentBuilderFactory.newInstance();
Document doc = null;
try {
DocumentBuilder docBuild = docBFac.newDocumentBuilder();
DOMImplementation impl = docBuild.getDOMImplementation();
doc = impl.createDocument("http://www.pnml.org/version-2009/grammar/pnml", "pnml", null);
} catch (ParserConfigurationException e) {
e.printStackTrace();
throw new SerializationException(e.getMessage());
}
Element root = doc.getDocumentElement();
Element netNode = doc.createElement("net");
root.appendChild(netNode);
if (!net.getId().equals(""))
netNode.setAttribute("id", net.getId());
else
netNode.setAttribute("id", "ptnet");
netNode.setAttribute("type", "http://www.pnml.org/version-2009/grammar/ptnet");
addElementWithText(doc, netNode, "name", net.getName());
Element page = doc.createElement("page");
page.setAttribute("id", "page0");
netNode.appendChild(page);
for (Place place:net.getPlaces()) {
addPlace(doc, page, net, place);
}
for (Transition trans:net.getTransitions()) {
addTransition(doc, page, trans);
}
for (Flow flow:net.getFlow()) {
addFlow(doc, page, flow);
}
if (tool == LOLA)
addFinalMarkings(doc, page, net);
return doc;
}