home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / ParentComponentManager.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-07-12  |  3.5 KB  |  55 lines

  1. package org.apache.cocoon.samples.parentcm;
  2.  
  3. import java.util.Hashtable;
  4. import javax.naming.Context;
  5. import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
  6. import org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory;
  7. import org.apache.avalon.framework.activity.Initializable;
  8. import org.apache.avalon.framework.component.Component;
  9. import org.apache.avalon.framework.component.ComponentException;
  10. import org.apache.avalon.framework.component.ComponentManager;
  11. import org.apache.avalon.framework.configuration.Configuration;
  12. import org.apache.avalon.framework.context.DefaultContext;
  13. import org.apache.avalon.framework.logger.LogEnabled;
  14. import org.apache.avalon.framework.logger.Logger;
  15.  
  16. public class ParentComponentManager implements ComponentManager, LogEnabled, Initializable {
  17.    private Logger logger;
  18.    private final String jndiName;
  19.    private final ExcaliburComponentManager delegate;
  20.  
  21.    public ParentComponentManager(String jndiName) {
  22.       this.jndiName = jndiName;
  23.       this.delegate = new ExcaliburComponentManager();
  24.    }
  25.  
  26.    public boolean hasComponent(String role) {
  27.       return this.delegate.hasComponent(role);
  28.    }
  29.  
  30.    public void initialize() throws Exception {
  31.       this.logger.debug("Looking up component manager configuration at : " + this.jndiName);
  32.       Hashtable environment = new Hashtable();
  33.       environment.put("java.naming.factory.initial", MemoryInitialContextFactory.class.getName());
  34.       Context initialContext = Configurator.initialContext;
  35.       Configuration config = (Configuration)initialContext.lookup(this.jndiName);
  36.       this.delegate.enableLogging(this.logger);
  37.       this.delegate.contextualize(new DefaultContext());
  38.       this.delegate.configure(config);
  39.       this.delegate.initialize();
  40.       this.logger.debug("Component manager successfully initialized.");
  41.    }
  42.  
  43.    public Component lookup(String role) throws ComponentException {
  44.       return this.delegate.lookup(role);
  45.    }
  46.  
  47.    public void release(Component component) {
  48.       this.delegate.release(component);
  49.    }
  50.  
  51.    public void enableLogging(Logger logger) {
  52.       this.logger = logger;
  53.    }
  54. }
  55.