bloritsch 2003/05/29 10:14:45 Modified: fortress/src/java/org/apache/avalon/fortress/impl/factory ProxyManager.java fortress/src/java/org/apache/avalon/fortress/impl DefaultContainer.java AbstractContainer.java Log: Update so that the proxymanager is set according to user preferences. Revision Changes Path 1.3 +34 -16 avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/factory/ProxyManager.java Index: ProxyManager.java =================================================================== RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/factory/ProxyManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ProxyManager.java 22 Apr 2003 16:12:48 -0000 1.2 +++ ProxyManager.java 29 May 2003 17:14:45 -0000 1.3 @@ -63,11 +63,16 @@ */ public final class ProxyManager { + public static final int DISCOVER = 0; + public static final int NONE = 1; + public static final int BCEL = 2; + public static final int PROXY = 3; private static final String BCEL_CLASS = "org.apache.bcel.classfile.JavaClass"; private static final String BCEL_WRAPPER = "org.apache.avalon.fortress.impl.factory.WrapperObjectFactory"; private static final String PROXY_WRAPPER = "org.apache.avalon.fortress.impl.factory.ProxyObjectFactory"; + private static final String NOOP_WRAPPER = "org.apache.avalon.fortress.impl.factory.NoopObjectFactory"; private static final boolean m_isBCELPresent; - private final boolean m_useBCELPreference; + private final String m_wrapperClassName; private Class m_factoryClass; static @@ -86,14 +91,34 @@ m_isBCELPresent = bcelPresent; } - public ProxyManager() + public ProxyManager( final int type ) throws Exception { - this( false ); - } - - public ProxyManager( final boolean useBCEL ) - { - m_useBCELPreference = useBCEL; + switch (type) + { + case NONE: + m_wrapperClassName = NOOP_WRAPPER; + break; + + case BCEL: + if ( ! m_isBCELPresent ) throw new IllegalStateException("BCEL is not available"); + m_wrapperClassName = BCEL_WRAPPER; + break; + + case PROXY: + m_wrapperClassName = PROXY_WRAPPER; + break; + + default: // DISCOVER + if ( m_isBCELPresent ) + { + m_wrapperClassName = BCEL_WRAPPER; + } + else + { + m_wrapperClassName = PROXY_WRAPPER; + } + break; + } } public ObjectFactory getWrappedObjectFactory( final ObjectFactory source ) throws Exception @@ -102,14 +127,7 @@ { final ClassLoader loader = source.getClass().getClassLoader(); - if ( m_useBCELPreference && m_isBCELPresent ) - { - m_factoryClass = loader.loadClass( BCEL_WRAPPER ); - } - else - { - m_factoryClass = loader.loadClass( PROXY_WRAPPER ); - } + m_factoryClass = loader.loadClass( m_wrapperClassName ); } final Constructor constr = m_factoryClass.getConstructor( new Class[]{ObjectFactory.class} ); 1.15 +31 -1 avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/DefaultContainer.java Index: DefaultContainer.java =================================================================== RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/DefaultContainer.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- DefaultContainer.java 20 May 2003 13:05:41 -0000 1.14 +++ DefaultContainer.java 29 May 2003 17:14:45 -0000 1.15 @@ -50,6 +50,7 @@ package org.apache.avalon.fortress.impl; import org.apache.avalon.fortress.MetaInfoEntry; +import org.apache.avalon.fortress.impl.factory.ProxyManager; import org.apache.avalon.framework.configuration.Configurable; import org.apache.avalon.framework.configuration.Configuration; import org.apache.avalon.framework.configuration.ConfigurationException; @@ -121,6 +122,8 @@ public void configure( final Configuration config ) throws ConfigurationException { + interpretProxy( config.getAttribute("proxy-type", "discover") ); + final Configuration[] elements = config.getChildren(); for ( int i = 0; i < elements.length; i++ ) { @@ -148,6 +151,33 @@ throw new ConfigurationException( "Could not add component", e ); } } + } + } + + /** + * Interpret the ProxyManager type from the configuration element. + * + * @param proxyType + * @throws ConfigurationException + */ + protected void interpretProxy( String proxyType ) throws ConfigurationException + { + int type = ProxyManager.DISCOVER; + + if ( proxyType.equals("none") ) type = ProxyManager.NONE; + if ( proxyType.equals("bcel") ) type = ProxyManager.BCEL; + if ( proxyType.equals("java") || proxyType.equals("proxy") ) type = ProxyManager.PROXY; + + if ( type == ProxyManager.DISCOVER && ! proxyType.equals("discover") ) + throw new ConfigurationException("Proxy type '" + proxyType + "' not supported"); + + try + { + setProxyManager( new ProxyManager( type ) ); + } + catch (Exception e) + { + throw new ConfigurationException("Could not create ProxyManager", e); } } 1.33 +32 -3 avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java Index: AbstractContainer.java =================================================================== RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- AbstractContainer.java 29 May 2003 16:29:06 -0000 1.32 +++ AbstractContainer.java 29 May 2003 17:14:45 -0000 1.33 @@ -141,7 +141,36 @@ protected List m_shutDownOrder; - private ProxyManager m_proxyManager = new ProxyManager( true ); + private ProxyManager m_proxyManager; + + /** + * Allows you to override the ProxyManager used in the container. In order for your proxymanager + * to be used, it <b>must</b> be set prior to adding any components. + * @param proxyManager + */ + protected void setProxyManager( ProxyManager proxyManager ) + { + if ( null == proxyManager ) throw new NullPointerException("proxyManager"); + if ( null != m_proxyManager ) throw new IllegalStateException("Can not double-assign the ProxyManager"); + m_proxyManager = proxyManager; + } + + /** + * Guarantees that the ProxyManager will be assigned before use. If you do not set the proxy + * manager, the AbstractContainer will use the ProxyManager.DISCOVER algorithm. + * + * @return the ProxyManager. + * @throws Exception if there is a problem + */ + protected ProxyManager getProxyManager() throws Exception + { + if ( null == m_proxyManager ) + { + m_proxyManager = new ProxyManager( ProxyManager.DISCOVER ); + } + + return m_proxyManager; + } /** * Pull the manager items from the context so we can use them to set up @@ -441,7 +470,7 @@ new ComponentFactory( clazz, configuration, m_serviceManager, m_componentContext, m_loggerManager, m_extManager ); - return m_proxyManager.getWrappedObjectFactory( componentFactory ); + return getProxyManager().getWrappedObjectFactory( componentFactory ); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]