You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2012/05/17 19:12:21 UTC
svn commit: r1339718 [7/10] - in /incubator/airavata/trunk: ./
modules/airavata-client/ modules/distribution/
modules/distribution/src/main/assembly/ modules/workflow-model/
modules/workflow-model/src/ modules/workflow-model/src/main/
modules/workflow-...
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/EndifNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/EndifNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/EndifNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/EndifNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,229 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.component.ComponentDataPort;
+import org.apache.airavata.workflow.model.component.system.EndifComponent;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port.Kind;
+import org.xmlpull.infoset.XmlElement;
+
+public class EndifNode extends SystemNode {
+
+ /**
+ * Creates a InputNode.
+ *
+ * @param graph
+ */
+ public EndifNode(Graph graph) {
+ super(graph);
+ }
+
+ /**
+ * Constructs a InputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public EndifNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public EndifComponent getComponent() {
+ EndifComponent component = (EndifComponent) super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new EndifComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Adds additional input port.
+ */
+ public void addInputPort() {
+ EndifComponent component = getComponent();
+ ComponentDataPort input = component.getInputPort();
+ DataPort port = input.createPort();
+ addInputPort(port);
+ }
+
+ /**
+ * Removes the last input port.
+ *
+ * @throws GraphException
+ */
+ public void removeInputPort() throws GraphException {
+ List<DataPort> inputPorts = getInputPorts();
+ // Remove the last one.
+ DataPort inputPort = inputPorts.get(inputPorts.size() - 1);
+ removeInputPort(inputPort);
+ }
+
+ /**
+ * Adds additional output port.
+ */
+ public void addOutputPort() {
+ EndifComponent component = getComponent();
+ ComponentDataPort outputPort = component.getOutputPort();
+ DataPort port = outputPort.createPort();
+ addOutputPort(port);
+ }
+
+ /**
+ * Removes the last output port.
+ *
+ * @throws GraphException
+ */
+ public void removeOutputPort() throws GraphException {
+ List<DataPort> outputPorts = getOutputPorts();
+ // Remove the last one.
+ DataPort outputPort = outputPorts.get(outputPorts.size() - 1);
+ removeOutputPort(outputPort);
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
+ */
+ @Override
+ protected void portTypeChanged(SystemDataPort port) throws GraphException {
+ super.portTypeChanged(port);
+
+ List<DataPort> inputPorts = getInputPorts();
+ List<DataPort> outputPorts = getOutputPorts();
+ int size = outputPorts.size();
+
+ Kind kind = port.getKind();
+ int index;
+ if (kind == Kind.DATA_IN) {
+ index = inputPorts.indexOf(port) % size;
+ } else if (kind == Kind.DATA_OUT) {
+ index = outputPorts.indexOf(port);
+ } else {
+ throw new WorkflowRuntimeException();
+ }
+
+ DataPort inputPort1 = inputPorts.get(index);
+ DataPort inputPort2 = inputPorts.get(size + index);
+ DataPort outputPort = outputPorts.get(index);
+
+ QName inputType1 = inputPort1.getType();
+ QName inputType2 = inputPort2.getType();
+ QName outputType = outputPort.getType();
+
+ QName portType = port.getType();
+ if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
+ // Do nothing
+ return;
+ }
+
+ if (port == inputPort1) {
+ // input1 -> input2
+ if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
+ inputPort2.copyType(port);
+ } else if (inputType2.equals(portType)) {
+ // Do nothing.
+ } else {
+ String message = "The type of input " + index + " (" + inputType1 + ") of " + getID()
+ + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
+ throw new GraphException(message);
+ }
+ // input1 -> output
+ if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
+ outputPort.copyType(port);
+ } else if (outputType.equals(portType)) {
+ // Do nothing.
+ } else {
+ String message = "The type of input " + index + " (" + inputType1 + ") of " + getID()
+ + " must be same as the type of output " + index + " (" + outputType + ").";
+ throw new GraphException(message);
+ }
+
+ } else if (port == inputPort2) {
+ // input2 -> input1
+ if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
+ inputPort1.copyType(port);
+ } else if (inputType1.equals(portType)) {
+ // Do nothing.
+ } else {
+ String message = "The type of input " + index + " (" + inputType1 + ") of " + getID()
+ + " must be same as the type of input " + (index + size) + " (" + inputType2 + ").";
+ throw new GraphException(message);
+ }
+ // input2 -> output
+ if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
+ outputPort.copyType(port);
+ } else if (outputType.equals(portType)) {
+ // Do nothing.
+ } else {
+ String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID()
+ + " must be same as the type of output " + index + " (" + outputType + ").";
+ throw new GraphException(message);
+ }
+ } else if (port == outputPort) {
+ // output -> input1
+ if (inputType1.equals(WSConstants.XSD_ANY_TYPE)) {
+ inputPort1.copyType(port);
+ } else if (inputType1.equals(portType)) {
+ // Do nothing.
+ } else {
+ String message = "The type of input " + index + " (" + inputType1 + ") of " + getID()
+ + " must be same as the type of output " + index + " (" + outputType + ").";
+ throw new GraphException(message);
+ }
+ // output -> input2
+ if (inputType2.equals(WSConstants.XSD_ANY_TYPE)) {
+ inputPort2.copyType(port);
+ } else if (inputType2.equals(portType)) {
+ // Do nothing.
+ } else {
+ String message = "The type of input " + (index + size) + " (" + inputType2 + ") of " + getID()
+ + " must be same as the type of input " + index + " (" + outputType + ").";
+ throw new GraphException(message);
+ }
+ } else {
+ throw new WorkflowRuntimeException();
+ }
+ }
+
+ @Override
+ protected XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_ENDIF);
+ return nodeElement;
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ExitNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ExitNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ExitNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ExitNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,81 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import org.apache.airavata.workflow.model.component.ExitComponent;
+import org.apache.airavata.workflow.model.graph.ControlEdge;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.impl.PortImpl;
+import org.xmlpull.infoset.XmlElement;
+
+public class ExitNode extends SystemNode {
+
+ /**
+ * Constructs a BPELExitNode.
+ *
+ * @param graph
+ */
+ public ExitNode(Graph graph) {
+ super(graph);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ protected void parseComponent(XmlElement componentElement) {
+ // No need to parse the XML.
+ setComponent(new ExitComponent());
+ }
+
+ /**
+ * @return the node xml
+ */
+ @Override
+ protected XmlElement toXML() {
+
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_EXIT);
+ return nodeElement;
+ }
+
+ @Override
+ protected void edgeWasAdded(Edge edge) throws GraphException {
+ super.edgeWasAdded(edge);
+ if (edge instanceof ControlEdge) {
+ List<ControlEdge> edges = getEdges();
+ if (edges.size() > 1) {
+ throw new GraphException("Cannot connect more than one Control Ports to the Exit node.");
+ }
+ }
+ }
+
+ protected List<ControlEdge> getEdges() {
+ PortImpl port = getControlInPort();
+ List<ControlEdge> edges = (List<ControlEdge>) port.getEdges();
+ return edges;
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ForEachNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ForEachNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ForEachNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ForEachNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,308 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.component.ComponentDataPort;
+import org.apache.airavata.workflow.model.component.system.ForEachComponent;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.EPRPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.Port.Kind;
+import org.apache.airavata.workflow.model.graph.dynamic.PortAddable;
+import org.xmlpull.infoset.XmlElement;
+
+public class ForEachNode extends SystemNode implements PortAddable{
+
+ // private static final MLogger logger = MLogger.getLogger();
+
+ /**
+ * Creates a InputNode.
+ *
+ * @param graph
+ */
+ public ForEachNode(Graph graph) {
+ super(graph);
+ }
+
+ /**
+ * Constructs a InputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public ForEachNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ *
+ * @return
+ */
+ @Override
+ public ForEachComponent getComponent() {
+ ForEachComponent component = (ForEachComponent) super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new ForEachComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Adds additional input port.
+ */
+ public void addInputPort() {
+ ForEachComponent component = getComponent();
+ ComponentDataPort input = component.getInputPort();
+ DataPort port = input.createPort();
+ addInputPort(port);
+ }
+
+ public DataPort addInputPortAndReturn() {
+ ForEachComponent component = getComponent();
+ ComponentDataPort input = component.getInputPort();
+ DataPort port = input.createPort();
+ addInputPort(port);
+ return port;
+ }
+
+
+
+ public void removeInputPort() throws GraphException {
+ List<DataPort> inputPorts = getInputPorts();
+ // Remove the last one.
+ DataPort inputPort = inputPorts.get(inputPorts.size() - 1);
+ removeInputPort(inputPort);
+ }
+
+
+
+
+ /**
+ * Adds additional output port.
+ */
+ public void addOutputPort() {
+ ForEachComponent component = getComponent();
+ ComponentDataPort outputPort = component.getOutputPort();
+ DataPort port = outputPort.createPort();
+ addOutputPort(port);
+ }
+
+ /**
+ * Removes the last output port.
+ *
+ * @throws GraphException
+ */
+ public void removeOutputPort() throws GraphException {
+ List<DataPort> outputPorts = getOutputPorts();
+ // Remove the last one.
+ DataPort outputPort = outputPorts.get(outputPorts.size() - 1);
+ removeOutputPort(outputPort);
+ }
+
+
+ /**
+ *
+ * @param edge
+ * @throws GraphException
+ */
+
+ @Override
+ protected void edgeWasAdded(Edge edge) throws GraphException {
+ // XXX cannot detect if the type is array or not from WSDL at this
+ // point. so no check here.
+ // super.edgeWasAdded(edge);
+
+ Port fromPort = edge.getFromPort();
+ Port toPort = edge.getToPort();
+ if (edge instanceof DataEdge) {
+ if (fromPort instanceof EPRPort) {
+ // TODO
+ return;
+ }
+
+ DataPort fromDataPort = (DataPort) fromPort;
+ DataPort toDataPort = (DataPort) toPort;
+
+ QName fromType = fromDataPort.getType();
+ QName toType = toDataPort.getType();
+
+ if (fromDataPort.getNode() == this) {
+ if (!(toType == null || toType.equals(WSConstants.XSD_ANY_TYPE))) {
+ fromDataPort.copyType(toDataPort);
+ }
+ } else if (toDataPort.getNode() == this) {
+ if (!(fromType == null || fromType
+ .equals(WSConstants.XSD_ANY_TYPE))) {
+ toDataPort.copyType(fromDataPort);
+ }
+ } else {
+ throw new WorkflowRuntimeException();
+ }
+ }
+ }
+
+ /**
+ *
+ * @param port
+ * @throws GraphException
+ */
+
+ @Override
+ protected void portTypeChanged(SystemDataPort port) throws GraphException {
+ super.portTypeChanged(port);
+
+ List<DataPort> inputPorts = getInputPorts();
+ List<DataPort> outputPorts = getOutputPorts();
+
+ Kind kind = port.getKind();
+ int index;
+ if (kind == Kind.DATA_IN) {
+ index = inputPorts.indexOf(port);
+ } else if (kind == Kind.DATA_OUT) {
+ index = outputPorts.indexOf(port);
+ } else {
+ throw new WorkflowRuntimeException();
+ }
+
+ SystemDataPort inputPort = (SystemDataPort) inputPorts.get(index);
+ SystemDataPort outputPort = (SystemDataPort) outputPorts.get(index);
+
+ QName inputType = inputPort.getType();
+ QName outputType = outputPort.getType();
+
+ QName portType = port.getType();
+ if (portType == null || portType.equals(WSConstants.XSD_ANY_TYPE)) {
+ // Do nothing
+ return;
+ }
+
+ if (port == inputPort) {
+ // input -> output
+ if (outputType.equals(WSConstants.XSD_ANY_TYPE)) {
+ // outputPort.copyType(port, -1);
+ } else if (outputType.equals(portType)) {
+ // Do nothing.
+ } else {
+ // XXX cannot parse array from WSDL.
+ // String message = "The type of input " + index + " ("
+ // + inputType + ") of " + getID()
+ // + " must be same as the type of output " + index + " ("
+ // + outputType + ").";
+ // throw new GraphException(message);
+ }
+
+ } else if (port == outputPort) {
+ // output -> input1
+ if (inputType.equals(WSConstants.XSD_ANY_TYPE)) {
+ // inputPort.copyType(port, 1);
+ } else if (inputType.equals(portType)) {
+ // Do nothing.
+ } else {
+ // XXX cannot parse array from WSDL.
+ // String message = "The type of input " + index + " ("
+ // + inputType + ") of " + getID()
+ // + " must be same as the type of output " + index + " ("
+ // + outputType + ").";
+ // throw new GraphException(message);
+ }
+ } else {
+ throw new WorkflowRuntimeException();
+ }
+ }
+
+ public DataPort getFreeInPort() {
+ List<DataPort> inputPorts = this.getInputPorts();
+ for (DataPort dataPort : inputPorts) {
+ if (null == dataPort.getFromNode()) {
+ return dataPort;
+ }
+ }
+ addOutputPort();
+ return addInputPortAndReturn();
+ }
+
+
+ public void removeLastDynamicallyAddedInPort() throws GraphException {
+
+ List<DataPort> inputPorts = this.getInputPorts();
+ List<DataPort> outputPorts = this.getOutputPorts();
+ if (inputPorts.size() == 1) {
+ //This is the initial port, so leave it alone
+ return;
+ }
+ if (outputPorts.size() == 1) {
+ return;
+ }
+ DataPort portToBeRemoved = null;
+ for (DataPort dataPort : inputPorts) {
+ if (null == dataPort.getFromNode()) {
+ removeInputPort(dataPort);
+ portToBeRemoved = dataPort;
+ break;
+ }
+ }
+
+ if(outputPorts.size() == this.getInputPorts().size()){
+ return;
+ }
+ for (DataPort dataPort : outputPorts) {
+ if (0 == dataPort.getToNodes().size()) {
+ removeOutputPort(dataPort);
+ portToBeRemoved = dataPort;
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected void parseConfiguration(XmlElement configElement) {
+ super.parseConfiguration(configElement);
+ }
+
+ @Override
+ protected XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS,
+ GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_SPLIT);
+ return nodeElement;
+ }
+
+ @Override
+ protected XmlElement addConfigurationElement(XmlElement nodeElement) {
+ XmlElement configElement = nodeElement.addElement(GraphSchema.NS,
+ GraphSchema.NODE_CONFIG_TAG);
+ return configElement;
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/IfNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/IfNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/IfNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/IfNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,141 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import org.apache.airavata.workflow.model.component.system.IfComponent;
+import org.apache.airavata.workflow.model.component.system.SystemComponentDataPort;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.xmlpull.infoset.XmlElement;
+
+public class IfNode extends SystemNode {
+
+ private static final String XPATH_TAG_NAME = "xpath";
+
+ private String xpath;
+
+ /**
+ * Creates a InputNode.
+ *
+ * @param graph
+ */
+ public IfNode(Graph graph) {
+ super(graph);
+
+ // Set the default to $0, which means that the input is boolean and
+ // xpath uses it as it is.
+ this.xpath = "$0";
+ }
+
+ /**
+ * Constructs an IfNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public IfNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ * Returns the xpath.
+ *
+ * @return The xpath
+ */
+ public String getXPath() {
+ return this.xpath;
+ }
+
+ /**
+ * Sets xpath.
+ *
+ * @param xpath
+ * The xpath to set.
+ */
+ public void setXPath(String xpath) {
+ this.xpath = xpath;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public IfComponent getComponent() {
+ IfComponent component = (IfComponent) super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new IfComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Adds additional input port.
+ */
+ public void addInputPort() {
+ IfComponent component = getComponent();
+ SystemComponentDataPort input = component.getInputPort();
+ SystemDataPort port = input.createPort();
+ addInputPort(port);
+ }
+
+ /**
+ * @throws GraphException
+ */
+ public void removeInputPort() throws GraphException {
+ List<DataPort> inputPorts = getInputPorts();
+ // Remove the last one.
+ DataPort inputPort = inputPorts.get(inputPorts.size() - 1);
+ removeInputPort(inputPort);
+ }
+
+ @Override
+ protected void parseConfiguration(XmlElement configElement) {
+ super.parseConfiguration(configElement);
+ XmlElement element = configElement.element(null, XPATH_TAG_NAME);
+ if (element != null) {
+ this.xpath = element.requiredText();
+ }
+ }
+
+ @Override
+ protected XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_IF);
+ return nodeElement;
+ }
+
+ @Override
+ protected XmlElement addConfigurationElement(XmlElement nodeElement) {
+ XmlElement configElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_CONFIG_TAG);
+ if (this.xpath != null) {
+ XmlElement element = configElement.addElement(GraphSchema.NS, XPATH_TAG_NAME);
+ element.addChild(this.xpath.toString());
+ }
+ return configElement;
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/InputNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,332 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.system.InputComponent;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.ws.WSPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.infoset.XmlElement;
+
+public class InputNode extends ParameterNode {
+
+ private static final String VALUE_TAG_NAME = "value";
+
+ private static final String VISIBILITY_TAG_NAME = "visibility";
+
+ private static final Logger logger = LoggerFactory.getLogger(InputNode.class);
+
+ private Object defaultValue;
+
+ private boolean visibility;
+
+ /**
+ * Creates an InputNode.
+ *
+ * @param graph
+ */
+ public InputNode(Graph graph) {
+ super(graph);
+ // Default value for visibility when creating a new node is true
+ visibility = true;
+ }
+
+ /**
+ * Constructs an InputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public InputNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ public boolean isVisibility() {
+ return visibility;
+ }
+
+ public void setVisibility(boolean visibility) {
+ this.visibility = visibility;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public Component getComponent() {
+ Component component = super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new InputComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Returns the type of the parameter
+ *
+ * @return The type of the parameter (e.g. string, int)
+ */
+ @Override
+ public QName getParameterType() {
+ List<DataEdge> edges = getEdges();
+ QName parameterType = super.getParameterType();
+ if (parameterType == null && getEdges().size() > 0) {
+ // This happens when the graph XML doesn't have parameterType.
+ DataEdge edge = edges.get(0);
+ DataPort toPort = edge.getToPort();
+ parameterType = toPort.getType();
+ }
+ return parameterType;
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return The defaultValue.
+ */
+ public Object getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValue
+ * The default value to set.
+ */
+ public void setDefaultValue(Object defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Returns the port of this InputNode.
+ *
+ * Note that an InputNode always has only one output port.
+ *
+ * @return The port
+ */
+ @Override
+ public SystemDataPort getPort() {
+ return (SystemDataPort) getOutputPorts().get(0);
+ }
+
+ /**
+ * Returns the first port that this input node is connected to.
+ *
+ * @return The first port that this input node is connected to
+ */
+ @Override
+ public Port getConnectedPort() {
+ return getPort().getEdge(0).getToPort();
+ }
+
+ /**
+ * Checks if the user input is valid.
+ *
+ * @param input
+ * The user input
+ * @return true if the user input is valid against the parameter type; false otherwise
+ */
+ public boolean isInputValid(String input) {
+ logger.debug("Input:" + input);
+ // TODO type checks
+ return true;
+ }
+
+ /**
+ * Called whan an Edge was added to the parameter port. Change the name of this node.
+ *
+ * @throws GraphException
+ *
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
+ */
+ @Override
+ protected void edgeWasAdded(Edge edge) throws GraphException {
+ super.edgeWasAdded(edge);
+
+ // TODO organize this.
+ if (edge instanceof DataEdge) {
+ DataEdge dataEdge = (DataEdge) edge;
+ DataPort toPort = dataEdge.getToPort();
+ QName toType = toPort.getType();
+
+ List<DataEdge> edges = getEdges();
+ if (edges.size() == 1) {
+ // The first edge.
+ setParameterType(toType);
+
+ if (!isConfigured() && toPort instanceof WSPort) {
+ // Copy
+ copyDefaultConfiguration((WSPort) toPort);
+ }
+ } else if (edges.size() > 1) {
+ // Not the first edge.
+ QName parameterType = getParameterType();
+ if (!toType.equals(WSConstants.XSD_ANY_TYPE) && !parameterType.equals(toType)) {
+ throw new GraphException("Cannot connect ports with different types.");
+ }
+
+ } else {
+ // Should not happen.
+ throw new WorkflowRuntimeException("edges.size(): " + edges.size());
+ }
+ }
+ }
+
+ /**
+ * Called whan an Edge was removed from the parameter port. Change the name of the node.
+ *
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasRemoved(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
+ */
+ @Override
+ protected void edgeWasRemoved(Edge removedEdge) {
+ super.edgeWasRemoved(removedEdge);
+ // TODO organize this.
+ List<DataEdge> edges = getEdges();
+ if (edges.size() == 0) {
+ setParameterType(null);
+
+ if (!isConfigured()) {
+ // Reset
+ setName(getComponent().getName());
+ setDescription("");
+ setDefaultValue(null);
+ setMetadata(null);
+ }
+
+ } else {
+ Edge edge = edges.get(0);
+ Port toPort = edge.getToPort();
+ WSPort toWsPort = (WSPort) toPort;
+ QName toType = toWsPort.getType();
+ setParameterType(toType);
+
+ if (!isConfigured()) {
+ // Copy
+ copyDefaultConfiguration(toWsPort);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
+ */
+ @Override
+ protected void portTypeChanged(SystemDataPort port) throws GraphException {
+ super.portTypeChanged(port);
+ setParameterType(port.getType());
+ }
+
+ @Override
+ protected void parseComponent(XmlElement componentElement) {
+ // No need to parse the XML.
+ setComponent(new InputComponent());
+ }
+
+ @Override
+ protected void parseConfiguration(XmlElement configElement) {
+ super.parseConfiguration(configElement);
+ XmlElement element = configElement.element(null, VALUE_TAG_NAME);
+ if (element != null) {
+ // It might be a String or XmlElement
+ for (Object child : element.children()) {
+ if (child instanceof String) {
+ if (((String) child).trim().length() == 0) {
+ // Skip white space before xml element.
+ continue;
+ }
+ }
+ this.defaultValue = child;
+ break;
+ }
+ // this.defaultValue = element.requiredText();
+ }
+ element = configElement.element(null, VISIBILITY_TAG_NAME);
+ if (element != null) {
+ // It might be a String or XmlElement
+ for (Object child : element.children()) {
+ if (child instanceof String) {
+ if (((String) child).trim().length() == 0) {
+ // Skip white space before xml element.
+ continue;
+ }
+ }
+ this.visibility = Boolean.parseBoolean((String) child);
+ break;
+ }
+ // this.defaultValue = element.requiredText();
+ } else {
+ this.visibility = true;
+ }
+ }
+
+ @Override
+ public XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_INPUT);
+ return nodeElement;
+ }
+
+ @Override
+ protected XmlElement addConfigurationElement(XmlElement nodeElement) {
+ XmlElement configElement = super.addConfigurationElement(nodeElement);
+ if (this.defaultValue != null) {
+ XmlElement element = configElement.addElement(GraphSchema.NS, VALUE_TAG_NAME);
+ element.addChild(this.defaultValue);
+ }
+ XmlElement element = configElement.addElement(GraphSchema.NS,
+ VISIBILITY_TAG_NAME);
+ element.addChild(Boolean.toString(this.visibility));
+ return configElement;
+ }
+
+ /**
+ * @param toWSPort
+ */
+ private void copyDefaultConfiguration(WSPort toWSPort) {
+ // TODO support recursive search for WSPort in case the input is
+ // connected to special nodes.
+ setName(toWSPort.getName());
+ WSComponentPort componentPort = toWSPort.getComponentPort();
+ setDescription(componentPort.getDescription());
+ setDefaultValue(componentPort.getDefaultValue());
+ setMetadata(componentPort.getAppinfo());
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/MemoNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/MemoNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/MemoNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/MemoNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,92 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.xmlpull.infoset.XmlElement;
+
+public class MemoNode extends SystemNode {
+
+ private String memo;
+
+ /**
+ * Constructs a ParameterNode.
+ *
+ * @param graph
+ *
+ */
+ public MemoNode(Graph graph) {
+ super(graph);
+ this.memo = "Double click here\nto take memo.";
+ }
+
+ /**
+ * Constructs a MemoNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public MemoNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ * Returns the memo.
+ *
+ * @return The memo
+ */
+ public String getMemo() {
+ return this.memo;
+ }
+
+ /**
+ * Sets memo.
+ *
+ * @param memo
+ * The memo to set.
+ */
+ public void setMemo(String memo) {
+ this.memo = memo;
+ }
+
+ @Override
+ protected XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_MEMO);
+ XmlElement memoElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_MEMO_TAG);
+ memoElement.addChild(this.memo);
+ return nodeElement;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#parse(org.xmlpull.infoset.XmlElement)
+ */
+ @Override
+ protected void parse(XmlElement nodeElement) throws GraphException {
+ super.parse(nodeElement);
+ XmlElement memoElement = nodeElement.element(GraphSchema.NODE_MEMO_TAG);
+ this.memo = memoElement.requiredText();
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/OutputNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,202 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.system.OutputComponent;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.ws.WSPort;
+import org.xmlpull.infoset.XmlElement;
+
+public class OutputNode extends ParameterNode {
+
+ /**
+ * Creates a OutputNode.
+ *
+ * @param graph
+ */
+ public OutputNode(Graph graph) {
+ super(graph);
+ }
+
+ /**
+ * Constructs a OutputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public OutputNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ * Returns the type of the parameter
+ *
+ * @return The type of the parameter (e.g. string, int)
+ */
+ @Override
+ public QName getParameterType() {
+ List<DataEdge> edges = getEdges();
+ QName parameterType = super.getParameterType();
+ if (parameterType == null && getEdges().size() > 0) {
+ Edge edge = edges.get(0);
+ WSPort fromPort = (WSPort) edge.getFromPort();
+ setParameterType(fromPort.getType());
+ }
+ return parameterType;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public Component getComponent() {
+ Component component = super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new OutputComponent();
+ }
+ return component;
+ }
+
+ /**
+ * Returns the port of this OutputNode.
+ *
+ * Note that an OutputNode always has only one input port.
+ *
+ * @return The port
+ */
+ @Override
+ public SystemDataPort getPort() {
+ return (SystemDataPort) getInputPorts().get(0);
+ }
+
+ /**
+ * Returns the first port that this output node is connected from.
+ *
+ * @return The first port that this output node is connected from
+ */
+ @Override
+ public Port getConnectedPort() {
+ return getPort().getEdge(0).getFromPort();
+ }
+
+ /**
+ * Called whan an Edge was added to the parameter port. Change the name of this node.
+ *
+ * @throws GraphException
+ *
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
+ */
+ @Override
+ protected void edgeWasAdded(Edge edge) throws GraphException {
+ super.edgeWasAdded(edge);
+ // TODO organize
+ Port fromPort = edge.getFromPort();
+
+ if (edge instanceof DataEdge) {
+ DataPort fromDataPort = (DataPort) fromPort;
+ QName fromType = fromDataPort.getType();
+
+ List<DataEdge> edges = getEdges();
+ if (edges.size() == 1) {
+ setParameterType(fromType);
+
+ if (!isConfigured() && fromDataPort instanceof WSPort) {
+ setName(fromDataPort.getName());
+ WSComponentPort componentPort = ((WSPort) fromDataPort).getComponentPort();
+ setDescription(componentPort.getDescription());
+ setMetadata(componentPort.getAppinfo());
+ }
+ } else {
+ throw new GraphException("Cannot connect more than one output ports to the output parameter.");
+ }
+ }
+ }
+
+ /**
+ * Called whan an Edge was removed from the parameter port. Change the name of the node.
+ *
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasRemoved(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
+ */
+ @Override
+ protected void edgeWasRemoved(Edge removedEdge) {
+ super.edgeWasRemoved(removedEdge);
+ // TODO organize
+ List<DataEdge> edges = getEdges();
+ if (edges.size() == 0) {
+ setParameterType(null);
+
+ if (!isConfigured()) {
+ // Reset
+ setName(OutputComponent.NAME);
+ setDescription("");
+ setMetadata(null);
+ }
+
+ } else if (edges.size() == 1) {
+ // This happens when the second edges was wrongly added and removed.
+ } else {
+ // Should not happen
+ throw new WorkflowRuntimeException("edges.size(): " + edges.size());
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
+ */
+ @Override
+ protected void portTypeChanged(SystemDataPort port) throws GraphException {
+ super.portTypeChanged(port);
+ setParameterType(port.getType());
+ }
+
+ @Override
+ protected void parseComponent(XmlElement componentElement) {
+ // No need to parse the XML.
+ setComponent(new OutputComponent());
+ }
+
+ /**
+ * @return the node xml
+ */
+ @Override
+ public XmlElement toXML() {
+
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_OUTPUT);
+ return nodeElement;
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ParameterNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,308 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.exception.UtilsException;
+import org.apache.airavata.common.utils.XMLUtil;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.xmlpull.infoset.XmlElement;
+import org.xmlpull.infoset.XmlNamespace;
+
+abstract public class ParameterNode extends SystemNode {
+
+ private static final String NAME_TAG = "name";
+
+ private static final String DESCRIPTION_TAG = "description";
+
+ private static final String DATA_TYPE_QNAME_TAG = "dataType";
+
+ private static final String METADATA_TAG = "metadata";
+
+ private boolean configured;
+
+ /**
+ * Type of the parameter (e.g. xsd:string, xsd:int)
+ */
+ private QName parameterType;
+
+ private String configuredName;
+
+ private String description;
+
+ private XmlElement metadata;
+
+ /**
+ * Constructs a ParameterNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public ParameterNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ * Constructs a ParameterNode.
+ *
+ * @param graph
+ *
+ */
+ public ParameterNode(Graph graph) {
+ super(graph);
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#setName(java.lang.String)
+ */
+ @Override
+ public void setName(String name) {
+ super.setName(name);
+ // Creates the ID to the new one based on the new name. This is
+ // for readability of workflow scripts.
+ createID();
+ }
+
+ /**
+ * @param parameterType
+ */
+ public void setParameterType(QName parameterType) {
+ this.parameterType = parameterType;
+ }
+
+ /**
+ * Returns the type of the parameter
+ *
+ * @return The type of the parameter (e.g. string, int)
+ */
+ public QName getParameterType() {
+ return this.parameterType;
+ }
+
+ /**
+ * Returns the configuredName.
+ *
+ * @return The configuredName
+ */
+ public String getConfiguredName() {
+ return this.configuredName;
+ }
+
+ /**
+ * Sets configuredName.
+ *
+ * @param configuredName
+ * The configuredName to set.
+ */
+ public void setConfiguredName(String configuredName) {
+ this.configuredName = configuredName;
+ setName(configuredName);
+ }
+
+ /**
+ * Returns the description.
+ *
+ * @return The description
+ */
+ public String getDescription() {
+ return this.description;
+ }
+
+ /**
+ * Sets description.
+ *
+ * @param description
+ * The description to set.
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @param metadata
+ */
+ public void setMetadata(XmlElement metadata) {
+ if (metadata == null) {
+ this.metadata = null;
+ return;
+ }
+
+ // clone and detach from the parent
+ try {
+ this.metadata = XMLUtil.deepClone(metadata);
+ } catch (UtilsException e) {
+ e.printStackTrace();
+ }
+
+ // Reformat
+ List<String> emptyTexts = new ArrayList<String>();
+ for (Object child : this.metadata.children()) {
+ if (child instanceof XmlElement) {
+ XmlElement element = (XmlElement) child;
+ for (XmlNamespace ns : element.namespaces()) {
+ // move the namespace declaration up if possible.
+ if (this.metadata.lookupNamespaceByPrefix(ns.getPrefix()) == null) {
+ // If this prefix is not used yet, copy to the root.
+ this.metadata.declareNamespace(ns);
+ }
+ }
+ } else if (child instanceof String) {
+ String text = (String) child;
+ // Remove the white spaces.
+ if (text.trim().length() == 0) {
+ // We cannot remove it in the iterator.
+ emptyTexts.add(text);
+ }
+ }
+ }
+ for (String text : emptyTexts) {
+ this.metadata.removeChild(text);
+ }
+ }
+
+ /**
+ * @return The metadata
+ */
+ public XmlElement getMetadata() {
+ return this.metadata;
+ }
+
+ /**
+ * @param configured
+ */
+ public void setConfigured(boolean configured) {
+ this.configured = configured;
+ }
+
+ /**
+ * @return true if configured; false otherwise.
+ */
+ public boolean isConfigured() {
+ return this.configured;
+ }
+
+ /**
+ * Checks if this InputNode is connected.
+ *
+ * @return true if this InputNode is connected; false otherwise;
+ */
+ public boolean isConnected() {
+ if (getEdges().size() > 0) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the port of this ParameterNode.
+ *
+ * Note that a ParameterNode always has only one port.
+ *
+ * @return The port
+ */
+ abstract public SystemDataPort getPort();
+
+ /**
+ * Returns the first port that this node is connected to/from.
+ *
+ * @return The first port that this node is connected to/from
+ */
+ abstract public Port getConnectedPort();
+
+ @Override
+ protected void parseConfiguration(XmlElement configElement) {
+ XmlElement nameElement = configElement.element(null, NAME_TAG);
+ if (nameElement != null) {
+ // If the name is set here, this node has been configured.
+ this.configured = true;
+ this.configuredName = nameElement.requiredText();
+ }
+ XmlElement descElement = configElement.element(null, DESCRIPTION_TAG);
+ if (descElement != null) {
+ this.description = descElement.requiredText();
+ }
+ XmlElement typeElement = configElement.element(null, DATA_TYPE_QNAME_TAG);
+ if (typeElement != null) {
+ String qnameText = typeElement.requiredText();
+ if (qnameText != null && !qnameText.equals("")) {
+ this.parameterType = QName.valueOf(qnameText);
+ }
+ }
+ XmlElement metadataElement = configElement.element(null, METADATA_TAG);
+ if (metadataElement != null) {
+ for (XmlElement appinfo : metadataElement.requiredElementContent()) {
+ // Call setMetadata to clone and reformat.
+ setMetadata(appinfo);
+ // It should have only one element.
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected XmlElement addConfigurationElement(XmlElement nodeElement) {
+
+ XmlElement configElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_CONFIG_TAG);
+
+ if (this.configured) {
+ // Don't save the name here if this node has not been configured.
+ XmlElement nameElement = configElement.addElement(GraphSchema.NS, NAME_TAG);
+ nameElement.addChild(this.configuredName);
+ }
+ if (this.description != null) {
+ XmlElement descriptionElement = configElement.addElement(GraphSchema.NS, DESCRIPTION_TAG);
+ descriptionElement.addChild(this.description);
+ }
+ if (this.parameterType != null) {
+ XmlElement qnameElement = configElement.addElement(GraphSchema.NS, DATA_TYPE_QNAME_TAG);
+ qnameElement.addChild(this.parameterType.toString());
+ }
+ if (this.metadata != null) {
+ XmlElement metadataElement = configElement.addElement(GraphSchema.NS, METADATA_TAG);
+ // Clone the metadata to avoid parent problem because this can be
+ // called multiple times.
+ try {
+ metadataElement.addChild(XMLUtil.deepClone(this.metadata));
+ } catch (UtilsException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return configElement;
+ }
+
+ protected List<DataEdge> getEdges() {
+ DataPort port = getPort();
+ List<DataEdge> edges = port.getEdges();
+ return edges;
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ReceiveNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ReceiveNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ReceiveNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/ReceiveNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,112 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import org.apache.airavata.workflow.model.component.system.ReceiveComponent;
+import org.apache.airavata.workflow.model.component.system.SystemComponentDataPort;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.xmlpull.infoset.XmlElement;
+
+public class ReceiveNode extends SystemNode {
+
+ /**
+ * Creates a InputNode.
+ *
+ * @param graph
+ */
+ public ReceiveNode(Graph graph) {
+ super(graph);
+ }
+
+ /**
+ * Constructs a InputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public ReceiveNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public ReceiveComponent getComponent() {
+ ReceiveComponent component = (ReceiveComponent) super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new ReceiveComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Adds additional output port.
+ */
+ public void addOutputPort() {
+ ReceiveComponent component = getComponent();
+ SystemComponentDataPort outputPort = component.getOutputPort();
+ SystemDataPort port = outputPort.createPort();
+ addOutputPort(port);
+ }
+
+ /**
+ * @throws GraphException
+ */
+ public void removeOutputPort() throws GraphException {
+ List<DataPort> outputPorts = getOutputPorts();
+ // Remove the last one.
+ DataPort outputPort = outputPorts.get(outputPorts.size() - 1);
+ removeOutputPort(outputPort);
+ }
+
+ @Override
+ protected void edgeWasAdded(Edge edge) {
+ // TODO
+ }
+
+ @Override
+ protected void parseConfiguration(XmlElement configElement) {
+ super.parseConfiguration(configElement);
+ }
+
+ @Override
+ protected XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_RECEIVE);
+ return nodeElement;
+ }
+
+ @Override
+ protected XmlElement addConfigurationElement(XmlElement nodeElement) {
+ XmlElement configElement = nodeElement.addElement(GraphSchema.NS, GraphSchema.NODE_CONFIG_TAG);
+ return configElement;
+ }
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/S3InputNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/S3InputNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/S3InputNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/S3InputNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,298 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.system.S3InputComponent;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.Edge;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.airavata.workflow.model.graph.ws.WSPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.infoset.XmlElement;
+
+public class S3InputNode extends InputNode {
+
+ private static final String VALUE_TAG_NAME = "value";
+
+ private static final Logger logger = LoggerFactory.getLogger(S3InputNode.class);
+
+ private Object defaultValue;
+
+ /**
+ * Creates an InputNode.
+ *
+ * @param graph
+ */
+ public S3InputNode(Graph graph) {
+ super(graph);
+ }
+
+ /**
+ * Constructs an InputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public S3InputNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public Component getComponent() {
+ Component component = super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new S3InputComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Returns the type of the parameter
+ *
+ * @return The type of the parameter (e.g. string, int)
+ */
+ @Override
+ public QName getParameterType() {
+ List<DataEdge> edges = getEdges();
+ QName parameterType = super.getParameterType();
+ if (parameterType == null && getEdges().size() > 0) {
+ // This happens when the graph XML doesn't have parameterType.
+ DataEdge edge = edges.get(0);
+ DataPort toPort = edge.getToPort();
+ parameterType = toPort.getType();
+ }
+ return parameterType;
+ }
+
+ /**
+ * Returns the default value.
+ *
+ * @return The defaultValue.
+ */
+ public Object getDefaultValue() {
+ return this.defaultValue;
+ }
+
+ /**
+ * Sets the default value.
+ *
+ * @param defaultValue
+ * The default value to set.
+ */
+ public void setDefaultValue(Object defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * Returns the port of this InputNode.
+ *
+ * Note that an InputNode always has only one output port.
+ *
+ * @return The port
+ */
+ @Override
+ public SystemDataPort getPort() {
+ return (SystemDataPort) getOutputPorts().get(0);
+ }
+
+ /**
+ * Returns the first port that this input node is connected to.
+ *
+ * @return The first port that this input node is connected to
+ */
+ @Override
+ public Port getConnectedPort() {
+ return getPort().getEdge(0).getToPort();
+ }
+
+ /**
+ * Checks if the user input is valid.
+ *
+ * @param input
+ * The user input
+ * @return true if the user input is valid against the parameter type; false otherwise
+ */
+ public boolean isInputValid(String input) {
+ logger.debug("Input:" + input);
+ // TODO type checks
+ return true;
+ }
+
+ /**
+ * Called whan an Edge was added to the parameter port. Change the name of this node.
+ *
+ * @throws GraphException
+ *
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasAdded(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
+ */
+ @Override
+ protected void edgeWasAdded(Edge edge) throws GraphException {
+ super.edgeWasAdded(edge);
+
+ // TODO organize this.
+ if (edge instanceof DataEdge) {
+ DataEdge dataEdge = (DataEdge) edge;
+ DataPort toPort = dataEdge.getToPort();
+ QName toType = toPort.getType();
+
+ List<DataEdge> edges = getEdges();
+ if (edges.size() == 1) {
+ // The first edge.
+ setParameterType(toType);
+
+ if (!isConfigured() && toPort instanceof WSPort) {
+ // Copy
+ copyDefaultConfiguration((WSPort) toPort);
+ }
+ } else if (edges.size() > 1) {
+ // Not the first edge.
+ QName parameterType = getParameterType();
+ if (!toType.equals(WSConstants.XSD_ANY_TYPE) && !parameterType.equals(toType)) {
+ throw new GraphException("Cannot connect ports with different types.");
+ }
+
+ } else {
+ // Should not happen.
+ throw new WorkflowRuntimeException("edges.size(): " + edges.size());
+ }
+ }
+ }
+
+ /**
+ * Called whan an Edge was removed from the parameter port. Change the name of the node.
+ *
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#edgeWasRemoved(org.apache.airavata.workflow.model.graph.impl.EdgeImpl)
+ */
+ @Override
+ protected void edgeWasRemoved(Edge removedEdge) {
+ super.edgeWasRemoved(removedEdge);
+ // TODO organize this.
+ List<DataEdge> edges = getEdges();
+ if (edges.size() == 0) {
+ setParameterType(null);
+
+ if (!isConfigured()) {
+ // Reset
+ setName(getComponent().getName());
+ setDescription("");
+ setDefaultValue(null);
+ setMetadata(null);
+ }
+
+ } else {
+ Edge edge = edges.get(0);
+ Port toPort = edge.getToPort();
+ WSPort toWsPort = (WSPort) toPort;
+ QName toType = toWsPort.getType();
+ setParameterType(toType);
+
+ if (!isConfigured()) {
+ // Copy
+ copyDefaultConfiguration(toWsPort);
+ }
+ }
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.system.SystemNode#portTypeChanged(org.apache.airavata.workflow.model.graph.system.SystemDataPort)
+ */
+ @Override
+ protected void portTypeChanged(SystemDataPort port) throws GraphException {
+ super.portTypeChanged(port);
+ setParameterType(port.getType());
+ }
+
+ @Override
+ protected void parseComponent(XmlElement componentElement) {
+ // No need to parse the XML.
+ setComponent(new S3InputComponent());
+ }
+
+ @Override
+ protected void parseConfiguration(XmlElement configElement) {
+ super.parseConfiguration(configElement);
+ XmlElement element = configElement.element(null, VALUE_TAG_NAME);
+ if (element != null) {
+ // It might be a String or XmlElement
+ for (Object child : element.children()) {
+ if (child instanceof String) {
+ if (((String) child).trim().length() == 0) {
+ // Skip white space before xml element.
+ continue;
+ }
+ }
+ this.defaultValue = child;
+ break;
+ }
+ // this.defaultValue = element.requiredText();
+ }
+ }
+
+ @Override
+ public XmlElement toXML() {
+ XmlElement nodeElement = super.toXML();
+ nodeElement.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_INPUT);
+ return nodeElement;
+ }
+
+ @Override
+ protected XmlElement addConfigurationElement(XmlElement nodeElement) {
+ XmlElement configElement = super.addConfigurationElement(nodeElement);
+ if (this.defaultValue != null) {
+ XmlElement element = configElement.addElement(GraphSchema.NS, VALUE_TAG_NAME);
+ element.addChild(this.defaultValue);
+ }
+ return configElement;
+ }
+
+ /**
+ * @param toWSPort
+ */
+ private void copyDefaultConfiguration(WSPort toWSPort) {
+ // TODO support recursive search for WSPort in case the input is
+ // connected to special nodes.
+ setName(toWSPort.getName());
+ WSComponentPort componentPort = toWSPort.getComponentPort();
+ setDescription(componentPort.getDescription());
+ setDefaultValue(componentPort.getDefaultValue());
+ setMetadata(componentPort.getAppinfo());
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/StreamSourceNode.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/StreamSourceNode.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/StreamSourceNode.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/StreamSourceNode.java Thu May 17 17:12:15 2012
@@ -0,0 +1,158 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import java.awt.Point;
+import java.util.ArrayList;
+
+import org.apache.airavata.workflow.model.component.Component;
+import org.apache.airavata.workflow.model.component.StreamSourceComponent;
+import org.apache.airavata.workflow.model.graph.Graph;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.Port;
+import org.apache.axiom.om.util.UUIDGenerator;
+import org.xmlpull.infoset.XmlElement;
+
+public class StreamSourceNode extends ParameterNode {
+
+ private String streamSourceURL;
+
+ private ArrayList<InputNode> inputNodes = new ArrayList<InputNode>();
+
+ private String label;
+
+ /**
+ * Creates an InputNode.
+ *
+ * @param graph
+ */
+ public StreamSourceNode(Graph graph) {
+ super(graph);
+ this.label = UUIDGenerator.getUUID();
+ }
+
+ /**
+ * Constructs an InputNode.
+ *
+ * @param nodeElement
+ * @throws GraphException
+ */
+ public StreamSourceNode(XmlElement nodeElement) throws GraphException {
+ super(nodeElement);
+ this.label = UUIDGenerator.getUUID();
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.NodeImpl#getComponent()
+ */
+ @Override
+ public Component getComponent() {
+ Component component = super.getComponent();
+ if (component == null) {
+ // The component is null when read from the graph XML.
+ component = new StreamSourceComponent();
+ setComponent(component);
+ }
+ return component;
+ }
+
+ /**
+ * Returns the port of this InputNode.
+ *
+ * Note that an InputNode always has only one output port.
+ *
+ * @return The port
+ */
+ @Override
+ public SystemDataPort getPort() {
+ return (SystemDataPort) getOutputPorts().get(0);
+ }
+
+ /**
+ * Returns the first port that this input node is connected to.
+ *
+ * @return The first port that this input node is connected to
+ */
+ @Override
+ public Port getConnectedPort() {
+ return getPort().getEdge(0).getToPort();
+ }
+
+ /**
+ * Returns the streamSourceURL.
+ *
+ * @return The streamSourceURL
+ */
+ public String getStreamSourceURL() {
+ return this.streamSourceURL;
+ }
+
+ /**
+ * Sets streamSourceURL.
+ *
+ * @param streamSourceURL
+ * The streamSourceURL to set.
+ */
+ public void setStreamSourceURL(String streamSourceURL) {
+ this.streamSourceURL = streamSourceURL;
+ }
+
+ /**
+ * @param inputNode
+ */
+ public void addInputNode(InputNode inputNode) {
+ if (!this.inputNodes.contains(inputNode)) {
+ this.inputNodes.add(inputNode);
+ }
+ setPosition(this.getPosition());
+
+ }
+
+ @Override
+ public void setPosition(Point point) {
+ super.setPosition(point);
+ int count = 0;
+ for (InputNode inputNode : this.inputNodes) {
+ inputNode.setPosition(new Point(point.x + 5 + count * 5, point.y + 25 + count * 45));
+ ++count;
+ }
+ }
+
+ public ArrayList<InputNode> getInputNodes() {
+ return this.inputNodes;
+ }
+
+ /**
+ *
+ */
+ public String getlabel() {
+ return this.label;
+ }
+
+ public XmlElement toXML() {
+ XmlElement xml = super.toXML();
+ xml.setAttributeValue(GraphSchema.NS, GraphSchema.NODE_TYPE_ATTRIBUTE, GraphSchema.NODE_TYPE_STREAM_SOURCE);
+ return xml;
+ }
+
+}
\ No newline at end of file
Added: incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java
URL: http://svn.apache.org/viewvc/incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java?rev=1339718&view=auto
==============================================================================
--- incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java (added)
+++ incubator/airavata/trunk/modules/workflow-model/src/main/java/org/apache/airavata/workflow/model/graph/system/SystemDataPort.java Thu May 17 17:12:15 2012
@@ -0,0 +1,183 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.workflow.model.graph.system;
+
+import javax.xml.namespace.QName;
+
+import org.apache.airavata.common.utils.WSConstants;
+import org.apache.airavata.workflow.model.component.ws.WSComponentPort;
+import org.apache.airavata.workflow.model.exceptions.WorkflowRuntimeException;
+import org.apache.airavata.workflow.model.graph.DataEdge;
+import org.apache.airavata.workflow.model.graph.DataPort;
+import org.apache.airavata.workflow.model.graph.GraphException;
+import org.apache.airavata.workflow.model.graph.GraphSchema;
+import org.apache.airavata.workflow.model.graph.ws.WSPort;
+import org.xmlpull.infoset.XmlElement;
+
+public class SystemDataPort extends DataPort {
+
+ private int arrayDimension;
+
+ private QName type;
+
+ private WSComponentPort wsComponentPort;
+
+ /**
+ * Constructs a DynamicWSPort.
+ */
+ public SystemDataPort() {
+ super();
+ resetType();
+ }
+
+ /**
+ * Constructs a DynamicWSPort.
+ *
+ * @param portElement
+ */
+ public SystemDataPort(XmlElement portElement) {
+ super(portElement);
+ resetType();
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#getNode()
+ */
+ @Override
+ public SystemNode getNode() {
+ return (SystemNode) super.getNode();
+ }
+
+ /**
+ * @return The type QName.
+ */
+ @Override
+ public QName getType() {
+ return this.type;
+ }
+
+ /**
+ * Returns the arrayDimension.
+ *
+ * @return The arrayDimension
+ */
+ public int getArrayDimension() {
+ return this.arrayDimension;
+ }
+
+ /**
+ * Sets arrayDimension.
+ *
+ * @param arrayDimension
+ * The arrayDimension to set.
+ */
+ public void setArrayDimension(int arrayDimension) {
+ this.arrayDimension = arrayDimension;
+ }
+
+ /**
+ * Returns the wsComponentPort.
+ *
+ * @return The wsComponentPort
+ */
+ public WSComponentPort getWSComponentPort() {
+ return this.wsComponentPort;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.DataPort#copyType(org.apache.airavata.workflow.model.graph.DataPort)
+ */
+ @Override
+ public void copyType(DataPort port) throws GraphException {
+ copyType(port, 0);
+ }
+
+ /**
+ * @param port
+ * @param arrayIncrement
+ * @throws GraphException
+ */
+ public void copyType(DataPort port, int arrayIncrement) throws GraphException {
+ QName newType = port.getType();
+ if (this.type != newType) {
+ this.type = newType;
+ if (port instanceof WSPort) {
+ WSPort wsPort = (WSPort) port;
+ this.wsComponentPort = wsPort.getComponentPort();
+ this.arrayDimension = 0;
+ } else if (port instanceof SystemDataPort) {
+ SystemDataPort systemPort = (SystemDataPort) port;
+ this.wsComponentPort = systemPort.getWSComponentPort();
+ this.arrayDimension = systemPort.getArrayDimension() + arrayIncrement;
+ }
+
+ // propagate to other ports of this node.
+ getNode().portTypeChanged(this);
+
+ // propagate to the connected ports.
+ Kind kind = getKind();
+ for (DataEdge edge : getEdges()) {
+ if (kind == Kind.DATA_IN) {
+ DataPort fromPort = edge.getFromPort();
+ fromPort.copyType(this);
+ } else if (kind == Kind.DATA_OUT) {
+ DataPort toPort = edge.getToPort();
+ toPort.copyType(this);
+ } else {
+ throw new WorkflowRuntimeException();
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public void resetType() {
+ this.arrayDimension = 0;
+ this.type = WSConstants.XSD_ANY_TYPE;
+ this.wsComponentPort = null;
+ }
+
+ /**
+ * @see org.apache.airavata.workflow.model.graph.impl.PortImpl#toXML()
+ */
+ @Override
+ protected XmlElement toXML() {
+ XmlElement portElement = super.toXML();
+
+ portElement.setAttributeValue(GraphSchema.NS, GraphSchema.PORT_TYPE_ATTRIBUTE,
+ GraphSchema.PORT_TYPE_SYSTEM_DATA);
+
+ return portElement;
+ }
+
+ public int getIndex(){
+ if(this.getNode() instanceof InputNode){
+ return this.getGraph().getCurrentInputNodeCount() + 1;
+ }else if (this.getNode() instanceof OutputNode){
+ return this.getGraph().getCurrentOutputNodeCount() + 1;
+ }
+ return super.getIndex();
+ }
+
+}
\ No newline at end of file