/** * 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(); }
/** * 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); } }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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); }