1 17 18 package org.apache.james.core; 19 20 import org.apache.avalon.framework.activity.Initializable; 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.component.Composable; 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.context.Context; 29 import org.apache.avalon.framework.context.ContextException; 30 import org.apache.avalon.framework.context.Contextualizable; 31 import org.apache.avalon.framework.logger.AbstractLogEnabled; 32 import org.apache.james.services.UsersRepository; 33 import org.apache.james.services.UsersStore; 34 35 import java.util.HashMap ; 36 import java.util.Iterator ; 37 38 42 public class AvalonUsersStore 43 extends AbstractLogEnabled 44 implements Component, Contextualizable, Composable, Configurable, Initializable, UsersStore { 45 46 50 private HashMap repositories; 51 52 55 protected Context context; 56 57 60 protected Configuration configuration; 61 62 65 protected ComponentManager componentManager; 66 67 70 public void contextualize(final Context context) 71 throws ContextException { 72 this.context = context; 73 } 74 75 78 public void compose( final ComponentManager componentManager ) 79 throws ComponentException { 80 this.componentManager = componentManager; 81 } 82 83 86 public void configure( final Configuration configuration ) 87 throws ConfigurationException { 88 this.configuration = configuration; 89 } 90 91 94 public void initialize() 95 throws Exception { 96 97 getLogger().info("AvalonUsersStore init..."); 98 repositories = new HashMap (); 99 100 Configuration[] repConfs = configuration.getChildren("repository"); 101 ClassLoader theClassLoader = null; 102 for ( int i = 0; i < repConfs.length; i++ ) 103 { 104 Configuration repConf = repConfs[i]; 105 String repName = repConf.getAttribute("name"); 106 String repClass = repConf.getAttribute("class"); 107 108 if (getLogger().isDebugEnabled()) { 109 getLogger().debug("Starting " + repClass); 110 } 111 112 if (theClassLoader == null) { 113 theClassLoader = this.getClass().getClassLoader(); 114 } 115 116 UsersRepository rep = (UsersRepository) theClassLoader.loadClass(repClass).newInstance(); 117 118 setupLogger((Component)rep); 119 120 if (rep instanceof Contextualizable) { 121 ((Contextualizable) rep).contextualize(context); 122 } 123 if (rep instanceof Composable) { 124 ((Composable) rep).compose( componentManager ); 125 } 126 if (rep instanceof Configurable) { 127 ((Configurable) rep).configure(repConf); 128 } 129 if (rep instanceof Initializable) { 130 ((Initializable) rep).initialize(); 131 } 132 repositories.put(repName, rep); 133 if (getLogger().isInfoEnabled()) { 134 StringBuffer logBuffer = 135 new StringBuffer (64) 136 .append("UsersRepository ") 137 .append(repName) 138 .append(" started."); 139 getLogger().info(logBuffer.toString()); 140 } 141 } 142 getLogger().info("AvalonUsersStore ...init"); 143 } 144 145 146 154 public UsersRepository getRepository(String name) { 155 UsersRepository response = (UsersRepository) repositories.get(name); 156 if ((response == null) && (getLogger().isWarnEnabled())) { 157 getLogger().warn("No users repository called: " + name); 158 } 159 return response; 160 } 161 162 169 public Iterator getRepositoryNames() { 170 return this.repositories.keySet().iterator(); 171 } 172 } 173 | Popular Tags |