/**
  * This method removes the identified method.
  *
  * @param method The method to remove.
  * @throws com.rift.coad.daemon.jython.JythonDaemonException
  */
 public void updateMethod(DataMapperMethod method) throws JythonDaemonException {
   try {
     Session session = SemanticUtil.getInstance(JythonMappingManagerDaemonImpl.class).getSession();
     List<DataMapperMethod> methods = listMethods(session);
     method.setService(Constants.SERVICE_ID);
     for (DataMapperMethod meth : methods) {
       if (meth.equals(method)) {
         session.persist(method);
         methods.remove(meth);
         methods.add(method);
         DataMapperBrokerUtil util1 =
             new DataMapperBrokerUtil(Constants.SERVICE_ID, Constants.DATA_MAPPER);
         util1.register(methods.toArray(new DataMapperMethod[0]));
         return;
       }
     }
     log.debug("The entry was not found to update.");
     throw new JythonDaemonException("The entry was not to update.");
   } catch (JythonDaemonException ex) {
     throw ex;
   } catch (Exception ex) {
     log.error("Failed to update the method : " + ex.getMessage(), ex);
     throw new JythonDaemonException("Failed to add method : " + ex.getMessage(), ex);
   }
 }
  /**
   * This method adds a new method to the list of methods
   *
   * @param method This method adds the specified method.
   * @throws com.rift.coad.daemon.jython.JythonDaemonException
   */
  public void addMethod(DataMapperMethod newMethod) throws JythonDaemonException {
    try {
      Session session = SemanticUtil.getInstance(JythonMappingManagerDaemonImpl.class).getSession();
      List<DataMapperMethod> methods = listMethods(session);
      for (DataMapperMethod method : methods) {
        if (method.equals(newMethod)) {
          log.error("Duplicate method : " + newMethod.getName());
          throw new JythonDaemonException("Duplicate method : " + newMethod.getName());
        }
      }
      newMethod.setService(Constants.SERVICE_ID);
      methods.add(newMethod);
      session.persist(newMethod);

      DataMapperBrokerUtil util1 =
          new DataMapperBrokerUtil(Constants.SERVICE_ID, Constants.DATA_MAPPER);
      util1.register(methods.toArray(new DataMapperMethod[0]));
    } catch (JythonDaemonException ex) {
      throw ex;
    } catch (Exception ex) {
      log.error("Failed to add method : " + ex.getMessage(), ex);
      throw new JythonDaemonException("Failed to add method : " + ex.getMessage(), ex);
    }
  }
  /**
   * This method returns a list of the methods.
   *
   * @param session The session to retrieve the list of methods from.
   * @return The list of methods.
   * @throws com.rift.coad.daemon.jython.JythonDaemonException
   */
  private List<DataMapperMethod> listMethods(Session session) throws JythonDaemonException {
    try {
      List<SPARQLResultRow> entries =
          session
              .createSPARQLQuery(
                  "SELECT ?s WHERE { "
                      + "?s a <http://www.coadunation.net/schema/rdf/1.0/datamapper#DataMapperMethod> ."
                      + "?s <http://www.coadunation.net/schema/rdf/1.0/datamapper#DataMapperMethodServiceId> ?ServiceId ."
                      + "FILTER (?ServiceId = ${ServiceId})}")
              .setString("ServiceId", Constants.SERVICE_ID)
              .execute();
      List<DataMapperMethod> methods = new ArrayList<DataMapperMethod>();
      for (SPARQLResultRow row : entries) {
        methods.add(row.get(0).cast(DataMapperMethod.class));
      }

      return methods;
    } catch (Exception ex) {
      log.error("Failed to retrieve a list of all the registered methods : " + ex.getMessage(), ex);
      throw new JythonDaemonException(
          "Failed to retrieve a list of all the registered methods : " + ex.getMessage(), ex);
    }
  }