示例#1
0
 /**
  * Create a script from another script object
  *
  * @param script2 script object source
  * @throws InvalidScriptException if the creation fails.
  */
 public Script(Script<?> script2) throws InvalidScriptException {
   this(
       script2.getScript(),
       script2.scriptEngineLookup,
       script2.getParameters(),
       script2.getScriptName());
 }
  /**
   * Corresponds to <element name="script">
   *
   * <p>The schema allows the specification of a script either by writing the script code either by
   * providing a file with arguments. Both will result in the same {@link
   * org.ow2.proactive.scripting.Script} object. In the current translation we will always translate
   * a Script object by inlining the script code using a "codeScript"element (first option).
   *
   * <p>The xml specification does not allow addding arguments to a script defined by its code.
   * Therefore, when we translate the script object to xml, if we encounter arguments, we will
   * insert their value directly in the script's code by inserting a line like:
   *
   * <p>var args = ["argument_1",...,"argument_n"];
   */
  private Element createScriptElement(Document doc, Script script) {
    Element scriptElement =
        doc.createElementNS(Schemas.SCHEMA_LATEST.namespace, XMLTags.SCRIPT_SCRIPT.getXMLName());
    Element codeE =
        doc.createElementNS(Schemas.SCHEMA_LATEST.namespace, XMLTags.SCRIPT_CODE.getXMLName());
    setAttribute(codeE, XMLAttributes.LANGUAGE, script.getEngineName(), true);
    String scriptText = script.getScript();
    Serializable[] params = script.getParameters();
    if (params != null) {

      scriptText = inlineScriptParametersInText(scriptText, params);
    }

    CDATASection scriptTextCDATA = doc.createCDATASection(scriptText);
    codeE.appendChild(scriptTextCDATA);

    scriptElement.appendChild(codeE);
    return scriptElement;
  }