コード例 #1
0
  /**
   * This method returns the input values for given foreach node
   *
   * @param forEachNode
   * @param listOfValues
   * @param invokerMap
   * @return
   * @throws WorkflowException
   */
  public static Object getInputsForForEachNode(
      final ForEachNode forEachNode,
      final LinkedList<String> listOfValues,
      Map<Node, Invoker> invokerMap)
      throws WorkflowException {
    List<DataPort> inputPorts = forEachNode.getInputPorts();

    Object returnValForProvenance = null;
    for (DataPort inputPort : inputPorts) {

      Node inputNode = inputPort.getFromNode();
      // if input node for for-each is WSNode
      if (inputNode instanceof InputNode) {
        //                for (DataPort dataPort : forEachNode.getInputPorts()) {
        returnValForProvenance = InterpreterUtil.findInputFromPort(inputPort, invokerMap);
        if (null == returnValForProvenance) {
          throw new WorkFlowInterpreterException(
              "Unable to find input for the node:" + forEachNode.getID());
        }
        String[] vals = StringUtil.getElementsFromString(returnValForProvenance.toString());
        listOfValues.addAll(Arrays.asList(vals));
        //                }
      } else {
        Invoker workflowInvoker = invokerMap.get(inputNode);
        if (workflowInvoker != null) {
          if (workflowInvoker instanceof GenericInvoker) {

            String outputName = inputNode.getOutputPort(0).getName();
            returnValForProvenance = workflowInvoker.getOutput(outputName);
            Iterator children = null;
            if (returnValForProvenance instanceof org.xmlpull.v1.builder.XmlElement) {
              org.xmlpull.v1.builder.XmlElement msgElmt =
                  (org.xmlpull.v1.builder.XmlElement) returnValForProvenance;
              children = msgElmt.children();
            } else {
              XmlElement msgElmt =
                  XmlConstants.BUILDER.parseFragmentFromString(
                      "<temp>" + returnValForProvenance + "</temp>");
              children = msgElmt.children().iterator();
            }
            while (children.hasNext()) {
              Object object = children.next();
              if (object instanceof org.xmlpull.v1.builder.XmlElement) {
                org.xmlpull.v1.builder.XmlElement child =
                    (org.xmlpull.v1.builder.XmlElement) object;
                Iterator valItr = child.children();
                if (valItr.hasNext()) {
                  Object object2 = valItr.next();
                  if (object2 instanceof String) {
                    listOfValues.add(object2.toString());
                  }
                }
              }
              if (object instanceof XmlElement) {
                listOfValues.add(((XmlElement) object).children().iterator().next().toString());
              }
              if (object instanceof String) {
                listOfValues.add(object.toString());
              }
            }
          } else if (workflowInvoker instanceof SystemComponentInvoker) {
            int index = inputNode.getOutputPorts().indexOf(inputPort.getEdge(0).getFromPort());
            String outputName = "";
            if (inputNode.getInputPort(index) instanceof SystemDataPort) {
              outputName =
                  ((SystemDataPort) inputNode.getInputPort(index)).getWSComponentPort().getName();
            } else if (inputNode.getInputPort(index) instanceof WSPort) {
              outputName =
                  ((SystemDataPort)
                          inputNode.getInputPort(
                              inputNode
                                  .getOutputPorts()
                                  .indexOf(inputPort.getEdge(0).getFromPort())))
                      .getWSComponentPort()
                      .getName();
            }
            returnValForProvenance = workflowInvoker.getOutput(outputName);
            XmlElement msgElmt =
                XmlConstants.BUILDER.parseFragmentFromString(
                    "<temp>" + returnValForProvenance + "</temp>");
            Iterator valItr = msgElmt.children().iterator();
            while (valItr.hasNext()) {
              Object object2 = valItr.next();
              if (object2 instanceof XmlElement) {
                listOfValues.add(((XmlElement) object2).children().iterator().next().toString());
              }
            }
          }
        } else {
          throw new WorkFlowInterpreterException("Did not find inputs from WS to foreach");
        }
      }
    }
    return returnValForProvenance;
  }
コード例 #2
0
  public static Integer[] getNumberOfInputsForForEachNode(
      final ForEachNode forEachNode, Map<Node, Invoker> invokerMap) throws WorkflowException {
    List<DataPort> inputPorts = forEachNode.getInputPorts();
    Integer[] inputNumbers = new Integer[inputPorts.size()];
    for (DataPort forEachInputPort : inputPorts) {
      // if input node for for-each is WSNode
      Node forEachInputNode = forEachInputPort.getFromNode();
      int index = 0;
      Object returnValForProvenance = null;
      if (forEachInputNode instanceof InputNode) {
        returnValForProvenance = InterpreterUtil.findInputFromPort(forEachInputPort, invokerMap);
        if (null == returnValForProvenance) {
          throw new WorkFlowInterpreterException(
              "Unable to find input for the node:" + forEachNode.getID());
        }
        String[] vals = StringUtil.getElementsFromString(returnValForProvenance.toString());
        inputNumbers[inputPorts.indexOf(forEachInputPort)] = vals.length;
      } else {
        Invoker workflowInvoker = invokerMap.get(forEachInputNode);
        if (workflowInvoker != null) {
          if (workflowInvoker instanceof GenericInvoker) {

            returnValForProvenance = ((GenericInvoker) workflowInvoker).getOutputs();
            String message = returnValForProvenance.toString();

            XmlElement msgElmt = XmlConstants.BUILDER.parseFragmentFromString(message);
            Iterator children = msgElmt.children().iterator();
            while (children.hasNext()) {
              Object object = children.next();
              // foreachWSNode.getInputPort(0).getType()
              if (object instanceof XmlElement) {
                index++;
              }
            }
          } else if (workflowInvoker instanceof WorkflowInvokerWrapperForGFacInvoker) {
            String outputName = forEachInputNode.getOutputPort(0).getName();
            returnValForProvenance = workflowInvoker.getOutput(outputName);
            org.xmlpull.v1.builder.XmlElement msgElmt =
                (org.xmlpull.v1.builder.XmlElement) returnValForProvenance;
            Iterator children = msgElmt.children();
            while (children.hasNext()) {
              Object object = children.next();
              if (object instanceof org.xmlpull.v1.builder.XmlElement) {
                org.xmlpull.v1.builder.XmlElement child =
                    (org.xmlpull.v1.builder.XmlElement) object;
                Iterator valItr = child.children();
                if (valItr.hasNext()) {
                  Object object2 = valItr.next();
                  if (object2 instanceof String) {
                    index++;
                  }
                }
              }
            }
            inputNumbers[inputPorts.indexOf(forEachInputPort)] = index;
          } else if (workflowInvoker instanceof SystemComponentInvoker) {
            int portIndex =
                forEachInputNode
                    .getOutputPorts()
                    .indexOf(forEachInputPort.getEdge(0).getFromPort());
            String outputName = "";
            if (forEachInputNode.getInputPort(portIndex) instanceof SystemDataPort) {
              outputName =
                  ((SystemDataPort) forEachInputNode.getInputPort(portIndex))
                      .getWSComponentPort()
                      .getName();
            } else if (forEachInputNode.getInputPort(portIndex) instanceof WSPort) {
              outputName =
                  ((WSPort) forEachInputNode.getInputPort(portIndex)).getComponentPort().getName();
            }
            returnValForProvenance = workflowInvoker.getOutput(outputName);
            XmlElement msgElmt =
                XmlConstants.BUILDER.parseFragmentFromString(
                    "<temp>" + returnValForProvenance + "</temp>");
            Iterator valItr = msgElmt.children().iterator();
            while (valItr.hasNext()) {
              Object object2 = valItr.next();
              if (object2 instanceof XmlElement) {
                index++;
              }
            }
            inputNumbers[inputPorts.indexOf(forEachInputPort)] = index;
          }

        } else {
          throw new WorkFlowInterpreterException("Did not find inputs from WS to foreach");
        }
      }
    }
    return inputNumbers;
  }