コード例 #1
0
  /**
   * Utility method for registering a handler. The parameters are the same as <code>
   * Registry.register</code> except for the <code>handlerName</code> and <code>requestListener
   * </code>. The <code>handlerName</code> demonstrates how to use an <code>ApplicationDescriptor
   * </code> to set the name of a handler. The <code>requestListener</code> parameter is used to set
   * the listener on the registered content handler server.
   */
  static void register(
      final String classname,
      final String[] types,
      final String[] suffixes,
      final String[] actions,
      final ActionNameMap[] actionnames,
      final String id,
      final String[] accessAllowed,
      String handlerName,
      final RequestListener requestListener)
      throws ContentHandlerException, ClassNotFoundException {

    // Get access to the registry and register as a content handler
    final Registry registry = Registry.getRegistry(classname);

    registry.register(classname, types, suffixes, actions, null, id, null);

    // When this content handler gets requests,
    // invocationRequestNotify() will be called
    final ContentHandlerServer contentHandlerServer = Registry.getServer(classname);
    contentHandlerServer.setListener(requestListener);

    // Set the name of the content handler by updating the
    // ApplicationDescriptor
    final DefaultContentHandlerRegistry defaultRegistry =
        DefaultContentHandlerRegistry.getDefaultContentHandlerRegistry(registry);
    final ApplicationDescriptor currentDescriptor =
        ApplicationDescriptor.currentApplicationDescriptor();
    handlerName = handlerName != null ? handlerName : currentDescriptor.getName();

    final ApplicationDescriptor descriptor =
        new ApplicationDescriptor(currentDescriptor, handlerName, null);
    defaultRegistry.setApplicationDescriptor(descriptor, id);
  }
コード例 #2
0
  /**
   * This method is called when the handler receives a request. This class needs to be set as the
   * listener on the <code>ContentHandlerServer</code>. See {@link #register}.
   *
   * @see RequestListener#invocationRequestNotify(ContentHandlerServer)
   */
  public void invocationRequestNotify(final ContentHandlerServer server) {
    // Retrieve Invocation from the content handler server
    final Invocation invoc = server.getRequest(false);

    if (invoc == null) {
      return; // Nothing to do
    }

    int invocationStatus = invoc.getStatus();

    try {
      final Registry registry = Registry.getRegistry(getClass().getName());
      final DefaultContentHandlerRegistry defaultRegistry =
          DefaultContentHandlerRegistry.getDefaultContentHandlerRegistry(registry);
      final ApplicationDescriptor descriptor =
          defaultRegistry.getApplicationDescriptor(server.getID());

      Dialog.alert(descriptor.getName() + " invoked for: " + invoc.getURL());

      // ...
      // Other processing could be done here
      // ...

      // If there are errors or exceptions, the invocation status
      // should be updated. In this case everything is OK.
      invocationStatus = Invocation.OK;
    } finally {
      server.finish(invoc, invocationStatus);
    }
  }