xpdlrepositoryhandler.java
来自「jawe的最新版本,基于Java的图形化工作流编辑器。图形化工作流编辑器 。使用」· Java 代码 · 共 402 行 · 第 1/2 页
JAVA
402 行
/** * Miroslav Popov, Apr 6, 2006 miroslav.popov@gmail.com */package org.enhydra.shark.xpdl;import java.util.Iterator;import java.util.List;import org.enhydra.shark.xpdl.elements.Condition;import org.enhydra.shark.xpdl.elements.Deadlines;import org.enhydra.shark.xpdl.elements.ExtendedAttribute;import org.enhydra.shark.xpdl.elements.ImplementationTypes;import org.enhydra.shark.xpdl.elements.Namespace;import org.enhydra.shark.xpdl.elements.Namespaces;import org.enhydra.shark.xpdl.elements.Package;import org.enhydra.shark.xpdl.elements.SchemaType;import org.enhydra.shark.xpdl.elements.Tools;import org.w3c.dom.Attr;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;/** * @author Miroslav Popov */public class XPDLRepositoryHandler { protected static boolean logging=false; protected String xpdlPrefix=""; public void setXPDLPrefixEnabled (boolean enable) { if (enable) { this.xpdlPrefix="xpdl:"; } else { this.xpdlPrefix=""; } } public boolean isXPDLPrefixEnabled () { return "xpdl:".equals(this.xpdlPrefix); } public void fromXML(Element node, Package pkg) { // long t1,t2; // t1=System.currentTimeMillis(); NamedNodeMap attribs = node.getAttributes(); Namespaces nss = pkg.getNamespaces(); for (int i = 0; i < attribs.getLength(); i++) { Node n = attribs.item(i); String nn = n.getNodeName(); if (nn.startsWith("xmlns:") && !nn.equals("xmlns:xsi")) { Namespace ns = (Namespace) nss.generateNewElement(); ns.setName(nn.substring(6, nn.length())); fromXML(n, (XMLAttribute) ns.get("location")); nss.add(ns); } } fromXML(node, (XMLComplexElement) pkg); // t2=System.currentTimeMillis(); // System.out.println("MFXML="+(t2-t1)); } public void fromXML(Node node, XMLCollection cel) { if (node == null || !node.hasChildNodes()) return; String nameSpacePrefix = XMLUtil.getNameSpacePrefix(node); XMLElement newOne = cel.generateNewElement(); String elName = newOne.toName(); NodeList children = node.getChildNodes(); int lng = children.getLength(); if (logging) System.out.println("FROMXML for " + cel.toName() + ", c=" + cel.getClass().getName()); for (int i = 0; i < lng; i++) { Node child = children.item(i); if (child.getNodeName().equals(nameSpacePrefix + elName)) { // System.out.println("I="+i); newOne = cel.generateNewElement(); // System.out.println("Now the collection element of collection // "+node.getNodeName()+" will be processed"); if (newOne instanceof XMLComplexElement) { fromXML(children.item(i), (XMLComplexElement) newOne); } else { fromXML(children.item(i), (XMLSimpleElement) newOne); } cel.add(newOne); } else { // System.err.println("Something's wrong with collection "+elName+" parsing - // c="+cel.getClass().getName()+" !"); } } // System.out.println("The length of collection "+name+" after importing // is"+size()); } public void fromXML(Node node, XMLComplexElement cel) { if (node == null || (!node.hasChildNodes() && !node.hasAttributes())) return; String nameSpacePrefix = node.getPrefix(); if (nameSpacePrefix != null) { nameSpacePrefix += ":"; } else { nameSpacePrefix = ""; } if (logging) System.out.println("FROMXML for " + cel.toName() + ", c=" + cel.getClass().getName()); if (node.hasAttributes()) { NamedNodeMap attribs = node.getAttributes(); for (int i = 0; i < attribs.getLength(); ++i) { Node attrib = attribs.item(i); try { // System.out.println("Getting attrib "+attrib.getNodeName()); fromXML(attrib, (XMLAttribute) cel.get(attrib.getNodeName())); } catch (NullPointerException npe) { /* * System.err.println("Processing attributes for "+ cel.toName() +" element * having problems with " + attrib.getNodeName()+" attribute\n" + * attrib.getNodeValue().trim()); */ } } } // getting elements if (node.hasChildNodes()) { // Specific code for handling Condition element - we don't support Xpression // element if (cel instanceof Condition) { String newVal = node.getChildNodes().item(0).getNodeValue(); if (newVal != null) { cel.setValue(newVal); } } // Specific code for handling SchemaType element if (cel instanceof SchemaType) { NodeList nl = node.getChildNodes(); for (int j = 0; j < nl.getLength(); j++) { Node sn = nl.item(j); if (sn instanceof Element) { cel.setValue(XMLUtil.getContent(sn, true)); break; } } } // Specific code for handling ExtendedAttribute element if (cel instanceof ExtendedAttribute) { cel.setValue(XMLUtil.getChildNodesContent(node)); } Iterator it = cel.getXMLElements().iterator(); while (it.hasNext()) { XMLElement el = (XMLElement) it.next(); String elName = el.toName(); if (el instanceof XMLComplexElement) { Node child = XMLUtil.getChildByName(node, nameSpacePrefix + elName); fromXML(child, (XMLComplexElement) el); // Specific case if element is Deadlines } else if (el instanceof Deadlines) { fromXML(node, (XMLCollection) el); } else if (el instanceof XMLCollection) { Node child = XMLUtil.getChildByName(node, nameSpacePrefix + elName); fromXML(child, (XMLCollection) el); } else if (el instanceof XMLComplexChoice) { fromXML(node, (XMLComplexChoice) el); } else if (el instanceof XMLSimpleElement) { Node child = XMLUtil.getChildByName(node, nameSpacePrefix + elName); fromXML(child, (XMLSimpleElement) el); } } } } public void fromXML(Node node, XMLComplexChoice el) { String nameSpacePrefix = XMLUtil.getNameSpacePrefix(node); List ch = el.getChoices(); if (logging) System.out.println("FROMXML for " + el.toName() + ", c=" + el.getClass().getName()); for (int i = 0; i < ch.size(); i++) { XMLElement chc = (XMLElement) ch.get(i); String chname = chc.toName(); // Specific code for handling Tools if (chname.equals("Tools")) { chname = "Tool"; } Node child = XMLUtil.getChildByName(node, nameSpacePrefix + chname); if (child != null) { if (chc instanceof XMLComplexElement) { fromXML(child, (XMLComplexElement) chc); } else { // it is XMLCollection // Specific code for handling Tools if (chc instanceof Tools) { fromXML(node, (XMLCollection) chc); } else { fromXML(child, (XMLCollection) chc);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?