1 17 18 package org.apache.avalon.fortress.impl; 19 20 import org.apache.avalon.fortress.MetaInfoEntry; 21 import org.apache.avalon.fortress.impl.factory.ProxyManager; 22 import org.apache.avalon.framework.configuration.Configurable; 23 import org.apache.avalon.framework.configuration.Configuration; 24 import org.apache.avalon.framework.configuration.ConfigurationException; 25 import org.apache.avalon.framework.service.ServiceManager; 26 27 34 public class DefaultContainer 35 extends AbstractContainer 36 implements Configurable 37 { 38 90 public void configure( final Configuration config ) 91 throws ConfigurationException 92 { 93 interpretProxy( config.getAttribute("proxy-type", "discover") ); 94 95 final Configuration[] elements = config.getChildren(); 96 for ( int i = 0; i < elements.length; i++ ) 97 { 98 final Configuration element = elements[i]; 99 final String hint = element.getAttribute( "id", null ); 100 if ( null == hint ) 101 { 102 getLogger().debug( "Ignoring configuration for component, " + element.getName() 104 + ", because the id attribute is missing." ); 105 } 106 else 107 { 108 final String classname = getClassname( element ); 109 final int activation = getActivation( element ); 110 final ComponentHandlerMetaData metaData = 111 new ComponentHandlerMetaData( hint, classname, element, activation ); 112 113 try 114 { 115 addComponent( metaData ); 116 } 117 catch ( Exception e ) 118 { 119 throw new ConfigurationException( "Could not add component", e ); 120 } 121 } 122 } 123 } 124 125 131 protected void interpretProxy( String proxyType ) throws ConfigurationException 132 { 133 int type = ProxyManager.DISCOVER; 134 135 if ( proxyType.equals("none") ) type = ProxyManager.NONE; 136 if ( proxyType.equals("bcel") ) type = ProxyManager.BCEL; 137 if ( proxyType.equals("java") || proxyType.equals("proxy") ) type = ProxyManager.PROXY; 138 139 if ( type == ProxyManager.DISCOVER && ! proxyType.equals("discover") ) 140 throw new ConfigurationException("Proxy type '" + proxyType + "' not supported"); 141 142 try 143 { 144 setProxyManager( new ProxyManager( type ) ); 145 } 146 catch (Exception e) 147 { 148 throw new ConfigurationException("Could not create ProxyManager", e); 149 } 150 } 151 152 158 private String getClassname( final Configuration config ) 159 throws ConfigurationException 160 { 161 final String className; 162 163 if ( "component".equals( config.getName() ) ) 164 { 165 className = config.getAttribute( "class" ); 166 } 167 else 168 { 169 final MetaInfoEntry roleEntry = m_metaManager.getMetaInfoForShortName( config.getName() ); 170 if ( null == roleEntry ) 171 { 172 final String message = "No class found matching configuration name " + 173 "[name: " + config.getName() + ", location: " + config.getLocation() + "]"; 174 throw new ConfigurationException( message ); 175 } 176 177 className = roleEntry.getComponentClass().getName(); 178 } 179 180 if ( getLogger().isDebugEnabled() ) 181 { 182 getLogger().debug( "Configuration processed for: " + className ); 183 } 184 185 return className; 186 } 187 188 205 private int getActivation( final Configuration component ) 206 throws ConfigurationException 207 { 208 final String activation = component.getAttribute( "activation", "background" ); 209 210 if ( "background".equalsIgnoreCase( activation ) 211 || "startup".equalsIgnoreCase( activation ) ) 212 { 213 return ComponentHandlerMetaData.ACTIVATION_BACKGROUND; 214 } 215 else if ( "inline".equalsIgnoreCase( activation ) ) 216 { 217 return ComponentHandlerMetaData.ACTIVATION_INLINE; 218 } 219 else if ( "lazy".equalsIgnoreCase( activation ) 220 || "request".equalsIgnoreCase( activation ) ) 221 { 222 return ComponentHandlerMetaData.ACTIVATION_LAZY; 223 } 224 else 225 { 226 final String classname = component.getAttribute( "class", null ); 228 229 final String message = 230 "Unknown activation policy for class " + classname + ", \"" + activation + "\" " 231 + "at " + component.getLocation(); 232 throw new ConfigurationException( message ); 233 } 234 } 235 236 241 public ServiceManager getServiceManager() 242 { 243 return super.getServiceManager(); 244 } 245 } 246 | Popular Tags |