1 19 20 package org.apache.avalon.fortress.impl.role; 21 22 import org.apache.avalon.fortress.MetaInfoEntry; 23 import org.apache.avalon.fortress.RoleManager; 24 import org.apache.avalon.fortress.util.Service; 25 import org.apache.avalon.framework.configuration.Configurable; 26 import org.apache.avalon.framework.configuration.Configuration; 27 import org.apache.avalon.framework.configuration.ConfigurationException; 28 import org.apache.avalon.framework.thread.SingleThreaded; 29 import org.apache.avalon.framework.thread.ThreadSafe; 30 31 37 public class ECMRoleManager 38 extends AbstractRoleManager 39 implements Configurable 40 { 41 42 45 public ECMRoleManager() 46 { 47 super( null, null ); 48 } 49 50 56 public ECMRoleManager( final ClassLoader loader ) 57 { 58 super( null, loader ); 59 } 60 61 67 public ECMRoleManager( final RoleManager parent ) 68 { 69 super( parent, null ); 70 } 71 72 79 public ECMRoleManager( final RoleManager parent, 80 final ClassLoader loader ) 81 { 82 super( parent, loader ); 83 } 84 85 92 public final void configure( final Configuration configuration ) 93 throws ConfigurationException 94 { 95 final Configuration[] roles = configuration.getChildren( "role" ); 96 97 for ( int i = 0; i < roles.length; i++ ) 98 { 99 final String role = roles[i].getAttribute( "name" ); 100 final String shorthand = roles[i].getAttribute( "shorthand" ); 101 final String defaultClassName = roles[i].getAttribute( "default-class", null ); 102 103 if ( ! addRole( shorthand, role, defaultClassName, getComponentHandlerClassName(defaultClassName)) ) 104 { 105 106 final String message = "Configuration error on invalid entry:\n\tRole: " + role + 107 "\n\tShorthand: " + shorthand + 108 "\n\tDefault Class: " + defaultClassName; 109 110 getLogger().warn(message); 111 } 112 113 } 114 } 115 116 protected String getComponentHandlerClassName(final String defaultClassName) 117 { 118 if ( defaultClassName == null ) 119 { 120 return null; 121 } 122 Class clazz; 123 try 124 { 125 clazz = getLoader().loadClass( defaultClassName ); 126 } 127 catch ( final Exception e ) 128 { 129 final String message = 130 "Unable to load class " + defaultClassName + ". Using dfault component handler."; 131 getLogger().warn( message ); 132 return null; 133 } 134 135 if ( ThreadSafe.class.isAssignableFrom( clazz ) ) 136 { 137 return MetaInfoEntry.THREADSAFE_HANDLER; 138 } 139 else if ( Service.isClassPoolable( clazz ) ) 140 { 141 return MetaInfoEntry.POOLABLE_HANDLER; 142 } 143 else if ( SingleThreaded.class.isAssignableFrom( clazz) ) 144 { 145 return MetaInfoEntry.FACTORY_HANDLER; 146 } 147 148 return null ; 150 } 151 } 152 | Popular Tags |