Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/LocalUsersRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/LocalUsersRepository.java?rev=829558&r1=829557&r2=829558&view=diff ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/LocalUsersRepository.java (original) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/LocalUsersRepository.java Sun Oct 25 12:30:55 2009 @@ -19,44 +19,34 @@ package org.apache.james.impl.user; -import org.apache.avalon.framework.activity.Initializable; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; import org.apache.james.api.user.User; import org.apache.james.api.user.UsersRepository; import org.apache.james.api.user.UsersStore; import java.util.Iterator; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; + /** * Provide access to the default "LocalUsers" UsersRepository. */ -public class LocalUsersRepository implements UsersRepository, Serviceable, Initializable { +public class LocalUsersRepository implements UsersRepository { private UsersStore usersStore; protected UsersRepository users; + @Resource(name="org.apache.james.api.user.UsersStore") public void setUsersStore(UsersStore usersStore) { this.usersStore = usersStore; } - /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager serviceManager) throws ServiceException { - UsersStore usersStore = - (UsersStore) serviceManager.lookup(UsersStore.ROLE); - setUsersStore(usersStore); - } - - /** - * @see org.apache.avalon.framework.activity.Initializable#initialize() - */ - public void initialize() throws Exception { + + @PostConstruct + public void init() throws Exception { users = usersStore.getRepository("LocalUsers"); if (users == null) { - throw new ServiceException("","The user repository could not be found."); + throw new Exception("The user repository could not be found."); } }
Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/UserManagement.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/UserManagement.java?rev=829558&r1=829557&r2=829558&view=diff ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/UserManagement.java (original) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/user/UserManagement.java Sun Oct 25 12:30:55 2009 @@ -22,9 +22,6 @@ package org.apache.james.impl.user; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; import org.apache.james.api.user.JamesUser; import org.apache.james.api.user.User; import org.apache.james.api.user.UsersRepository; @@ -33,12 +30,13 @@ import org.apache.james.api.user.management.UserManagementMBean; import org.apache.mailet.MailAddress; +import javax.annotation.Resource; import javax.mail.internet.ParseException; import java.util.Iterator; import java.util.ArrayList; import java.util.List; -public class UserManagement implements UserManagementMBean, Serviceable { +public class UserManagement implements UserManagementMBean { String ROLE = "org.apache.james.impl.user.UserManagement"; @@ -48,30 +46,17 @@ private UsersRepository localUsers; private UsersStore usersStore; - public void setLocalUsers(UsersRepository localUsers) { + @Resource(name="org.apache.james.api.user.UsersRepository") + public void setUsersRepository(UsersRepository localUsers) { this.localUsers = localUsers; } - + + @Resource(name="org.apache.james.api.user.UsersStore") public void setUsersStore(UsersStore usersStore) { this.usersStore = usersStore; } - /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service( final ServiceManager componentManager ) - throws ServiceException { - localUsers = (UsersRepository) componentManager.lookup(UsersRepository.ROLE); - if (localUsers == null) { - throw new ServiceException("","The local user repository could not be found."); - } - setLocalUsers(localUsers); - usersStore = (UsersStore)componentManager.lookup( UsersStore.ROLE ); - if (usersStore == null) { - throw new ServiceException("","The user store containing the user repositories could not be found."); - } - setUsersStore(usersStore); - } + private JamesUser getJamesUser(String userName, String repositoryName) throws UserManagementException { User baseuser = getUserRepository(repositoryName).getUserByName(userName); @@ -129,9 +114,9 @@ * @see org.apache.james.api.user.management.UserManagementMBean#listAllUsers(java.lang.String) */ public String[] listAllUsers(String repositoryName) throws UserManagementException { - List userNames = new ArrayList(); + List<String> userNames = new ArrayList<String>(); UsersRepository users = getUserRepository(repositoryName); - for (Iterator it = users.list(); it.hasNext();) { + for (Iterator<String> it = users.list(); it.hasNext();) { userNames.add(it.next()); } return (String[])userNames.toArray(new String[]{}); @@ -227,11 +212,11 @@ /** * @see org.apache.james.api.user.management.UserManagementMBean#getUserRepositoryNames() */ - public List getUserRepositoryNames() { - List result = new ArrayList(); + public List<String> getUserRepositoryNames() { + List<String> result = new ArrayList<String>(); if (usersStore == null) return result; - Iterator repositoryNames = usersStore.getRepositoryNames(); + Iterator<String> repositoryNames = usersStore.getRepositoryNames(); while (repositoryNames.hasNext()) { String name = (String) repositoryNames.next(); result.add(name); Added: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractAvalonVirtualUserTable.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractAvalonVirtualUserTable.java?rev=829558&view=auto ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractAvalonVirtualUserTable.java (added) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractAvalonVirtualUserTable.java Sun Oct 25 12:30:55 2009 @@ -0,0 +1,155 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.impl.vut; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.configuration.Configurable; +import org.apache.avalon.framework.configuration.Configuration; +import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.logger.LogEnabled; +import org.apache.avalon.framework.logger.Logger; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.impl.AvalonLogger; +import org.apache.james.api.dnsservice.DNSService; +import org.apache.james.api.domainlist.DomainList; +import org.apache.james.api.vut.ErrorMappingException; +import org.apache.james.api.vut.VirtualUserTable; +import org.apache.james.api.vut.management.InvalidMappingException; +import org.apache.james.api.vut.management.VirtualUserTableManagement; +import org.apache.james.smtpserver.mina.GuiceInjected; +import org.apache.james.util.ConfigurationAdapter; + +import com.google.inject.AbstractModule; +import com.google.inject.name.Names; + +public abstract class AbstractAvalonVirtualUserTable implements Serviceable, Initializable, Configurable, GuiceInjected, LogEnabled, VirtualUserTable, VirtualUserTableManagement, DomainList{ + + private DNSService dns; + private HierarchicalConfiguration config; + private Log log; + + protected abstract AbstractVirtualUserTable getVirtualUserTable(); + + + public void service(ServiceManager manager) throws ServiceException { + dns = (DNSService) manager.lookup(DNSService.ROLE); + } + + + public void enableLogging(Logger arg0) { + log = new AvalonLogger(arg0); + } + + + public void configure(Configuration arg0) throws ConfigurationException { + try { + config = new ConfigurationAdapter(arg0); + } catch (org.apache.commons.configuration.ConfigurationException e) { + throw new ConfigurationException("Unable to convert config",e); + } + } + + + public Collection<String> getMappings(String user, String domain) throws ErrorMappingException { + return getVirtualUserTable().getMappings(user, domain); + } + + public boolean addAddressMapping(String user, String domain, String address) throws InvalidMappingException { + return getVirtualUserTable().addAddressMapping(user, domain, address); + } + + public boolean addAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException { + return getVirtualUserTable().addAliasDomainMapping(aliasDomain, realDomain); + } + + public boolean addErrorMapping(String user, String domain, String error) throws InvalidMappingException { + return getVirtualUserTable().addErrorMapping(user, domain, error); + } + + public boolean addMapping(String user, String domain, String mapping) throws InvalidMappingException { + return getVirtualUserTable().addMapping(user, domain, mapping); + } + + public boolean addRegexMapping(String user, String domain, String regex) throws InvalidMappingException { + return getVirtualUserTable().addRegexMapping(user, domain, regex); + } + + public Map<String, Collection<String>> getAllMappings() { + return getVirtualUserTable().getAllMappings(); + } + + public Collection<String> getUserDomainMappings(String user, String domain) throws InvalidMappingException { + return getVirtualUserTable().getUserDomainMappings(user, domain); + } + + public boolean removeAddressMapping(String user, String domain, String address) throws InvalidMappingException { + return getVirtualUserTable().removeAddressMapping(user, domain, address); + } + + public boolean removeAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException { + return getVirtualUserTable().removeAliasDomainMapping(aliasDomain, realDomain); + } + + public boolean removeErrorMapping(String user, String domain, String error) throws InvalidMappingException { + return getVirtualUserTable().removeErrorMapping(user, domain, error); + } + + public boolean removeMapping(String user, String domain, String mapping) throws InvalidMappingException { + return getVirtualUserTable().removeMapping(user, domain, mapping); + } + + public boolean removeRegexMapping(String user, String domain, String regex) throws InvalidMappingException { + return getVirtualUserTable().removeRegexMapping(user, domain, regex); + } + + public boolean containsDomain(String domain) { + return getVirtualUserTable().containsDomain(domain); + } + + public List<String> getDomains() { + return getVirtualUserTable().getDomains(); + } + + public void setAutoDetect(boolean autodetect) { + getVirtualUserTable().setAutoDetect(autodetect); + } + + public void setAutoDetectIP(boolean autodetectIP) { + getVirtualUserTable().setAutoDetectIP(autodetectIP); + } + + public class BaseAvalonVirtualUserTableModule extends AbstractModule { + + @Override + protected void configure() { + bind(DNSService.class).annotatedWith(Names.named("org.apache.james.api.dnsservice.DNSService")).toInstance(dns); + bind(HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config); + bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(log); + } + + } +} Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java?rev=829558&r1=829557&r2=829558&view=diff ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java (original) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java Sun Oct 25 12:30:55 2009 @@ -30,16 +30,13 @@ import java.util.Locale; import java.util.Map; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; import javax.mail.internet.ParseException; -import org.apache.avalon.framework.configuration.Configurable; -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.avalon.framework.configuration.ConfigurationException; -import org.apache.avalon.framework.logger.AbstractLogEnabled; -import org.apache.avalon.framework.logger.Logger; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.logging.Log; import org.apache.james.api.dnsservice.DNSService; import org.apache.james.api.domainlist.DomainList; import org.apache.james.api.vut.ErrorMappingException; @@ -53,8 +50,7 @@ /** * */ -public abstract class AbstractVirtualUserTable extends AbstractLogEnabled - implements VirtualUserTable, VirtualUserTableManagement, DomainList, Serviceable, Configurable { +public abstract class AbstractVirtualUserTable implements VirtualUserTable, VirtualUserTableManagement, DomainList { private boolean autoDetect = true; private boolean autoDetectIP = true; @@ -65,40 +61,47 @@ // TODO: Should we use true or false as default ? private boolean recursive = true; + private HierarchicalConfiguration config; + private Log logger; - /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager arg0) throws ServiceException { - dns = (DNSService)arg0.lookup(DNSService.ROLE); + @Resource(name="org.apache.james.api.dnsservice.DNSService") + public void setDNSService(DNSService dns) { + this.dns = dns; + } + + @Resource(name="org.apache.commons.configuration.Configuration") + public void setConfiguration(HierarchicalConfiguration config) { + this.config = config; } - - - /** - * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration) - */ - public void configure(Configuration arg0) throws ConfigurationException { - Configuration recursiveConf = arg0.getChild("recursiveMapping", false); - if (recursiveConf != null) { - setRecursiveMapping(recursiveConf.getValueAsBoolean(true)); + @Resource(name="org.apache.commons.logging.Log") + public void setLogger(Log logger) { + this.logger = logger; + } + + private void configure() throws ConfigurationException { + setRecursiveMapping(config.getBoolean("recursiveMapping", true)); + try { + setMappingLimit(config.getInt("mappingLimit",10)); + } catch (IllegalArgumentException e) { + throw new ConfigurationException(e.getMessage()); } + doConfigure(config); + } + + protected void doConfigure(HierarchicalConfiguration conf) throws ConfigurationException { - Configuration mappingLimitConf = arg0.getChild("mappingLimit", false); - - if (mappingLimitConf != null ) { - try { - setMappingLimit(mappingLimitConf.getValueAsInteger(10)); - } catch (IllegalArgumentException e) { - throw new ConfigurationException(e.getMessage()); - } - } } public void setRecursiveMapping(boolean recursive) { this.recursive = recursive; } + @PostConstruct + public void init() throws Exception { + configure(); + } + /** * Set the mappingLimit * @@ -316,9 +319,9 @@ /** * @see org.apache.james.api.vut.management.VirtualUserTableManagement#getAllMappings() */ - public Map getAllMappings() { + public Map<String,Collection<String>> getAllMappings() { int count = 0; - Map mappings = getAllMappingsInternal(); + Map<String,Collection<String>> mappings = getAllMappingsInternal(); if (mappings != null) { count = mappings.size(); @@ -329,7 +332,7 @@ private boolean checkMapping(String user,String domain, String mapping) { - Collection mappings = getUserDomainMappings(user,domain); + Collection<String> mappings = getUserDomainMappings(user,domain); if (mappings != null && mappings.contains(mapping)) { return false; } else { @@ -341,8 +344,8 @@ /** * @see org.apache.james.api.domainlist.DomainList#getDomains() */ - public List getDomains() { - List domains = getDomainsInternal(); + public List<String> getDomains() { + List<String> domains = getDomainsInternal(); if (domains != null) { String hostName = null; @@ -361,7 +364,7 @@ } if (autoDetectIP == true) { - List ipList = getDomainsIP(domains,dns,getLogger()); + List<String> ipList = getDomainsIP(domains,dns,getLogger()); for(int i = 0; i < ipList.size(); i++) { if (domains.contains(ipList.get(i)) == false) { domains.add(ipList.get(i)); @@ -370,7 +373,7 @@ } if (getLogger().isInfoEnabled()) { - for (Iterator i = domains.iterator(); i.hasNext(); ) { + for (Iterator<String> i = domains.iterator(); i.hasNext(); ) { getLogger().info("Handling mail for: " + i.next()); } } @@ -386,11 +389,11 @@ * @param domains List of domains * @return domainIP List of ipaddress for domains */ - private static List getDomainsIP(List domains,DNSService dns,Logger log) { - List domainIP = new ArrayList(); + private static List<String> getDomainsIP(List<String> domains,DNSService dns,Log log) { + List<String> domainIP = new ArrayList<String>(); if (domains.size() > 0 ) { for (int i = 0; i < domains.size(); i++) { - List domList = getDomainIP(domains.get(i).toString(),dns,log); + List<String> domList = getDomainIP(domains.get(i).toString(),dns,log); for(int i2 = 0; i2 < domList.size();i2++) { if(domainIP.contains(domList.get(i2)) == false) { @@ -405,8 +408,8 @@ /** * @see #getDomainsIP(List, DNSService, Logger) */ - private static List getDomainIP(String domain, DNSService dns, Logger log) { - List domainIP = new ArrayList(); + private static List<String> getDomainIP(String domain, DNSService dns, Log log) { + List<String> domainIP = new ArrayList<String>(); try { InetAddress[] addrs = dns.getAllByName(domain); for (int j = 0; j < addrs.length ; j++) { @@ -424,7 +427,7 @@ /** * @see org.apache.james.api.vut.management.VirtualUserTableManagement#getUserDomainMappings(java.lang.String, java.lang.String) */ - public Collection getUserDomainMappings(String user, String domain) { + public Collection<String> getUserDomainMappings(String user, String domain) { return getUserDomainMappingsInternal(user, domain); } @@ -473,10 +476,10 @@ // check if we need to sort // TODO: Maybe we should just return the aliasdomain mapping if (mappings != null && mappings.indexOf(VirtualUserTable.ALIASDOMAIN_PREFIX) > -1) { - Collection mapCol = VirtualUserTableUtil.mappingToCollection(mappings); - Iterator mapIt = mapCol.iterator(); + Collection<String> mapCol = VirtualUserTableUtil.mappingToCollection(mappings); + Iterator<String> mapIt = mapCol.iterator(); - List col = new ArrayList(mapCol.size()); + List<String> col = new ArrayList<String>(mapCol.size()); while (mapIt.hasNext()) { int i = 0; @@ -495,6 +498,9 @@ } } + protected Log getLogger() { + return logger; + } /** * Add new mapping @@ -523,7 +529,7 @@ * * @return domains the domains */ - protected abstract List getDomainsInternal(); + protected abstract List<String> getDomainsInternal(); /** * Return Collection of all mappings for the given username and domain @@ -532,14 +538,14 @@ * @param domain the domain * @return Collection which hold the mappings */ - protected abstract Collection getUserDomainMappingsInternal(String user, String domain); + protected abstract Collection<String> getUserDomainMappingsInternal(String user, String domain); /** * Return a Map which holds all Mappings * * @return Map */ - protected abstract Map getAllMappingsInternal(); + protected abstract Map<String,Collection<String>> getAllMappingsInternal(); /** * Override to map virtual recipients to real recipients, both local and non-local. Added: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonDefaultVirtualUserTable.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonDefaultVirtualUserTable.java?rev=829558&view=auto ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonDefaultVirtualUserTable.java (added) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonDefaultVirtualUserTable.java Sun Oct 25 12:30:55 2009 @@ -0,0 +1,115 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + + +package org.apache.james.impl.vut; + +import java.util.Collection; +import java.util.Map; + +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.james.api.vut.ErrorMappingException; +import org.apache.james.api.vut.VirtualUserTableStore; +import org.apache.james.api.vut.management.InvalidMappingException; +import org.apache.james.smtpserver.mina.GuiceInjected; +import org.guiceyfruit.jsr250.Jsr250Module; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.name.Names; + +public class AvalonDefaultVirtualUserTable implements GuiceInjected, Serviceable, Initializable, org.apache.james.api.vut.management.VirtualUserTableManagement{ + + private VirtualUserTableStore store; + private DefaultVirtualUserTable vut; + + + public void service(ServiceManager manager) throws ServiceException { + store = (VirtualUserTableStore) manager.lookup(VirtualUserTableStore.ROLE); + } + + public void initialize() throws Exception { + vut = Guice.createInjector(new Jsr250Module(), new DefaultVirtualUserTableModule()).getInstance(DefaultVirtualUserTable.class); + } + + public boolean addAddressMapping(String user, String domain, String address) throws InvalidMappingException { + return vut.addAddressMapping(user, domain, address); + } + + public boolean addAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException { + return vut.addAliasDomainMapping(aliasDomain, realDomain); + } + + public boolean addErrorMapping(String user, String domain, String error) throws InvalidMappingException { + return vut.addErrorMapping(user, domain, error); + } + + public boolean addMapping(String user, String domain, String mapping) throws InvalidMappingException { + return vut.addMapping(user, domain, mapping); + } + + public boolean addRegexMapping(String user, String domain, String regex) throws InvalidMappingException { + return vut.addRegexMapping(user, domain, regex); + } + + public Map<String, Collection<String>> getAllMappings() { + return vut.getAllMappings(); + } + + public Collection<String> getUserDomainMappings(String user, String domain) throws InvalidMappingException { + return vut.getUserDomainMappings(user, domain); + } + + public boolean removeAddressMapping(String user, String domain, String address) throws InvalidMappingException { + return vut.removeAddressMapping(user, domain, address); + } + + public boolean removeAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException { + return vut.removeAliasDomainMapping(aliasDomain, realDomain); + } + + public boolean removeErrorMapping(String user, String domain, String error) throws InvalidMappingException { + return vut.removeErrorMapping(user, domain, error); + } + + public boolean removeMapping(String user, String domain, String mapping) throws InvalidMappingException { + return vut.removeMapping(user, domain, mapping); + } + + public boolean removeRegexMapping(String user, String domain, String regex) throws InvalidMappingException { + return vut.removeRegexMapping(user, domain, regex); + } + + public Collection<String> getMappings(String user, String domain) throws ErrorMappingException { + return vut.getMappings(user, domain); + } + + private class DefaultVirtualUserTableModule extends AbstractModule { + + @Override + protected void configure() { + bind(VirtualUserTableStore.class).annotatedWith(Names.named("org.apache.james.api.vut.VirtualUserTableStore")).toInstance(store); + } + + } + +} Added: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonVirtualUserTableManagement.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonVirtualUserTableManagement.java?rev=829558&view=auto ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonVirtualUserTableManagement.java (added) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AvalonVirtualUserTableManagement.java Sun Oct 25 12:30:55 2009 @@ -0,0 +1,110 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.impl.vut; + +import java.util.Collection; +import java.util.Map; + +import org.apache.avalon.framework.activity.Initializable; +import org.apache.avalon.framework.service.ServiceException; +import org.apache.avalon.framework.service.ServiceManager; +import org.apache.avalon.framework.service.Serviceable; +import org.apache.james.api.vut.VirtualUserTableStore; +import org.apache.james.api.vut.management.VirtualUserTableManagementException; +import org.apache.james.api.vut.management.VirtualUserTableManagementMBean; +import org.apache.james.api.vut.management.VirtualUserTableManagementService; +import org.guiceyfruit.jsr250.Jsr250Module; + +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.name.Names; + +public class AvalonVirtualUserTableManagement implements Serviceable, Initializable, VirtualUserTableManagementService, VirtualUserTableManagementMBean{ + + private VirtualUserTableManagement vutManage; + private org.apache.james.api.vut.management.VirtualUserTableManagement vManage; + private VirtualUserTableStore store; + + public void service(ServiceManager manager) throws ServiceException { + store = (VirtualUserTableStore) manager.lookup(VirtualUserTableStore.ROLE); + vManage= (org.apache.james.api.vut.management.VirtualUserTableManagement) manager.lookup(org.apache.james.api.vut.management.VirtualUserTableManagement.ROLE); + } + + public void initialize() throws Exception { + vutManage = Guice.createInjector(new Jsr250Module(), new VirtualUserTableManagementModule()).getInstance(VirtualUserTableManagement.class); + } + + public boolean addAddressMapping(String virtualUserTable, String user, String domain, String address) throws VirtualUserTableManagementException { + return vutManage.addAddressMapping(virtualUserTable, user, domain, address); + } + + public boolean addAliasDomainMapping(String virtualUserTable, String aliasDomain, String realDomain) throws VirtualUserTableManagementException { + return vutManage.addAliasDomainMapping(virtualUserTable, aliasDomain, realDomain); + } + + public boolean addErrorMapping(String virtualUserTable, String user, String domain, String error) throws VirtualUserTableManagementException { + return vutManage.addErrorMapping(virtualUserTable, user, domain, error); + } + + public boolean addMapping(String virtualUserTable, String user, String domain, String mapping) throws VirtualUserTableManagementException { + return vutManage.addMapping(virtualUserTable, user, domain, mapping); + } + + public boolean addRegexMapping(String virtualUserTable, String user, String domain, String regex) throws VirtualUserTableManagementException { + return vutManage.addRegexMapping(virtualUserTable, user, domain, regex); + } + + public Map<String,Collection<String>> getAllMappings(String virtualUserTable) throws VirtualUserTableManagementException { + return vutManage.getAllMappings(virtualUserTable); + } + + public Collection<String> getUserDomainMappings(String virtualUserTable, String user, String domain) throws VirtualUserTableManagementException { + return vutManage.getUserDomainMappings(virtualUserTable, user, domain); + } + + public boolean removeAddressMapping(String virtualUserTable, String user, String domain, String address) throws VirtualUserTableManagementException { + return vutManage.removeAddressMapping(virtualUserTable, user, domain, address); + } + + public boolean removeAliasDomainMapping(String virtualUserTable, String aliasDomain, String realDomain) throws VirtualUserTableManagementException { + return vutManage.removeAliasDomainMapping(virtualUserTable, aliasDomain, realDomain); + } + + public boolean removeErrorMapping(String virtualUserTable, String user, String domain, String error) throws VirtualUserTableManagementException { + return vutManage.removeErrorMapping(virtualUserTable, user, domain, error); + } + + public boolean removeMapping(String virtualUserTable, String user, String domain, String mapping) throws VirtualUserTableManagementException { + return vutManage.removeMapping(virtualUserTable, user, domain, mapping); + } + + public boolean removeRegexMapping(String virtualUserTable, String user, String domain, String regex) throws VirtualUserTableManagementException { + return vutManage.removeRegexMapping(virtualUserTable, user, domain, regex); + } + + private class VirtualUserTableManagementModule extends AbstractModule { + + @Override + protected void configure() { + bind(VirtualUserTableStore.class).annotatedWith(Names.named("org.apache.james.api.vut.VirtualUserTableStore")).toInstance(store); + bind(org.apache.james.api.vut.management.VirtualUserTableManagement.class).annotatedWith(Names.named("org.apache.james.api.vut.management.VirtualUserTableManagement")).toInstance(vManage); + } + + } +} Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/DefaultVirtualUserTable.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/DefaultVirtualUserTable.java?rev=829558&r1=829557&r2=829558&view=diff ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/DefaultVirtualUserTable.java (original) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/DefaultVirtualUserTable.java Sun Oct 25 12:30:55 2009 @@ -24,10 +24,9 @@ import java.util.Collection; import java.util.Map; -import org.apache.avalon.framework.activity.Initializable; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; + import org.apache.james.api.vut.ErrorMappingException; import org.apache.james.api.vut.VirtualUserTableStore; import org.apache.james.api.vut.management.InvalidMappingException; @@ -36,30 +35,26 @@ /** * Default VirtualUserTable */ -public class DefaultVirtualUserTable implements VirtualUserTableManagement, Serviceable, Initializable { +public class DefaultVirtualUserTable implements VirtualUserTableManagement { VirtualUserTableManagement vut = null; VirtualUserTableStore store = null; - /** - * @see org.apache.avalon.framework.activity.Initializable#initialize() - */ - public void initialize() throws Exception { + @Resource(name="org.apache.james.api.vut.VirtualUserTableStore") + public void setVirtualUserTableStore(VirtualUserTableStore store) { + this.store = store; + } + + @PostConstruct + public void init() throws Exception { vut = (VirtualUserTableManagement) store.getTable("DefaultVirtualUserTable"); if (vut == null) { - throw new ServiceException("","The DefaultVirtualUserTable could not be found."); + throw new RuntimeException("The DefaultVirtualUserTable could not be found."); } } /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager arg0) throws ServiceException { - store = (VirtualUserTableStore) arg0.lookup(VirtualUserTableStore.ROLE); - } - - /** * @see org.apache.james.api.vut.management.VirtualUserTableManagement#addAddressMapping(java.lang.String, java.lang.String, java.lang.String) */ public boolean addAddressMapping(String user, String domain, String address) throws InvalidMappingException { @@ -83,7 +78,7 @@ /** * @see org.apache.james.api.vut.management.VirtualUserTableManagement#getUserDomainMappings(java.lang.String, java.lang.String) */ - public Collection getUserDomainMappings(String user, String domain) throws InvalidMappingException { + public Collection<String> getUserDomainMappings(String user, String domain) throws InvalidMappingException { return vut.getUserDomainMappings(user, domain); } @@ -132,7 +127,7 @@ /** * @see org.apache.james.api.vut.management.VirtualUserTableManagement#getAllMappings() */ - public Map getAllMappings() { + public Map<String,Collection<String>> getAllMappings() { return vut.getAllMappings(); } Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableManagement.java URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableManagement.java?rev=829558&r1=829557&r2=829558&view=diff ============================================================================== --- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableManagement.java (original) +++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableManagement.java Sun Oct 25 12:30:55 2009 @@ -24,9 +24,8 @@ import java.util.Collection; import java.util.Map; -import org.apache.avalon.framework.service.ServiceException; -import org.apache.avalon.framework.service.ServiceManager; -import org.apache.avalon.framework.service.Serviceable; +import javax.annotation.Resource; + import org.apache.james.api.vut.VirtualUserTable; import org.apache.james.api.vut.VirtualUserTableStore; import org.apache.james.api.vut.management.InvalidMappingException; @@ -39,24 +38,18 @@ * Management for VirtualUserTables * */ -public class VirtualUserTableManagement implements Serviceable, VirtualUserTableManagementService, VirtualUserTableManagementMBean { - - VirtualUserTableStore store; - org.apache.james.api.vut.management.VirtualUserTableManagement defaultVUT; +public class VirtualUserTableManagement implements VirtualUserTableManagementService, VirtualUserTableManagementMBean { - /** - * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager) - */ - public void service(ServiceManager arg0) throws ServiceException { - setVirtualUserTableStore((VirtualUserTableStore) arg0.lookup(VirtualUserTableStore.ROLE)); - setDefaultVirtualUserTable((org.apache.james.api.vut.management.VirtualUserTableManagement) arg0.lookup(DefaultVirtualUserTable.ROLE)); - } + private VirtualUserTableStore store; + private org.apache.james.api.vut.management.VirtualUserTableManagement defaultVUT; + @Resource(name="org.apache.james.api.vut.VirtualUserTableStore") public void setVirtualUserTableStore(VirtualUserTableStore store) { this.store = store; } - public void setDefaultVirtualUserTable(org.apache.james.api.vut.management.VirtualUserTableManagement defaultVUT) { + @Resource(name="org.apache.james.api.vut.management.VirtualUserTableManagement") + public void setVirtualUserTableManagement(org.apache.james.api.vut.management.VirtualUserTableManagement defaultVUT) { this.defaultVUT = defaultVUT; } @@ -122,7 +115,7 @@ /** * @see org.apache.james.api.vut.management.VirtualUserTableManagementService#getUserDomainMappings(java.lang.String, java.lang.String, java.lang.String) */ - public Collection getUserDomainMappings(String virtualUserTable, String user, String domain) throws VirtualUserTableManagementException { + public Collection<String> getUserDomainMappings(String virtualUserTable, String user, String domain) throws VirtualUserTableManagementException { try { return getTable(virtualUserTable).getUserDomainMappings(user, domain); } catch (InvalidMappingException e) { @@ -188,7 +181,7 @@ /** * @see org.apache.james.api.vut.management.VirtualUserTableManagementService#getAllMappings(java.lang.String) */ - public Map getAllMappings(String virtualUserTable) throws VirtualUserTableManagementException{ + public Map<String,Collection<String>> getAllMappings(String virtualUserTable) throws VirtualUserTableManagementException{ return getTable(virtualUserTable).getAllMappings(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
