private boolean checkMandatoryParameters(
      Repository repositoryDocument,
      boolean propertyChanged,
      ArrayList<Property> newPropertyList,
      HashSet<String> configVariableNames) {
    /*
     * mandatory paramters, the ones from param that have not been covered yet.
     */
    // If there was no required parameters given by WPSconfig, host and port defaults will be added
    // (RServe_User and RServe_port won't be added)
    if (configVariableNames.contains(RWPSConfigVariables.RSERVE_HOST.toString().toLowerCase())) {
      Property host = repositoryDocument.addNewProperty();
      host.setActive(true);
      host.setName(RWPSConfigVariables.RSERVE_HOST.toString());
      host.setStringValue(R_Config.getInstance().rServeHost);
      newPropertyList.add(host);
      propertyChanged = true;
    }

    if (configVariableNames.contains(RWPSConfigVariables.RSERVE_PORT.toString().toLowerCase())) {
      Property port = repositoryDocument.addNewProperty();
      port.setActive(true);
      port.setName(RWPSConfigVariables.RSERVE_PORT.toString());
      port.setStringValue(Integer.toString(R_Config.getInstance().rServePort));
      newPropertyList.add(port);
      propertyChanged = true;
    }
    return propertyChanged;
  }
  private boolean addMissingAlgorithms(
      Repository repositoryDocument,
      HashMap<String, Property> algorithmPropertyHash,
      boolean propertyChanged,
      ArrayList<Property> newPropertyList) {
    // check script dir for R process files
    // adjusts WPS config
    String scriptDir = R_Config.getInstance().getScriptDirFullPath();
    File algorithmDir = new File(scriptDir);
    if (algorithmDir.isDirectory()) {
      File[] scripts = algorithmDir.listFiles(new R_Config.RFileExtensionFilter());
      LOGGER.debug("Loading script files from " + algorithmDir + ": " + Arrays.toString(scripts));
      for (File scriptf : scripts) {
        String wkn = R_Config.getInstance().FileToWkn(scriptf);
        Property prop = algorithmPropertyHash.get(wkn);

        // case: property is missing in wps config
        if (prop == null) {
          // Change Property if Algorithm is not inside process description:
          prop = repositoryDocument.addNewProperty();
          prop.setActive(true);
          prop.setName(RWPSConfigVariables.ALGORITHM.toString());
          prop.setStringValue(wkn);
          newPropertyList.add(prop);
          LOGGER.debug("Added new algorithm property to repo document: " + prop);

          propertyChanged = true;
        } else {
          LOGGER.debug("Algorithm property already repo document: " + prop);
          newPropertyList.add(algorithmPropertyHash.remove(wkn));
        }

        /*
         * if(prop.getActive() && addAlgorithm){ repository.addAlgorithm(wkn); }
         */
      }
    }
    return propertyChanged;
  }
  public void updateRepositoryConfiguration() {
    // Retrieve repository document and properties:
    String localRAlgorithmRepository_className = LocalRAlgorithmRepository.class.getCanonicalName();
    Repository[] repositoryDocuments = WPSConfig.getInstance().getRegisterdAlgorithmRepositories();
    Repository repositoryDocument = null;

    for (Repository doc : repositoryDocuments) {
      if (doc.getClassName().equals(localRAlgorithmRepository_className)) {
        repositoryDocument = doc;
      }
    }

    if (repositoryDocument == null) {
      LOGGER.error("Local R Algorithm Repository is not registered");
      // return;
    }

    Property[] oldPropertyArray = repositoryDocument.getPropertyArray();
    HashMap<String, Property> algorithmPropertyHash = new HashMap<String, Property>();

    boolean propertyChanged = false;
    ArrayList<Property> newPropertyList = new ArrayList<Property>();

    // test if host and port of rserve are available in config properties, if not, values from
    // R_Config
    // will be used

    // retrieve set of string representations for all config variables:
    HashSet<String> configVariableNames = new HashSet<String>();

    for (RWPSConfigVariables var : RWPSConfigVariables.values()) {
      configVariableNames.add(var.toString().toLowerCase());
    }

    for (Property property : oldPropertyArray) {
      String pname = property.getName().toLowerCase();

      // check the name and active state
      if (pname.equalsIgnoreCase(RWPSConfigVariables.ALGORITHM.toString())) {
        LOGGER.debug("Algorithm property: " + property);

        // put id into a dictionary to check and add later:
        algorithmPropertyHash.put(property.getStringValue(), property);
      } else {
        LOGGER.debug("NOT-algorithm property: " + property);

        if (configVariableNames.contains(pname)) {
          boolean success = handleConfigVariable(property);
          if (!success) LOGGER.warn("Invalid config variable was omitted and deleted: " + property);

          // config variable should occur only once, doubling will be omitted:
          configVariableNames.remove(pname);
        } else {
          // valid properties which are not algorithms will be just passed to the new list
          LOGGER.debug("Unprocessed property: " + property);
        }

        newPropertyList.add(property);
      }
    }

    propertyChanged =
        checkMandatoryParameters(
            repositoryDocument, propertyChanged, newPropertyList, configVariableNames);

    propertyChanged =
        addMissingAlgorithms(
            repositoryDocument, algorithmPropertyHash, propertyChanged, newPropertyList);

    // there might be registered algorithms, which don't got a script file any more,
    // those will be deleted here:
    if (!algorithmPropertyHash.isEmpty()) propertyChanged = true;

    propertyChanged = checkPropertyOrder(oldPropertyArray, propertyChanged);

    if (propertyChanged) {
      Property[] newPropertyArray = newPropertyList.toArray(new Property[0]);

      // sort list of properties lexicographically:

      Arrays.sort(newPropertyArray, new PropertyComparator());
      repositoryDocument.setPropertyArray(newPropertyArray);
      propertyChanged = true;

      // write new WPSConfig if property had to be changed
      WPSConfigurationDocument wpsConfigurationDocument =
          WPSConfigurationDocument.Factory.newInstance();
      WPSConfiguration wpsConfig = WPSConfig.getInstance().getWPSConfig();
      wpsConfigurationDocument.setWPSConfiguration(wpsConfig);

      // writes the new WPSConfig to a file
      try {
        String configurationPath = WPSConfig.getConfigPath();
        File XMLFile = new File(configurationPath);
        wpsConfigurationDocument.save(
            XMLFile,
            new org.apache.xmlbeans.XmlOptions().setUseDefaultNamespace().setSavePrettyPrint());
        WPSConfig.forceInitialization(configurationPath);
        LOGGER.info("WPS Config was changed.");
      } catch (IOException e) {
        LOGGER.error("Could not write configuration to file: " + e.getMessage());
      } catch (org.apache.xmlbeans.XmlException e) {
        LOGGER.error("Could not generate XML File from Data: " + e.getMessage());
      }
    }
  }