You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/10/27 19:13:21 UTC
svn commit: r830276 [2/3] - in /james/server/trunk:
avalon-user-function/src/main/java/org/apache/james/userrepository/
avalon-user-function/src/test/java/org/apache/james/userrepository/
core-function/src/main/java/org/apache/james/dnsserver/ core-fun...
Copied: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/GuiceMailStore.java (from r829946, james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/AvalonMailStore.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/GuiceMailStore.java?p2=james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/GuiceMailStore.java&p1=james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/AvalonMailStore.java&r1=829946&r2=830276&rev=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/AvalonMailStore.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/GuiceMailStore.java Tue Oct 27 18:13:19 2009
@@ -21,31 +21,35 @@
package org.apache.james.mailrepository;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
import org.apache.avalon.cornerstone.services.store.Store;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.service.DefaultServiceManager;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.Serviceable;
-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.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
import org.apache.commons.collections.map.ReferenceMap;
-
-import java.util.HashMap;
-import java.util.Map;
+import org.apache.commons.configuration.CombinedConfiguration;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.services.FileSystem;
+import org.guiceyfruit.jsr250.Jsr250Module;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.name.Names;
/**
* Provides a registry of mail repositories. A mail repository is uniquely
* identified by its destinationURL, type and model.
*
*/
-public class AvalonMailStore
- extends AbstractLogEnabled
- implements Serviceable, Configurable, Initializable, Store {
+public class GuiceMailStore
+ implements Store {
// Prefix for repository names
private static final String REPOSITORY_NAME = "Repository";
@@ -62,54 +66,65 @@
private Map<String,String> classes;
// map of [protocol(destinationURL) + type ]->default config for repository.
- private Map<String,Configuration> defaultConfigs;
+ private Map<String,HierarchicalConfiguration> defaultConfigs;
/**
* The Avalon configuration used by the instance
*/
- protected Configuration configuration;
+ private HierarchicalConfiguration configuration;
- /**
- * The Avalon component manager used by the instance
- */
- protected ServiceManager m_manager;
+ private Log logger;
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service( final ServiceManager manager )
- throws ServiceException
- {
- DefaultServiceManager def_manager = new DefaultServiceManager(manager);
- def_manager.put(Store.ROLE, this);
- m_manager = def_manager;
+ private FileSystem fs;
+
+ private DataSourceSelector datasources;
+
+ @Resource(name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")
+ public void setDatasources(DataSourceSelector datasources) {
+ this.datasources = datasources;
}
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure( final Configuration configuration )
- throws ConfigurationException
- {
+ @Resource(name="org.apache.commons.logging.Log")
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ protected Log getLogger() {
+ return logger;
+ }
+
+ @Resource(name="org.apache.commons.configuration.Configuration")
+ public void setConfiguration(HierarchicalConfiguration configuration) {
this.configuration = configuration;
}
-
+
/**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize()
+ * Set the Store to use
+ *
+ * @param store the Store
+ */
+ @Resource(name="org.apache.james.services.FileSystem")
+ public void setFileSystem(FileSystem fs) {
+ this.fs = fs;
+ }
+
+
+ @PostConstruct
+ @SuppressWarnings("unchecked")
+ public void init()
throws Exception {
getLogger().info("JamesMailStore init...");
+
repositories = new ReferenceMap();
classes = new HashMap<String,String>();
- defaultConfigs = new HashMap<String,Configuration>();
- Configuration[] registeredClasses
- = configuration.getChild("repositories").getChildren("repository");
- for ( int i = 0; i < registeredClasses.length; i++ )
+ defaultConfigs = new HashMap<String, HierarchicalConfiguration>();
+ List<HierarchicalConfiguration> registeredClasses
+ = configuration.configurationsAt("repositories/repository");
+ for ( int i = 0; i < registeredClasses.size(); i++ )
{
- registerRepository(registeredClasses[i]);
+ registerRepository(registeredClasses.get(i));
}
}
@@ -127,23 +142,24 @@
* @throws ConfigurationException if an error occurs accessing the
* Configuration object
*/
- public synchronized void registerRepository(Configuration repConf)
+ @SuppressWarnings("unchecked")
+ public synchronized void registerRepository(HierarchicalConfiguration repConf)
throws ConfigurationException {
- String className = repConf.getAttribute("class");
+ String className = repConf.getString("/ @class");
boolean infoEnabled = getLogger().isInfoEnabled();
- Configuration[] protocols
- = repConf.getChild("protocols").getChildren("protocol");
- Configuration[] types = repConf.getChild("types").getChildren("type");
- for ( int i = 0; i < protocols.length; i++ )
+ List<String> protocols = repConf.getList("protocols/protocol");
+ List<String >types = repConf.getList("types/type");
+
+ for ( int i = 0; i < protocols.size(); i++ )
{
- String protocol = protocols[i].getValue();
+ String protocol = protocols.get(i);
// Get the default configuration for these protocol/type combinations.
- Configuration defConf = repConf.getChild("config");
+ HierarchicalConfiguration defConf = repConf.configurationAt("config");
- for ( int j = 0; j < types.length; j++ )
+ for ( int j = 0; j < types.size(); j++ )
{
- String type = types[j].getValue();
+ String type = types.get(j);
String key = protocol + type ;
if (infoEnabled) {
StringBuffer infoBuffer =
@@ -188,31 +204,26 @@
*/
@SuppressWarnings("unchecked")
public synchronized Object select(Object hint) throws ServiceException {
- Configuration repConf = null;
+ HierarchicalConfiguration repConf = null;
try {
- repConf = (Configuration) hint;
+ repConf = (HierarchicalConfiguration) hint;
} catch (ClassCastException cce) {
throw new ServiceException("",
"hint is of the wrong type. Must be a Configuration", cce);
}
String destination = null;
String protocol = null;
- try {
- destination = repConf.getAttribute("destinationURL");
+
+ destination = repConf.getString("/ @destinationURL");
int idx = destination.indexOf(':');
if ( idx == -1 )
throw new ServiceException("",
"destination is malformed. Must be a valid URL: "
+ destination);
protocol = destination.substring(0,idx);
- } catch (ConfigurationException ce) {
- throw new ServiceException("",
- "Malformed configuration has no destinationURL attribute", ce);
- }
+
- try
- {
- String type = repConf.getAttribute("type");
+ String type = repConf.getString("/ @type");
String repID = destination + type;
Object reply = repositories.get(repID);
StringBuffer logBuffer = null;
@@ -247,25 +258,28 @@
// configuration element using the default values
// and the values in the selector.
// If no default values, just use the selector.
- Configuration config;
- Configuration defConf = (Configuration)defaultConfigs.get(key);
+ final CombinedConfiguration config = new CombinedConfiguration();
+ HierarchicalConfiguration defConf = defaultConfigs.get(key);
if ( defConf == null) {
- config = repConf;
+ config.addConfiguration(repConf);
}
else {
- config = new DefaultConfiguration(repConf.getName(),
- repConf.getLocation());
- copyConfig(defConf, (DefaultConfiguration)config);
- copyConfig(repConf, (DefaultConfiguration)config);
+ config.addConfiguration(repConf);
+ config.addConfiguration(defConf);
}
try {
- reply = Thread.currentThread().getContextClassLoader().loadClass(repClass).newInstance();
- ContainerUtil.enableLogging(reply,getLogger());
- ContainerUtil.service(reply,m_manager);
-
- ContainerUtil.configure(reply,config);
- ContainerUtil.initialize(reply);
+ Class<?> objectClass = Thread.currentThread().getContextClassLoader().loadClass(repClass);
+ reply = Guice.createInjector(new Jsr250Module(), new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
+ bind(HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
+ bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(fs);
+ bind(DataSourceSelector.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")).toInstance(datasources);
+ }
+ }).getInstance(objectClass);
repositories.put(repID, reply);
if (getLogger().isInfoEnabled()) {
@@ -288,9 +302,7 @@
e);
}
}
- } catch( final ConfigurationException ce ) {
- throw new ServiceException("", "Malformed configuration", ce );
- }
+
}
/**
@@ -302,7 +314,7 @@
* @return a new repository name
*/
public static final String getName() {
- synchronized (AvalonMailStore.class) {
+ synchronized (GuiceMailStore.class) {
return REPOSITORY_NAME + id++;
}
}
@@ -328,44 +340,6 @@
}
/**
- * Copies values from one config into another, overwriting duplicate attributes
- * and merging children.
- *
- * @param fromConfig the Configuration to be copied
- * @param toConfig the Configuration to which data is being copied
- */
- private void copyConfig(Configuration fromConfig, DefaultConfiguration toConfig)
- {
- // Copy attributes
- String[] attrs = fromConfig.getAttributeNames();
- for ( int i = 0; i < attrs.length; i++ ) {
- String attrName = attrs[i];
- String attrValue = fromConfig.getAttribute(attrName, null);
- toConfig.setAttribute(attrName, attrValue);
- }
-
- // Copy children
- Configuration[] children = fromConfig.getChildren();
- for ( int i = 0; i < children.length; i++ ) {
- Configuration child = children[i];
- String childName = child.getName();
- Configuration existingChild = toConfig.getChild(childName, false);
- if ( existingChild == null ) {
- toConfig.addChild(child);
- }
- else {
- copyConfig(child, (DefaultConfiguration)existingChild);
- }
- }
-
- // Copy value
- String val = fromConfig.getValue(null);
- if ( val != null ) {
- toConfig.setValue(val);
- }
- }
-
- /**
* Return the <code>Component</code> when you are finished with it. In this
* implementation it does nothing
*
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCMailRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCMailRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCMailRepository.java Tue Oct 27 18:13:19 2009
@@ -24,11 +24,9 @@
import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
import org.apache.avalon.cornerstone.services.store.StreamRepository;
import org.apache.avalon.excalibur.datasource.DataSourceComponent;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.core.MailImpl;
import org.apache.james.core.MimeMessageCopyOnWriteProxy;
import org.apache.james.core.MimeMessageWrapper;
@@ -38,6 +36,8 @@
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
@@ -139,43 +139,24 @@
private FileSystem fileSystem;
+ @Resource(name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")
public void setDatasources(DataSourceSelector datasources) {
this.datasources = datasources;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service( final ServiceManager componentManager )
- throws ServiceException {
- super.service(componentManager);
- StringBuffer logBuffer = null;
- if (getLogger().isDebugEnabled()) {
- logBuffer =
- new StringBuffer(64)
- .append(this.getClass().getName())
- .append(".compose()");
- getLogger().debug(logBuffer.toString());
- }
- // Get the DataSourceSelector service
- DataSourceSelector datasources = (DataSourceSelector)componentManager.lookup( DataSourceSelector.ROLE );
- setDatasources(datasources);
- setFileSystem((FileSystem) componentManager.lookup(FileSystem.ROLE));
- }
- private void setFileSystem(FileSystem fileSystem) {
+ @Resource(name="org.apache.james.services.FileSystem")
+ public void setFileSystem(FileSystem fileSystem) {
this.fileSystem = fileSystem;
}
-
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure(Configuration conf) throws ConfigurationException {
+
+ protected void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException {
+ super.doConfigure(configuration);
if (getLogger().isDebugEnabled()) {
getLogger().debug(this.getClass().getName() + ".configure()");
}
- String destination = conf.getAttribute("destinationURL");
+ String destination = configuration.getString("/ @destinationURL");
// normalize the destination, to simplify processing.
if ( ! destination.endsWith("/") ) {
destination += "/";
@@ -202,7 +183,7 @@
new StringBuffer(256)
.append("Malformed destinationURL - Must be of the format '")
.append("db://<data-source>[/<table>[/<repositoryName>]]'. Was passed ")
- .append(conf.getAttribute("destinationURL"));
+ .append(configuration.getString("/ @destinationURL"));
throw new ConfigurationException(exceptionBuffer.toString());
}
if (urlParams.size() >= 1) {
@@ -232,12 +213,14 @@
getLogger().debug(logBuffer.toString());
}
- inMemorySizeLimit = conf.getChild("inMemorySizeLimit").getValueAsInteger(409600000);
+ inMemorySizeLimit = configuration.getInt("inMemorySizeLimit", 409600000);
- String filestore = conf.getChild("filestore").getValue(null);
- sqlFileName = conf.getChild("sqlFile").getValue();
+ String filestore = configuration.getString("filestore", null);
+ sqlFileName = configuration.getString("sqlFile");
try {
if (filestore != null) {
+
+ //TODO Remove me ???
//prepare Configurations for stream repositories
DefaultConfiguration streamConfiguration
= new DefaultConfiguration( "repository",
@@ -266,8 +249,10 @@
getLogger().error(message, e);
throw new ConfigurationException(message, e);
}
+
}
+
/**
* Initialises the JDBC repository.
* 1) Tests the connection to the database.
@@ -278,8 +263,10 @@
*
* @throws Exception if an error occurs
*/
- public void initialize() throws Exception {
- super.initialize();
+ @PostConstruct
+ public void init() throws Exception {
+ super.init();
+
StringBuffer logBuffer = null;
if (getLogger().isDebugEnabled()) {
getLogger().debug(this.getClass().getName() + ".initialize()");
@@ -305,7 +292,7 @@
try {
sqlFile = fileSystem.getResource(sqlFileName);
} catch (Exception e) {
- getLogger().fatalError(e.getMessage(), e);
+ getLogger().error(e.getMessage(), e);
throw e;
}
@@ -405,7 +392,7 @@
+ "in table '"
+ tableName
+ "').");
- getLogger().fatalError(logBuffer.toString());
+ getLogger().error(logBuffer.toString());
throw new SQLException(logBuffer.toString());
}
if (!hasUpdateMessageAttributesSQL && hasRetrieveMessageAttributesSQL) {
@@ -414,7 +401,7 @@
+ "in table '"
+ tableName
+ "'.");
- getLogger().fatalError(logBuffer.toString());
+ getLogger().error(logBuffer.toString());
throw new SQLException(logBuffer.toString());
}
if (!hasMessageAttributesColumn
@@ -425,7 +412,7 @@
+ "' is missing in table '"
+ tableName
+ "'.");
- getLogger().fatalError(logBuffer.toString());
+ getLogger().error(logBuffer.toString());
throw new SQLException(logBuffer.toString());
}
if (hasUpdateMessageAttributesSQL && hasRetrieveMessageAttributesSQL) {
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCSpoolRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCSpoolRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCSpoolRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/JDBCSpoolRepository.java Tue Oct 27 18:13:19 2009
@@ -21,9 +21,8 @@
package org.apache.james.mailrepository;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.james.services.SpoolRepository;
import org.apache.mailet.Mail;
@@ -33,6 +32,8 @@
import java.sql.SQLException;
import java.util.LinkedList;
+import javax.annotation.PostConstruct;
+
/**
* Implementation of a SpoolRepository on a database.
*
@@ -114,11 +115,17 @@
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
- public void configure(Configuration conf) throws ConfigurationException {
- super.configure(conf);
- maxPendingMessages = conf.getChild("maxcache").getValueAsInteger(1000);
+ protected void doConfigure(HierarchicalConfiguration conf) throws ConfigurationException {
+ super.doConfigure(conf);
+ maxPendingMessages = conf.getInt("maxcache",1000);
}
+ @PostConstruct
+ public void init() throws Exception {
+ super.init();
+ }
+
+
/**
* @see org.apache.james.services.SpoolRepository#accept()
*/
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MBoxMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MBoxMailRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MBoxMailRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MBoxMailRepository.java Tue Oct 27 18:13:19 2009
@@ -47,10 +47,9 @@
package org.apache.james.mailrepository;
-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.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
import org.apache.james.core.MailImpl;
import org.apache.james.services.MailRepository;
import org.apache.mailet.Mail;
@@ -59,6 +58,8 @@
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Matcher;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
@@ -110,9 +111,7 @@
*/
-public class MBoxMailRepository
- extends AbstractLogEnabled
- implements MailRepository, Configurable {
+public class MBoxMailRepository implements MailRepository {
static final SimpleDateFormat dy = new SimpleDateFormat("EE MMM dd HH:mm:ss yyyy", Locale.US);
@@ -155,6 +154,28 @@
/**
+ * The repository configuration
+ */
+ private HierarchicalConfiguration configuration;
+
+ private Log logger;
+
+
+ @Resource(name="org.apache.commons.logging.Log")
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ @Resource(name="org.apache.commons.configuration.Configuration")
+ public void setConfiguration(HierarchicalConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ protected Log getLogger() {
+ return logger;
+ }
+
+ /**
* Convert a MimeMessage into raw text
* @param mc The mime message to convert
* @return A string representation of the mime message
@@ -781,12 +802,12 @@
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
- public void configure(Configuration conf) throws ConfigurationException {
+ protected void configure(HierarchicalConfiguration conf) throws ConfigurationException {
String destination;
this.mList = null;
- BUFFERING = conf.getAttributeAsBoolean("BUFFERING", true);
- fifo = conf.getAttributeAsBoolean("FIFO", false);
- destination = conf.getAttribute("destinationURL");
+ BUFFERING = conf.getBoolean("/ @BUFFERING", true);
+ fifo = conf.getBoolean("/ @FIFO", false);
+ destination = conf.getString("/ @destinationURL");
if (destination.charAt(destination.length() - 1) == '/') {
// Remove the trailing / as well as the protocol marker
mboxFile = destination.substring("mbox://".length(), destination.lastIndexOf("/"));
@@ -798,7 +819,7 @@
getLogger().debug("MBoxMailRepository.destinationURL: " + destination);
}
- String checkType = conf.getAttribute("type");
+ String checkType = conf.getString("/ @type");
if (!(checkType.equals("MAIL") || checkType.equals("SPOOL"))) {
String exceptionString = "Attempt to configure MboxMailRepository as " + checkType;
if (getLogger().isWarnEnabled()) {
@@ -808,4 +829,8 @@
}
}
+ @PostConstruct
+ public void init() throws Exception {
+ configure(configuration);
+ }
}
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MailStoreSpoolRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MailStoreSpoolRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MailStoreSpoolRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/MailStoreSpoolRepository.java Tue Oct 27 18:13:19 2009
@@ -22,17 +22,14 @@
package org.apache.james.mailrepository;
import org.apache.avalon.cornerstone.services.store.Store;
-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.AbstractLogEnabled;
-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.services.SpoolRepository;
import org.apache.mailet.Mail;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.util.Collection;
@@ -50,9 +47,7 @@
*
* @version This is $Revision: 165416 $
*/
-public class MailStoreSpoolRepository
- extends AbstractLogEnabled
- implements Serviceable, Initializable, Configurable, SpoolRepository {
+public class MailStoreSpoolRepository implements SpoolRepository {
/**
* The wrapped spoolRepository
@@ -67,32 +62,42 @@
/**
* The repository configuration
*/
- private Configuration configuration;
+ private HierarchicalConfiguration configuration;
+ private Log logger;
+
+
+ @Resource(name="org.apache.commons.logging.Log")
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+ @Resource(name="org.apache.commons.configuration.Configuration")
+ public void setConfiguration(HierarchicalConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ @Resource(name="org.apache.avalon.cornerstone.services.store.Store")
public void setStore(Store store) {
mailStore = store;
}
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager serviceManager) throws ServiceException {
- Store mailStore = (Store) serviceManager.lookup(Store.ROLE);
- setStore(mailStore);
+ protected Log getLogger() {
+ return logger;
}
/**
* @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
- public void configure(Configuration conf) throws ConfigurationException {
- this.configuration = conf;
+ protected void configure(HierarchicalConfiguration conf) throws ConfigurationException {
}
/**
* @see org.apache.avalon.framework.activity.Initializable#initialize()
*/
+ @PostConstruct
public void initialize() throws Exception {
+ configure(configuration);
try {
spoolRep = (SpoolRepository) mailStore.select(configuration);
} catch (Exception e) {
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/AbstractJavamailStoreMailRepository.java Tue Oct 27 18:13:19 2009
@@ -27,6 +27,8 @@
import java.util.Properties;
import java.util.Random;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.NoSuchProviderException;
@@ -34,15 +36,9 @@
import javax.mail.Store;
import javax.mail.URLName;
-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.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.services.FileSystem;
import org.apache.james.services.MailRepository;
import org.apache.mailet.Mail;
@@ -55,9 +51,7 @@
* TODO examine for thread-safety
*/
-public abstract class AbstractJavamailStoreMailRepository extends
- AbstractLogEnabled implements MailRepository, StoreGateKeeperAware, FolderAdapterFactory, Configurable,
- Initializable,Serviceable {
+public abstract class AbstractJavamailStoreMailRepository implements MailRepository, StoreGateKeeperAware, FolderAdapterFactory {
/**
* Whether 'deep debugging' is turned on.
@@ -72,7 +66,7 @@
*/
private String destination;
- protected Logger log;
+ protected Log log;
/**
* The underlaying Store can be used externaly via the StoreAware.getStore()
@@ -107,32 +101,47 @@
*/
private File home;
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service(ServiceManager serviceManager) throws ServiceException {
- try {
- home = ((FileSystem) serviceManager.lookup(FileSystem.ROLE)).getBasedir();
- } catch (FileNotFoundException e) {
- throw new ServiceException(FileSystem.ROLE, "Cannot find the base directory of the application", e);
- }
- }
+ private FileSystem fileSystem;
+
+ private Log logger;
+ private HierarchicalConfiguration configuration;
+
+ @Resource(name="org.apache.james.services.FileSystem")
+ public void setFileSystem(FileSystem fileSystem) {
+ this.fileSystem = fileSystem;
+ }
+
+
+ @Resource(name="org.apache.commons.logging.Log")
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ protected Log getLogger() {
+ return logger;
+ }
+
+ @Resource(name="org.apache.commons.configuration.Configuration")
+ public void setConfiguration(HierarchicalConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+
/**
* builds destination from attributes destinationURL and postfix.
* at the moment james does not hand over additional parameters like postfix.
*
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*
*/
- public void configure(Configuration conf) throws ConfigurationException {
+ protected void doConfigure(HierarchicalConfiguration conf) throws ConfigurationException {
log.debug("JavamailStoreMailRepository configure");
- destination = conf.getAttribute("destinationURL");
+ destination = conf.getString("/ @destinationURL");
log.debug("JavamailStoreMailRepository.destinationURL: " + destination);
if (!destination.endsWith("/")) {
destination += "/";
}
- String postfix = conf.getAttribute("postfix", "");
+ String postfix = conf.getString("/ @postfix", "");
if (postfix.length() > 0) {
if (postfix.startsWith("/")) {
postfix = postfix.substring(1);
@@ -186,7 +195,7 @@
+ destination, e);
}
- String checkType = conf.getAttribute("type");
+ String checkType = conf.getString("/ @type");
if (!checkType.equals(TYPE)) {
String exceptionString = "Attempt to configure JavaMailStoreMailRepository as "
+ checkType;
@@ -196,12 +205,17 @@
log.debug("JavaMailStoreMailRepository configured");
}
- /**
- * Does nothing
- * @see Initializable#initialize()
- */
- public void initialize() throws Exception {
+ @PostConstruct
+ public void init() throws Exception {
log.debug("JavaMailStoreMailRepository initialized");
+
+ doConfigure(configuration);
+ try {
+ home = fileSystem.getBasedir();
+ } catch (FileNotFoundException e) {
+
+ throw new FileNotFoundException("Cannot find the base directory of the application");
+ }
}
private String getDirAsUrl(String dir) throws MalformedURLException {
@@ -347,16 +361,6 @@
}
- /**
- * Set the Logger to use
- *
- * @see org.apache.avalon.framework.logger.AbstractLogEnabled#enableLogging(Logger)
- */
- public void enableLogging(Logger log) {
- super.enableLogging(log);
- this.log=log;
-
- }
/**
* possibility to replace FolderGateKeeper implementation. Only used for
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/HashJavamailStoreMailRepository.java Tue Oct 27 18:13:19 2009
@@ -31,6 +31,7 @@
import java.util.SortedMap;
import java.util.TreeMap;
+import javax.annotation.PostConstruct;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
@@ -594,4 +595,9 @@
return new FolderAdapter(folder);
}
+
+ @PostConstruct
+ public void init() throws Exception {
+ super.init();
+ }
}
Modified: james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java (original)
+++ james/server/trunk/core-function/src/main/java/org/apache/james/mailrepository/javamail/UIDPlusFolderMailRepository.java Tue Oct 27 18:13:19 2009
@@ -28,6 +28,7 @@
import java.util.Map;
import java.util.NoSuchElementException;
+import javax.annotation.PostConstruct;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
@@ -372,4 +373,12 @@
}
+
+ @PostConstruct
+ @Override
+ public void init() throws Exception {
+ super.init();
+ }
+
+
}
Modified: james/server/trunk/core-function/src/main/resources/org/apache/james/dnsserver/DNSServer.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/resources/org/apache/james/dnsserver/DNSServer.xinfo?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/resources/org/apache/james/dnsserver/DNSServer.xinfo (original)
+++ james/server/trunk/core-function/src/main/resources/org/apache/james/dnsserver/DNSServer.xinfo Tue Oct 27 18:13:19 2009
@@ -1,38 +0,0 @@
-<?xml version="1.0"?>
-<!--
- 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.
--->
-
-<blockinfo>
-
- <!-- section to describe block -->
- <block>
- <version>1.0</version>
- </block>
-
- <!-- services that are offered by this block -->
- <services>
- <service name="org.apache.james.api.dnsservice.DNSService" version="1.0"/>
- </services>
-
- <!-- interfaces that may be exported to manange this block -->
- <management-access-points>
- <service name="org.apache.james.dnsserver.DNSServerMBean"/>
- </management-access-points>
-
-</blockinfo>
Modified: james/server/trunk/core-function/src/main/resources/org/apache/james/domain/JDBCDomainList.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/resources/org/apache/james/domain/JDBCDomainList.xinfo?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/resources/org/apache/james/domain/JDBCDomainList.xinfo (original)
+++ james/server/trunk/core-function/src/main/resources/org/apache/james/domain/JDBCDomainList.xinfo Tue Oct 27 18:13:19 2009
@@ -1,44 +0,0 @@
-<?xml version="1.0"?>
-<!--
- 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.
--->
-
-<blockinfo>
-
- <!-- section to describe block -->
- <block>
- <version>1.0</version>
- </block>
-
- <services>
- <service name="org.apache.james.api.domainlist.ManageableDomainList" version="1.0" />
- <service name="org.apache.james.api.domainlist.DomainList" version="1.0" />
- </services>
-
- <dependencies>
- <dependency>
- <service name="org.apache.james.api.dnsservice.DNSService" version="1.0"/>
- </dependency>
- <dependency>
- <service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector" version="1.0"/>
- </dependency>
- <dependency>
- <service name="org.apache.james.services.FileSystem" version="1.0"/>
- </dependency>
- </dependencies>
-</blockinfo>
Modified: james/server/trunk/core-function/src/main/resources/org/apache/james/domain/XMLDomainList.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/resources/org/apache/james/domain/XMLDomainList.xinfo?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/resources/org/apache/james/domain/XMLDomainList.xinfo (original)
+++ james/server/trunk/core-function/src/main/resources/org/apache/james/domain/XMLDomainList.xinfo Tue Oct 27 18:13:19 2009
@@ -1,38 +0,0 @@
-<?xml version="1.0"?>
-<!--
- 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.
--->
-
-<blockinfo>
-
- <!-- section to describe block -->
- <block>
- <version>1.0</version>
- </block>
-
- <services>
- <service name="org.apache.james.api.domainlist.ManageableDomainList" version="1.0" />
- <service name="org.apache.james.api.domainlist.DomainList" version="1.0" />
- </services>
-
- <dependencies>
- <dependency>
- <service name="org.apache.james.api.dnsservice.DNSService" version="1.0"/>
- </dependency>
- </dependencies>
-</blockinfo>
Modified: james/server/trunk/core-function/src/main/resources/org/apache/james/mailrepository/MailStoreSpoolRepository.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/main/resources/org/apache/james/mailrepository/MailStoreSpoolRepository.xinfo?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/main/resources/org/apache/james/mailrepository/MailStoreSpoolRepository.xinfo (original)
+++ james/server/trunk/core-function/src/main/resources/org/apache/james/mailrepository/MailStoreSpoolRepository.xinfo Tue Oct 27 18:13:19 2009
@@ -1,39 +0,0 @@
-<?xml version="1.0"?>
-<!--
- 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.
--->
-
-<blockinfo>
-
- <!-- section to describe block -->
- <block>
- <version>1.0</version>
- </block>
-
- <!-- services that are offered by this block -->
- <services>
- <service name="org.apache.james.services.SpoolRepository" version="1.0" />
- </services>
-
- <dependencies>
- <dependency>
- <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
- </dependency>
- </dependencies>
-
-</blockinfo>
Modified: james/server/trunk/core-function/src/test/java/org/apache/james/dnsserver/DNSServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/test/java/org/apache/james/dnsserver/DNSServerTest.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/test/java/org/apache/james/dnsserver/DNSServerTest.java (original)
+++ james/server/trunk/core-function/src/test/java/org/apache/james/dnsserver/DNSServerTest.java Tue Oct 27 18:13:19 2009
@@ -19,10 +19,8 @@
package org.apache.james.dnsserver;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.impl.SimpleLog;
import org.apache.mailet.HostAddress;
import org.xbill.DNS.Cache;
import org.xbill.DNS.DClass;
@@ -112,12 +110,10 @@
dnsServer = new TestableDNSServer();
DefaultConfigurationBuilder db = new DefaultConfigurationBuilder();
- Configuration c = db.build(
- new ByteArrayInputStream("<dnsserver><autodiscover>true</autodiscover><authoritative>false</authoritative></dnsserver>".getBytes()),
- "dnsserver");
- ContainerUtil.enableLogging(dnsServer, new MockLogger());
- ContainerUtil.configure(dnsServer, c);
- ContainerUtil.initialize(dnsServer);
+ db.load(new ByteArrayInputStream("<dnsserver><autodiscover>true</autodiscover><authoritative>false</authoritative></dnsserver>".getBytes()));
+ dnsServer.setLogger(new SimpleLog("MockLog"));
+ dnsServer.setConfiguration(db);
+ dnsServer.init();
defaultCache = Lookup.getDefaultCache(DClass.IN);
@@ -130,7 +126,7 @@
protected void tearDown() throws Exception {
dnsServer.setCache(null);
- ContainerUtil.dispose(dnsServer);
+ dnsServer = null;
Lookup.setDefaultCache(defaultCache, DClass.IN);
Lookup.setDefaultResolver(defaultResolver);
Lookup.setDefaultSearchPath(defaultSearchPaths);
Modified: james/server/trunk/core-function/src/test/java/org/apache/james/domain/JDBCDomainListTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/test/java/org/apache/james/domain/JDBCDomainListTest.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/test/java/org/apache/james/domain/JDBCDomainListTest.java (original)
+++ james/server/trunk/core-function/src/test/java/org/apache/james/domain/JDBCDomainListTest.java Tue Oct 27 18:13:19 2009
@@ -32,15 +32,12 @@
import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
import org.apache.avalon.excalibur.datasource.DataSourceComponent;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.impl.SimpleLog;
import org.apache.james.api.dnsservice.AbstractDNSServer;
import org.apache.james.api.dnsservice.DNSService;
-import org.apache.james.services.FileSystem;
-import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.test.mock.avalon.MockServiceManager;
import org.apache.james.test.mock.james.MockFileSystem;
import org.apache.james.test.util.Util;
import org.apache.james.util.sql.JDBCUtil;
@@ -95,16 +92,10 @@
protected void delegatedLog(String logString) {}
};
- private Configuration setUpConfiguration(String url) {
- DefaultConfiguration configuration = new DefaultConfiguration("test");
- DefaultConfiguration reposConf = new DefaultConfiguration("repositoryPath");
- reposConf.setValue(url);
- configuration.addChild(reposConf);
-
- DefaultConfiguration sqlConf = new DefaultConfiguration("sqlFile");
- sqlConf.setValue("file://conf/sqlResources.xml");
- configuration.addChild(sqlConf);
-
+ private HierarchicalConfiguration setUpConfiguration(String url) {
+ DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder();
+ configuration.addProperty("repositoryPath", url);
+ configuration.addProperty("sqlFile", "file://conf/sqlResources.xml");
return configuration;
}
@@ -124,23 +115,18 @@
};
return dns;
}
-
- private MockServiceManager setUpServiceManager(DNSService dns) throws Exception {
- MockServiceManager service = new MockServiceManager();
- service.put(DNSService.ROLE, dns);
- service.put(FileSystem.ROLE, new MockFileSystem());
- service.put(DataSourceSelector.ROLE, dataSource);
- return service;
- }
+
public void testAddRemoveGetDomains() throws Exception {
JDBCDomainList dom = new JDBCDomainList();
- ContainerUtil.enableLogging(dom,new MockLogger());
- dom.service(setUpServiceManager(setUpDNSServer("localhost")));
- dom.configure(setUpConfiguration(repos + table));
- dom.initialize();
+ dom.setDNSService(setUpDNSServer("localhost"));
+ dom.setFileSystem(new MockFileSystem());
+ dom.setDataSourceSelector(dataSource);
+ dom.setConfiguration(setUpConfiguration(repos + table));
+ dom.setLogger(new SimpleLog("MockLog"));
+ dom.init();
dom.addDomain("domain1.");
assertEquals("two domain found",dom.getDomains().size(),2);
@@ -153,25 +139,18 @@
public void testThrowConfigurationException() throws Exception {
boolean exception = false;
- boolean exception2 = false;
JDBCDomainList dom = new JDBCDomainList();
- ContainerUtil.enableLogging(dom,new MockLogger());
- dom.service(setUpServiceManager(setUpDNSServer("localhost")));
+ dom.setDNSService(setUpDNSServer("localhost"));
+ dom.setFileSystem(new MockFileSystem());
+ dom.setDataSourceSelector(dataSource);
+ dom.setConfiguration(new DefaultConfigurationBuilder());
+ dom.setLogger(new SimpleLog("MockLog"));
try {
- dom.configure(new DefaultConfiguration("invalid"));
- dom.initialize();
+ dom.init();
} catch (ConfigurationException e) {
exception = true;
}
assertTrue("Exception thrown",exception);
-
- try {
- dom.configure(setUpConfiguration(null));
- } catch (ConfigurationException e) {
- exception2 = true;
- }
-
- assertTrue("Exception thrown",exception2);
}
}
Modified: james/server/trunk/core-function/src/test/java/org/apache/james/domain/XMLDomainListTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/test/java/org/apache/james/domain/XMLDomainListTest.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/test/java/org/apache/james/domain/XMLDomainListTest.java (original)
+++ james/server/trunk/core-function/src/test/java/org/apache/james/domain/XMLDomainListTest.java Tue Oct 27 18:13:19 2009
@@ -27,38 +27,24 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.impl.SimpleLog;
import org.apache.james.api.dnsservice.AbstractDNSServer;
import org.apache.james.api.dnsservice.DNSService;
-import org.apache.james.api.domainlist.ManageableDomainList;
-import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.test.mock.avalon.MockServiceManager;
import junit.framework.TestCase;
public class XMLDomainListTest extends TestCase {
- private Configuration setUpConfiguration(boolean auto,boolean autoIP, List<String> names) {
- DefaultConfiguration configuration = new DefaultConfiguration("test");
- DefaultConfiguration sNamesConf = new DefaultConfiguration("domainnames");
- DefaultConfiguration autoConf = new DefaultConfiguration("autodetect");
- autoConf.setValue(auto);
- configuration.addChild(autoConf);
-
- DefaultConfiguration autoIPConf = new DefaultConfiguration("autodetectIP");
- autoIPConf.setValue(autoIP);
- configuration.addChild(autoIPConf);
+ private HierarchicalConfiguration setUpConfiguration(boolean auto,boolean autoIP, List<String> names) {
+ DefaultConfigurationBuilder configuration = new DefaultConfigurationBuilder();
+ configuration.addProperty("autodetect", auto);
+ configuration.addProperty("autodetectIP", autoIP);
for (int i= 0; i< names.size(); i++) {
- DefaultConfiguration nameConf = new DefaultConfiguration("domainname");
-
- nameConf.setValue(names.get(i).toString());
- sNamesConf.addChild(nameConf);
+ configuration.addProperty("domainnames/domainname", names.get(i).toString());
}
-
- configuration.addChild(sNamesConf);
return configuration;
}
@@ -78,23 +64,17 @@
};
return dns;
}
-
- private MockServiceManager setUpServiceManager(DNSService dns) {
- MockServiceManager service = new MockServiceManager();
- service.put(DNSService.ROLE, dns);
- return service;
- }
-
+
public void testGetDomains() throws Exception {
List<String> domains = new ArrayList<String>();
domains.add("domain1.");
domains.add("domain2.");
XMLDomainList dom = new XMLDomainList();
- ContainerUtil.enableLogging(dom,new MockLogger());
- ContainerUtil.service(dom,setUpServiceManager(setUpDNSServer("localhost")));
- ContainerUtil.configure(dom, setUpConfiguration(false,false,domains));
- ContainerUtil.initialize(dom);
+ dom.setLogger(new SimpleLog("MockLog"));
+ dom.setDNSService(setUpDNSServer("localhost"));
+ dom.setConfiguration(setUpConfiguration(false,false,domains));
+ dom.init();
assertTrue("Two domain found",dom.getDomains().size() ==2);
}
@@ -104,11 +84,10 @@
domains.add("domain1.");
XMLDomainList dom = new XMLDomainList();
- ContainerUtil.enableLogging(dom,new MockLogger());
- ContainerUtil.service(dom,setUpServiceManager(setUpDNSServer("local")));
- ContainerUtil.configure(dom, setUpConfiguration(true,false,domains));
- ContainerUtil.initialize(dom);
-
+ dom.setLogger(new SimpleLog("MockLog"));
+ dom.setDNSService(setUpDNSServer("local"));
+ dom.setConfiguration(setUpConfiguration(true,false,domains));
+ dom.init();
assertEquals("Two domains found",dom.getDomains().size(), 2);
}
@@ -116,11 +95,11 @@
List<String> domains = new ArrayList<String>();
domains.add("domain1.");
- ManageableDomainList dom = new XMLDomainList();
- ContainerUtil.enableLogging(dom,new MockLogger());
- ContainerUtil.service(dom,setUpServiceManager(setUpDNSServer("localhost")));
- ContainerUtil.configure(dom, setUpConfiguration(true,false,domains));
- ContainerUtil.initialize(dom);
+ XMLDomainList dom = new XMLDomainList();
+ dom.setLogger(new SimpleLog("MockLog"));
+ dom.setDNSService(setUpDNSServer("localhost"));
+ dom.setConfiguration(setUpConfiguration(true,false,domains));
+ dom.init();
assertEquals("One domain found",dom.getDomains().size(), 1);
}
Copied: james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/FileMailRepositoryTest.java (from r829946, james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/AvalonMailRepositoryTest.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/FileMailRepositoryTest.java?p2=james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/FileMailRepositoryTest.java&p1=james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/AvalonMailRepositoryTest.java&r1=829946&r2=830276&rev=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/AvalonMailRepositoryTest.java (original)
+++ james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/FileMailRepositoryTest.java Tue Oct 27 18:13:19 2009
@@ -21,18 +21,16 @@
package org.apache.james.mailrepository;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.DefaultServiceManager;
import org.apache.avalon.framework.service.ServiceException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.impl.SimpleLog;
import org.apache.james.mailrepository.filepair.File_Persistent_Object_Repository;
import org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository;
-import org.apache.james.services.FileSystem;
import org.apache.james.services.MailRepository;
-import org.apache.james.test.mock.avalon.MockLogger;
import org.apache.james.test.mock.avalon.MockStore;
import org.apache.james.test.mock.james.MockFileSystem;
-public class AvalonMailRepositoryTest extends AbstractMailRepositoryTest {
+public class FileMailRepositoryTest extends AbstractMailRepositoryTest {
/**
* @return
@@ -40,35 +38,36 @@
* @throws ConfigurationException
* @throws Exception
*/
- protected MailRepository getMailRepository() throws ServiceException, ConfigurationException, Exception {
- DefaultServiceManager serviceManager = new DefaultServiceManager();
- serviceManager.put(FileSystem.ROLE, new MockFileSystem());
- AvalonMailRepository mr = new AvalonMailRepository();
+ protected MailRepository getMailRepository() throws Exception {
+ MockFileSystem fs = new MockFileSystem();
+ FileMailRepository mr = new FileMailRepository();
MockStore mockStore = new MockStore();
File_Persistent_Stream_Repository file_Persistent_Stream_Repository = new File_Persistent_Stream_Repository();
- file_Persistent_Stream_Repository.service(serviceManager);
- file_Persistent_Stream_Repository.enableLogging(new MockLogger());
- DefaultConfiguration defaultConfiguration2 = new DefaultConfiguration("conf");
- defaultConfiguration2.setAttribute("destinationURL", "file://target/var/mr");
- file_Persistent_Stream_Repository.configure(defaultConfiguration2);
- file_Persistent_Stream_Repository.initialize();
+ file_Persistent_Stream_Repository.setFileSystem(fs);
+ file_Persistent_Stream_Repository.setLogger(new SimpleLog("MockLog"));
+
+ DefaultConfigurationBuilder defaultConfiguration2 = new DefaultConfigurationBuilder();
+ defaultConfiguration2.addProperty("/ @destinationURL", "file://target/var/mr");
+ file_Persistent_Stream_Repository.setConfiguration(defaultConfiguration2);
+ file_Persistent_Stream_Repository.init();
+
mockStore.add("STREAM.mr", file_Persistent_Stream_Repository);
File_Persistent_Object_Repository file_Persistent_Object_Repository = new File_Persistent_Object_Repository();
- file_Persistent_Object_Repository.service(serviceManager);
- file_Persistent_Object_Repository.enableLogging(new MockLogger());
- DefaultConfiguration defaultConfiguration22 = new DefaultConfiguration("conf");
- defaultConfiguration22.setAttribute("destinationURL", "file://target/var/mr");
- file_Persistent_Object_Repository.configure(defaultConfiguration22);
- file_Persistent_Object_Repository.initialize();
+ file_Persistent_Object_Repository.setFileSystem(fs);
+ file_Persistent_Object_Repository.setLogger(new SimpleLog("MockLog"));
+ DefaultConfigurationBuilder defaultConfiguration22 = new DefaultConfigurationBuilder();
+ defaultConfiguration22.addProperty("/ @destinationURL", "file://target/var/mr");
+ file_Persistent_Object_Repository.setConfiguration(defaultConfiguration22);
+ file_Persistent_Object_Repository.init();
mockStore.add("OBJECT.mr", file_Persistent_Object_Repository);
mr.setStore(mockStore);
- mr.enableLogging(new MockLogger());
- DefaultConfiguration defaultConfiguration = new DefaultConfiguration("ReposConf");
- defaultConfiguration.setAttribute("destinationURL","file://target/var/mr");
- defaultConfiguration.setAttribute("type","MAIL");
- mr.configure(defaultConfiguration);
- mr.initialize();
+ mr.setLogger(new SimpleLog("MockLog"));
+ DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
+ defaultConfiguration.addProperty("/ @destinationURL","file://target/var/mr");
+ defaultConfiguration.addProperty("/ @type","MAIL");
+ mr.setConfiguration(defaultConfiguration);
+ mr.init();
return mr;
}
Modified: james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/JDBCMailRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/JDBCMailRepositoryTest.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/JDBCMailRepositoryTest.java (original)
+++ james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/JDBCMailRepositoryTest.java Tue Oct 27 18:13:19 2009
@@ -21,18 +21,12 @@
package org.apache.james.mailrepository;
import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
-import org.apache.avalon.cornerstone.services.store.Store;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.DefaultServiceManager;
-import org.apache.avalon.framework.service.ServiceException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.impl.SimpleLog;
import org.apache.james.mailrepository.filepair.File_Persistent_Stream_Repository;
-import org.apache.james.services.FileSystem;
import org.apache.james.services.MailRepository;
-import org.apache.james.test.mock.avalon.MockLogger;
import org.apache.james.test.mock.avalon.MockStore;
import org.apache.james.test.mock.james.MockFileSystem;
-import org.apache.james.test.mock.util.AttrValConfiguration;
import org.apache.james.test.util.Util;
public class JDBCMailRepositoryTest extends AbstractMailRepositoryTest {
@@ -43,32 +37,32 @@
* @throws ConfigurationException
* @throws Exception
*/
- protected MailRepository getMailRepository() throws ServiceException, ConfigurationException, Exception {
- DefaultServiceManager serviceManager = new DefaultServiceManager();
- serviceManager.put(FileSystem.ROLE, new MockFileSystem());
- serviceManager.put(DataSourceSelector.ROLE, Util.getDataSourceSelector());
+ protected MailRepository getMailRepository() throws Exception {
+ MockFileSystem fs = new MockFileSystem();
+ DataSourceSelector selector = Util.getDataSourceSelector();
JDBCMailRepository mr = new JDBCMailRepository();
// only used for dbfile
MockStore mockStore = new MockStore();
File_Persistent_Stream_Repository file_Persistent_Stream_Repository = new File_Persistent_Stream_Repository();
- file_Persistent_Stream_Repository.service(serviceManager);
- file_Persistent_Stream_Repository.enableLogging(new MockLogger());
- DefaultConfiguration defaultConfiguration2 = new DefaultConfiguration("conf");
- defaultConfiguration2.setAttribute("destinationURL", "file://target/var/mr/testrepo");
- file_Persistent_Stream_Repository.configure(defaultConfiguration2);
- file_Persistent_Stream_Repository.initialize();
+ file_Persistent_Stream_Repository.setFileSystem(fs);
+ file_Persistent_Stream_Repository.setLogger(new SimpleLog("MockLog"));
+ DefaultConfigurationBuilder defaultConfiguration2 = new DefaultConfigurationBuilder();
+ defaultConfiguration2.addProperty("/ @destinationURL", "file://target/var/mr/testrepo");
+ file_Persistent_Stream_Repository.setConfiguration(defaultConfiguration2);
+ file_Persistent_Stream_Repository.init();
mockStore.add("STREAM.mr", file_Persistent_Stream_Repository);
- serviceManager.put(Store.ROLE,mockStore);
-
- mr.enableLogging(new MockLogger());
- DefaultConfiguration defaultConfiguration = new DefaultConfiguration("ReposConf");
- defaultConfiguration.setAttribute("destinationURL","db://maildb/mr/testrepo");
- defaultConfiguration.addChild(new AttrValConfiguration("sqlFile","file://conf/sqlResources.xml"));
- defaultConfiguration.setAttribute("type","MAIL");
- mr.service(serviceManager);
- mr.configure(defaultConfiguration);
- mr.initialize();
+
+ DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
+ defaultConfiguration.addProperty("/ @destinationURL","db://maildb/mr/testrepo");
+ defaultConfiguration.addProperty("sqlFile","file://conf/sqlResources.xml");
+ defaultConfiguration.addProperty("/ @type","MAIL");
+ mr.setFileSystem(fs);
+ mr.setStore(mockStore);
+ mr.setDatasources(selector);
+ mr.setLogger(new SimpleLog("MockLog"));
+ mr.setConfiguration(defaultConfiguration);
+ mr.init();
return mr;
}
Modified: james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/MBoxMailRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/MBoxMailRepositoryTest.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/MBoxMailRepositoryTest.java (original)
+++ james/server/trunk/core-function/src/test/java/org/apache/james/mailrepository/MBoxMailRepositoryTest.java Tue Oct 27 18:13:19 2009
@@ -25,11 +25,9 @@
import junit.framework.TestCase;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.ServiceException;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.impl.SimpleLog;
import org.apache.james.services.MailRepository;
-import org.apache.james.test.mock.avalon.MockLogger;
import org.apache.james.test.mock.james.MockFileSystem;
/**
@@ -42,25 +40,26 @@
public class MBoxMailRepositoryTest extends TestCase {
- protected MailRepository getMailRepository() throws ServiceException, ConfigurationException, Exception {
+ protected MailRepository getMailRepository() throws Exception {
MBoxMailRepository mr = new MBoxMailRepository();
- mr.enableLogging(new MockLogger());
- DefaultConfiguration defaultConfiguration = new DefaultConfiguration("ReposConf");
+ DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
File fInbox = new MockFileSystem().getFile("file://conf/org/apache/james/mailrepository/testdata/Inbox");
String mboxPath = "mbox://"+fInbox.toURI().toString().substring(new File("").toURI().toString().length());
- defaultConfiguration.setAttribute("destinationURL",mboxPath);
- defaultConfiguration.setAttribute("type","MAIL");
- mr.configure(defaultConfiguration);
+ defaultConfiguration.addProperty("/ @destinationURL",mboxPath);
+ defaultConfiguration.addProperty("/ @type","MAIL");
+ mr.setConfiguration(defaultConfiguration);
+ mr.setLogger(new SimpleLog("MockLog"));;
+ mr.init();
return mr;
}
// Try to write a unit test for JAMES-744. At the moment it seems that we cannot reproduce it.
- public void testReadMboxrdFile() throws ServiceException, ConfigurationException, Exception {
+ public void testReadMboxrdFile() throws Exception {
MailRepository mr = getMailRepository();
-
+
Iterator<String> keys = mr.list();
assertTrue("Two messages in list", keys.hasNext());
Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/AbstractFileRepository.java Tue Oct 27 18:13:19 2009
@@ -22,14 +22,10 @@
package org.apache.james.mailrepository.filepair;
import org.apache.avalon.cornerstone.services.store.Repository;
-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.AbstractLogEnabled;
-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.services.FileSystem;
import org.apache.james.util.io.ExtensionFileFilter;
@@ -43,15 +39,17 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
/**
* This an abstract class implementing functionality for creating a file-store.
*
*/
public abstract class AbstractFileRepository
- extends AbstractLogEnabled
- implements Repository, Serviceable, Configurable, Initializable
-{
+ implements Repository {
protected static final boolean DEBUG = false;
protected static final String HANDLED_URL = "file://";
@@ -68,45 +66,64 @@
protected FilenameFilter m_filter;
protected File m_baseDirectory;
- protected ServiceManager m_serviceManager;
+ private FileSystem fileSystem;
- protected abstract String getExtensionDecorator();
+ private Log logger;
- /**
- * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
- */
- public void service( final ServiceManager serviceManager )
- throws ServiceException
- {
- m_serviceManager = serviceManager;
- try {
- m_baseDirectory = ((FileSystem) serviceManager.lookup(FileSystem.ROLE)).getBasedir();
- } catch (FileNotFoundException e) {
- throw new ServiceException(FileSystem.ROLE, "Cannot find the base directory of the application", e);
- }
+ private HierarchicalConfiguration configuration;
+
+
+ @Resource(name="org.apache.commons.configuration.Configuration")
+ public void setConfiguration(HierarchicalConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+
+ @Resource(name="org.apache.james.services.FileSystem")
+ public void setFileSystem(FileSystem fileSystem) {
+ this.fileSystem = fileSystem;
+ }
+
+
+ @Resource(name="org.apache.commons.logging.Log")
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ protected Log getLogger() {
+ return logger;
}
+
+
+ protected abstract String getExtensionDecorator();
- /**
- * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
- */
- public void configure( final Configuration configuration )
+
+
+ protected void doConfigure( final HierarchicalConfiguration configuration )
throws ConfigurationException
{
if( null == m_destination )
{
- final String destination = configuration.getAttribute( "destinationURL" );
+ final String destination = configuration.getString( "/ @destinationURL" );
setDestination( destination );
}
}
- /**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize()
+ @PostConstruct
+ public void init()
throws Exception
{
getLogger().info( "Init " + getClass().getName() + " Store" );
+ doConfigure(configuration);
+ try {
+ m_baseDirectory = fileSystem.getBasedir();
+ } catch (FileNotFoundException e) {
+ getLogger().error("Cannot find the base directory of the application",e);
+ throw new FileNotFoundException("Cannot find the base directory of the application");
+ }
+
+
m_name = "Repository";
String m_postfix = getExtensionDecorator();
m_extension = "." + m_name + m_postfix;
@@ -225,16 +242,8 @@
childName + " : " + e );
}
- try
- {
- child.service( m_serviceManager );
- }
- catch( final ServiceException cme )
- {
- throw new RuntimeException( "Cannot service child " +
- "repository " + childName +
- " : " + cme );
- }
+ child.setFileSystem(fileSystem);
+ child.setLogger(logger);
try
{
@@ -250,7 +259,7 @@
try
{
- child.initialize();
+ child.init();
}
catch( final Exception e )
{
@@ -358,11 +367,11 @@
/**
* Returns the list of used keys.
*/
- public Iterator list()
+ public Iterator<String> list()
{
final File storeDir = new File( m_path );
final String[] names = storeDir.list( m_filter );
- final ArrayList list = new ArrayList();
+ final List<String> list = new ArrayList<String>();
for( int i = 0; i < names.length; i++ )
{
Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Object_Repository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Object_Repository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Object_Repository.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Object_Repository.java Tue Oct 27 18:13:19 2009
@@ -25,6 +25,9 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
+
+import javax.annotation.PostConstruct;
+
import org.apache.avalon.cornerstone.services.store.ObjectRepository;
import org.apache.james.util.io.ClassLoaderObjectInputStream;
@@ -37,7 +40,11 @@
extends AbstractFileRepository
implements ObjectRepository
{
-
+
+ @PostConstruct
+ public void init() throws Exception {
+ super.init();
+ }
/**
* @see org.apache.james.mailrepository.filepair.AbstractFileRepository#getExtensionDecorator()
*/
Modified: james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Stream_Repository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Stream_Repository.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Stream_Repository.java (original)
+++ james/server/trunk/core-library/src/main/java/org/apache/james/mailrepository/filepair/File_Persistent_Stream_Repository.java Tue Oct 27 18:13:19 2009
@@ -28,6 +28,8 @@
import java.io.InputStream;
import java.io.OutputStream;
+import javax.annotation.PostConstruct;
+
/**
* Implementation of a StreamRepository to a File.
* TODO: -retieve(String key) should return a FilterInputStream to allow
@@ -38,6 +40,11 @@
extends AbstractFileRepository
implements StreamRepository
{
+
+ @PostConstruct
+ public void init() throws Exception {
+ super.init();
+ }
/**
* @see org.apache.james.mailrepository.filepair.AbstractFileRepository#getExtensionDecorator()
Modified: james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java (original)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/services/MailServerTestAllImplementations.java Tue Oct 27 18:13:19 2009
@@ -32,7 +32,7 @@
protected static final String EXISTING_USER_NAME = "testExistingUserName";
- abstract public MailServer createMailServer() throws ServiceException;
+ abstract public MailServer createMailServer() throws ServiceException, Exception;
abstract public boolean allowsPasswordlessUser();
/**
@@ -43,7 +43,7 @@
abstract public boolean canTestUserExists();
abstract public boolean isUserExisting(MailServer mailServerImpl, String username);
- public void testId() throws ServiceException {
+ public void testId() throws Exception {
MailServer mailServer = createMailServer();
String id = mailServer.getId();
@@ -51,7 +51,7 @@
assertFalse("mail id not empty", "".equals(id));
}
- public void testIdIncrement() throws ServiceException {
+ public void testIdIncrement() throws Exception {
MailServer mailServer = createMailServer();
String id1 = mailServer.getId();
@@ -59,7 +59,7 @@
assertFalse("next id is different", id1.equals(id2));
}
- public void testAddUser() throws ServiceException {
+ public void testAddUser() throws Exception {
// addUser acts on field localUsers for class org.apache.james.James
// thus, it is unrelated to getUserInbox() for the only known implementation of MailServer
@@ -99,7 +99,7 @@
}
- public void testGetNonexistingUserInbox() throws ServiceException {
+ public void testGetNonexistingUserInbox() throws Exception {
MailServer mailServer = createMailServer();
@@ -110,7 +110,7 @@
assertEquals("test user does not exist", null, userInbox);
}
- public void testGetExisitingUserInbox() throws ServiceException {
+ public void testGetExisitingUserInbox() throws Exception {
MailServer mailServer = createMailServer();
MailRepository userInbox = mailServer.getUserInbox(EXISTING_USER_NAME);
Modified: james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/avalon/MockStore.java
URL: http://svn.apache.org/viewvc/james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/avalon/MockStore.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/avalon/MockStore.java (original)
+++ james/server/trunk/core-library/src/test/java/org/apache/james/test/mock/avalon/MockStore.java Tue Oct 27 18:13:19 2009
@@ -22,9 +22,8 @@
package org.apache.james.test.mock.avalon;
import org.apache.avalon.cornerstone.services.store.Store;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.service.ServiceException;
+import org.apache.commons.configuration.Configuration;
import java.util.HashMap;
import java.util.Map;
@@ -44,28 +43,26 @@
private Object get(Object object) {
Object key = extractKeyObject(object);
- System.err.println(key);
+ System.out.println(key);
return m_storedObjectMap.get(key);
}
private Object extractKeyObject(Object object) {
if (object instanceof Configuration) {
Configuration repConf = (Configuration) object;
- try {
- String type = repConf.getAttribute("type");
- String prefix = "";
- if (!"MAIL".equals(type) && !"SPOOL".equals(type)) {
- prefix = type+".";
- }
- String attribute = repConf.getAttribute("destinationURL");
- String[] strings = attribute.split("/");
- if (strings.length > 0) {
- return prefix+strings[strings.length-1];
- }
- } catch (ConfigurationException e) {
- throw new RuntimeException("test configuration setup failed");
+
+ String type = repConf.getString("/ @type");
+ String prefix = "";
+ if (!"MAIL".equals(type) && !"SPOOL".equals(type)) {
+ prefix = type + ".";
+ }
+ String attribute = repConf.getString("/ @destinationURL");
+ String[] strings = attribute.split("/");
+ System.out.println(prefix);
+ if (strings.length > 0) {
+ return prefix + strings[strings.length - 1];
}
-
+
}
return object;
}
Modified: james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java?rev=830276&r1=830275&r2=830276&view=diff
==============================================================================
--- james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java (original)
+++ james/server/trunk/mailets-function/src/main/java/org/apache/james/transport/mailets/RemoteDelivery.java Tue Oct 27 18:13:19 2009
@@ -22,10 +22,10 @@
package org.apache.james.transport.mailets;
import org.apache.avalon.cornerstone.services.store.Store;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
import org.apache.james.Constants;
import org.apache.james.api.dnsservice.DNSService;
import org.apache.james.api.dnsservice.TemporaryResolutionException;
@@ -360,10 +360,9 @@
// Instantiate a MailRepository for mails to be processed.
Store mailstore = (Store) compMgr.lookup(Store.ROLE);
- DefaultConfiguration spoolConf = new DefaultConfiguration(
- "repository", "generated:RemoteDelivery");
- spoolConf.setAttribute("destinationURL", workRepositoryPath);
- spoolConf.setAttribute("type", "SPOOL");
+ DefaultConfigurationBuilder spoolConf = new DefaultConfigurationBuilder();
+ spoolConf.addProperty("/ @destinationURL", workRepositoryPath);
+ spoolConf.addProperty("/ @type", "SPOOL");
workRepository = (SpoolRepository) mailstore.select(spoolConf);
} catch (ServiceException cnfe) {
log("Failed to retrieve Store component:" + cnfe.getMessage());
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org