示例#1
0
  /**
   * This method is called to aggregate the list of services that the widgets relevant to this
   * widget provide. This allows the server to act as a proxy to the individual widgets' services.
   * This should be called after a constructor sets the widget handles to use or after setWidgets()
   * has been called.
   *
   * @return the server services
   */
  protected Services initServices() {
    if (widgets == null) {
      return null;
    }

    Services services = new Services();
    for (int i = 0; i < widgets.size(); i++) {
      WidgetHandle handle = widgets.getWidgetHandleAt(i);
      DataObject widgetServices =
          getWidgetServices(handle.getHostName(), handle.getPort(), handle.getId());
      String error = new Error(widgetServices).getError();
      if (error != null) {
        if (error.equals(Error.NO_ERROR)) {
          ServiceDescriptions wServices = new ServiceDescriptions(widgetServices);
          for (int j = 0; j < wServices.numServiceDescriptions(); j++) {
            ServiceDescription desc = wServices.getServiceDescriptionAt(j);
            services.addService(
                new InheritedService(
                    this,
                    getId(),
                    desc.getName(),
                    desc.getFunctionDescriptions(),
                    handle.getHostName(),
                    Integer.toString(handle.getPort()),
                    handle.getId()));
          }
        }
      }
    }
    services.addServices(setServerServices());

    return services;
  }
示例#2
0
  /**
   * This method is called to aggregate the list of constant 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 AttributeNameValues the server constant attributes
   */
  protected Attributes initConstantAttributes() {
    // 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);

      DataObject widgetAtts =
          getWidgetConstantAttributes(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++) {
            AttributeNameValue wAtt = (AttributeNameValue) wAtts.getAttributeAt(j);
            if (atts.getAttributeNameValue(wAtt.getName()) == null) {
              atts.addAttributeNameValue(wAtt);
            }
          }
        }
      }
    }

    atts.addAttributes(setServerConstantAttributes());

    return atts;
  }
示例#3
0
  /**
   * This method is called to subscribe to the widgets this server is interested in. It allows the
   * server to act as a proxy to the callbacks provided by each individual widget. This should be
   * called after a constructor sets the widget handles to use or after setWidgets() has been
   * called.
   *
   * @see #setCallbacks()
   */
  protected Callbacks initCallbacks() {
    // 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;
    }

    Callbacks calls = new Callbacks();
    // For all widgets
    for (int i = 0; i < widgets.size(); i++) {
      WidgetHandle handle = widgets.getWidgetHandleAt(i);
      addWidgetCallbacksSubscription(handle, calls);
    }
    calls.addCallbacks(setServerCallbacks());

    return calls;
  }
示例#4
0
  /**
   * This method allows to subscribe to a new widget
   *
   * @param handle The widget to subscribe to
   * @author Agathe
   */
  protected void addCallback(WidgetHandle handle) {
    // Add that to widgets
    widgets.addWidgetHandle(handle);

    Callbacks calls = new Callbacks();

    // Get the callbacks and subscribe
    addWidgetCallbacksSubscription(handle, calls);

    // Add the calls to callbacks
    callbacks.addCallbacks(calls);

    // Update the discoverer
    if (discoverer != null) {
      this.discovererUpdate();
    }
  }