Пример #1
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;
  }
 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;
 }