private SequenceDefinition(
      final Node sequenceRootNode,
      final String solutionPath,
      final ILogger logger,
      final IApplicationContext applicationContext) {

    // initialize this object from the contents of the xml

    this.xactionPath = solutionPath;
    this.applicationContext = applicationContext;

    // get the descriptive entries
    version = XmlDom4JHelper.getNodeText("version", sequenceRootNode); // $NON-NLS-1$
    title = XmlDom4JHelper.getNodeText("title", sequenceRootNode); // $NON-NLS-1$

    isWebService =
        "true"
            .equals(
                XmlDom4JHelper.getNodeText(
                    "web-service", sequenceRootNode)); // $NON-NLS-1$ //$NON-NLS-2$
    loggingLevel =
        Logger.getLogLevel(
            XmlDom4JHelper.getNodeText("logging-level", sequenceRootNode)); // $NON-NLS-1$

    description =
        XmlDom4JHelper.getNodeText("documentation/description", sequenceRootNode); // $NON-NLS-1$
    help = XmlDom4JHelper.getNodeText("documentation/help", sequenceRootNode); // $NON-NLS-1$
    author = XmlDom4JHelper.getNodeText("documentation/author", sequenceRootNode); // $NON-NLS-1$
    resultType =
        XmlDom4JHelper.getNodeText("documentation/result-type", sequenceRootNode); // $NON-NLS-1$
    iconPath = XmlDom4JHelper.getNodeText("documentation/icon", sequenceRootNode); // $NON-NLS-1$

    // get the input parameter definitions
    inputDefinitions = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            sequenceRootNode, logger, "inputs/*", inputDefinitions, null, true); // $NON-NLS-1$

    // get the ouput definitions
    outputDefinitions = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            sequenceRootNode, logger, "outputs/*", outputDefinitions, null, false); // $NON-NLS-1$
    if (errorCode != ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK) {
      logger.info(
          Messages.getInstance()
              .getString(
                  "SequenceDefinition.INFO_OUTPUT_PARAMETERS_NOT_DEFINED")); //$NON-NLS-1$
    }
    // get the resource definitions
    errorCode = parseResourceDefinitions(sequenceRootNode, logger);
    if (errorCode != ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK) {
      logger.info(
          Messages.getInstance()
              .getString(
                  "SequenceDefinition.INFO_RESOURCES_PARAMETERS_NOT_DEFINED")); //$NON-NLS-1$
    }
  }
Exemplo n.º 2
0
  public ActionDefinition(final Node actionRootNode, final ILogger logger) {

    this.actionRootNode = actionRootNode;

    errorCode = ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    // this.sequenceData = sequenceData;

    // get the input parameter definitions
    actionInputDefinitions = new ListOrderedMap();
    actionInputMapping = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            actionRootNode,
            logger,
            "action-inputs/*",
            actionInputDefinitions,
            actionInputMapping,
            true); //$NON-NLS-1$

    // get the ouput definitions
    actionOutputDefinitions = new ListOrderedMap();
    actionOutputMapping = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            actionRootNode,
            logger,
            "action-outputs/*",
            actionOutputDefinitions,
            actionOutputMapping,
            false); //$NON-NLS-1$

    // get the resource definitions
    actionResourceMapping = new ListOrderedMap();
    if (actionRootNode.selectNodes("action-resources/*").size() > 0) { // $NON-NLS-1$
      hasActionResources = true;
      errorCode =
          SequenceDefinition.parseActionResourceDefinitions(
              actionRootNode, logger, "action-resources/*", actionResourceMapping); // $NON-NLS-1$
    }

    componentName = XmlDom4JHelper.getNodeText("component-name", actionRootNode); // $NON-NLS-1$
    String loggingLevelString =
        XmlDom4JHelper.getNodeText("logging-level", actionRootNode); // $NON-NLS-1$
    loggingLevel = Logger.getLogLevel(loggingLevelString);

    // get the component payload
    componentNode = actionRootNode.selectSingleNode("component-definition"); // $NON-NLS-1$
    if (componentNode == null) {
      componentNode = ((Element) actionRootNode).addElement("component-definition"); // $NON-NLS-1$
    }

    // TODO populate preExecuteAuditList and postExecuteAuditList
  }
  private static Object getDefaultValue(final Node parameterNode) {
    Node rootNode = parameterNode.selectSingleNode("default-value"); // $NON-NLS-1$
    if (rootNode == null) {
      return (null);
    }

    String dataType = XmlDom4JHelper.getNodeText("@type", rootNode); // $NON-NLS-1$
    if (dataType == null) {
      dataType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$
    }

    if ("string-list".equals(dataType)) { // $NON-NLS-1$
      List nodes = rootNode.selectNodes("list-item"); // $NON-NLS-1$
      if (nodes == null) {
        return (null);
      }

      ArrayList rtnList = new ArrayList();
      for (Iterator it = nodes.iterator(); it.hasNext(); ) {
        rtnList.add(((Node) it.next()).getText());
      }
      return (rtnList);
    } else if ("property-map-list".equals(dataType)) { // $NON-NLS-1$
      List nodes = rootNode.selectNodes("property-map"); // $NON-NLS-1$
      if (nodes == null) {
        return (null);
      }

      ArrayList rtnList = new ArrayList();
      for (Iterator it = nodes.iterator(); it.hasNext(); ) {
        Node mapNode = (Node) it.next();
        rtnList.add(SequenceDefinition.getMapFromNode(mapNode));
      }
      return (rtnList);
    } else if ("property-map".equals(dataType)) { // $NON-NLS-1$
      return (SequenceDefinition.getMapFromNode(
          rootNode.selectSingleNode("property-map"))); // $NON-NLS-1$
    } else if ("long".equals(dataType)) { // $NON-NLS-1$
      try {
        return (new Long(rootNode.getText()));
      } catch (Exception e) {
      }
      return (null);
    } else if ("result-set".equals(dataType)) { // $NON-NLS-1$

      return (MemoryResultSet.createFromActionSequenceInputsNode(parameterNode));
    } else { // Assume String
      return (rootNode.getText());
    }
  }
  public static IActionSequence ActionSequenceFactory(
      final Document document,
      final String solutionPath,
      final ILogger logger,
      final IApplicationContext applicationContext,
      final int loggingLevel) {

    // Check for a sequence document
    Node sequenceDefinitionNode = document.selectSingleNode("//action-sequence"); // $NON-NLS-1$
    if (sequenceDefinitionNode == null) {
      logger.error(
          Messages.getInstance()
              .getErrorString(
                  "SequenceDefinition.ERROR_0002_NO_ACTION_SEQUENCE_NODE",
                  "",
                  solutionPath,
                  "")); //$NON-NLS-1$
      return null;
    }

    ISequenceDefinition seqDef =
        new SequenceDefinition(sequenceDefinitionNode, solutionPath, logger, applicationContext);

    Node actionNode = sequenceDefinitionNode.selectSingleNode("actions"); // $NON-NLS-1$

    return (SequenceDefinition.getNextLoopGroup(
        seqDef, actionNode, solutionPath, logger, loggingLevel));
  }
  private static IActionSequence getNextLoopGroup(
      final ISequenceDefinition seqDef,
      final Node actionsNode,
      final String solutionPath,
      final String solutionName,
      final ILogger logger,
      final int loggingLevel) {

    String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode); // $NON-NLS-1$
    boolean loopUsingPeek =
        "true"
            .equalsIgnoreCase(
                XmlDom4JHelper.getNodeText("@peek-only", actionsNode)); // $NON-NLS-1$ //$NON-NLS-2$

    Node actionDefinitionNode;
    ActionDefinition actionDefinition;

    List actionDefinitionList = new ArrayList();

    List nodeList = actionsNode.selectNodes("*"); // $NON-NLS-1$
    Iterator actionDefinitionNodes = nodeList.iterator();
    while (actionDefinitionNodes.hasNext()) {
      actionDefinitionNode = (Node) actionDefinitionNodes.next();
      if (actionDefinitionNode.getName().equals("actions")) { // $NON-NLS-1$
        actionDefinitionList.add(
            SequenceDefinition.getNextLoopGroup(
                seqDef, actionDefinitionNode, solutionPath, solutionName, logger, loggingLevel));
      } else if (actionDefinitionNode.getName().equals("action-definition")) { // $NON-NLS-1$
        actionDefinition = new ActionDefinition(actionDefinitionNode, logger);
        actionDefinition.setLoggingLevel(loggingLevel);
        actionDefinitionList.add(actionDefinition);
      }
    }
    // action sequences with 0 actions are valid, see: JIRA PLATFORM-837

    IConditionalExecution conditionalExecution =
        SequenceDefinition.parseConditionalExecution(
            actionsNode, logger, "condition"); // $NON-NLS-1$

    ActionSequence sequence =
        new ActionSequence(loopParameterName, seqDef, actionDefinitionList, loopUsingPeek);

    sequence.setConditionalExecution(conditionalExecution);
    return sequence;
  }
  static int parseParameters(
      final Node actionRootNode,
      final ILogger logger,
      final String nodePath,
      final Map parameterMap,
      final Map mapTo,
      final boolean inputVar) {
    try {
      List parameters = actionRootNode.selectNodes(nodePath);

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator parametersIterator = parameters.iterator();
      Node parameterNode;
      String parameterName;
      String parameterType;
      ActionParameter parameter;
      List variableNodes;
      List variables;
      Node variableNode;
      Iterator variablesIterator;
      String variableSource;
      String variableName;
      int variableIdx;
      Object defaultValue = null;

      while (parametersIterator.hasNext()) {
        parameterNode = (Node) parametersIterator.next();
        parameterName = parameterNode.getName();
        parameterType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$

        if (mapTo != null) {
          mapTo.put(
              parameterName,
              XmlDom4JHelper.getNodeText("@mapping", parameterNode, parameterName)); // $NON-NLS-1$
        }

        defaultValue = SequenceDefinition.getDefaultValue(parameterNode);
        // get the list of sources for this parameter
        variableNodes =
            parameterNode.selectNodes(
                (inputVar) ? "sources/*" : "destinations/*"); // $NON-NLS-1$ //$NON-NLS-2$
        variablesIterator = variableNodes.iterator();
        variableIdx = 1;
        variables = new ArrayList();
        while (variablesIterator.hasNext()) {
          variableNode = (Node) variablesIterator.next();
          // try to resolve the parameter value for this
          try {
            variableSource = variableNode.getName();
            variableName = variableNode.getText();
            ActionParameterSource variable =
                new ActionParameterSource(variableSource, variableName);
            if (SequenceDefinition.debug) {
              logger.debug(
                  Messages.getInstance()
                      .getString(
                          "SequenceDefinition.DEBUG_ADDING_SOURCE_FOR_PARAMETER",
                          variableSource,
                          parameterName)); //$NON-NLS-1$
            }

            variables.add(variable);
          } catch (Exception e) {
            logger.error(
                Messages.getInstance()
                    .getErrorString(
                        "SequenceDefinition.ERROR_0004_VARIABLE_SOURCE_NOT_VALID",
                        Integer.toString(variableIdx),
                        parameterName),
                e); //$NON-NLS-1$
          }
          variableIdx++;
        }
        if (defaultValue != null) {
          if (SequenceDefinition.debug) {
            logger.debug(
                Messages.getInstance()
                    .getString(
                        "SequenceDefinition.DEBUG_USING_DEFAULT_VALUE",
                        defaultValue.toString(),
                        parameterName)); //$NON-NLS-1$
          }
        }
        parameter =
            new ActionParameter(parameterName, parameterType, null, variables, defaultValue);
        parameterMap.put(parameterName, parameter);
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"),
          e); //$NON-NLS-1$
    }

    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }