Author: rdonkin
Date: Wed Aug 19 18:42:59 2009
New Revision: 805922
URL: http://svn.apache.org/viewvc?rev=805922&view=rev
Log:
Switched mailet and matcher loaders to service injection via JSR250 setters.
Moved inject code into superclass.
Modified:
james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo
james/server/trunk/spring-deployment/src/main/config/james/james-assembly.xml
Modified: james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml (original)
+++ james/server/trunk/phoenix-deployment/src/conf/james-assembly.xml Wed Aug
19 18:42:59 2009
@@ -68,14 +68,10 @@
</block>
<block name="matcherpackages"
class="org.apache.james.transport.JamesMatcherLoader" >
- <provide name="James" role="org.apache.mailet.MailetContext"/>
- <provide name="filesystem" role="org.apache.james.services.FileSystem" />
<proxy disable='true'/>
</block>
<block name="mailetpackages"
class="org.apache.james.transport.JamesMailetLoader" >
- <provide name="James" role="org.apache.mailet.MailetContext"/>
- <provide name="filesystem" role="org.apache.james.services.FileSystem" />
<proxy disable='true'/>
</block>
Modified:
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
---
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java
(original)
+++
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/AbstractLoader.java
Wed Aug 19 18:42:59 2009
@@ -19,25 +19,24 @@
package org.apache.james.transport;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Vector;
+import javax.annotation.Resource;
-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.DefaultServiceManager;
-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.kernel.ServiceLocator;
import org.apache.mailet.MailetContext;
import org.apache.mailet.MailetException;
/**
* Common services for loaders.
*/
-public abstract class AbstractLoader extends AbstractLogEnabled implements
Serviceable, Configurable, Initializable {
+public abstract class AbstractLoader extends AbstractLogEnabled implements
Configurable {
/**
* The list of packages that may contain Mailets or matchers
@@ -45,28 +44,72 @@
protected Vector<String> packages;
/**
- * System service manager
+ * Mailet context
*/
- private ServiceManager serviceManager;
+ protected MailetContext mailetContext;
+
+
+ private ServiceLocator serviceLocator;
/**
- * Mailet context
+ * Gets the service locator.
+ * @return the serviceLocator, not null after initialisation
*/
- protected MailetContext mailetContext;
+ public final ServiceLocator getServiceLocator() {
+ return serviceLocator;
+ }
+
+ /**
+ * Sets the service locator.
+ * @param serviceLocator the serviceLocator to set
+ */
+ @Resource(name="org.apache.james.ServiceLocator")
+ public final void setServiceLocator(ServiceLocator serviceLocator) {
+ this.serviceLocator = serviceLocator;
+ }
+
/**
* Set the MailetContext
*
* @param mailetContext the MailetContext
*/
+ // Pheonix used to play games with service names
+ // TODO: Support type based injection
+ @Resource(name="org.apache.james.James")
public void setMailetContext(MailetContext mailetContext) {
this.mailetContext = mailetContext;
}
+ private void injectResources(Object base) throws IllegalArgumentException,
IllegalAccessException,
+
InvocationTargetException {
+ if (serviceLocator == null) {
+ getLogger().warn("Service locator not set. Cannot load services.");
+ } else {
+ Method[] methods = base.getClass().getMethods();
+ for (Method method : methods) {
+ Resource resourceAnnotation =
method.getAnnotation(Resource.class);
+ if (resourceAnnotation != null) {
+ final String name = resourceAnnotation.name();
+ final Object resource = serviceLocator.get(name);
+ if (resource == null) {
+ if (getLogger().isWarnEnabled()) {
+ getLogger().warn("Unknown service: " + name);
+ }
+ } else {
+ Object[] args = {resource};
+ method.invoke(base, args);
+ }
+ }
+ }
+ }
+ }
protected Object load(String className) throws InstantiationException,
- IllegalAccessException, ClassNotFoundException {
- return
Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+ IllegalAccessException, ClassNotFoundException,
IllegalArgumentException, InvocationTargetException {
+ final Object newInstance =
Thread.currentThread().getContextClassLoader().loadClass(className).newInstance();
+ injectResources(newInstance);
+ return newInstance;
}
protected void getPackages(Configuration conf, String packageType)
@@ -83,20 +126,6 @@
packages.addElement(packageName);
}
}
-
- /**
- * @see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
- */
- public void service(ServiceManager sm) throws ServiceException {
- serviceManager = new DefaultServiceManager(sm);
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize() throws Exception {
- setMailetContext((MailetContext)
serviceManager.lookup(MailetContext.class.getName()));
- }
/**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
Modified:
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
---
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java
(original)
+++
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMailetLoader.java
Wed Aug 19 18:42:59 2009
@@ -19,15 +19,10 @@
package org.apache.james.transport;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import javax.annotation.Resource;
import javax.mail.MessagingException;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.james.api.kernel.ServiceLocator;
import org.apache.mailet.Mailet;
/**
* Loads Mailets for use inside James.
@@ -36,26 +31,9 @@
public class JamesMailetLoader extends AbstractLoader implements MailetLoader {
private static final String DISPLAY_NAME = "mailet";
- private ServiceLocator serviceLocator;
+
private final String MAILET_PACKAGE = "mailetpackage";
-
- /**
- * Gets the service locator.
- * @return the serviceLocator, not null after initialisation
- */
- public final ServiceLocator getServiceLocator() {
- return serviceLocator;
- }
-
- /**
- * Sets the service locator.
- * @param serviceLocator the serviceLocator to set
- */
- @Resource(name="org.apache.james.ServiceLocator")
- public final void setServiceLocator(ServiceLocator serviceLocator) {
- this.serviceLocator = serviceLocator;
- }
-
+
/**
* @see
org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
*/
@@ -71,15 +49,14 @@
for (final String packageName:packages) {
final String className = packageName + mailetName;
try {
- final Mailet mailet = (Mailet) load(className);
+ final Mailet mailet = (Mailet) load(className);;
+
final MailetConfigImpl configImpl = new MailetConfigImpl();
configImpl.setMailetName(mailetName);
configImpl.setConfiguration(configuration);
configImpl.setMailetContext(new
MailetContextWrapper(mailetContext, getLogger().getChildLogger(mailetName)));
-
- injectServices(mailet);
-
mailet.init(configImpl);
+
return mailet;
} catch (ClassNotFoundException cnfe) {
//do this so we loop through all the packages
@@ -93,30 +70,6 @@
}
}
- private void injectServices(Mailet mailet) throws
IllegalArgumentException, IllegalAccessException,
-
InvocationTargetException {
- if (serviceLocator == null) {
- getLogger().warn("Service locator not set. Cannot load services.");
- } else {
- Method[] methods = mailet.getClass().getMethods();
- for (Method method : methods) {
- Resource resourceAnnotation =
method.getAnnotation(Resource.class);
- if (resourceAnnotation != null) {
- final String name = resourceAnnotation.name();
- final Object resource = serviceLocator.get(name);
- if (resource == null) {
- if (getLogger().isWarnEnabled()) {
- getLogger().warn("Unknown service: " + name);
- }
- } else {
- Object[] args = {resource};
- method.invoke(mailet, args);
- }
- }
- }
- }
- }
-
/**
* @see AbstractLoader#getDisplayName()
*/
Modified:
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
---
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java
(original)
+++
james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/JamesMatcherLoader.java
Wed Aug 19 18:42:59 2009
@@ -55,11 +55,13 @@
final String className = packageName + matchName;
try {
final Matcher matcher = (Matcher) load(className);
+
final MatcherConfigImpl configImpl = new
MatcherConfigImpl();
configImpl.setMatcherName(matchName);
configImpl.setCondition(condition);
configImpl.setMailetContext(new
MailetContextWrapper(mailetContext, getLogger().getChildLogger(matchName)));
matcher.init(configImpl);
+
return matcher;
} catch (ClassNotFoundException cnfe) {
//do this so we loop through all the packages
Modified:
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
---
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo
(original)
+++
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMailetLoader.xinfo
Wed Aug 19 18:42:59 2009
@@ -30,12 +30,6 @@
</services>
<dependencies>
- <dependency>
- <service name="org.apache.mailet.MailetContext" version="1.0"/>
- </dependency>
- <dependency>
- <service name="org.apache.james.services.FileSystem" version="1.0"/>
- </dependency>
</dependencies>
</blockinfo>
Modified:
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
---
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo
(original)
+++
james/server/trunk/spoolmanager-function/src/main/resources/org/apache/james/transport/JamesMatcherLoader.xinfo
Wed Aug 19 18:42:59 2009
@@ -30,12 +30,6 @@
</services>
<dependencies>
- <dependency>
- <service name="org.apache.mailet.MailetContext" version="1.0"/>
- </dependency>
- <dependency>
- <service name="org.apache.james.services.FileSystem" version="1.0"/>
- </dependency>
</dependencies>
</blockinfo>
Modified:
james/server/trunk/spring-deployment/src/main/config/james/james-assembly.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/james-assembly.xml?rev=805922&r1=805921&r2=805922&view=diff
==============================================================================
---
james/server/trunk/spring-deployment/src/main/config/james/james-assembly.xml
(original)
+++
james/server/trunk/spring-deployment/src/main/config/james/james-assembly.xml
Wed Aug 19 18:42:59 2009
@@ -64,13 +64,9 @@
</block>
<block name="matcherpackages"
class="org.apache.james.transport.JamesMatcherLoader" >
- <provide name="James" role="org.apache.mailet.MailetContext"/>
- <provide name="filesystem" role="org.apache.james.services.FileSystem" />
</block>
<block name="mailetpackages"
class="org.apache.james.transport.JamesMailetLoader" >
- <provide name="James" role="org.apache.mailet.MailetContext"/>
- <provide name="filesystem" role="org.apache.james.services.FileSystem" />
</block>
<block name="dnsserver" class="org.apache.james.dnsserver.DNSServer" />
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]