コード例 #1
0
ファイル: OpalClient.java プロジェクト: Elblonko/kepler
  /**
   * this function adds all the parameters necessary to have the documentation of the OpalClient
   * abviously this documentation is fetch from the remote server
   */
  private void _addDocumentation(AppMetadata app) throws IllegalActionException {
    // let's get the variable we need
    Attribute documentation = this.getAttribute("KeplerDocumentation");
    if (documentation == null)
      throw new IllegalActionException(
          this, "Unable to set the custom documentation (KeplerDocumentation not present).");
    Attribute userDoc = documentation.getAttribute("userLevelDocumentation");
    if (userDoc == null)
      throw new IllegalActionException(
          this, "Unable to set the custom documentation (userLevelDocumentation not present).");
    // -- we have to delete all the documentation that is already there
    // before updating it
    List tempList = documentation.attributeList();
    Attribute[] paramArray = (Attribute[]) tempList.toArray(new Attribute[tempList.size()]);
    for (int i = 0; i < paramArray.length; i++) {
      try {
        if (paramArray[i].getName().startsWith("prop:")
            || paramArray[i].getName().startsWith("port:output")
            || paramArray[i].getName().startsWith("port:baseUrl"))
          // let's remove the parameters
          paramArray[i].setContainer(null);
      } catch (NameDuplicationException e) {
        log.error(
            "The parameter could not be deleted from the documentation. Error message: "
                + e.getMessage());
        throw new IllegalActionException(
            this,
            "Error resetting the ducumentation, there is a duplicated name: " + e.getMessage());
      }
    }
    // After deleting we can finally set the documentation
    String stringDoc = _docHead;
    // let's set the general documentaion
    if (app.getUsage() != null) stringDoc += "<p>" + app.getUsage() + "</p>";
    if (app.getInfo() != null) {
      String[] infos = app.getInfo();
      for (int i = 0; i < infos.length; i++) stringDoc += "<pre>" + forXML(infos[i]) + "</pre>";
    } // if
    log.debug("the stringDoc is: " + stringDoc);
    ((ConfigurableAttribute) userDoc).setExpression(stringDoc);

    // -- let's set the documentation for the various properties --
    // some properties are always there... hence also the documentation
    // should be always there
    try {
      ((ConfigurableAttribute) userDoc).value();
      ConfigurableAttribute parameterDoc = new ConfigurableAttribute(documentation, "port:output");
      parameterDoc.setExpression(
          "It returns a list of Strings, containing the URL of the output files");
      parameterDoc = new ConfigurableAttribute(documentation, "port:baseUrl");
      parameterDoc.setExpression(
          "The base URL containing the working directory of the running jobs");
      parameterDoc = new ConfigurableAttribute(documentation, "prop:serviceURL");
      parameterDoc.setExpression("The URL of the Opal service that you want to execute");
      parameterDoc = new ConfigurableAttribute(documentation, "prop:numberOfExtraInputFiles");
      parameterDoc.setExpression(
          "The number of extra input files that are needed to execture the application");
      // parameterDoc = new ConfigurableAttribute(documentation,
      // "prop:methods");
      // parameterDoc.setExpression("Not implemented yet.");
    } catch (NameDuplicationException e) {
      log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
      throw new IllegalActionException(
          this, "Error building the ducumentation, there is a duplicated name: " + e.getMessage());
    } catch (IOException e) {
      log.error("There is an error while setting the general documentation: " + e.getMessage());
    }
    // we have to list the documentation for every parameters
    if (app.isArgMetadataEnable()) {
      Group[] group = app.getGroups();
      try {
        if (group != null) {
          for (int i = 0; i < group.length; i++) {
            // first the parameters
            ArgParam[] argParams = group[i].getArgParams();
            if (argParams != null) {
              for (int paramCount = 0; paramCount < argParams.length; paramCount++) {
                ConfigurableAttribute parameterDoc =
                    new ConfigurableAttribute(
                        documentation, "prop:" + argParams[paramCount].getId());
                parameterDoc.setExpression(forXML(argParams[paramCount].getTextDesc()));
              } // for argParam
            } // argParams
            // and then the flags
            ArgFlag[] argFlags = group[i].getArgFlags();
            if (argFlags != null) {
              for (int paramCount = 0; paramCount < argFlags.length; paramCount++) {
                ConfigurableAttribute parameterDoc =
                    new ConfigurableAttribute(
                        documentation, "prop:" + argFlags[paramCount].getId());
                parameterDoc.setExpression(forXML(argFlags[paramCount].getTextDesc()));
                log.info(
                    "The parameter "
                        + argFlags[paramCount].getId()
                        + " has the following doc: "
                        + parameterDoc.value());
                parameterDoc.validate();
              }
            } // argFlags
          }
        } // group
      } catch (NameDuplicationException e) {
        log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
        throw new IllegalActionException(
            this,
            "Error building the ducumentation, there is a duplicated name: " + e.getMessage());
      } catch (IOException e) {
        log.error(
            "There is an error while setting the documentation of an element with messge: "
                + e.getMessage());
      }
    } // if we have metadata
    else {
      // if we don't have metadata we document the standard parameters
      try {
        ConfigurableAttribute parameterDoc =
            new ConfigurableAttribute(documentation, "prop:commandLine");
        parameterDoc.setExpression(
            "Insert the command line you want to execute (without the application name)");
        parameterDoc = new ConfigurableAttribute(documentation, "prop:cpuNumber");
        parameterDoc.setExpression("If it is a parallel application insert the CPU number");
        parameterDoc = new ConfigurableAttribute(documentation, "prop:inputFile");
        parameterDoc.setExpression("Select an input file");
      } catch (NameDuplicationException e) {
        log.error("The parameter could not be instantiated. Error message: " + e.getMessage());
        throw new IllegalActionException(
            this,
            "Error building the ducumentation, there is a duplicated name: " + e.getMessage());
      }
    }
  } // _addDocumentation