예제 #1
0
  /** Overloads the BaseObject method */
  public DataObject getUserDescription() {
    DataObject result;

    // Get the incoming attributes
    DataObject doInAtt_ = setInAttributes().toDataObject();
    Vector vInAtt = new Vector();
    vInAtt.addElement(doInAtt_);
    DataObject doInAtt = new DataObject(Discoverer.INCOMING_ATTRIBUTE_NAME_VALUES, vInAtt);

    // Get the outgoing attributes
    DataObject doOutAtt_ = setOutAttributes().toDataObject();
    Vector vOutAtt = new Vector();
    vOutAtt.addElement(doOutAtt_);
    DataObject doOutAtt = new DataObject(Discoverer.OUTGOING_ATTRIBUTE_NAME_VALUES, vOutAtt);

    Vector v = new Vector();
    v.addElement(doInAtt);
    v.addElement(doOutAtt);

    // Get getInterpreterDescription
    DataObject doDescrip = getInterpreterDescription();
    if (doDescrip != null) {
      Vector vDescrip = doDescrip.getChildren();
      Enumeration e = vDescrip.elements();
      DataObject temp;
      while (e.hasMoreElements()) {
        temp = (DataObject) e.nextElement();
        v.addElement(temp);
      }
    }

    result = new DataObject(Discoverer.TEMP_DEST, v);

    return result;
  }
예제 #2
0
  /**
   * This method is meant to handle any internal methods that the baseObject doesn't handle. In
   * particular, this method handles interpret requests. It ensures that the ID of the incoming
   * request matches this interpreter. If the method is an INTERPRET method, it sends it to the
   * interpreter. Otherwise runInterpreterMethod() is called.
   *
   * @param data DataObject containing the method to run and parameters
   * @return DataObject containing the results of running the method
   * @see #runInterpreterMethod(DataObject,String)
   */
  public DataObject runUserMethod(DataObject data) {
    debugprintln(DEBUG, "Interpreter <runUserMethod>");
    DataObject interpreter = data.getDataObject(ID);
    String error = null;

    // Test the id
    if (interpreter == null) {
      error = Error.INVALID_ID_ERROR;
      return (new Error(error)).toDataObject();
    } else {
      String queryId = (String) (interpreter.getValue().firstElement());
      if (!queryId.equals(getId())) {
        error = Error.INVALID_ID_ERROR;
        return (new Error(error)).toDataObject();
      }
    }

    String methodType = data.getName();

    if (methodType.equals(INTERPRET)) {
      return callInterpreter(data, error);
    } else {
      return runInterpreterMethod(data, error);
    }
  }
예제 #3
0
  /**
   * This method looks for an element in this DataObject.
   *
   * @param name Name of an element
   * @return boolean true if there is an element by that name, else false
   */
  public boolean existsElement(String name) {
    int n = this.countChildren();
    boolean result = false;

    if (n > 0) {
      Vector children = this.getChildren();
      for (int i = 0; i < n; i++) {
        DataObject currentChild = (DataObject) children.elementAt(i);
        String currentName = currentChild.getName();

        if (currentName.equals(name)) {
          // sounds like we've found it
          result = true;
        }
        if (result == false) { // carry on searching the children
          if (currentChild.countChildren() > 0) {
            result = currentChild.existsElement(name);
          }
          if (result) { // did we find it?
            break; // then stop here
          }
        }
      } // for
    }
    return result;
  }
예제 #4
0
 /**
  * Note similarity to getDataObject, but maybe this doesn't do a recursive search TODO: so why
  * would this be called instead of getDataObject?? --Brian
  */
 public DataObject getChild(String name) {
   for (DataObject child : children) {
     if (name.equals(child.getName())) {
       return child;
     }
   }
   return null;
 }
 /**
  * Basic constructor that creates a function description object from a DataObject. The dataObject
  * is expected to have a <FUNCTION> tag as the top level.
  *
  * @param data DataObject containing function description info
  */
 public FunctionDescription(DataObject data) {
   DataObject nameObj = data.getDataObject(FUNCTION_NAME);
   name = nameObj.getValue();
   DataObject descriptionObj = data.getDataObject(FUNCTION_DESCRIPTION);
   description = descriptionObj.getValue();
   attributes = Attributes.fromDataObject(data.getDataObject(Attributes.ATTRIBUTES));
   DataObject timingObj = data.getDataObject(FUNCTION_SYNCHRONICITY);
   synchronicity = timingObj.getValue();
 }
예제 #6
0
 /**
  * This method adds an element to this DataObject
  *
  * @param name Name of an element
  */
 public void addElement(String name) {
   currentObject.name = name;
   DataObject tmp = new DataObject();
   tmp.parent = currentObject;
   if (currentObject.parent != null) {
     currentObject.parent.getValue().addElement(currentObject);
   }
   currentObject = tmp;
 }
예제 #7
0
 /**
  * This method closes the currently open/added element in order to do some internal housecleaning.
  *
  * @param name Name of the element being closed
  */
 public void closeElement(String name) {
   DataObject tmp = new DataObject();
   if (currentObject.parent != null) {
     tmp.parent = currentObject.parent.parent;
   } else {
     tmp.parent = null;
   }
   currentObject = tmp;
 }
예제 #8
0
 /**
  * Returns the first value of the DataObject element/sub-element with the specified name, if it
  * exists. Returns null otherwise.
  *
  * @param string Name of the element to return
  * @return 1st value of the DataObject with the specified name or null, if not found
  */
 public Object getDataObjectFirstValue(String string) {
   DataObject dobj = getDataObject(string);
   if (dobj != null) {
     Vector v = dobj.getValue();
     if (v != null) {
       return v.firstElement();
     }
   }
   return null;
 }
예제 #9
0
  /**
   * This method adds an element and list of attributes to this DataObject. So far this was only
   * used by SAX_XMLDecoder
   *
   * @param name Name of an element
   * @param atts Map list of attributes; actually not being used anymore (deprecated)
   */
  public void addElement(String name, Map<String, String> atts) {
    currentObject.name = name;

    DataObject newObject = new DataObject();
    newObject.parent = currentObject; // new object is a child of the current
    if (currentObject.parent != null) {
      //			currentObject.parent.getValue().addElement(currentObject);
      currentObject.parent.children.add(currentObject);
    }
    currentObject = newObject;
  }
예제 #10
0
 /**
  * This method adds an element and list of attributes to this DataObject
  *
  * @param name Name of an element
  * @param atts Hashtable list of attributes
  */
 public void addElement(String name, Hashtable atts) {
   if (atts.size() != 0) {
     currentObject.attributes = atts;
   }
   currentObject.name = name;
   DataObject tmp = new DataObject();
   tmp.parent = currentObject;
   if (currentObject.parent != null) {
     currentObject.parent.getValue().addElement(currentObject);
   }
   currentObject = tmp;
 }
예제 #11
0
  /**
   * This method creates a string version of the recursive DataObject
   *
   * @return String version (printable) version of the DataObject
   */
  public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("\n[name=" + getName());

    // print value
    sb.append(", value=" + value);

    // print children
    int i = 0;
    for (DataObject child : children) {
      sb.append(", " + name + "-child(" + i++ + ")=");
      sb.append(child.toString());
    }
    sb.append("]");
    return sb.toString();
  }
예제 #12
0
  /**
   * Returns all (possibly multiple) the DataObject elements/sub-elements with the specified name.
   * Could include itself or any recursively selected child.
   *
   * @param name Name of the element to return
   * @return DataObject with the specified name or null, if not found
   */
  public List<DataObject> getDataObjects(String name) {
    List<DataObject> result = new ArrayList<DataObject>();

    // object's name matches, so add it
    if (this.name.equals(name)) {
      result.add(this);
    }

    // so recursively search among children
    for (DataObject child : children) { // iterate through each child to add more
      // note that child may add an empty list
      result.addAll(child.getDataObjects(name));
    }

    return result;
  }
예제 #13
0
  /**
   * Returns the DataObject element/sub-element with the specified name. Could return itself or any
   * recursively selected child. If multiple children have the same name, then only the first child
   * is returned.
   *
   * @see getDataObjects to retrieve multiple children with name.
   * @param name Name of the element to return
   * @return DataObject with the specified name or null, if not found
   */
  public DataObject getDataObject(String name) {
    // object's name matches, so return it
    if (this.name.equals(name)) {
      return this;
    }

    // not found, so recursively search among children
    for (DataObject child : children) { // iterate through each child
      DataObject result = child.getDataObject(name);
      if (result != null) {
        return result;
      }
    }

    // didn't find anything
    return null;
  }
예제 #14
0
  /**
   * Returns the DataObject element/sub-element with the specified name
   *
   * @param string Name of the element to return
   * @return DataObject with the specified name or null, if not found
   */
  public DataObject getDataObject(String string) {
    DataObject result = null;

    if (!(this.name.equals(string))) {
      Vector v = getValue();
      for (int i = 0; i < v.size(); i++) {
        if (v.elementAt(i).getClass().getName().equals("context.arch.comm.DataObject")) {
          DataObject obj = ((DataObject) (v.elementAt(i)));
          if ((result = obj.getDataObject(string)) != null) { // height-first search
            return result;
          }
        }
      }
    } else {
      return this;
    }
    return null;
  }
예제 #15
0
  /**
   * This method looks for an element in this DataObject. Why does this method exist? No external
   * class uses this! --Brian
   *
   * @param name Name of an element
   * @return boolean true if there is an element by that name, else false
   */
  protected boolean elementExists(String name) {
    //		int n = this.countChildren();
    boolean result = false;

    for (DataObject currentChild : this.getChildren()) {
      String currentName = currentChild.getName();

      if (currentName.equals(name)) {
        // sounds like we've found it
        result = true;
      }
      if (result == false) { // carry on searching the children
        if (currentChild.countChildren() > 0) {
          result = currentChild.elementExists(name);
        }
        if (result) { // did we find it?
          break; // then stop here
        }
      }
    }
    return result;
  }
예제 #16
0
 /**
  * Basic constructor that creates a subscriber object from a DataObject. The DataObject must
  * contain a <SUBSCRIBER> tag
  *
  * @param data DataObject containing the subscriber info
  */
 public Subscriber(DataObject data) {
   DataObject sub = data.getDataObject(SUBSCRIBER);
   id = (String) sub.getDataObject(SUBSCRIBER_ID).getValue().firstElement();
   host = (String) sub.getDataObject(HOSTNAME).getValue().firstElement();
   port = new Integer(((String) sub.getDataObject(PORT).getValue().firstElement())).intValue();
   callback = (String) sub.getDataObject(CALLBACK_NAME).getValue().firstElement();
   tag = (String) sub.getDataObject(CALLBACK_TAG).getValue().firstElement();
   conditions = new Conditions(sub);
   attributes = new Attributes(sub);
   errors = 0;
 }
예제 #17
0
  /**
   * Returns the Nth DataObject element/sub-element with the specified name NB: we assume the
   * current DataObject has 1 level of children. Thus, getNthDataObject (x, 1) is not equivalent to
   * getDataObject (x) I'll fix this later. --DS
   *
   * <p>Returns the Nth DataObject element/sub-element with the specified name NB: Solved the
   * problem with the previous method which considered only 1 level of children ~~Kanupriya
   *
   * @param name Name of the element to return
   * @return DataObject with the specified name or null, if not found
   */
  public DataObject getNthDataObject(String name, int n) {
    DataObject result = null;
    int count = 0;

    if (this.name.equals(name)) {
      result = this;
      count++;
      if (count == n) {
        return result;
      }
    }

    for (DataObject object : children) {
      result = object.getDataObject(name);
      if (result != null) {
        count++;
        if (count == n) {
          return result;
        }
      }
    }
    return null;
  }
예제 #18
0
파일: Server.java 프로젝트: hlambertOld/ctk
  /**
   * This method overloads the widget method It returns the server specific description
   *
   * @return DataObject The information common to all servers
   */
  public DataObject getWidgetDescription() {
    DataObject result;

    // Get the server non constant attributes
    DataObject doAtt_ = setServerAttributes().toDataObject();
    println("server all att = " + doAtt_.toString());
    Vector vAtt = new Vector();
    vAtt.addElement(doAtt_);
    DataObject doAtt = new DataObject(Discoverer.SERVER_NON_CONSTANT_ATTRIBUTES, vAtt);

    // Get the server constant attributes
    DataObject doCstAtt_ = setServerConstantAttributes().toDataObject();
    println("server att = " + doCstAtt_.toString());
    Vector vCstAtt = new Vector();
    vCstAtt.addElement(doCstAtt_);
    DataObject doCstAtt = new DataObject(Discoverer.SERVER_CONSTANT_ATTRIBUTES, vCstAtt);

    // Get the server callbacks
    DataObject doCallbacks_ = setServerCallbacks().toDataObject();
    Vector vCall = new Vector();
    vCall.addElement(doCallbacks_);
    DataObject doCallbacks = new DataObject(Discoverer.SERVER_CALLBACKS, vCall);

    // Get the server services
    DataObject doServices_ = setServerServices().toDataObject();
    Vector vSer = new Vector();
    vSer.addElement(doServices_);
    DataObject doServices = new DataObject(Discoverer.SERVER_SERVICES, vSer);

    Vector v = new Vector();
    v.addElement(doAtt);
    v.addElement(doCstAtt);
    v.addElement(doCallbacks);
    v.addElement(doServices);

    // Get getWidgetDescription
    DataObject doDescrip = getServerDescription();
    if (doDescrip != null) {
      Vector vDescrip = doDescrip.getChildren();
      Enumeration e = vDescrip.elements();
      DataObject temp;
      while (e.hasMoreElements()) {
        temp = (DataObject) e.nextElement();
        v.addElement(temp);
      }
    }

    result = new DataObject(Discoverer.TEMP_DEST, v);

    return result;
  }
예제 #19
0
  /**
   * Adds a value to the current element. Not really adding to this, per se, but setting the value
   * of an internally shifted currentObject's parent. TODO: should really be refactored more --Brian
   *
   * @param value Value being added to the current element
   */
  public void addValue(String value) {
    //		currentObject.parent.getValue().addElement(value);

    currentObject.parent.value = value; // assume this only happens once for each currentObject

    /*
     * I'm not sure if this gets called more than once per DataObject.
     * It's only called by SAX_XMLDecoder.character.
     * I'll assume it's called only once, since elsewhere in the toolkit, only one value is possible.
     * Warn me and kill the process disgracefully if otherwise.
     * WORKS well w/o this condition failing so far
     * --Brian
     */
    //		currentObject.parent.numInvocations_addValue++;
    //		if (currentObject.parent.numInvocations_addValue > 1) {
    //			System.err.println("DataObject " + currentObject.parent + "(" +
    // currentObject.parent.hashCode() + ").addValue(value) called more than once");
    //			System.exit(-1); // quit
    //		}
  }
예제 #20
0
 /**
  * Constructor that takes a DataObject holding the callback info. The expected tag of the
  * DataObject is <CALLBACK>
  *
  * @param data DataObject containing the callback info
  */
 public Callback(DataObject data) {
   DataObject nameObj = data.getDataObject(CALLBACK_NAME);
   this.name = nameObj.getValue();
   this.attributes = Attributes.fromDataObject(data);
 }
예제 #21
0
 /** Basic constructor. Sets up necessary internal variables. */
 public DataObject() {
   currentObject = this;
   currentObject.parent = null;
 }
예제 #22
0
 /** Basic constructor. Sets up necessary internal variables. */
 public DataObject() {
   currentObject = this;
   currentObject.parent = null;
   this.value = new Vector();
 }