Exemplo n.º 1
0
  /**
   * This method ensures that the incoming attributes are correct and calls interpretData(). It
   * returns the interpreted results.
   *
   * @param data Incoming interpret request
   * @param error Incoming error, if any
   * @return interpreted results
   * @see #interpretData(AttributeNameValues)
   */
  public DataObject callInterpreter(DataObject data, String error) {
    Vector v = new Vector();
    DataObject result = new DataObject(INTERPRET_REPLY, v);
    Attributes dataToInterpret = null;
    Error err = new Error(error);
    if (err.getError() == null) {
      dataToInterpret = new Attributes(data);
      if (dataToInterpret == null) {
        err.setError(Error.MISSING_PARAMETER_ERROR);
      } else if (!canHandle(dataToInterpret)) {
        err.setError(Error.INVALID_ATTRIBUTE_ERROR);
      }
    }

    if (err.getError() == null) {
      Attributes interpreted = interpretData(dataToInterpret);
      if (interpreted != null) {
        v.addElement(interpreted.toDataObject());
        err.setError(Error.NO_ERROR);
      } else {
        err.setError(Error.INVALID_DATA_ERROR);
      }
    }
    v.addElement(err.toDataObject());
    return result;
  }
Exemplo n.º 2
0
  /**
   * This method runs a query on a widget, asking for either it's latest acquired data (QUERY) or
   * asking for the widget to acquire and return new data (UPDATE_AND_QUERY). Currently, it deals
   * with QUERY and UPDATE_AND_QUERY in exactly the same way.
   *
   * @param query DataObject containing the query request
   * @param update Whether or not to acquire new data
   * @param error String containing the incoming error value
   * @return DataObject containing the reply to the query
   */
  protected DataObject queryWidget(DataObject query, boolean update, String error) {
    System.out.println(query);
    DataObject result = null;
    Vector v = new Vector();
    if (update) {
      result = new DataObject(UPDATE_AND_QUERY_REPLY, v);
    } else {
      result = new DataObject(QUERY_REPLY, v);
    }

    Attributes atts = new Attributes(query);
    Error err = new Error(error);
    if (err.getError() == null) {
      if (atts == null) {
        err.setError(Error.MISSING_PARAMETER_ERROR);
      } else if (!canHandle(atts)) {
        err.setError(Error.INVALID_ATTRIBUTE_ERROR);
      }
    }

    if (err.getError() == null) {
      Attributes subset = attributesCache.getSubset(atts);
      if (subset.numAttributes() == 0) {
        err.setError(Error.INVALID_DATA_ERROR);
      } else {
        v.addElement(subset.toDataObject());
        if (subset.numAttributes() >= atts.numAttributes()) {
          err.setError(Error.NO_ERROR);
        } else {
          err.setError(Error.INCOMPLETE_DATA_ERROR);
        }
      }
    }
    v.addElement(err.toDataObject());
    return result;
  }