/** Corresponds to <element name="javaExecutable"> */
  private Element createJavaExecutableElement(Document doc, JavaTask t) {
    Element executableE =
        doc.createElementNS(Schemas.SCHEMA_LATEST.namespace, XMLTags.JAVA_EXECUTABLE.getXMLName());
    setAttribute(executableE, XMLAttributes.TASK_CLASS_NAME, t.getExecutableClassName(), true);

    // <ref name="javaParameters"/>
    try {
      Map<String, Serializable> args = t.getArguments();
      if ((args != null) && (args.size() > 0)) {
        // <element name="parameter">
        Element paramsE =
            doc.createElementNS(
                Schemas.SCHEMA_LATEST.namespace, XMLTags.TASK_PARAMETERS.getXMLName());
        for (String name : args.keySet()) {
          Serializable val = args.get(name);
          Element paramE =
              doc.createElementNS(
                  Schemas.SCHEMA_LATEST.namespace, XMLTags.TASK_PARAMETER.getXMLName());
          setAttribute(paramE, XMLAttributes.COMMON_NAME, name, true);
          setAttribute(paramE, XMLAttributes.COMMON_VALUE, val.toString(), true);
          paramsE.appendChild(paramE);
        }
        executableE.appendChild(paramsE);
      }
    } catch (Exception e) {
      logger.error("Could not add arguments for Java Executable element of task " + t.getName(), e);
    }
    return executableE;
  }
示例#2
0
  /**
   * Create an internal java Task with the given java task (user)
   *
   * @param task the user java task that will be used to create the internal java task.
   * @return the created internal task.
   * @throws JobCreationException an exception if the factory cannot create the given task.
   */
  @SuppressWarnings("unchecked")
  private static InternalTask createTask(Job userJob, JavaTask task) throws JobCreationException {
    InternalTask javaTask;

    if (task.getExecutableClassName() != null) {
      HashMap<String, byte[]> args = task.getSerializedArguments();

      try {
        if (isForkingTask()) {
          javaTask =
              new InternalForkedScriptTask(
                  new ScriptExecutableContainer(
                      new TaskScript(
                          new SimpleScript(
                              task.getExecutableClassName(),
                              JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME,
                              new Serializable[] {args}))));
          javaTask.setForkEnvironment(task.getForkEnvironment());
          configureRunAsMe(task);
        } else {
          javaTask =
              new InternalScriptTask(
                  new ScriptExecutableContainer(
                      new TaskScript(
                          new SimpleScript(
                              task.getExecutableClassName(),
                              JavaClassScriptEngineFactory.JAVA_CLASS_SCRIPT_ENGINE_NAME,
                              new Serializable[] {args}))));
        }
      } catch (InvalidScriptException e) {
        throw new JobCreationException(e);
      }
    } else {
      String msg =
          "You must specify your own executable task class to be launched (in every task)!";
      logger.info(msg);
      throw new JobCreationException(msg);
    }

    // set task common properties
    try {
      setTaskCommonProperties(userJob, task, javaTask);
    } catch (Exception e) {
      throw new JobCreationException(e);
    }
    return javaTask;
  }