1 17 18 package org.apache.forrest.locationmap; 19 20 import java.util.Iterator ; 21 import java.util.Map ; 22 23 import org.apache.avalon.framework.activity.Disposable; 24 import org.apache.avalon.framework.configuration.Configurable; 25 import org.apache.avalon.framework.configuration.Configuration; 26 import org.apache.avalon.framework.configuration.ConfigurationException; 27 import org.apache.avalon.framework.logger.AbstractLogEnabled; 28 import org.apache.avalon.framework.logger.LogEnabled; 29 import org.apache.avalon.framework.service.ServiceException; 30 import org.apache.avalon.framework.service.ServiceManager; 31 import org.apache.avalon.framework.service.Serviceable; 32 33 import org.apache.cocoon.components.modules.input.InputModule; 34 35 public abstract class AbstractWrappingModule extends AbstractLogEnabled 36 implements InputModule, Configurable, Serviceable, Disposable { 37 38 InputModule child; 39 ServiceManager manager; 40 41 public void service(ServiceManager manager) throws ServiceException { 42 this.manager = manager; 43 } 44 45 public void configure(Configuration config) throws ConfigurationException { 46 47 Configuration childConf = config.getChild("component-instance"); 48 String childClassName = childConf.getAttribute("class"); 49 getLogger().debug("Loading wrapped class:"+childClassName); 50 51 try{ 52 child = (InputModule) Class.forName(childClassName).newInstance(); 53 getLogger().debug("Wrapped class instantiated:"+child); 54 55 if(child instanceof LogEnabled){ 56 ((LogEnabled)child).enableLogging( getLogger() ); 57 getLogger().debug("Wrapped class LogEnabled"); 58 } 59 60 if(child instanceof Serviceable){ 61 ((Serviceable)child).service( manager ); 62 getLogger().debug("Wrapped class Serviced"); 63 } 64 65 if(child instanceof Configurable){ 66 ((Configurable)child).configure(config.getChild("component-instance")); 67 getLogger().debug("Wrapped class Configured"); 68 } 69 70 }catch(Exception e){ 71 throw new ConfigurationException 72 ("Cannot instatiate the wrapped Module of class:"+childClassName, e); 73 } 74 } 75 76 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 77 throws ConfigurationException { 78 return child.getAttribute(name, modeConf, objectModel); 79 } 80 81 public Iterator getAttributeNames(Configuration modeConf, Map objectModel) 82 throws ConfigurationException { 83 return child.getAttributeNames(modeConf, objectModel); 84 } 85 86 public Object [] getAttributeValues(String name, Configuration modeConf, Map objectModel) 87 throws ConfigurationException { 88 return child.getAttributeValues(name, modeConf, objectModel); 89 } 90 91 public void dispose() { 92 if(child instanceof Disposable){ 93 ((Disposable)child).dispose(); 94 } 95 } 96 97 } 98 | Popular Tags |