001: /**
002: * Miroslav Popov, Apr 6, 2006 miroslav.popov@gmail.com
003: */package org.enhydra.jawe.base.xpdlhandler;
004:
005: import java.util.Arrays;
006: import java.util.Iterator;
007: import java.util.List;
008:
009: import org.enhydra.jawe.JaWEEAHandler;
010: import org.enhydra.jawe.components.graph.GraphEAConstants;
011: import org.enhydra.shark.xpdl.XMLCollection;
012: import org.enhydra.shark.xpdl.XMLComplexElement;
013: import org.enhydra.shark.xpdl.XMLElement;
014: import org.enhydra.shark.xpdl.XMLSimpleElement;
015: import org.enhydra.shark.xpdl.XMLUtil;
016: import org.enhydra.shark.xpdl.XPDLRepositoryHandler;
017: import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
018: import org.w3c.dom.Node;
019: import org.w3c.dom.NodeList;
020:
021: /**
022: * @author Miroslav Popov
023: */
024: public class XPDLRepHandler extends XPDLRepositoryHandler {
025:
026: private static final List dontSave = Arrays
027: .asList(new Object[] {
028: GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION,
029: GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION,
030: GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER,
031: GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER,
032: GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW,
033: GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW,
034: GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK,
035: GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK,
036: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID,
037: GraphEAConstants.EA_JAWE_GRAPH_OFFSET,
038: GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS,
039: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE,
040: JaWEEAHandler.EA_EDITING_TOOL,
041: JaWEEAHandler.EA_EDITING_TOOL_VERSION,
042: JaWEEAHandler.EA_JAWE_EXTERNAL_PACKAGE_ID,
043: JaWEEAHandler.EA_JAWE_CONFIGURATION,
044: JaWEEAHandler.EA_JAWE_TYPE });
045:
046: private static final List dontLoad = Arrays
047: .asList(new Object[] {
048: GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORIENTATION,
049: GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORIENTATION,
050: GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER,
051: GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER,
052: GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW,
053: GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW,
054: GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK,
055: GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK,
056: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID,
057: GraphEAConstants.EA_JAWE_GRAPH_OFFSET,
058: GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS,
059: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE,
060: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ID_OLD,
061: GraphEAConstants.EA_JAWE_GRAPH_WORKFLOW_PARTICIPANT_ORDER_OLD,
062: GraphEAConstants.EA_JAWE_GRAPH_BLOCK_PARTICIPANT_ORDER_OLD,
063: GraphEAConstants.EA_JAWE_GRAPH_START_OF_WORKFLOW_OLD,
064: GraphEAConstants.EA_JAWE_GRAPH_END_OF_WORKFLOW_OLD,
065: GraphEAConstants.EA_JAWE_GRAPH_START_OF_BLOCK_OLD,
066: GraphEAConstants.EA_JAWE_GRAPH_END_OF_BLOCK_OLD,
067: GraphEAConstants.EA_JAWE_GRAPH_OFFSET_OLD_X,
068: GraphEAConstants.EA_JAWE_GRAPH_OFFSET_OLD_Y,
069: GraphEAConstants.EA_JAWE_GRAPH_TRANSITION_STYLE_OLD,
070: GraphEAConstants.EA_JAWE_GRAPH_BREAK_POINTS_OLD });
071:
072: public void fromXML(Node node, XMLCollection cel) {
073: if (node == null || !node.hasChildNodes())
074: return;
075: String nameSpacePrefix = XMLUtil.getNameSpacePrefix(node);
076:
077: XMLElement newOne = cel.generateNewElement();
078: String elName = newOne.toName();
079:
080: NodeList children = node.getChildNodes();
081: int lng = children.getLength();
082:
083: for (int i = 0; i < lng; i++) {
084: Node child = children.item(i);
085: if (child.getNodeName().equals(nameSpacePrefix + elName)) {
086: newOne = cel.generateNewElement();
087:
088: if (newOne instanceof ExtendedAttribute) {
089: if (dontLoad.contains(child.getAttributes().item(0)
090: .getNodeValue()))
091: continue;
092: }
093:
094: if (newOne instanceof XMLComplexElement) {
095: fromXML(children.item(i),
096: (XMLComplexElement) newOne);
097: } else {
098: fromXML(children.item(i), (XMLSimpleElement) newOne);
099: }
100: cel.add(newOne);
101: }
102: }
103: }
104:
105: public void toXML(Node parent, XMLCollection cel) {
106: if (!cel.isEmpty() || cel.isRequired()) {
107: if (parent != null) {
108: String elName = cel.toName();
109: Node node = parent;
110: // Specific code for handling Deadlines and Tools
111: if (!(elName.equals("Deadlines") || elName
112: .equals("Tools"))) {
113: node = (parent.getOwnerDocument())
114: .createElement(xpdlPrefix + elName);
115: }
116: for (Iterator it = cel.toElements().iterator(); it
117: .hasNext();) {
118: XMLElement el = (XMLElement) it.next();
119:
120: if (el instanceof ExtendedAttribute) {
121: ExtendedAttribute extA = (ExtendedAttribute) el;
122:
123: if (dontSave.contains(extA.getName()))
124: continue;
125: }
126:
127: if (el instanceof XMLSimpleElement) {
128: toXML(node, (XMLSimpleElement) el);
129: } else {
130: toXML(node, (XMLComplexElement) el);
131: }
132: }
133: // If Deadlines or Tools are handled, node==parent
134: if (node != parent
135: && node.getChildNodes().getLength() != 0) {
136: parent.appendChild(node);
137: }
138: }
139: }
140: }
141: }
|