/** * 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); }
/** * Utility method for unregistering a content handler class. This method also sets the request * listener to null on the content handler server. */ static void unregister(final String classname) throws ContentHandlerException { if (classname == null) { return; } final ContentHandlerServer contentHandlerServer = Registry.getServer(classname); contentHandlerServer.setListener(null); final Registry registry = Registry.getRegistry(classname); registry.unregister(classname); }