Author: koen.aers(a)jboss.com
Date: 2009-01-21 19:33:50 -0500 (Wed, 21 Jan 2009)
New Revision: 13175
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java
Log:
GPD-287: Support preservation of unknown attributes
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java 2009-01-21
23:10:50 UTC (rev 13174)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlDeserializer.java 2009-01-22
00:33:50 UTC (rev 13175)
@@ -22,28 +22,36 @@
public class JpdlDeserializer {
- interface AttributeHandler {
- void processAttributes(Wrapper wrapper, Element element);
+ interface AttributeDeserializer {
+ void deserializeAttributes(Wrapper wrapper, Element element);
}
- interface ChildNodeHandler {
- Wrapper processChildNode(Wrapper parent, Node node);
+ interface ChildNodeDeserializer {
+ Wrapper deserializeChildNode(Wrapper parent, Node node);
}
interface PostProcessor {
void postProcess(Wrapper wrapper);
}
- class ProcessAttributeHandler implements AttributeHandler {
- public void processAttributes(Wrapper wrapper, Element element) {
+ class DefaultAttributeDeserializer implements AttributeDeserializer {
+ public void deserializeAttributes(Wrapper wrapper, Element element) {
+ wrapper.getElement().setMetaData("attributes", element.getAttributes());
+ }
+ }
+
+ class ProcessAttributeHandler extends DefaultAttributeDeserializer {
+ public void deserializeAttributes(Wrapper wrapper, Element element) {
+ super.deserializeAttributes(wrapper, element);
if (!(wrapper instanceof FlowWrapper)) return;
FlowWrapper flowWrapper = (FlowWrapper)wrapper;
((Flow)flowWrapper.getElement()).setName(element.getAttribute("name"));
}
}
- class NodeAttributeHandler implements AttributeHandler {
- public void processAttributes(Wrapper wrapper, Element element) {
+ class NodeAttributeHandler extends DefaultAttributeDeserializer {
+ public void deserializeAttributes(Wrapper wrapper, Element element) {
+ super.deserializeAttributes(wrapper, element);
if (!(wrapper instanceof NodeWrapper)) return;
NodeWrapper nodeWrapper = (NodeWrapper)wrapper;
addGraphics(nodeWrapper, element);
@@ -51,8 +59,9 @@
}
}
- class ConnectionAttributeHandler implements AttributeHandler {
- public void processAttributes(Wrapper wrapper, Element element) {
+ class ConnectionAttributeHandler extends DefaultAttributeDeserializer {
+ public void deserializeAttributes(Wrapper wrapper, Element element) {
+ super.deserializeAttributes(wrapper, element);
if (!(wrapper instanceof ConnectionWrapper)) return;
ConnectionWrapper connectionWrapper = (ConnectionWrapper)wrapper;
addGraphics(connectionWrapper, element);
@@ -60,8 +69,8 @@
}
}
- class ProcessChildNodeHandler implements ChildNodeHandler {
- public Wrapper processChildNode(Wrapper parent, Node node) {
+ class ProcessChildNodeHandler implements ChildNodeDeserializer {
+ public Wrapper deserializeChildNode(Wrapper parent, Node node) {
Wrapper result = null;
if (!(parent instanceof FlowWrapper)) return result;
FlowWrapper flowWrapper = (FlowWrapper)parent;
@@ -75,9 +84,9 @@
}
}
- class NodeChildNodeHandler implements ChildNodeHandler {
+ class NodeChildNodeHandler implements ChildNodeDeserializer {
@SuppressWarnings("unchecked")
- public Wrapper processChildNode(Wrapper parent, Node node) {
+ public Wrapper deserializeChildNode(Wrapper parent, Node node) {
Wrapper result = null;
if (!(parent instanceof NodeWrapper)) return result;
NodeWrapper nodeWrapper = (NodeWrapper)parent;
@@ -139,16 +148,16 @@
if (elementId == null) return null;
Wrapper result = ElementRegistry.createWrapper(elementId);
if (result == null) return null;
- AttributeHandler attributeHandler = getAttributeHandler(result);
+ AttributeDeserializer attributeHandler = getAttributeHandler(result);
if (attributeHandler != null) {
- attributeHandler.processAttributes(result, element);
+ attributeHandler.deserializeAttributes(result, element);
}
- ChildNodeHandler childNodeHandler = getChildNodeHandler(result);
+ ChildNodeDeserializer childNodeHandler = getChildNodeHandler(result);
if (childNodeHandler != null) {
NodeList nodeList = element.getChildNodes();
ArrayList<Node> unknownNodeList = new ArrayList<Node>();
for (int i = 0; i < nodeList.getLength(); i++) {
- Wrapper childWrapper = childNodeHandler.processChildNode(result,
nodeList.item(i));
+ Wrapper childWrapper = childNodeHandler.deserializeChildNode(result,
nodeList.item(i));
if (childWrapper != null) {
childWrapper.getElement().setMetaData("leadingNodes", unknownNodeList);
unknownNodeList = new ArrayList<Node>();
@@ -172,7 +181,7 @@
return null;
}
- private AttributeHandler getAttributeHandler(Wrapper wrapper) {
+ private AttributeDeserializer getAttributeHandler(Wrapper wrapper) {
if (wrapper instanceof FlowWrapper) {
return new ProcessAttributeHandler();
} else if (wrapper instanceof NodeWrapper) {
@@ -183,7 +192,7 @@
return null;
}
- private ChildNodeHandler getChildNodeHandler(Wrapper wrapper) {
+ private ChildNodeDeserializer getChildNodeHandler(Wrapper wrapper) {
if (wrapper instanceof FlowWrapper) {
return new ProcessChildNodeHandler();
} else if (wrapper instanceof NodeWrapper) {
Modified:
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java
===================================================================
---
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java 2009-01-21
23:10:50 UTC (rev 13174)
+++
trunk/jbpm/plugins/org.jboss.tools.flow.jpdl4/src/org/jboss/tools/flow/jpdl4/editor/JpdlSerializer.java 2009-01-22
00:33:50 UTC (rev 13175)
@@ -17,11 +17,13 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.jboss.tools.flow.common.model.Element;
import org.jboss.tools.flow.common.wrapper.ConnectionWrapper;
import org.jboss.tools.flow.common.wrapper.ContainerWrapper;
+import org.jboss.tools.flow.common.wrapper.FlowWrapper;
import org.jboss.tools.flow.common.wrapper.NodeWrapper;
import org.jboss.tools.flow.common.wrapper.Wrapper;
import org.jboss.tools.flow.jpdl4.Logger;
@@ -34,6 +36,7 @@
import org.jboss.tools.flow.jpdl4.model.JavaTask;
import org.jboss.tools.flow.jpdl4.model.JoinParallelGateway;
import org.jboss.tools.flow.jpdl4.model.Process;
+import org.jboss.tools.flow.jpdl4.model.ProcessNode;
import org.jboss.tools.flow.jpdl4.model.ScriptTask;
import org.jboss.tools.flow.jpdl4.model.SequenceFlow;
import org.jboss.tools.flow.jpdl4.model.ServiceTask;
@@ -42,6 +45,7 @@
import org.jboss.tools.flow.jpdl4.model.SuperState;
import org.jboss.tools.flow.jpdl4.model.TerminateEndEvent;
import org.jboss.tools.flow.jpdl4.model.WaitTask;
+import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public class JpdlSerializer {
@@ -77,7 +81,7 @@
buffer.append(body);
appendClosing(buffer, wrapper, level);
} else {
- buffer.append("/>");
+ buffer.append("/>");
}
}
@@ -102,245 +106,448 @@
}
}
- @SuppressWarnings("unchecked")
- private void appendOpening(StringBuffer buffer, Wrapper wrapper, int level) {
- Element element = (Element)wrapper.getElement();
- ArrayList<Node> leadingNodeList =
(ArrayList<Node>)element.getMetaData("leadingNodes");
- boolean appendLeadingNodes = leadingNodeList != null &&
!leadingNodeList.isEmpty();
- if (appendLeadingNodes) {
- appendNodeList(buffer, leadingNodeList);
+ interface WrapperSerializer {
+ void appendOpening(StringBuffer buffer, Wrapper wrapper, int level);
+ }
+
+ abstract class AbstractWrapperSerializer implements WrapperSerializer {
+ protected abstract List<String> getAttributesToSave();
+ protected abstract void appendAttributeToSave(String nodeName, StringBuffer buffer,
Wrapper wrapper);
+ @SuppressWarnings("unchecked")
+ protected void appendLeadingNodes(StringBuffer buffer, Wrapper wrapper, int level) {
+ ArrayList<Node> leadingNodeList =
(ArrayList<Node>)wrapper.getElement().getMetaData("leadingNodes");
+ boolean appendLeadingNodes = leadingNodeList != null &&
!leadingNodeList.isEmpty();
+ if (appendLeadingNodes) {
+ appendNodeList(buffer, leadingNodeList);
+ } else {
+ buffer.append("\n");
+ appendPadding(buffer, level);
+ }
}
- if (element instanceof SequenceFlow) {
- SequenceFlow transition = (SequenceFlow)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
+ protected void appendDefaultAttribute(StringBuffer buffer, Node node) {
+ buffer.append(" " + node.getNodeName() + "=\"" +
node.getNodeValue() + "\"");
+ }
+ protected void appendAttributes(StringBuffer buffer, Wrapper wrapper, int level) {
+ Element element = wrapper.getElement();
+ if (element == null) return;
+ NamedNodeMap attributes =
(NamedNodeMap)element.getMetaData("attributes");
+ List<String> attributeNames = getAttributesToSave();
+ if (attributes != null) {
+ for (int i = 0; i < attributes.getLength(); i++) {
+ String nodeName = attributes.item(i).getNodeName();
+ if (attributeNames.contains(nodeName)) {
+ appendAttributeToSave(nodeName, buffer, wrapper);
+ attributeNames.remove(nodeName);
+ } else {
+ appendDefaultAttribute(buffer, attributes.item(i));
+ }
+ }
}
- buffer.append("<flow");
- if (transition.getTo() != null) {
- buffer.append(" ");
- String value = transition.getTo().getName();
- value = value == null ? "" : value;
- buffer.append("to=\"" + value + "\"");
+ for (int i = 0; i < attributeNames.size(); i++) {
+ appendAttributeToSave(attributeNames.get(i), buffer, wrapper);
+ }
+ }
+ public void appendOpening(StringBuffer buffer, Wrapper wrapper, int level) {
+ appendLeadingNodes(buffer, wrapper, level);
+ buffer.append("<" + getNodeName(wrapper.getElement()));
+ appendAttributes(buffer, wrapper, level);
+ }
+ public void appendClosing(StringBuffer buffer, Wrapper wrapper) {
+ buffer.append("</" + getNodeName(wrapper.getElement()) +
">");
+ }
+ }
+
+ private String getNodeName(Element element) {
+ IConfigurationElement configuration =
(IConfigurationElement)element.getMetaData("configurationElement");
+ String elementId = configuration.getAttribute("id");
+ if ("org.jboss.tools.flow.jpdl4.process".equals(elementId)) return
"process";
+ else if ("org.jboss.tools.flow.jpdl4.startEvent".equals(elementId)) return
"start";
+ else if ("org.jboss.tools.flow.jpdl4.terminateEndEvent".equals(elementId))
return "end";
+ else if ("org.jboss.tools.flow.jpdl4.errorEndEvent".equals(elementId)) return
"end-error";
+ else if ("org.jboss.tools.flow.jpdl4.cancelEndEvent".equals(elementId))
return "end-cancel";
+ else if ("org.jboss.tools.flow.jpdl4.waitTask".equals(elementId)) return
"state";
+ else if ("org.jboss.tools.flow.jpdl4.hqlTask".equals(elementId)) return
"hql";
+ else if ("org.jboss.tools.flow.jpdl4.sqlTask".equals(elementId)) return
"sql";
+ else if ("org.jboss.tools.flow.jpdl4.javaTask".equals(elementId)) return
"java";
+ else if ("org.jboss.tools.flow.jpdl4.scriptTask".equals(elementId)) return
"script";
+ else if ("org.jboss.tools.flow.jpdl4.serviceTask".equals(elementId)) return
"esb";
+ else if ("org.jboss.tools.flow.jpdl4.humanTask".equals(elementId)) return
"task";
+ else if ("org.jboss.tools.flow.jpdl4.exclusiveGateway".equals(elementId))
return "exclusive";
+ else if ("org.jboss.tools.flow.jpdl4.parallelJoinGateway".equals(elementId))
return "join";
+ else if ("org.jboss.tools.flow.jpdl4.parallelForkGateway".equals(elementId))
return "fork";
+ else if ("org.jboss.tools.flow.jpdl4.sequenceFlow".equals(elementId)) return
"flow";
+ else return null;
+ }
+
+ class SequenceFlowWrapperSerializer extends AbstractWrapperSerializer {
+ protected List<String> getAttributesToSave() {
+ ArrayList<String> result = new ArrayList<String>();
+ result.add("to");
+ result.add("g");
+ return result;
+ }
+ protected void appendAttributeToSave(String attributeName, StringBuffer buffer,
Wrapper wrapper) {
+ if (!(wrapper instanceof ConnectionWrapper)) return;
+ Element element = wrapper.getElement();
+ if (!(element instanceof SequenceFlow)) return;
+ if ("to".equals(attributeName)) {
+ appendTo(buffer, (SequenceFlow)element);
+ } else if ("g".equals(attributeName)) {
+ appendGraphics(buffer, (ConnectionWrapper)wrapper);
}
- appendConnectionGraphics(buffer, (ConnectionWrapper)wrapper);
- } else if (element instanceof TerminateEndEvent) {
- TerminateEndEvent terminateEndEvent = (TerminateEndEvent)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
+ }
+ protected void appendTo(StringBuffer buffer, SequenceFlow sequenceFlow) {
+ if (sequenceFlow.getTo() == null) return;
+ String value = sequenceFlow.getTo().getName();
+ if (value == null || "".equals(value)) return;
+ buffer.append(" to=\"" + value + "\"");
+ }
+ protected void appendGraphics(StringBuffer buffer, ConnectionWrapper wrapper) {
+ List<Point> bendPoints = wrapper.getBendpoints();
+ if (bendPoints == null || bendPoints.size() == 0) return;
+ buffer.append(" g=\"");
+ for (int i = 0; i < bendPoints.size(); i++) {
+ buffer.append(bendPoints.get(i).x);
+ buffer.append(",");
+ buffer.append(bendPoints.get(i).y);
+ if (i < bendPoints.size() - 1) buffer.append(";");
+ }
+ buffer.append("\"");
+ }
+ }
+
+ class ProcessNodeWrapperSerializer extends AbstractWrapperSerializer {
+ protected List<String> getAttributesToSave() {
+ ArrayList<String> result = new ArrayList<String>();
+ result.add("name");
+ result.add("g");
+ return result;
+ }
+ protected void appendAttributeToSave(String attributeName, StringBuffer buffer,
Wrapper wrapper) {
+ if (!(wrapper instanceof NodeWrapper)) return;
+ Element element = wrapper.getElement();
+ if (!(element instanceof ProcessNode)) return;
+ if ("name".equals(attributeName)) {
+ appendName(buffer, (ProcessNode)element);
+ } else if ("g".equals(attributeName)) {
+ appendGraphics(buffer, (NodeWrapper)wrapper);
}
- buffer.append("<end");
- if (!isEmpty(terminateEndEvent.getName())) {
- buffer.append(" ");
- String value = terminateEndEvent.getName();
- buffer.append("name=\"" + value + "\"");
+ }
+ protected void appendName(StringBuffer buffer, ProcessNode processNode) {
+ String value = processNode.getName();
+ if (value == null || "".equals(value)) return;
+ buffer.append(" name=\"" + value + "\"");
+ }
+ protected void appendGraphics(StringBuffer buffer, NodeWrapper wrapper) {
+ Rectangle constraint = wrapper.getConstraint();
+ buffer.append(" g=\"");
+ buffer.append(constraint.x);
+ buffer.append(",");
+ buffer.append(constraint.y);
+ buffer.append(",");
+ buffer.append(constraint.width);
+ buffer.append(",");
+ buffer.append(constraint.height);
+ buffer.append("\"");
+ }
+ }
+
+ class ProcessWrapperSerializer extends AbstractWrapperSerializer {
+ public void appendOpening(StringBuffer buffer, Wrapper wrapper, int level) {
+ buffer.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n\n");
+ buffer.append("<" + getNodeName(wrapper.getElement()));
+ appendAttributes(buffer, wrapper, level);
+ }
+ protected List<String> getAttributesToSave() {
+ ArrayList<String> result = new ArrayList<String>();
+ result.add("xmlns");
+ result.add("name");
+ result.add("initial");
+ return result;
+ }
+ protected void appendAttributeToSave(String attributeName, StringBuffer buffer,
Wrapper wrapper) {
+ if (!(wrapper instanceof FlowWrapper)) return;
+ Element element = wrapper.getElement();
+ if (element == null || !(element instanceof Process)) return;
+ if ("xmlns".equals(attributeName)) {
+ buffer.append("
xmlns=\"http://jbpm.org/4/jpdl\"");
+ } else if ("name".equals(attributeName)) {
+ appendName(buffer, (Process)element);
+ } else if ("initial".equals(attributeName)) {
+ appendInitial(buffer, (Process)element);
}
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ }
+ protected void appendName(StringBuffer buffer, Process process) {
+ String value = process.getName();
+ if (value == null || "".equals(value)) return;
+ buffer.append(" name=\"" + value + "\"");
+ }
+ protected void appendInitial(StringBuffer buffer, Process process) {
+ if (process.getInitial() == null) return;
+ String value = process.getInitial().getName();
+ if (value == null || "".equals(value)) return;
+ buffer.append(" initial=\"" + value + "\"");
+ }
+ }
+
+ private void appendOpening(StringBuffer buffer, Wrapper wrapper, int level) {
+ Element element = (Element)wrapper.getElement();
+// ArrayList<Node> leadingNodeList =
(ArrayList<Node>)element.getMetaData("leadingNodes");
+// boolean appendLeadingNodes = leadingNodeList != null &&
!leadingNodeList.isEmpty();
+// if (appendLeadingNodes) {
+// appendNodeList(buffer, leadingNodeList);
+// } else {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+ if (element instanceof SequenceFlow) {
+ new SequenceFlowWrapperSerializer().appendOpening(buffer, wrapper, level);
+// SequenceFlow transition = (SequenceFlow)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<flow");
+// if (transition.getTo() != null) {
+// buffer.append(" ");
+// String value = transition.getTo().getName();
+// value = value == null ? "" : value;
+// buffer.append("to=\"" + value + "\"");
+// }
+// appendConnectionGraphics(buffer, (ConnectionWrapper)wrapper);
+ } else if (element instanceof TerminateEndEvent) {
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// TerminateEndEvent terminateEndEvent = (TerminateEndEvent)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<end");
+// if (!isEmpty(terminateEndEvent.getName())) {
+// buffer.append(" ");
+// String value = terminateEndEvent.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof ErrorEndEvent) {
- ErrorEndEvent errorEndEvent = (ErrorEndEvent)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<end-error");
- if (!isEmpty(errorEndEvent.getName())) {
- buffer.append(" ");
- String value = errorEndEvent.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// ErrorEndEvent errorEndEvent = (ErrorEndEvent)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<end-error");
+// if (!isEmpty(errorEndEvent.getName())) {
+// buffer.append(" ");
+// String value = errorEndEvent.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof CancelEndEvent) {
- CancelEndEvent cancelEndEvent = (CancelEndEvent)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<end-cancel");
- if (!isEmpty(cancelEndEvent.getName())) {
- buffer.append(" ");
- String value = cancelEndEvent.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// CancelEndEvent cancelEndEvent = (CancelEndEvent)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<end-cancel");
+// if (!isEmpty(cancelEndEvent.getName())) {
+// buffer.append(" ");
+// String value = cancelEndEvent.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof StartEvent) {
- StartEvent startEvent = (StartEvent)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<start");
- if (!isEmpty(startEvent.getName())) {
- buffer.append(" ");
- String value = startEvent.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// StartEvent startEvent = (StartEvent)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<start");
+// if (!isEmpty(startEvent.getName())) {
+// buffer.append(" ");
+// String value = startEvent.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof SuperState) {
- SuperState superState = (SuperState)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<super-state");
- if (!isEmpty(superState.getName())) {
- buffer.append(" ");
- String value = superState.getName();
- buffer.append("name=\"" + value + "\"");
- }
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// SuperState superState = (SuperState)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<super-state");
+// if (!isEmpty(superState.getName())) {
+// buffer.append(" ");
+// String value = superState.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
} else if (element instanceof WaitTask) {
- WaitTask waitTask = (WaitTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<state");
- if (!isEmpty(waitTask.getName())) {
- buffer.append(" ");
- String value = waitTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// WaitTask waitTask = (WaitTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<state");
+// if (!isEmpty(waitTask.getName())) {
+// buffer.append(" ");
+// String value = waitTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof HqlTask) {
- HqlTask hqlTask = (HqlTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<hql");
- if (!isEmpty(hqlTask.getName())) {
- buffer.append(" ");
- String value = hqlTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// HqlTask hqlTask = (HqlTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<hql");
+// if (!isEmpty(hqlTask.getName())) {
+// buffer.append(" ");
+// String value = hqlTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof SqlTask) {
- SqlTask sqlTask = (SqlTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<sql");
- if (!isEmpty(sqlTask.getName())) {
- buffer.append(" ");
- String value = sqlTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// SqlTask sqlTask = (SqlTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<sql");
+// if (!isEmpty(sqlTask.getName())) {
+// buffer.append(" ");
+// String value = sqlTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof JavaTask) {
- JavaTask javaTask = (JavaTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<java");
- if (!isEmpty(javaTask.getName())) {
- buffer.append(" ");
- String value = javaTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// JavaTask javaTask = (JavaTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<java");
+// if (!isEmpty(javaTask.getName())) {
+// buffer.append(" ");
+// String value = javaTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof ScriptTask) {
- ScriptTask scriptTask = (ScriptTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<script");
- if (!isEmpty(scriptTask.getName())) {
- buffer.append(" ");
- String value = scriptTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// ScriptTask scriptTask = (ScriptTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<script");
+// if (!isEmpty(scriptTask.getName())) {
+// buffer.append(" ");
+// String value = scriptTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof ServiceTask) {
- ServiceTask serviceTask = (ServiceTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<esb");
- if (!isEmpty(serviceTask.getName())) {
- buffer.append(" ");
- String value = serviceTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// ServiceTask serviceTask = (ServiceTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<esb");
+// if (!isEmpty(serviceTask.getName())) {
+// buffer.append(" ");
+// String value = serviceTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof HumanTask) {
- HumanTask humanTask = (HumanTask)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<task");
- if (!isEmpty(humanTask.getName())) {
- buffer.append(" ");
- String value = humanTask.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// HumanTask humanTask = (HumanTask)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<task");
+// if (!isEmpty(humanTask.getName())) {
+// buffer.append(" ");
+// String value = humanTask.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof ExclusiveGateway) {
- ExclusiveGateway exclusiveGateway = (ExclusiveGateway)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<exclusive");
- if (!isEmpty(exclusiveGateway.getName())) {
- buffer.append(" ");
- String value = exclusiveGateway.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// ExclusiveGateway exclusiveGateway = (ExclusiveGateway)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<exclusive");
+// if (!isEmpty(exclusiveGateway.getName())) {
+// buffer.append(" ");
+// String value = exclusiveGateway.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof ForkParallelGateway) {
- ForkParallelGateway parallelForkGateway = (ForkParallelGateway)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<fork");
- if (!isEmpty(parallelForkGateway.getName())) {
- buffer.append(" ");
- String value = parallelForkGateway.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// ForkParallelGateway parallelForkGateway = (ForkParallelGateway)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<fork");
+// if (!isEmpty(parallelForkGateway.getName())) {
+// buffer.append(" ");
+// String value = parallelForkGateway.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof JoinParallelGateway) {
- JoinParallelGateway parallelJoinGateway = (JoinParallelGateway)element;
- if (!appendLeadingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("<join");
- if (!isEmpty(parallelJoinGateway.getName())) {
- buffer.append(" ");
- String value = parallelJoinGateway.getName();
- buffer.append("name=\"" + value + "\"");
- }
- appendNodeGraphics(buffer, (NodeWrapper)wrapper);
+ new ProcessNodeWrapperSerializer().appendOpening(buffer, wrapper, level);
+// JoinParallelGateway parallelJoinGateway = (JoinParallelGateway)element;
+// if (!appendLeadingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+// buffer.append("<join");
+// if (!isEmpty(parallelJoinGateway.getName())) {
+// buffer.append(" ");
+// String value = parallelJoinGateway.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
+// appendNodeGraphics(buffer, (NodeWrapper)wrapper);
} else if (element instanceof Process) {
- Process process = (Process)element;
- buffer.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n\n");
- buffer.append("<process");
- buffer.append("
xmlns=\"http://jbpm.org/4/jpdl\"");
- if (process.getInitial() != null) {
- buffer.append(" ");
- String value = process.getInitial().getName();
- value = value == null ? "" : value;
- buffer.append("initial=\"" + value + "\"");
- }
- if (!isEmpty(process.getName())) {
- buffer.append(" ");
- String value = process.getName();
- buffer.append("name=\"" + value + "\"");
- }
+ new ProcessWrapperSerializer().appendOpening(buffer, wrapper, level);
+// Process process = (Process)element;
+// buffer.append("<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n\n");
+// buffer.append("<process");
+// buffer.append("
xmlns=\"http://jbpm.org/4/jpdl\"");
+// if (process.getInitial() != null) {
+// buffer.append(" ");
+// String value = process.getInitial().getName();
+// value = value == null ? "" : value;
+// buffer.append("initial=\"" + value + "\"");
+// }
+// if (!isEmpty(process.getName())) {
+// buffer.append(" ");
+// String value = process.getName();
+// buffer.append("name=\"" + value + "\"");
+// }
}
}
- private boolean isEmpty(String str) {
- return str == null || "".equals(str);
- }
+// private boolean isEmpty(String str) {
+// return str == null || "".equals(str);
+// }
private void appendPadding(StringBuffer buffer, int level) {
for (int i = 0; i < level; i++) {
@@ -348,120 +555,120 @@
}
}
- @SuppressWarnings("unchecked")
private void appendClosing(StringBuffer buffer, Wrapper wrapper, int level) {
Element element = (Element)wrapper.getElement();
- ArrayList<Node> trailingNodeList =
(ArrayList<Node>)element.getMetaData("trailingNodes");
- boolean appendTrailingNodes = trailingNodeList != null &&
!trailingNodeList.isEmpty();
- if (appendTrailingNodes) {
- appendNodeList(buffer, trailingNodeList);
- }
+// ArrayList<Node> trailingNodeList =
(ArrayList<Node>)element.getMetaData("trailingNodes");
+// boolean appendTrailingNodes = trailingNodeList != null &&
!trailingNodeList.isEmpty();
+// if (appendTrailingNodes) {
+// appendNodeList(buffer, trailingNodeList);
+// }
if (element instanceof SequenceFlow) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</flow>");
} else if (element instanceof TerminateEndEvent) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</end>");
} else if (element instanceof ErrorEndEvent) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</end-error>");
} else if (element instanceof CancelEndEvent) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</end-cancel>");
} else if (element instanceof StartEvent) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
- buffer.append("</start>");
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
+ buffer.append("</start>");
} else if (element instanceof SuperState) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</super-state>");
} else if (element instanceof WaitTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</state>");
} else if (element instanceof HqlTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</hql>");
} else if (element instanceof SqlTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</sql>");
} else if (element instanceof JavaTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</java>");
} else if (element instanceof ScriptTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</script>");
} else if (element instanceof ServiceTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</esb>");
} else if (element instanceof HumanTask) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</task>");
} else if (element instanceof ExclusiveGateway) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</exclusive>");
} else if (element instanceof ForkParallelGateway) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</fork>");
} else if (element instanceof JoinParallelGateway) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</join>");
} else if (element instanceof Process) {
- if (!appendTrailingNodes) {
- buffer.append("\n");
- appendPadding(buffer, level);
- }
+// if (!appendTrailingNodes) {
+// buffer.append("\n");
+// appendPadding(buffer, level);
+// }
buffer.append("</process>");
}
}
- private void appendBody(StringBuffer buffer, Wrapper wrapper, int level) {
+ @SuppressWarnings("unchecked")
+ private void appendBody(StringBuffer buffer, Wrapper wrapper, int level) {
if (wrapper instanceof ContainerWrapper) {
ContainerWrapper containerWrapper = (ContainerWrapper)wrapper;
List<NodeWrapper> children = containerWrapper.getElements();
@@ -476,32 +683,41 @@
appendToBuffer(buffer, connectionWrapper, level+1);
}
}
- }
-
- private void appendNodeGraphics(StringBuffer buffer, NodeWrapper wrapper) {
- Rectangle constraint = wrapper.getConstraint();
- buffer.append(" g=\"");
- buffer.append(constraint.x);
- buffer.append(",");
- buffer.append(constraint.y);
- buffer.append(",");
- buffer.append(constraint.width);
- buffer.append(",");
- buffer.append(constraint.height);
- buffer.append("\"");
- }
-
- private void appendConnectionGraphics(StringBuffer buffer, ConnectionWrapper wrapper)
{
- List<Point> bendPoints = wrapper.getBendpoints();
- if (bendPoints.size() == 0) return;
- buffer.append(" g=\"");
- for (int i = 0; i < bendPoints.size(); i++) {
- buffer.append(bendPoints.get(i).x);
- buffer.append(",");
- buffer.append(bendPoints.get(i).y);
- if (i < bendPoints.size() - 1) buffer.append(";");
+ Element element = (Element)wrapper.getElement();
+ ArrayList<Node> trailingNodeList =
(ArrayList<Node>)element.getMetaData("trailingNodes");
+ boolean appendTrailingNodes = trailingNodeList != null &&
!trailingNodeList.isEmpty();
+ if (appendTrailingNodes) {
+ appendNodeList(buffer, trailingNodeList);
+ } else if (buffer.length() > 0){
+ buffer.append("\n");
+ appendPadding(buffer, level);
}
- buffer.append("\"");
}
+// private void appendNodeGraphics(StringBuffer buffer, NodeWrapper wrapper) {
+// Rectangle constraint = wrapper.getConstraint();
+// buffer.append(" g=\"");
+// buffer.append(constraint.x);
+// buffer.append(",");
+// buffer.append(constraint.y);
+// buffer.append(",");
+// buffer.append(constraint.width);
+// buffer.append(",");
+// buffer.append(constraint.height);
+// buffer.append("\"");
+// }
+//
+// private void appendConnectionGraphics(StringBuffer buffer, ConnectionWrapper
wrapper) {
+// List<Point> bendPoints = wrapper.getBendpoints();
+// if (bendPoints.size() == 0) return;
+// buffer.append(" g=\"");
+// for (int i = 0; i < bendPoints.size(); i++) {
+// buffer.append(bendPoints.get(i).x);
+// buffer.append(",");
+// buffer.append(bendPoints.get(i).y);
+// if (i < bendPoints.size() - 1) buffer.append(";");
+// }
+// buffer.append("\"");
+// }
+//
}