public boolean hasReferencedElement(
     String managed_element_uuid, String reference_name, String referenced_element_uuri) {
   ManagedElement me1 = getLocalElement(managed_element_uuid);
   if (me1 != null) {
     Reference r = me1.getReference(reference_name);
     if (r != null) {
       return r.hasReferencedElement(referenced_element_uuri);
     }
   } else {
     String auri = agent.getExternalAgentUri(managed_element_uuid);
     if (auri != null) {
       CMessage msg = new CMessage();
       msg.setTo(auri);
       msg.setObject("runtimemodel");
       msg.setBody("hasReferencedElement");
       msg.addHeader("uuid", managed_element_uuid);
       msg.addHeader("name", reference_name);
       msg.addHeader("refuuid", referenced_element_uuri);
       try {
         CMessage resultmsg = sendAndWait(msg);
         if (resultmsg != null) {
           if (resultmsg.getBody() != null) {
             if (resultmsg.getBody().toString().equalsIgnoreCase("true")) {
               return true;
             }
           }
         }
       } catch (TimeOutException e) {
         e.printStackTrace();
       }
     }
   }
   return false;
 }
 public boolean addReferencedElement(
     String managed_element_uuid,
     String reference_name,
     boolean onlyone,
     String referenced_element_uuid)
     throws InvalidNameException {
   ManagedElement me1 = getLocalElement(managed_element_uuid);
   if (me1 != null) {
     // System.out.println("add Local Reference Element ...");
     Reference r = me1.getReference(reference_name);
     if (r == null) {
       // System.out.println("Reference '"+reference_name+"' does not exists! we will create it!");
       r = me1.addReference(reference_name, onlyone);
     }
     if (r != null) {
       r.addReferencedElement(referenced_element_uuid);
       return true;
     }
   } else {
     // System.out.println("add Remote Reference Element ...");
     String auri = agent.getExternalAgentUri(managed_element_uuid);
     if (auri != null) {
       CMessage msg = new CMessage();
       msg.setTo(auri);
       msg.setObject("runtimemodel");
       msg.setBody("addReferencedElement");
       msg.addHeader("uuid", managed_element_uuid);
       msg.addHeader("name", reference_name);
       msg.addHeader("onlyone", onlyone == true ? "true" : "false");
       msg.addHeader("refuuid", referenced_element_uuid);
       try {
         CMessage resultmsg = sendAndWait(msg);
         if (resultmsg != null) {
           if (resultmsg.getBody() != null) {
             if (resultmsg.getBody().toString().equalsIgnoreCase("true")) {
               return true;
             }
           }
         }
       } catch (TimeOutException e) {
         e.printStackTrace();
       }
     } else {
       System.out.println("External agent of element '" + managed_element_uuid + "' not found!");
     }
   }
   return false;
 }
  public List<String> getReferencedElements(String managed_element_uuid, String reference_name) {

    List<String> result = new ArrayList<String>();
    ManagedElement me1 = getLocalElement(managed_element_uuid);
    if (me1 != null) {
      Reference r = me1.getReference(reference_name);
      if (r != null) {
        return r.getReferencedElements();
      } else {
        // System.out.println("CONTROLLER: no reference with name: " + reference_name);
      }
    } else {
      String auri = agent.getExternalAgentUri(managed_element_uuid);
      if (auri != null) {
        CMessage msg = new CMessage();
        msg.setTo(auri);
        msg.setObject("runtimemodel");
        msg.setBody("getReferencedElements");
        msg.addHeader("uuid", managed_element_uuid);
        msg.addHeader("name", reference_name);
        try {
          CMessage resultmsg = sendAndWait(msg);
          if (resultmsg != null) {
            if (resultmsg.getBody() != null) {
              String[] tmp = resultmsg.getBody().toString().split(",");
              for (int i = 0; i < tmp.length; i++) {
                if (tmp[i] != null && tmp[i].length() > 0) {
                  String[] tmp2 = tmp[i].split("###");
                  String agenturi = tmp2[0];
                  String elementuuid = tmp2[1];
                  if (!agenturi.equalsIgnoreCase(getCubeAgent().getUri())) {
                    this.agent.addExternalElement(elementuuid, agenturi);
                  }
                  result.add(elementuuid);
                }
              }
            }
          }
        } catch (TimeOutException e) {
          e.printStackTrace();
        }
      }
    }
    return result;
  }
Пример #4
0
  /**
   * Applies the predicate information located on the objectVariable, on the subjectVariable to
   * limit the research domain space.
   *
   * <p>It should be only implemented for UnaryConstraints.
   *
   * @param subjectVariable
   * @param objectVariable
   */
  public boolean applyDescription(
      CubeAgent agent, Variable subjectVariable, Variable objectVariable) {
    if (subjectVariable != null && objectVariable != null && objectVariable.getValue() != null) {

      Reference ref = subjectVariable.getReference(Scope.CORE_SCOPE_MASTER);
      if (ref == null) {
        try {
          Reference r = subjectVariable.addReference(Scope.CORE_SCOPE_MASTER, true);
          if (r != null) {
            r.addReferencedElement(objectVariable.getValue().toString());
            return true;
          }
        } catch (InvalidNameException e) {
          e.printStackTrace();
        }
      } else {
        ref.addReferencedElement(objectVariable.getValue().toString());
        return true;
      }
    }
    return false;
  }