http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/DSCUtil.java ---------------------------------------------------------------------- diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/DSCUtil.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/DSCUtil.java index 3ed669e..7a67672 100644 --- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/DSCUtil.java +++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/DSCUtil.java @@ -41,80 +41,80 @@ import org.apache.airavata.workflow.model.graph.util.GraphUtil; import org.apache.airavata.workflow.model.graph.ws.WSNode; import org.apache.airavata.workflow.model.wf.Workflow; -import xsul5.wsdl.WsdlDefinitions; -import xsul5.wsdl.WsdlPortType; -import xsul5.wsdl.WsdlResolver; -import xsul5.wsdl.WsdlUtil; +//import xsul5.wsdl.WsdlDefinitions; +//import xsul5.wsdl.WsdlPortType; +//import xsul5.wsdl.WsdlResolver; +//import xsul5.wsdl.WsdlUtil; public class DSCUtil { - /** - * For debugging - * - * @param args - */ - public static void main(String[] args) { - WsdlDefinitions awsdl = WsdlResolver.getInstance().loadWsdl(DSCUtil.class, "wsdls/math/adder-awsdl.xml"); - WsdlDefinitions cwsdl = convertToCWSDL(awsdl, URI.create("http://localhost")); - System.out.println(cwsdl.xmlStringPretty()); - } - - /** - * Creates CWSDLs for all WSDLs in a workflow. - * - * @param workflow - * @param dscURL - * @return The Map<partnerLinkName, CWSDL>. - * @throws URISyntaxException - */ - public static Map<String, WsdlDefinitions> createCWSDLs(Workflow workflow, String dscURL) throws URISyntaxException { - return createCWSDLs(workflow, new URI(dscURL)); - } - - /** - * @param workflow - * @param dscURL - * @return The Map<partnerLinkName, CWSDL>. - */ - public static Map<String, WsdlDefinitions> createCWSDLs(Workflow workflow, URI dscURL) { - Map<String, WsdlDefinitions> WSDLMap = new HashMap<String, WsdlDefinitions>(); - Graph graph = workflow.getGraph(); -// for (WSNode node : GraphUtil.getWSNodes(graph)) { -// String partnerLinkName = BPELScript.createPartnerLinkName(node.getID()); -// WsdlDefinitions wsdl = node.getComponent().getWSDL(); -// if (WSDLUtil.isAWSDL(wsdl)) { -// try { -// wsdl = convertToCWSDL(WSDLUtil.deepClone(wsdl), dscURL); -// } catch (UtilsException e) { -// e.printStackTrace(); -// } -// } -// WSDLMap.put(partnerLinkName, wsdl); +//// /** +//// * For debugging +//// * +//// * @param args +//// */ +//// public static void main(String[] args) { +//// WsdlDefinitions awsdl = WsdlResolver.getInstance().loadWsdl(DSCUtil.class, "wsdls/math/adder-awsdl.xml"); +//// WsdlDefinitions cwsdl = convertToCWSDL(awsdl, URI.create("http://localhost")); +//// System.out.println(cwsdl.xmlStringPretty()); +//// } +// +// /** +// * Creates CWSDLs for all WSDLs in a workflow. +// * +// * @param workflow +// * @param dscURL +// * @return The Map<partnerLinkName, CWSDL>. +// * @throws URISyntaxException +// */ +// public static Map<String, WsdlDefinitions> createCWSDLs(Workflow workflow, String dscURL) throws URISyntaxException { +// return createCWSDLs(workflow, new URI(dscURL)); +// } +// +// /** +// * @param workflow +// * @param dscURL +// * @return The Map<partnerLinkName, CWSDL>. +// */ +// public static Map<String, WsdlDefinitions> createCWSDLs(Workflow workflow, URI dscURL) { +// Map<String, WsdlDefinitions> WSDLMap = new HashMap<String, WsdlDefinitions>(); +// Graph graph = workflow.getGraph(); +//// for (WSNode node : GraphUtil.getWSNodes(graph)) { +//// String partnerLinkName = BPELScript.createPartnerLinkName(node.getID()); +//// WsdlDefinitions wsdl = node.getComponent().getWSDL(); +//// if (WSDLUtil.isAWSDL(wsdl)) { +//// try { +//// wsdl = convertToCWSDL(WSDLUtil.deepClone(wsdl), dscURL); +//// } catch (UtilsException e) { +//// e.printStackTrace(); +//// } +//// } +//// WSDLMap.put(partnerLinkName, wsdl); +//// } +// return WSDLMap; +// } +// +// /** +// * Converts a specified AWSDL to CWSDL using DSC URI. +// * +// * @param definitions +// * The specified AWSDL. This will be modified. +// * @param dscURI +// * @return The CWSDL converted. +// */ +// public static WsdlDefinitions convertToCWSDL(WsdlDefinitions definitions, URI dscURI) { +// // Create a new List to avoid ConcurrentModificationException. +// List<WsdlPortType> portTypes = new ArrayList<WsdlPortType>(); +// for (WsdlPortType portType : definitions.portTypes()) { +// portTypes.add(portType); // } - return WSDLMap; - } - - /** - * Converts a specified AWSDL to CWSDL using DSC URI. - * - * @param definitions - * The specified AWSDL. This will be modified. - * @param dscURI - * @return The CWSDL converted. - */ - public static WsdlDefinitions convertToCWSDL(WsdlDefinitions definitions, URI dscURI) { - // Create a new List to avoid ConcurrentModificationException. - List<WsdlPortType> portTypes = new ArrayList<WsdlPortType>(); - for (WsdlPortType portType : definitions.portTypes()) { - portTypes.add(portType); - } - - for (WsdlPortType portType : portTypes) { - URI uri = creatEPR(dscURI, portType.getQName()); - WsdlUtil.createCWSDL(definitions, portType, uri); - } - return definitions; - } +// +// for (WsdlPortType portType : portTypes) { +// URI uri = creatEPR(dscURI, portType.getQName()); +// WsdlUtil.createCWSDL(definitions, portType, uri); +// } +// return definitions; +// } private static URI creatEPR(URI dscURI, QName portTypeQName) { String encodedPortType;
http://git-wip-us.apache.org/repos/asf/airavata/blob/9a6eaaae/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/BPELScript.java ---------------------------------------------------------------------- diff --git a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/BPELScript.java b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/BPELScript.java index 2b8ef85..182c0e8 100644 --- a/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/BPELScript.java +++ b/modules/workflow-model/workflow-model-core/src/main/java/org/apache/airavata/workflow/model/gpel/script/BPELScript.java @@ -63,23 +63,23 @@ import org.apache.airavata.workflow.model.graph.ws.WSNode; import org.apache.airavata.workflow.model.utils.WorkflowConstants; import org.apache.airavata.workflow.model.utils.ApplicationVersion; import org.apache.airavata.workflow.model.wf.Workflow; -import org.gpel.GpelConstants; -import org.gpel.model.GpelAssign; -import org.gpel.model.GpelAssignCopy; -import org.gpel.model.GpelAssignCopyFrom; -import org.gpel.model.GpelAssignCopyTo; -import org.gpel.model.GpelCondition; -import org.gpel.model.GpelElse; -import org.gpel.model.GpelFlow; -import org.gpel.model.GpelForEach; -import org.gpel.model.GpelIf; -import org.gpel.model.GpelInvoke; -import org.gpel.model.GpelProcess; -import org.gpel.model.GpelReceive; -import org.gpel.model.GpelReply; -import org.gpel.model.GpelScope; -import org.gpel.model.GpelSequence; -import org.gpel.model.GpelVariable; +//import org.gpel.GpelConstants; +//import org.gpel.model.GpelAssign; +//import org.gpel.model.GpelAssignCopy; +//import org.gpel.model.GpelAssignCopyFrom; +//import org.gpel.model.GpelAssignCopyTo; +//import org.gpel.model.GpelCondition; +//import org.gpel.model.GpelElse; +//import org.gpel.model.GpelFlow; +//import org.gpel.model.GpelForEach; +//import org.gpel.model.GpelIf; +//import org.gpel.model.GpelInvoke; +//import org.gpel.model.GpelProcess; +//import org.gpel.model.GpelReceive; +//import org.gpel.model.GpelReply; +//import org.gpel.model.GpelScope; +//import org.gpel.model.GpelSequence; +//import org.gpel.model.GpelVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.xmlpull.infoset.XmlComment; @@ -87,9 +87,9 @@ import org.xmlpull.infoset.XmlElement; import org.xmlpull.infoset.XmlInfosetBuilder; import org.xmlpull.infoset.XmlNamespace; -import xsul5.wsdl.WsdlPortType; -import xsul5.wsdl.plnk.PartnerLinkRole; -import xsul5.wsdl.plnk.PartnerLinkType; +//import xsul5.wsdl.WsdlPortType; +//import xsul5.wsdl.plnk.PartnerLinkRole; +//import xsul5.wsdl.plnk.PartnerLinkType; public class BPELScript { @@ -158,7 +158,7 @@ public class BPELScript { */ private List<Node> remainNodes; - private GpelProcess process; +// private GpelProcess process; private XmlNamespace targetNamespace; @@ -194,9 +194,9 @@ public class BPELScript { * * @return The GPEL Process */ - public GpelProcess getGpelProcess() { - return this.process; - } +// public GpelProcess getGpelProcess() { +// return this.process; +// } /** * @return the WSDL of the workflow @@ -305,56 +305,56 @@ public class BPELScript { } } - /** - * @throws GraphException - */ - public void create(BPELScriptType type) throws GraphException { - try { - // Create WSDL for the workflow. - // This has to be done before generating the BPEL document. - this.workflowWSDL.create(); - - this.remainNodes = new LinkedList<Node>(this.graph.getNodes()); - - String bpelTargetNamespace = TARGET_NS_NAME + this.graph.getID() + "/"; - - this.workflowPrefix = StringUtil.convertToJavaIdentifier(this.graph.getName()); - - if (BPELScriptType.BPEL2 == type) { - GpelConstants.GPEL_NS = XmlInfosetBuilder.newInstance().newNamespace(BPEL, BPEL2_NS); - this.bpelNS = XmlInfosetBuilder.newInstance().newNamespace(BPEL, BPEL2_NS); - this.process = new GpelProcess(bpelNS, bpelTargetNamespace); - } else if (BPELScriptType.GPEL == type) { - GpelConstants.GPEL_NS = XmlInfosetBuilder.newInstance().newNamespace(GPEL, GPELNS); - this.bpelNS = XmlInfosetBuilder.newInstance().newNamespace(GPEL, GPELNS); - this.process = new GpelProcess(bpelNS, bpelTargetNamespace); - } else { - throw new GraphException("Unknown BPEL type " + type); - } - - // Target namespace of the workflow WSDL - this.targetNamespace = this.process.xml().declareNamespace(this.workflowWSDL.getTargetNamespace()); - - // Types namespace of the workflow WSDL - this.typesNamespace = this.process.xml().declareNamespace(this.workflowWSDL.getTypesNamespace()); - - // xsd - XMLUtil.declareNamespaceIfNecessary(WSConstants.XSD_NS.getPrefix(), WSConstants.XSD_NS.getName(), false, - this.process.xml()); - - this.process.setActivity(createMainSequence()); - - // comment - addComment(); - - // Validate - this.process.xmlValidate(); - - logger.debug(this.process.xmlStringPretty()); - } catch (RuntimeException e) { - throw new GraphException(e); - } - } +// /** +// * @throws GraphException +// */ +// public void create(BPELScriptType type) throws GraphException { +// try { +// // Create WSDL for the workflow. +// // This has to be done before generating the BPEL document. +// this.workflowWSDL.create(); +// +// this.remainNodes = new LinkedList<Node>(this.graph.getNodes()); +// +// String bpelTargetNamespace = TARGET_NS_NAME + this.graph.getID() + "/"; +// +// this.workflowPrefix = StringUtil.convertToJavaIdentifier(this.graph.getName()); +// +// if (BPELScriptType.BPEL2 == type) { +// GpelConstants.GPEL_NS = XmlInfosetBuilder.newInstance().newNamespace(BPEL, BPEL2_NS); +// this.bpelNS = XmlInfosetBuilder.newInstance().newNamespace(BPEL, BPEL2_NS); +// this.process = new GpelProcess(bpelNS, bpelTargetNamespace); +// } else if (BPELScriptType.GPEL == type) { +// GpelConstants.GPEL_NS = XmlInfosetBuilder.newInstance().newNamespace(GPEL, GPELNS); +// this.bpelNS = XmlInfosetBuilder.newInstance().newNamespace(GPEL, GPELNS); +// this.process = new GpelProcess(bpelNS, bpelTargetNamespace); +// } else { +// throw new GraphException("Unknown BPEL type " + type); +// } +// +// // Target namespace of the workflow WSDL +// this.targetNamespace = this.process.xml().declareNamespace(this.workflowWSDL.getTargetNamespace()); +// +// // Types namespace of the workflow WSDL +// this.typesNamespace = this.process.xml().declareNamespace(this.workflowWSDL.getTypesNamespace()); +// +// // xsd +// XMLUtil.declareNamespaceIfNecessary(WSConstants.XSD_NS.getPrefix(), WSConstants.XSD_NS.getName(), false, +// this.process.xml()); +// +// this.process.setActivity(createMainSequence()); +// +// // comment +// addComment(); +// +// // Validate +// this.process.xmlValidate(); +// +// logger.debug(this.process.xmlStringPretty()); +// } catch (RuntimeException e) { +// throw new GraphException(e); +// } +// } /** * @param nodeID @@ -365,335 +365,335 @@ public class BPELScript { } private void addComment() { - XmlComment comment = this.process.xml().newComment( - "\nThis document is automatically generated by " + WorkflowConstants.APPLICATION_NAME_ + " " - + ApplicationVersion.VERSION + ".\n"); - this.process.xml().insertChild(0, "\n"); - this.process.xml().insertChild(0, comment); - this.process.xml().insertChild(0, "\n"); - } - - private GpelSequence createMainSequence() throws GraphException { - GpelSequence sequence = new GpelSequence(this.bpelNS); - - // Remove InputNodes and MemoNodes. - removeUnnecessaryNodes(this.remainNodes); - - addInitialReceive(sequence); - - addBlock(this.remainNodes, sequence); - - addFinalReply(sequence); - - if (this.remainNodes.size() > 0) { - throw new GraphException("Some node(s) are not connected."); - } - - return sequence; - } - - private void addInitialReceive(GpelSequence sequence) { - // Create a partner link - String partnerLinkName = WORKFLOW_PARTNER_LINK; - XmlNamespace partnerLinkTypeNS = this.workflowWSDL.getTargetNamespace(); - String partnerLinkTypeName = this.workflowPrefix + PARTNER_LINK_TYPE_SUFFIX; - String myRollName = this.workflowPrefix + MY_ROLE_SUFFIX; - - this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkTypeName, myRollName, null); - this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, myRollName, - this.workflowWSDL.getPortTypeQName()); - - // Create a variable - this.process.addMessageVariable(WORKFLOW_INPUT_NAME, this.targetNamespace, - this.workflowWSDL.getWorkflowInputMessageName()); - - GpelReceive receive = new GpelReceive(this.bpelNS, WORKFLOW_PARTNER_LINK, this.workflowWSDL.getPortTypeQName(), - this.workflowWSDL.getWorkflowOperationName()); - receive.setGpelVariableName(WORKFLOW_INPUT_NAME); - sequence.addActivity(receive); - } - - private void addFinalReply(GpelSequence sequence) throws GraphException { - // Create a variable - this.process.addMessageVariable(WORKFLOW_OUTPUT_NAME, this.targetNamespace, - this.workflowWSDL.getWorkflowOutputMessageName()); - - List<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); - List<OutputNode> outputNodes = GraphUtil.getNodes(this.graph, OutputNode.class); - this.remainNodes.removeAll(outputNodes); - for (OutputNode outputNode : outputNodes) { - Port port = outputNode.getPort(); - GpelAssignCopyFrom from = createAssignCopyFrom(port); - GpelAssignCopyTo to = createAssignCopyTo(port, false); - - copies.add(new GpelAssignCopy(this.bpelNS, from, to)); - } - - if (copies.size() != 0) { - // When there is no outputs, we don't create assign. - GpelAssign assign = new GpelAssign(this.bpelNS, copies); - sequence.addActivity(assign); - } - - GpelReply reply = new GpelReply(this.bpelNS, WORKFLOW_PARTNER_LINK, this.workflowWSDL.getPortTypeQName(), - this.workflowWSDL.getWorkflowOperationName()); - reply.setVariableName(WORKFLOW_OUTPUT_NAME); - sequence.addActivity(reply); - } - - /** - * @param block - * @param sequence - * @throws GraphException - */ - private void addBlock(Collection<Node> block, GpelSequence sequence) throws GraphException { - List<Node> nextNodes = getNextExecutableNodes(block); - while (nextNodes.size() > 0) { - block.removeAll(nextNodes); - removeUnnecessaryNodes(nextNodes); - if (nextNodes.size() == 0) { - // Everything was uncessary nodes (constants, etc.). Move on. - } else if (nextNodes.size() == 1) { - addSingle(nextNodes.get(0), block, sequence); - } else if (nextNodes.size() > 1) { - // XXX The algorithm used here is not efficient. It introduces - // unnessary barriers. - addFlow(nextNodes, block, sequence); - } else { - // Should not happen. - throw new WorkflowRuntimeException("nextNodes.size(): " + nextNodes.size()); - } - nextNodes = getNextExecutableNodes(block); - } - } - - private void addFlow(List<Node> nextNodes, Collection<Node> block, GpelSequence sequence) throws GraphException { - GpelFlow flow = new GpelFlow(this.bpelNS); - for (Node node : nextNodes) { - GpelSequence childSequence = new GpelSequence(this.bpelNS); - flow.addActivity(childSequence); - addSingle(node, block, childSequence); - } - sequence.addActivity(flow); - } - - // TODO: Add xml to BPEL - private void addSingle(Node node, Collection<Node> block, GpelSequence sequence) throws GraphException { - logger.debug("Processing + " + node.getID()); - if (node instanceof WSNode) { - addInvoke((WSNode) node, sequence); - } else if (node instanceof ConstantNode) { - // nothing - } else if (node instanceof ForEachNode) { - addForEach((ForEachNode) node, block, sequence); - } else if (node instanceof EndForEachNode) { - // nothing. - } else if (node instanceof IfNode) { - addIf((IfNode) node, block, sequence); - } else if (node instanceof EndifNode) { - // nothing - } else if (node instanceof ReceiveNode) { - addReceive((ReceiveNode) node, sequence); - } else if (node instanceof BlockNode) { - addBlock((BlockNode) node, block, sequence); - } else if (node instanceof EndBlockNode) { - // nothing - } else if (node instanceof StreamSourceNode) { - addStreamSource((StreamSourceNode) node, sequence); - } else if (node instanceof ExitNode) { - addExit((ExitNode) node, sequence); - } else if (node instanceof ResourceNode) { - // nothing - } else { - - throw new GraphException(node.getClass().getName() + " is not supported."); - } - } - - /** - * @param node - * @param sequence - */ - private void addStreamSource(StreamSourceNode node, GpelSequence sequence) { - GpelFlow flow = new GpelFlow(this.bpelNS); - new GpelSequence(this.bpelNS); - sequence.addActivity(flow); - - } - - /** - * @param node - * @param sequence - */ - private void addExit(ExitNode node, GpelSequence sequence) { - sequence.xml().addElement(this.bpelNS, "exit"); - } - - private void addInvoke(WSNode node, GpelSequence sequence) throws GraphException { - String id = node.getID(); - - WSComponent wsdlComponent = node.getComponent(); - String operation = wsdlComponent.getOperationName(); - - QName portTypeQName = wsdlComponent.getPortTypeQName(); - XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(id.toLowerCase(), portTypeQName.getNamespaceURI(), - false, this.process.xml()); - - // Variable - String inputVariableName = id + INPUT_SUFFIX; - this.process.addMessageVariable(inputVariableName, namespace, portTypeQName.getLocalPart()); - String outputVariableName = id + OUTPUT_SUFFIX; - this.process.addMessageVariable(outputVariableName, namespace, portTypeQName.getLocalPart()); - - // Assign - List<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); - for (Port port : node.getInputPorts()) { - Port fromPort = port.getFromPort(); - if (fromPort == null) { - // optional input - continue; - } - GpelAssignCopyFrom from = createAssignCopyFrom(port); - GpelAssignCopyTo to = createAssignCopyTo(port, true); - - GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); - copies.add(copy); - } - - GpelAssign assign = new GpelAssign(this.bpelNS, copies); - sequence.addActivity(assign); - - PartnerLinkRole partnerRoll = this.workflowWSDL.getPartnerRoll(portTypeQName); - if (partnerRoll == null) { - String partnerLinkTypeName = id + PARTNER_LINK_TYPE_SUFFIX; - String partnerRollName = id + PARTNER_ROLE_SUFFIX; - partnerRoll = this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, partnerRollName, - portTypeQName); - } - PartnerLinkType partnerLinkType = partnerRoll.getPartnerLinkType(); - - // partnerLink - String partnerLinkName = createPartnerLinkName(id); - XmlNamespace partnerLinkTypeNS = this.targetNamespace; - this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkType.getName(), null, - partnerRoll.getName()); - - // Invoke - GpelInvoke invoke = new GpelInvoke(this.bpelNS, partnerLinkName, namespace, portTypeQName.getLocalPart(), - operation); - invoke.setName(INVOKE_NAME_PREFIX + id); - invoke.setInputVariableName(inputVariableName); - invoke.setOutputVariableName(outputVariableName); - - sequence.addActivity(invoke); - } - - /** - * Creates BpelAssignCopyFrom for a specified port. - * - * @param port - * @return The BpelAssignCopyFrom created - * @throws GraphException - */ - private GpelAssignCopyFrom createAssignCopyFrom(Port port) throws GraphException { - GpelAssignCopyFrom from = new GpelAssignCopyFrom(this.bpelNS); - - Port fromPort = port.getFromPort(); - Node fromNode = fromPort.getNode(); - if (fromNode instanceof InputNode) { - from.setVariable(WORKFLOW_INPUT_NAME); - from.setPart(WorkflowWSDL.INPUT_PART_NAME); - from.setQuery("/" + this.typesNamespace.getPrefix() + ":" - + this.workflowWSDL.getWorkflowInputMessageElelmentName() + "/" + fromNode.getID()); - } else if (fromNode instanceof ConstantNode) { - ConstantNode constNode = (ConstantNode) fromNode; - Object value = constNode.getValue(); - // The namaspace and name of the literal element will be set - // correctly in from.setLiteral(). - XmlElement literalElement = XMLUtil.BUILDER.newFragment(GpelAssignCopyFrom.LITERAL_EL); - literalElement.addChild(value); - from.setLiteral(literalElement); - } else if (fromNode instanceof WSNode) { - String fromID = fromNode.getID(); - WSComponent fromWsdlComponent = (WSComponent) fromNode.getComponent(); - - WSComponentPort fromWsdlPort = (WSComponentPort) fromPort.getComponentPort(); - - from.setVariable(fromID + OUTPUT_SUFFIX); - from.setPart(fromWsdlComponent.getOutputPartName()); - - if (fromWsdlPort.isSchemaUsed()) { - String typesTargetNamespace = fromWsdlPort.getTargetNamespace(); - XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(fromID.toLowerCase() + TYPENS_SUFFIX, - typesTargetNamespace, false, this.process.xml()); - - from.setQuery("/" + namespace.getPrefix() + ":" + fromWsdlComponent.getOutputTypeName() + "/" - + fromWsdlPort.getName()); - } else { - // No query needed? - } - } else if (fromNode instanceof ForEachNode) { - from.setVariable(fromNode.getID() + FOREACH_VALUE_SUFFIX); - } else if (fromNode instanceof EndForEachNode) { - from.setVariable(fromNode.getID() + ARRAY_SUFIX); - } else if (fromNode instanceof EndifNode) { - // endif has multiple outputs, so we use port ID here. - from.setVariable(fromPort.getID() + OUTPUT_SUFFIX); - } else if (fromNode instanceof ReceiveNode) { - if (fromPort instanceof EPRPort) { - from.setPartnerLink(fromNode.getID() + PARTNER_LINK_NAME_SUFFIX); - from.setEndpointReference("myRole"); - } else { - from.setVariable(fromNode.getID() + INPUT_SUFFIX); - } - } else if (fromNode instanceof InstanceNode) { - // no op - } else { - throw new GraphException("Unexpected node," + fromNode.getClass().getName() + " is connected"); - } - return from; +// XmlComment comment = this.process.xml().newComment( +// "\nThis document is automatically generated by " + WorkflowConstants.APPLICATION_NAME_ + " " +// + ApplicationVersion.VERSION + ".\n"); +// this.process.xml().insertChild(0, "\n"); +// this.process.xml().insertChild(0, comment); +// this.process.xml().insertChild(0, "\n"); } - /** - * Creates BpelAssignCopyFrom for a specified port. - * - * @param toPort - * @param input - * @return The GpelAssignCopyTo created - */ - private GpelAssignCopyTo createAssignCopyTo(Port toPort, boolean input) { - GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); - - Node toNode = toPort.getNode(); - if (toNode instanceof OutputNode) { - to.setVariable(WORKFLOW_OUTPUT_NAME); - to.setPart(WorkflowWSDL.OUTPUT_PART_NAME); - to.setQuery("/" + this.typesNamespace.getPrefix() + ":" - + this.workflowWSDL.getWorkflowOutputMessageElementName() + "/" + toNode.getID()); - } else { - WSComponentPort toComponentPort = (WSComponentPort) toPort.getComponentPort(); - - String toID = toNode.getID(); - WSComponent toWSComponent = (WSComponent) toNode.getComponent(); - to.setVariable(toID + INPUT_SUFFIX); - to.setPart(toWSComponent.getInputPartName()); - - if (toComponentPort.isSchemaUsed()) { - // Normal case. - // e.g. <part name="name" type="typens:fooType"> - String typesTargetNamespace = toComponentPort.getTargetNamespace(); - XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(toID.toLowerCase() + TYPENS_SUFFIX, - typesTargetNamespace, false, this.process.xml()); - - String typeName = input ? toWSComponent.getInputTypeName() : toWSComponent.getOutputTypeName(); - to.setQuery("/" + namespace.getPrefix() + ":" + typeName + "/" + toComponentPort.getName()); - } else { - // e.g. <part name="name" type="xsd:string"> - // No query is needed? - } - } - return to; - } +// private GpelSequence createMainSequence() throws GraphException { +// GpelSequence sequence = new GpelSequence(this.bpelNS); +// +// // Remove InputNodes and MemoNodes. +// removeUnnecessaryNodes(this.remainNodes); +// +// addInitialReceive(sequence); +// +// addBlock(this.remainNodes, sequence); +// +// addFinalReply(sequence); +// +// if (this.remainNodes.size() > 0) { +// throw new GraphException("Some node(s) are not connected."); +// } +// +// return sequence; +// } +// +// private void addInitialReceive(GpelSequence sequence) { +// // Create a partner link +// String partnerLinkName = WORKFLOW_PARTNER_LINK; +// XmlNamespace partnerLinkTypeNS = this.workflowWSDL.getTargetNamespace(); +// String partnerLinkTypeName = this.workflowPrefix + PARTNER_LINK_TYPE_SUFFIX; +// String myRollName = this.workflowPrefix + MY_ROLE_SUFFIX; +// +// this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkTypeName, myRollName, null); +// this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, myRollName, +// this.workflowWSDL.getPortTypeQName()); +// +// // Create a variable +// this.process.addMessageVariable(WORKFLOW_INPUT_NAME, this.targetNamespace, +// this.workflowWSDL.getWorkflowInputMessageName()); +// +// GpelReceive receive = new GpelReceive(this.bpelNS, WORKFLOW_PARTNER_LINK, this.workflowWSDL.getPortTypeQName(), +// this.workflowWSDL.getWorkflowOperationName()); +// receive.setGpelVariableName(WORKFLOW_INPUT_NAME); +// sequence.addActivity(receive); +// } +// +// private void addFinalReply(GpelSequence sequence) throws GraphException { +// // Create a variable +// this.process.addMessageVariable(WORKFLOW_OUTPUT_NAME, this.targetNamespace, +// this.workflowWSDL.getWorkflowOutputMessageName()); +// +// List<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); +// List<OutputNode> outputNodes = GraphUtil.getNodes(this.graph, OutputNode.class); +// this.remainNodes.removeAll(outputNodes); +// for (OutputNode outputNode : outputNodes) { +// Port port = outputNode.getPort(); +// GpelAssignCopyFrom from = createAssignCopyFrom(port); +// GpelAssignCopyTo to = createAssignCopyTo(port, false); +// +// copies.add(new GpelAssignCopy(this.bpelNS, from, to)); +// } +// +// if (copies.size() != 0) { +// // When there is no outputs, we don't create assign. +// GpelAssign assign = new GpelAssign(this.bpelNS, copies); +// sequence.addActivity(assign); +// } +// +// GpelReply reply = new GpelReply(this.bpelNS, WORKFLOW_PARTNER_LINK, this.workflowWSDL.getPortTypeQName(), +// this.workflowWSDL.getWorkflowOperationName()); +// reply.setVariableName(WORKFLOW_OUTPUT_NAME); +// sequence.addActivity(reply); +// } +// +// /** +// * @param block +// * @param sequence +// * @throws GraphException +// */ +// private void addBlock(Collection<Node> block, GpelSequence sequence) throws GraphException { +// List<Node> nextNodes = getNextExecutableNodes(block); +// while (nextNodes.size() > 0) { +// block.removeAll(nextNodes); +// removeUnnecessaryNodes(nextNodes); +// if (nextNodes.size() == 0) { +// // Everything was uncessary nodes (constants, etc.). Move on. +// } else if (nextNodes.size() == 1) { +// addSingle(nextNodes.get(0), block, sequence); +// } else if (nextNodes.size() > 1) { +// // XXX The algorithm used here is not efficient. It introduces +// // unnessary barriers. +// addFlow(nextNodes, block, sequence); +// } else { +// // Should not happen. +// throw new WorkflowRuntimeException("nextNodes.size(): " + nextNodes.size()); +// } +// nextNodes = getNextExecutableNodes(block); +// } +// } +// +// private void addFlow(List<Node> nextNodes, Collection<Node> block, GpelSequence sequence) throws GraphException { +// GpelFlow flow = new GpelFlow(this.bpelNS); +// for (Node node : nextNodes) { +// GpelSequence childSequence = new GpelSequence(this.bpelNS); +// flow.addActivity(childSequence); +// addSingle(node, block, childSequence); +// } +// sequence.addActivity(flow); +// } +// +// // TODO: Add xml to BPEL +// private void addSingle(Node node, Collection<Node> block, GpelSequence sequence) throws GraphException { +// logger.debug("Processing + " + node.getID()); +// if (node instanceof WSNode) { +// addInvoke((WSNode) node, sequence); +// } else if (node instanceof ConstantNode) { +// // nothing +// } else if (node instanceof ForEachNode) { +// addForEach((ForEachNode) node, block, sequence); +// } else if (node instanceof EndForEachNode) { +// // nothing. +// } else if (node instanceof IfNode) { +// addIf((IfNode) node, block, sequence); +// } else if (node instanceof EndifNode) { +// // nothing +// } else if (node instanceof ReceiveNode) { +// addReceive((ReceiveNode) node, sequence); +// } else if (node instanceof BlockNode) { +// addBlock((BlockNode) node, block, sequence); +// } else if (node instanceof EndBlockNode) { +// // nothing +// } else if (node instanceof StreamSourceNode) { +// addStreamSource((StreamSourceNode) node, sequence); +// } else if (node instanceof ExitNode) { +// addExit((ExitNode) node, sequence); +// } else if (node instanceof ResourceNode) { +// // nothing +// } else { +// +// throw new GraphException(node.getClass().getName() + " is not supported."); +// } +// } +// +// /** +// * @param node +// * @param sequence +// */ +// private void addStreamSource(StreamSourceNode node, GpelSequence sequence) { +// GpelFlow flow = new GpelFlow(this.bpelNS); +// new GpelSequence(this.bpelNS); +// sequence.addActivity(flow); +// +// } +// +// /** +// * @param node +// * @param sequence +// */ +// private void addExit(ExitNode node, GpelSequence sequence) { +// sequence.xml().addElement(this.bpelNS, "exit"); +// } +// +// private void addInvoke(WSNode node, GpelSequence sequence) throws GraphException { +// String id = node.getID(); +// +// WSComponent wsdlComponent = node.getComponent(); +// String operation = wsdlComponent.getOperationName(); +// +// QName portTypeQName = wsdlComponent.getPortTypeQName(); +// XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(id.toLowerCase(), portTypeQName.getNamespaceURI(), +// false, this.process.xml()); +// +// // Variable +// String inputVariableName = id + INPUT_SUFFIX; +// this.process.addMessageVariable(inputVariableName, namespace, portTypeQName.getLocalPart()); +// String outputVariableName = id + OUTPUT_SUFFIX; +// this.process.addMessageVariable(outputVariableName, namespace, portTypeQName.getLocalPart()); +// +// // Assign +// List<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); +// for (Port port : node.getInputPorts()) { +// Port fromPort = port.getFromPort(); +// if (fromPort == null) { +// // optional input +// continue; +// } +// GpelAssignCopyFrom from = createAssignCopyFrom(port); +// GpelAssignCopyTo to = createAssignCopyTo(port, true); +// +// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); +// copies.add(copy); +// } +// +// GpelAssign assign = new GpelAssign(this.bpelNS, copies); +// sequence.addActivity(assign); +// +// PartnerLinkRole partnerRoll = this.workflowWSDL.getPartnerRoll(portTypeQName); +// if (partnerRoll == null) { +// String partnerLinkTypeName = id + PARTNER_LINK_TYPE_SUFFIX; +// String partnerRollName = id + PARTNER_ROLE_SUFFIX; +// partnerRoll = this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, partnerRollName, +// portTypeQName); +// } +// PartnerLinkType partnerLinkType = partnerRoll.getPartnerLinkType(); +// +// // partnerLink +// String partnerLinkName = createPartnerLinkName(id); +// XmlNamespace partnerLinkTypeNS = this.targetNamespace; +// this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkType.getName(), null, +// partnerRoll.getName()); +// +// // Invoke +// GpelInvoke invoke = new GpelInvoke(this.bpelNS, partnerLinkName, namespace, portTypeQName.getLocalPart(), +// operation); +// invoke.setName(INVOKE_NAME_PREFIX + id); +// invoke.setInputVariableName(inputVariableName); +// invoke.setOutputVariableName(outputVariableName); +// +// sequence.addActivity(invoke); +// } + +// /** +// * Creates BpelAssignCopyFrom for a specified port. +// * +// * @param port +// * @return The BpelAssignCopyFrom created +// * @throws GraphException +// */ +// private GpelAssignCopyFrom createAssignCopyFrom(Port port) throws GraphException { +// GpelAssignCopyFrom from = new GpelAssignCopyFrom(this.bpelNS); +// +// Port fromPort = port.getFromPort(); +// Node fromNode = fromPort.getNode(); +// if (fromNode instanceof InputNode) { +// from.setVariable(WORKFLOW_INPUT_NAME); +// from.setPart(WorkflowWSDL.INPUT_PART_NAME); +// from.setQuery("/" + this.typesNamespace.getPrefix() + ":" +// + this.workflowWSDL.getWorkflowInputMessageElelmentName() + "/" + fromNode.getID()); +// } else if (fromNode instanceof ConstantNode) { +// ConstantNode constNode = (ConstantNode) fromNode; +// Object value = constNode.getValue(); +// // The namaspace and name of the literal element will be set +// // correctly in from.setLiteral(). +// XmlElement literalElement = XMLUtil.BUILDER.newFragment(GpelAssignCopyFrom.LITERAL_EL); +// literalElement.addChild(value); +// from.setLiteral(literalElement); +// } else if (fromNode instanceof WSNode) { +// String fromID = fromNode.getID(); +// WSComponent fromWsdlComponent = (WSComponent) fromNode.getComponent(); +// +// WSComponentPort fromWsdlPort = (WSComponentPort) fromPort.getComponentPort(); +// +// from.setVariable(fromID + OUTPUT_SUFFIX); +// from.setPart(fromWsdlComponent.getOutputPartName()); +// +// if (fromWsdlPort.isSchemaUsed()) { +// String typesTargetNamespace = fromWsdlPort.getTargetNamespace(); +// XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(fromID.toLowerCase() + TYPENS_SUFFIX, +// typesTargetNamespace, false, this.process.xml()); +// +// from.setQuery("/" + namespace.getPrefix() + ":" + fromWsdlComponent.getOutputTypeName() + "/" +// + fromWsdlPort.getName()); +// } else { +// // No query needed? +// } +// } else if (fromNode instanceof ForEachNode) { +// from.setVariable(fromNode.getID() + FOREACH_VALUE_SUFFIX); +// } else if (fromNode instanceof EndForEachNode) { +// from.setVariable(fromNode.getID() + ARRAY_SUFIX); +// } else if (fromNode instanceof EndifNode) { +// // endif has multiple outputs, so we use port ID here. +// from.setVariable(fromPort.getID() + OUTPUT_SUFFIX); +// } else if (fromNode instanceof ReceiveNode) { +// if (fromPort instanceof EPRPort) { +// from.setPartnerLink(fromNode.getID() + PARTNER_LINK_NAME_SUFFIX); +// from.setEndpointReference("myRole"); +// } else { +// from.setVariable(fromNode.getID() + INPUT_SUFFIX); +// } +// } else if (fromNode instanceof InstanceNode) { +// // no op +// } else { +// throw new GraphException("Unexpected node," + fromNode.getClass().getName() + " is connected"); +// } +// return from; +// } +// +// /** +// * Creates BpelAssignCopyFrom for a specified port. +// * +// * @param toPort +// * @param input +// * @return The GpelAssignCopyTo created +// */ +// private GpelAssignCopyTo createAssignCopyTo(Port toPort, boolean input) { +// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); +// +// Node toNode = toPort.getNode(); +// if (toNode instanceof OutputNode) { +// to.setVariable(WORKFLOW_OUTPUT_NAME); +// to.setPart(WorkflowWSDL.OUTPUT_PART_NAME); +// to.setQuery("/" + this.typesNamespace.getPrefix() + ":" +// + this.workflowWSDL.getWorkflowOutputMessageElementName() + "/" + toNode.getID()); +// } else { +// WSComponentPort toComponentPort = (WSComponentPort) toPort.getComponentPort(); +// +// String toID = toNode.getID(); +// WSComponent toWSComponent = (WSComponent) toNode.getComponent(); +// to.setVariable(toID + INPUT_SUFFIX); +// to.setPart(toWSComponent.getInputPartName()); +// +// if (toComponentPort.isSchemaUsed()) { +// // Normal case. +// // e.g. <part name="name" type="typens:fooType"> +// String typesTargetNamespace = toComponentPort.getTargetNamespace(); +// XmlNamespace namespace = XMLUtil.declareNamespaceIfNecessary(toID.toLowerCase() + TYPENS_SUFFIX, +// typesTargetNamespace, false, this.process.xml()); +// +// String typeName = input ? toWSComponent.getInputTypeName() : toWSComponent.getOutputTypeName(); +// to.setQuery("/" + namespace.getPrefix() + ":" + typeName + "/" + toComponentPort.getName()); +// } else { +// // e.g. <part name="name" type="xsd:string"> +// // No query is needed? +// } +// } +// return to; +// } private void removeUnnecessaryNodes(List<Node> block) { List<Node> unnecessaryNodes = new ArrayList<Node>(); @@ -854,60 +854,60 @@ public class BPELScript { throw new GraphException("Cannot find matching " + endClass.getName() + " for " + startClass.getName() + "."); } - private void addForEach(ForEachNode splitNode, Collection<Node> parentBlock, GpelSequence sequence) - throws GraphException { - Set<Node> forEachBlock = getForEachBlock(splitNode); - parentBlock.removeAll(forEachBlock); - - GpelSequence subSequence = new GpelSequence(this.bpelNS); - GpelScope scope = new GpelScope(this.bpelNS, subSequence); - - String arrayName = splitNode.getID() + ARRAY_SUFIX; - // TODO This should be type instead of messageType - this.process.addMessageVariable(arrayName, WSConstants.XSD_NS, WSConstants.XSD_ANY_TYPE.getLocalPart()); - - // Extract array from the previous node. - GpelAssignCopyFrom arrayFrom = createAssignCopyFrom(splitNode.getInputPort(0)); - GpelAssignCopyTo arrayTo = new GpelAssignCopyTo(this.bpelNS); - arrayTo.setVariable(arrayName); - GpelAssignCopy arrayCopy = new GpelAssignCopy(this.bpelNS, arrayFrom, arrayTo); - GpelAssign arrayAssign = new GpelAssign(this.bpelNS, arrayCopy); - sequence.addActivity(arrayAssign); - - // Extract a item from array - String valueName = splitNode.getID() + FOREACH_VALUE_SUFFIX; - // TODO set local variable in scope instead of process - // TODO This should be type instead of messageType - this.process.addMessageVariable(valueName, WSConstants.XSD_NS, WSConstants.XSD_ANY_TYPE.getLocalPart()); - GpelAssignCopyFrom valueFrom = new GpelAssignCopyFrom(this.bpelNS); - valueFrom.setVariable(arrayName); - valueFrom.setQuery("$" + arrayName + "/*[$i]"); - GpelAssignCopyTo valueTo = new GpelAssignCopyTo(this.bpelNS); - valueTo.setVariable(valueName); - GpelAssignCopy valueCopy = new GpelAssignCopy(this.bpelNS, valueFrom, valueTo); - GpelAssign valueAssign = new GpelAssign(this.bpelNS, valueCopy); - - subSequence.addActivity(valueAssign); - - addBlock(forEachBlock, subSequence); - - Node mergeNode = getMergeNode(splitNode); - String outputName = mergeNode.getID() + ARRAY_SUFIX; - // TODO This should be type instead of messageType - this.process.addMessageVariable(outputName, WSConstants.XSD_NS, WSConstants.XSD_ANY_TYPE.getLocalPart()); - GpelAssignCopyFrom outputFrom = createAssignCopyFrom(mergeNode.getInputPort(0).getFromPort()); - GpelAssignCopyTo outputTo = new GpelAssignCopyTo(this.bpelNS); - outputTo.setVariable(outputName); - outputTo.setQuery("/value[$i]"); - GpelAssignCopy outputCopy = new GpelAssignCopy(this.bpelNS, outputFrom, outputTo); - GpelAssign outputAssign = new GpelAssign(this.bpelNS, outputCopy); - subSequence.addActivity(outputAssign); - - GpelForEach forEach = new GpelForEach(this.bpelNS, "i", "1", "count($" + arrayName + "/*)", - true /* parallel */, scope); - - sequence.addActivity(forEach); - } +// private void addForEach(ForEachNode splitNode, Collection<Node> parentBlock, GpelSequence sequence) +// throws GraphException { +// Set<Node> forEachBlock = getForEachBlock(splitNode); +// parentBlock.removeAll(forEachBlock); +// +// GpelSequence subSequence = new GpelSequence(this.bpelNS); +// GpelScope scope = new GpelScope(this.bpelNS, subSequence); +// +// String arrayName = splitNode.getID() + ARRAY_SUFIX; +// // TODO This should be type instead of messageType +// this.process.addMessageVariable(arrayName, WSConstants.XSD_NS, WSConstants.XSD_ANY_TYPE.getLocalPart()); +// +// // Extract array from the previous node. +// GpelAssignCopyFrom arrayFrom = createAssignCopyFrom(splitNode.getInputPort(0)); +// GpelAssignCopyTo arrayTo = new GpelAssignCopyTo(this.bpelNS); +// arrayTo.setVariable(arrayName); +// GpelAssignCopy arrayCopy = new GpelAssignCopy(this.bpelNS, arrayFrom, arrayTo); +// GpelAssign arrayAssign = new GpelAssign(this.bpelNS, arrayCopy); +// sequence.addActivity(arrayAssign); +// +// // Extract a item from array +// String valueName = splitNode.getID() + FOREACH_VALUE_SUFFIX; +// // TODO set local variable in scope instead of process +// // TODO This should be type instead of messageType +// this.process.addMessageVariable(valueName, WSConstants.XSD_NS, WSConstants.XSD_ANY_TYPE.getLocalPart()); +// GpelAssignCopyFrom valueFrom = new GpelAssignCopyFrom(this.bpelNS); +// valueFrom.setVariable(arrayName); +// valueFrom.setQuery("$" + arrayName + "/*[$i]"); +// GpelAssignCopyTo valueTo = new GpelAssignCopyTo(this.bpelNS); +// valueTo.setVariable(valueName); +// GpelAssignCopy valueCopy = new GpelAssignCopy(this.bpelNS, valueFrom, valueTo); +// GpelAssign valueAssign = new GpelAssign(this.bpelNS, valueCopy); +// +// subSequence.addActivity(valueAssign); +// +// addBlock(forEachBlock, subSequence); +// +// Node mergeNode = getMergeNode(splitNode); +// String outputName = mergeNode.getID() + ARRAY_SUFIX; +// // TODO This should be type instead of messageType +// this.process.addMessageVariable(outputName, WSConstants.XSD_NS, WSConstants.XSD_ANY_TYPE.getLocalPart()); +// GpelAssignCopyFrom outputFrom = createAssignCopyFrom(mergeNode.getInputPort(0).getFromPort()); +// GpelAssignCopyTo outputTo = new GpelAssignCopyTo(this.bpelNS); +// outputTo.setVariable(outputName); +// outputTo.setQuery("/value[$i]"); +// GpelAssignCopy outputCopy = new GpelAssignCopy(this.bpelNS, outputFrom, outputTo); +// GpelAssign outputAssign = new GpelAssign(this.bpelNS, outputCopy); +// subSequence.addActivity(outputAssign); +// +// GpelForEach forEach = new GpelForEach(this.bpelNS, "i", "1", "count($" + arrayName + "/*)", +// true /* parallel */, scope); +// +// sequence.addActivity(forEach); +// } private Set<Node> getForEachBlock(ForEachNode node) throws GraphException { Set<Node> forEachBlock = new HashSet<Node>(); @@ -919,112 +919,112 @@ public class BPELScript { return findEndNode(node, 0, ForEachNode.class, EndForEachNode.class); } - private void addIf(IfNode ifNode, Collection<Node> parentBlock, GpelSequence sequence) throws GraphException { - // - // Condition - // - String booleanExpression = ifNode.getXPath(); - if (booleanExpression == null) { - throw new GraphException("XPath cannot be null"); - } - // replace $1, $2,... with actual value. - List<? extends Port> inputPorts = ifNode.getInputPorts(); - ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); - for (int i = 0; i < inputPorts.size(); i++) { - Port port = inputPorts.get(i); - Port fromPort = port.getFromPort(); - if (fromPort != null) { - String variableName = port.getID() + INPUT_SUFFIX; - - GpelVariable ifVar = new GpelVariable(this.process.xml().getNamespace(), variableName); - XmlNamespace xsdNS = process.xml().lookupNamespaceByName(WSConstants.XSD_NS_URI); - if (null != xsdNS && xsdNS.getPrefix() != null) { - ifVar.xml().setAttributeValue("element", - xsdNS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); - } else { - this.process.xml().declareNamespace(WSConstants.XSD_NS); - ifVar.xml().setAttributeValue("element", - WSConstants.XSD_NS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); - } - this.process.getVariables().addVariable(ifVar); - - GpelAssignCopyFrom from = createAssignCopyFrom(fromPort); - GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); - to.setVariable(variableName); - GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); - copies.add(copy); - - booleanExpression = booleanExpression.replaceAll("\\$" + i, "\\$" + variableName); - } - } - if (copies.size() > 0) { - GpelAssign assign = new GpelAssign(this.bpelNS, copies); - sequence.addActivity(assign); - } - GpelCondition condition = new GpelCondition(this.bpelNS, booleanExpression); - - // - // If block - // - EndifNode endifNode = getEndifNode(ifNode); - GpelSequence ifSequence = createIfSequence(ifNode, endifNode, true, parentBlock); - GpelIf gpelIf = new GpelIf(this.bpelNS, condition, ifSequence); - - // - // Else block - // - GpelSequence elseSequence = createIfSequence(ifNode, endifNode, false, parentBlock); - GpelElse gpelElse = new GpelElse(this.bpelNS, elseSequence); - gpelIf.setElse(gpelElse); - - // - // Create global variables for endif. - // - for (Port outputPort : endifNode.getOutputPorts()) { - String variable = outputPort.getID() + OUTPUT_SUFFIX; - GpelVariable ifVar = new GpelVariable(this.process.xml().getNamespace(), variable); - XmlNamespace xsdNS = process.xml().lookupNamespaceByName(WSConstants.XSD_NS_URI); - if (null != xsdNS && xsdNS.getPrefix() != null) { - ifVar.xml().setAttributeValue("element", - xsdNS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); - } else { - this.process.xml().declareNamespace(WSConstants.XSD_NS); - ifVar.xml().setAttributeValue("element", - WSConstants.XSD_NS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); - } - this.process.getVariables().addVariable(ifVar); - } - - sequence.addActivity(gpelIf); - } - - private GpelSequence createIfSequence(IfNode ifNode, EndifNode endifNode, boolean ifBlock, - Collection<Node> parentBlock) throws GraphException { - Set<Node> block = getIfBlock(ifNode, ifBlock); - parentBlock.removeAll(block); - GpelSequence sequence = new GpelSequence(this.bpelNS); - addBlock(block, sequence); - - // Create a copy to global variable. - List<DataPort> outputPorts = endifNode.getOutputPorts(); - ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); - for (int i = 0; i < outputPorts.size(); i++) { - DataPort outputPort = outputPorts.get(i); - String variable = outputPort.getID() + OUTPUT_SUFFIX; - int index = ifBlock ? i : i + outputPorts.size(); - DataPort inputPort = endifNode.getInputPort(index); - Port fromPort = inputPort.getFromPort(); - GpelAssignCopyFrom from = createAssignCopyFrom(fromPort); - GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); - to.setVariable(variable); - GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); - copies.add(copy); - } - GpelAssign assign = new GpelAssign(this.bpelNS, copies); - sequence.addActivity(assign); - - return sequence; - } +// private void addIf(IfNode ifNode, Collection<Node> parentBlock, GpelSequence sequence) throws GraphException { +// // +// // Condition +// // +// String booleanExpression = ifNode.getXPath(); +// if (booleanExpression == null) { +// throw new GraphException("XPath cannot be null"); +// } +// // replace $1, $2,... with actual value. +// List<? extends Port> inputPorts = ifNode.getInputPorts(); +// ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); +// for (int i = 0; i < inputPorts.size(); i++) { +// Port port = inputPorts.get(i); +// Port fromPort = port.getFromPort(); +// if (fromPort != null) { +// String variableName = port.getID() + INPUT_SUFFIX; +// +// GpelVariable ifVar = new GpelVariable(this.process.xml().getNamespace(), variableName); +// XmlNamespace xsdNS = process.xml().lookupNamespaceByName(WSConstants.XSD_NS_URI); +// if (null != xsdNS && xsdNS.getPrefix() != null) { +// ifVar.xml().setAttributeValue("element", +// xsdNS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); +// } else { +// this.process.xml().declareNamespace(WSConstants.XSD_NS); +// ifVar.xml().setAttributeValue("element", +// WSConstants.XSD_NS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); +// } +// this.process.getVariables().addVariable(ifVar); +// +// GpelAssignCopyFrom from = createAssignCopyFrom(fromPort); +// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); +// to.setVariable(variableName); +// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); +// copies.add(copy); +// +// booleanExpression = booleanExpression.replaceAll("\\$" + i, "\\$" + variableName); +// } +// } +// if (copies.size() > 0) { +// GpelAssign assign = new GpelAssign(this.bpelNS, copies); +// sequence.addActivity(assign); +// } +// GpelCondition condition = new GpelCondition(this.bpelNS, booleanExpression); +// +// // +// // If block +// // +// EndifNode endifNode = getEndifNode(ifNode); +// GpelSequence ifSequence = createIfSequence(ifNode, endifNode, true, parentBlock); +// GpelIf gpelIf = new GpelIf(this.bpelNS, condition, ifSequence); +// +// // +// // Else block +// // +// GpelSequence elseSequence = createIfSequence(ifNode, endifNode, false, parentBlock); +// GpelElse gpelElse = new GpelElse(this.bpelNS, elseSequence); +// gpelIf.setElse(gpelElse); +// +// // +// // Create global variables for endif. +// // +// for (Port outputPort : endifNode.getOutputPorts()) { +// String variable = outputPort.getID() + OUTPUT_SUFFIX; +// GpelVariable ifVar = new GpelVariable(this.process.xml().getNamespace(), variable); +// XmlNamespace xsdNS = process.xml().lookupNamespaceByName(WSConstants.XSD_NS_URI); +// if (null != xsdNS && xsdNS.getPrefix() != null) { +// ifVar.xml().setAttributeValue("element", +// xsdNS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); +// } else { +// this.process.xml().declareNamespace(WSConstants.XSD_NS); +// ifVar.xml().setAttributeValue("element", +// WSConstants.XSD_NS.getPrefix() + ":" + WSConstants.XSD_ANY_TYPE.getLocalPart()); +// } +// this.process.getVariables().addVariable(ifVar); +// } +// +// sequence.addActivity(gpelIf); +// } +// +// private GpelSequence createIfSequence(IfNode ifNode, EndifNode endifNode, boolean ifBlock, +// Collection<Node> parentBlock) throws GraphException { +// Set<Node> block = getIfBlock(ifNode, ifBlock); +// parentBlock.removeAll(block); +// GpelSequence sequence = new GpelSequence(this.bpelNS); +// addBlock(block, sequence); +// +// // Create a copy to global variable. +// List<DataPort> outputPorts = endifNode.getOutputPorts(); +// ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); +// for (int i = 0; i < outputPorts.size(); i++) { +// DataPort outputPort = outputPorts.get(i); +// String variable = outputPort.getID() + OUTPUT_SUFFIX; +// int index = ifBlock ? i : i + outputPorts.size(); +// DataPort inputPort = endifNode.getInputPort(index); +// Port fromPort = inputPort.getFromPort(); +// GpelAssignCopyFrom from = createAssignCopyFrom(fromPort); +// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); +// to.setVariable(variable); +// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); +// copies.add(copy); +// } +// GpelAssign assign = new GpelAssign(this.bpelNS, copies); +// sequence.addActivity(assign); +// +// return sequence; +// } private Set<Node> getIfBlock(Node node, boolean ifBlock) throws GraphException { Set<Node> block = new HashSet<Node>(); @@ -1042,83 +1042,83 @@ public class BPELScript { return findEndNode(node, 0, IfNode.class, EndifNode.class); } - /** - * @param node - * @param block - * @param sequence - */ - private void addReceive(ReceiveNode node, GpelSequence sequence) { - String id = node.getID(); - String operationName = id; - - // Create this operation and type in WSDL. - WsdlPortType portType = this.workflowWSDL.addReceivePortType(operationName, node); - QName portTypeQName = portType.getQName(); - - // Partner link - String partnerLinkName = createPartnerLinkName(id); - XmlNamespace partnerLinkTypeNS = this.targetNamespace; - String partnerLinkTypeName = id + PARTNER_LINK_TYPE_SUFFIX; - String myRollName = id + MY_ROLE_SUFFIX; - this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkTypeName, myRollName, null); - this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, myRollName, portTypeQName); - - GpelReceive receive = new GpelReceive(this.bpelNS, partnerLinkName, portTypeQName, operationName); - String variableName = id + INPUT_SUFFIX; - this.process.addMessageVariable(variableName, WSConstants.XSD_NS, variableName); - receive.setGpelVariableName(variableName); - sequence.addActivity(receive); - } - - private void addBlock(BlockNode blockNode, Collection<Node> parentBlock, GpelSequence sequence) - throws GraphException { - - // - // normal block - // - EndBlockNode endBlockNode = getEndBlockNode(blockNode); - GpelSequence normalSequence = createBlockSequence(blockNode, endBlockNode, true, parentBlock); - GpelScope scope = new GpelScope(this.bpelNS, normalSequence); - - // - // exception block - // - // GpelSequence compensationSequence = createBlockSequence(blockNode, - // endBlockNode, false, parentBlock); - // TODO GpelExceptionHandler handler - // = new GpelExceptionHandler(compensationSequence); - // scope.add(handler); - - sequence.addActivity(scope); - } - - private GpelSequence createBlockSequence(BlockNode blockNode, EndBlockNode endBlockNode, boolean blockBlock, - Collection<Node> parentBlock) throws GraphException { - Set<Node> block = getBlockBlock(blockNode, blockBlock); - parentBlock.removeAll(block); - GpelSequence sequence = new GpelSequence(this.bpelNS); - addBlock(block, sequence); - - // Create a copy to global variable. - List<DataPort> outputPorts = endBlockNode.getOutputPorts(); - ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); - for (int i = 0; i < outputPorts.size(); i++) { - DataPort outputPort = outputPorts.get(i); - String variable = outputPort.getID() + OUTPUT_SUFFIX; - int index = blockBlock ? i : i + outputPorts.size(); - DataPort inputPort = endBlockNode.getInputPort(index); - Port fromPort = inputPort.getFromPort(); - GpelAssignCopyFrom from = createAssignCopyFrom(fromPort); - GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); - to.setVariable(variable); - GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); - copies.add(copy); - } - GpelAssign assign = new GpelAssign(this.bpelNS, copies); - sequence.addActivity(assign); - - return sequence; - } +// /** +// * @param node +// * @param block +// * @param sequence +// */ +// private void addReceive(ReceiveNode node, GpelSequence sequence) { +// String id = node.getID(); +// String operationName = id; +// +// // Create this operation and type in WSDL. +// WsdlPortType portType = this.workflowWSDL.addReceivePortType(operationName, node); +// QName portTypeQName = portType.getQName(); +// +// // Partner link +// String partnerLinkName = createPartnerLinkName(id); +// XmlNamespace partnerLinkTypeNS = this.targetNamespace; +// String partnerLinkTypeName = id + PARTNER_LINK_TYPE_SUFFIX; +// String myRollName = id + MY_ROLE_SUFFIX; +// this.process.addPartnerLink(partnerLinkName, partnerLinkTypeNS, partnerLinkTypeName, myRollName, null); +// this.workflowWSDL.addPartnerLinkTypeAndRoll(partnerLinkTypeName, myRollName, portTypeQName); +// +// GpelReceive receive = new GpelReceive(this.bpelNS, partnerLinkName, portTypeQName, operationName); +// String variableName = id + INPUT_SUFFIX; +// this.process.addMessageVariable(variableName, WSConstants.XSD_NS, variableName); +// receive.setGpelVariableName(variableName); +// sequence.addActivity(receive); +// } +// +// private void addBlock(BlockNode blockNode, Collection<Node> parentBlock, GpelSequence sequence) +// throws GraphException { +// +// // +// // normal block +// // +// EndBlockNode endBlockNode = getEndBlockNode(blockNode); +// GpelSequence normalSequence = createBlockSequence(blockNode, endBlockNode, true, parentBlock); +// GpelScope scope = new GpelScope(this.bpelNS, normalSequence); +// +// // +// // exception block +// // +// // GpelSequence compensationSequence = createBlockSequence(blockNode, +// // endBlockNode, false, parentBlock); +// // TODO GpelExceptionHandler handler +// // = new GpelExceptionHandler(compensationSequence); +// // scope.add(handler); +// +// sequence.addActivity(scope); +// } +// +// private GpelSequence createBlockSequence(BlockNode blockNode, EndBlockNode endBlockNode, boolean blockBlock, +// Collection<Node> parentBlock) throws GraphException { +// Set<Node> block = getBlockBlock(blockNode, blockBlock); +// parentBlock.removeAll(block); +// GpelSequence sequence = new GpelSequence(this.bpelNS); +// addBlock(block, sequence); +// +// // Create a copy to global variable. +// List<DataPort> outputPorts = endBlockNode.getOutputPorts(); +// ArrayList<GpelAssignCopy> copies = new ArrayList<GpelAssignCopy>(); +// for (int i = 0; i < outputPorts.size(); i++) { +// DataPort outputPort = outputPorts.get(i); +// String variable = outputPort.getID() + OUTPUT_SUFFIX; +// int index = blockBlock ? i : i + outputPorts.size(); +// DataPort inputPort = endBlockNode.getInputPort(index); +// Port fromPort = inputPort.getFromPort(); +// GpelAssignCopyFrom from = createAssignCopyFrom(fromPort); +// GpelAssignCopyTo to = new GpelAssignCopyTo(this.bpelNS); +// to.setVariable(variable); +// GpelAssignCopy copy = new GpelAssignCopy(this.bpelNS, from, to); +// copies.add(copy); +// } +// GpelAssign assign = new GpelAssign(this.bpelNS, copies); +// sequence.addActivity(assign); +// +// return sequence; +// } private Set<Node> getBlockBlock(Node node, boolean blockBlock) throws GraphException { Set<Node> block = new HashSet<Node>();
