1 16 package org.apache.cocoon.samples.parentcm; 17 18 import org.apache.avalon.excalibur.component.ExcaliburComponentManager; 19 import org.apache.avalon.excalibur.naming.memory.MemoryInitialContextFactory; 20 import org.apache.avalon.framework.activity.Initializable; 21 import org.apache.avalon.framework.component.Component; 22 import org.apache.avalon.framework.component.ComponentException; 23 import org.apache.avalon.framework.component.ComponentManager; 24 import org.apache.avalon.framework.configuration.Configuration; 25 import org.apache.avalon.framework.context.DefaultContext; 26 import org.apache.avalon.framework.logger.LogEnabled; 27 import org.apache.avalon.framework.logger.Logger; 28 29 import javax.naming.Context ; 30 import java.util.Hashtable ; 31 32 40 public class ParentComponentManager implements ComponentManager, LogEnabled, Initializable { 41 42 45 private Logger logger; 46 47 50 private final String jndiName; 51 52 56 private final ExcaliburComponentManager delegate; 57 58 public ParentComponentManager(final String jndiName) { 59 this.jndiName = jndiName; 60 61 this.delegate = new ExcaliburComponentManager(); 63 } 64 65 public boolean hasComponent(final String role) { 66 return delegate.hasComponent(role); 67 } 68 69 73 public void initialize() throws Exception { 74 this.logger.debug("Looking up component manager configuration at : " + this.jndiName); 75 76 Hashtable environment = new Hashtable (); 77 environment.put(Context.INITIAL_CONTEXT_FACTORY, MemoryInitialContextFactory.class.getName()); 78 79 Context initialContext = Configurator.initialContext; 88 89 Configuration config = (Configuration) initialContext.lookup(this.jndiName); 90 91 this.delegate.enableLogging(logger); 94 this.delegate.contextualize(new DefaultContext()); 95 this.delegate.configure(config); 96 this.delegate.initialize(); 97 98 this.logger.debug("Component manager successfully initialized."); 99 } 100 101 public Component lookup(final String role) throws ComponentException { 102 return this.delegate.lookup(role); 103 } 104 105 public void release(final Component component) { 106 this.delegate.release(component); 107 } 108 109 114 public void enableLogging(Logger logger) { 115 this.logger = logger; 116 } 117 } 118 119 | Popular Tags |