1 16 package org.outerj.daisy.frontend.components; 17 18 import org.apache.avalon.excalibur.component.ExcaliburComponentManager; 19 import org.apache.avalon.framework.activity.Initializable; 20 import org.apache.avalon.framework.activity.Disposable; 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.configuration.DefaultConfigurationBuilder; 26 import org.apache.avalon.framework.context.DefaultContext; 27 import org.apache.avalon.framework.context.Contextualizable; 28 import org.apache.avalon.framework.context.Context; 29 import org.apache.avalon.framework.context.ContextException; 30 import org.apache.avalon.framework.logger.LogEnabled; 31 import org.apache.avalon.framework.logger.Logger; 32 import org.outerj.daisy.configutil.PropertyResolver; 33 import org.outerj.daisy.frontend.util.WikiDataDirHelper; 34 35 39 public class DaisyComponentManager implements ComponentManager, Initializable, LogEnabled, Disposable, Contextualizable { 40 41 private final String confFileName; 42 private Logger logger; 43 private Context context; 44 45 private final ExcaliburComponentManager delegate; 46 47 public DaisyComponentManager (String confFileName) { 48 this.confFileName = confFileName;; 49 delegate = new ExcaliburComponentManager(); 50 } 51 52 public void contextualize(Context context) throws ContextException { 53 this.context = context; 54 } 55 56 public Component lookup(String role) throws ComponentException { 57 return this.delegate.lookup(role); 58 } 59 60 public boolean hasComponent(String role) { 61 return delegate.hasComponent(role); 62 } 63 64 public void release(Component component) { 65 this.delegate.release(component); 66 } 67 68 public void initialize() throws Exception { 69 DefaultConfigurationBuilder configBuilder = new DefaultConfigurationBuilder(); 70 String resolvedConfFileName = PropertyResolver.resolveProperties(confFileName, WikiDataDirHelper.getResolveProperties(context)); 71 Configuration config = configBuilder.buildFromFile(resolvedConfFileName); 72 73 this.delegate.enableLogging(logger); 74 this.delegate.contextualize(context); 75 this.delegate.configure(config); 76 this.delegate.initialize(); 77 78 this.logger.debug("Daisy Component manager successfully initialized."); 79 } 80 81 public void enableLogging(Logger logger) { 82 this.logger = logger; 83 } 84 85 public void dispose() { 86 delegate.dispose(); 87 } 88 } 89 | Popular Tags |