Example #1
0
  /**
   * This method is called to aggregate the list of non cosntant attributes that the widgets
   * relevant to this server provide. This should be called after a constructor sets the widget
   * handles to use or after setWidgets() has been called.
   *
   * @return the server attributes
   */
  protected Attributes initAttributes() {
    // this protects us against the Widget constructor
    // that calls us too early (we havent' got the widgets yet)
    // it's good practice anyway
    if (widgets == null) {
      return null;
    }

    Attributes atts = new Attributes();
    for (int i = 0; i < widgets.size(); i++) {
      WidgetHandle handle = widgets.getWidgetHandleAt(i);
      System.out.println(handle);
      DataObject widgetAtts =
          getWidgetAttributes(handle.getHostName(), handle.getPort(), handle.getId());

      String error = new Error(widgetAtts).getError();
      if (error != null) {
        if (error.equals(Error.NO_ERROR)) {
          Attributes wAtts = new Attributes(widgetAtts);
          for (int j = 0; j < wAtts.numAttributes(); j++) {
            Attribute wAtt = wAtts.getAttributeAt(j);
            if (atts.getAttribute(wAtt.getName()) == null) {
              atts.addAttribute(wAtt);
            }
          }
        }
      }
    }

    atts.addAttributes(setServerAttributes());

    return atts;
  }