/**
   * sbarkdull: method appears to never be used anywhere
   *
   * @param actionRootNode
   * @param logger
   * @param nodePath
   * @param mapTo
   * @return
   */
  static int parseActionResourceDefinitions(
      final Node actionRootNode, final ILogger logger, final String nodePath, final Map mapTo) {

    try {
      List resources = actionRootNode.selectNodes(nodePath);

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator resourcesIterator = resources.iterator();

      Node resourceNode;
      String resourceName;
      while (resourcesIterator.hasNext()) {
        resourceNode = (Node) resourcesIterator.next();
        resourceName = resourceNode.getName();
        if (mapTo != null) {
          mapTo.put(
              resourceName,
              XmlDom4JHelper.getNodeText("@mapping", resourceNode, resourceName)); // $NON-NLS-1$
        }
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"),
          e); //$NON-NLS-1$
    }
    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }
  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));
  }
 static IConditionalExecution parseConditionalExecution(
     final Node actionRootNode, final ILogger logger, final String nodePath) {
   try {
     Node condition = actionRootNode.selectSingleNode(nodePath);
     if (condition == null) {
       return null;
     }
     String script = condition.getText();
     IConditionalExecution ce = PentahoSystem.get(IConditionalExecution.class, null);
     ce.setScript(script);
     return ce;
   } catch (Exception ex) {
     logger.error(
         Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"),
         ex); //$NON-NLS-1$
   }
   return null;
 }
  protected void init(Util.PropertyList properties) {
    try {
      if (nativeConnection != null) { // Assume we're open
        close();
      }

      // Set a locale for this connection if specified in the platform's mondrian metadata
      // This is required if mondrian.i18n.LocalizingDynamicSchemaProcessor is being used
      if (properties.get(RolapConnectionProperties.Locale.name()) == null) {
        properties.put(
            RolapConnectionProperties.Locale.name(), LocaleHelper.getLocale().toString());
      }

      String dataSourceName = properties.get(RolapConnectionProperties.DataSource.name());

      mapPlatformRolesToMondrianRoles(properties);

      if (dataSourceName != null) {
        IDBDatasourceService datasourceService =
            PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
        DataSource dataSourceImpl = datasourceService.getDataSource(dataSourceName);
        if (dataSourceImpl != null) {
          properties.remove(RolapConnectionProperties.DataSource.name());
          nativeConnection = DriverManager.getConnection(properties, null, dataSourceImpl);
        } else {
          nativeConnection = DriverManager.getConnection(properties, null);
        }
      } else {
        nativeConnection = DriverManager.getConnection(properties, null);
      }

      if (nativeConnection != null) {
        if (role != null) {
          nativeConnection.setRole(role);
        }
      }

      if (nativeConnection == null) {
        logger.error(
            Messages.getInstance()
                .getErrorString(
                    "MDXConnection.ERROR_0002_INVALID_CONNECTION",
                    properties != null
                        ? properties.toString()
                        : "null")); //$NON-NLS-1$ //$NON-NLS-2$
      }
    } catch (Throwable t) {
      if (logger != null) {
        logger.error(
            Messages.getInstance()
                .getErrorString(
                    "MDXConnection.ERROR_0002_INVALID_CONNECTION",
                    properties != null ? properties.toString() : "null"),
            t); //$NON-NLS-1$ //$NON-NLS-2$
      } else {
        Logger.error(
            this.getClass().getName(),
            Messages.getInstance()
                .getErrorString(
                    "MDXConnection.ERROR_0002_INVALID_CONNECTION",
                    properties != null ? properties.toString() : "null"),
            t); //$NON-NLS-1$ //$NON-NLS-2$
      }
    }
  }
  private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) {

    resourceDefinitions = new ListOrderedMap();

    try {
      List resources = actionRootNode.selectNodes("resources/*"); // $NON-NLS-1$

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator resourcesIterator = resources.iterator();

      Node resourceNode;
      String resourceName;
      String resourceTypeName;
      String resourceMimeType;
      int resourceType;
      ActionResource resource;
      Node typeNode, mimeNode;
      while (resourcesIterator.hasNext()) {
        resourceNode = (Node) resourcesIterator.next();
        typeNode = resourceNode.selectSingleNode("./*"); // $NON-NLS-1$
        if (typeNode != null) {
          resourceName = resourceNode.getName();
          resourceTypeName = typeNode.getName();
          resourceType = ActionResource.getResourceType(resourceTypeName);
          String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); // $NON-NLS-1$
          if (resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) {
            if (resourceLocation == null) {
              logger.error(
                  Messages.getInstance()
                      .getErrorString(
                          "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION",
                          resourceName)); //$NON-NLS-1$
              continue;
            }
          } else if (resourceType == IActionSequenceResource.STRING) {
            resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); // $NON-NLS-1$
          } else if (resourceType == IActionSequenceResource.XML) {
            // resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$
            Node xmlNode = typeNode.selectSingleNode("./location/*"); // $NON-NLS-1$
            // Danger, we have now lost the character encoding of the XML in this node
            // see BISERVER-895
            resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); // $NON-NLS-1$
          }
          mimeNode = typeNode.selectSingleNode("mime-type"); // $NON-NLS-1$
          if (mimeNode != null) {
            resourceMimeType = mimeNode.getText();
            resource =
                new ActionResource(
                    resourceName,
                    resourceType,
                    resourceMimeType,
                    solutionName,
                    solutionPath,
                    resourceLocation);
            resourceDefinitions.put(resourceName, resource);
          } else {
            logger.error(
                Messages.getInstance()
                    .getErrorString(
                        "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE",
                        resourceName)); //$NON-NLS-1$
          }
        }
        // input = new ActionParameter( resourceName, resourceType, null
        // );
        // resourceDefinitions.put( inputName, input );
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"),
          e); //$NON-NLS-1$
    }
    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }
  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;
  }