Author: norman
Date: Mon Jan  4 09:54:57 2010
New Revision: 895586

URL: http://svn.apache.org/viewvc?rev=895586&view=rev
Log:
* Add migrate notes
* Add abstract LoaderService to share some more code
* Remove old dependencies wich are not needed anymore
* Fix log4j.properties
* "Fix" paths in james-config.xml
* Add name for imapserver.protocolfactoryhandler to act as Poster 
* Register shutdown hook

Added:
    james/server/sandbox/active/pure_spring_deployment/MIGRATE.txt
    
james/server/sandbox/active/pure_spring_deployment/core-api/src/main/java/org/apache/james/api/kernel/AbstractJSR250LoaderService.java
Removed:
    
james/server/sandbox/active/pure_spring_deployment/spring-deployment/lib/phoenix-runtime/
Modified:
    
james/server/sandbox/active/pure_spring_deployment/core-api/src/test/java/org/apache/james/api/kernel/mock/FakeLoader.java
    
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/james-config.xml
    
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/log4j.properties
    
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/spring-beans.xml
    
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/Main.java
    
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/JSR250LoaderService.java

Added: james/server/sandbox/active/pure_spring_deployment/MIGRATE.txt
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/MIGRATE.txt?rev=895586&view=auto
==============================================================================
--- james/server/sandbox/active/pure_spring_deployment/MIGRATE.txt (added)
+++ james/server/sandbox/active/pure_spring_deployment/MIGRATE.txt Mon Jan  4 
09:54:57 2010
@@ -0,0 +1,21 @@
+# Needed steps to migrate from phoenix based deployment to the new spring one
+
+1. Copy your old config.xml file to conf/james-config.xml
+
+       % cp /path/to/james-old/apps/james/SAR-INF/config.xml 
/path/to/james/conf/config.xml
+
+
+2. Copy over your old data from /path/to/james-old/apps/james/var/ to 
/path/to/james/var .
+
+       % cp -r /path/to/james-old/apps/james/var/* /path/to/james/var/
+       
+       
+3. Adjust paths in james-config.xml. Replace ../apps/james/var/* with ../var/*
+
+       
+4. If you made any adjustments in the assembly.xml you need todo the same 
adjustment in the spring-beans.xml file. 
+   For more details how the spring beans get configured please see the spring 
documentation
+
+
+5. If you made any adjustments in the enviroment.xml for logging you need to 
configure the same in log4j.properties. 
+   For more details how log4j.properties are configured please see the log4j 
documentation.
\ No newline at end of file

Added: 
james/server/sandbox/active/pure_spring_deployment/core-api/src/main/java/org/apache/james/api/kernel/AbstractJSR250LoaderService.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/core-api/src/main/java/org/apache/james/api/kernel/AbstractJSR250LoaderService.java?rev=895586&view=auto
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/core-api/src/main/java/org/apache/james/api/kernel/AbstractJSR250LoaderService.java
 (added)
+++ 
james/server/sandbox/active/pure_spring_deployment/core-api/src/main/java/org/apache/james/api/kernel/AbstractJSR250LoaderService.java
 Mon Jan  4 09:54:57 2010
@@ -0,0 +1,127 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.api.kernel;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.lifecycle.Configurable;
+import org.apache.james.lifecycle.LogEnabled;
+
+/**
+ * Abstract base class which implements a JSR250 based LoaderService
+ * 
+ *
+ */
+public abstract class AbstractJSR250LoaderService implements LoaderService{
+
+        /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.api.kernel.LoaderService#injectDependencies(java.lang.Object)
+        */
+       public void injectDependencies(Object obj) {
+        try {
+            injectResources(obj);
+            postConstruct(obj);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException("Unable to handle dependency injection 
of object " + obj, e);
+        } catch (InvocationTargetException e) {
+            throw new RuntimeException("Unable to handle dependency injection 
of object " + obj, e);
+        }
+    }
+
+          
+    private void postConstruct(Object resource) throws IllegalAccessException,
+            InvocationTargetException {
+        Method[] methods = resource.getClass().getMethods();
+        for (Method method : methods) {
+            PostConstruct postConstructAnnotation = method
+                    .getAnnotation(PostConstruct.class);
+            if (postConstructAnnotation != null) {
+                Object[] args = {};
+                method.invoke(resource, args);
+
+            }
+        }
+    }
+    
+    private void injectResources(Object resource) {
+        final Method[] methods = resource.getClass().getMethods();
+        for (Method method : methods) {
+            final Resource resourceAnnotation = 
method.getAnnotation(Resource.class);
+            if (resourceAnnotation != null) {
+                final String name = resourceAnnotation.name();
+                if (name == null) {
+                    throw new UnsupportedOperationException("Resource 
annotation without name specified is not supported by this implementation");
+                } else {
+                    // Name indicates a service
+                    final Object service = getObjectForName(name);
+                    
+                    if (service == null) {
+                        throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource name " + name + 
", because no mapping was found");
+                   } else {
+                        try {
+                            Object[] args = {service};
+                            method.invoke(resource, args);
+                        } catch (IllegalAccessException e) {
+                            throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource " + service, e);
+                        } catch (IllegalArgumentException e) {
+                            throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource " + service, e);
+                        } catch (InvocationTargetException e) {
+                            throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource " + service, e);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+       /*
+        * (non-Javadoc)
+        * @see 
org.apache.james.api.kernel.LoaderService#injectDependenciesWithLifecycle(java.lang.Object,
 org.apache.commons.logging.Log, 
org.apache.commons.configuration.HierarchicalConfiguration)
+        */
+       public void injectDependenciesWithLifecycle(Object obj, Log logger,
+                       HierarchicalConfiguration config) {
+               if (obj instanceof LogEnabled) {
+                       ((LogEnabled) obj).setLog(logger);
+               }
+               if (obj instanceof Configurable) {
+                       try {
+                       ((Configurable) obj).configure(config);
+                       } catch (ConfigurationException ex) {
+                               throw new RuntimeException("Unable to configure 
object " + obj, ex);
+                       }
+               }
+               injectDependencies(obj);
+       }
+       
+       /**
+        * Return the Object which should be injected for given name
+        * 
+        * @param name
+        * @return object
+        */
+       protected abstract Object getObjectForName(String name);
+}

Modified: 
james/server/sandbox/active/pure_spring_deployment/core-api/src/test/java/org/apache/james/api/kernel/mock/FakeLoader.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/core-api/src/test/java/org/apache/james/api/kernel/mock/FakeLoader.java?rev=895586&r1=895585&r2=895586&view=diff
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/core-api/src/test/java/org/apache/james/api/kernel/mock/FakeLoader.java
 (original)
+++ 
james/server/sandbox/active/pure_spring_deployment/core-api/src/test/java/org/apache/james/api/kernel/mock/FakeLoader.java
 Mon Jan  4 09:54:57 2010
@@ -19,23 +19,13 @@
 
 package org.apache.james.api.kernel.mock;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-
 import org.apache.avalon.framework.service.ServiceException;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.james.api.kernel.LoaderService;
-import org.apache.james.lifecycle.Configurable;
-import org.apache.james.lifecycle.LogEnabled;
+import org.apache.james.api.kernel.AbstractJSR250LoaderService;
 
-public class FakeLoader implements LoaderService, 
org.apache.avalon.framework.service.ServiceManager{
+public class FakeLoader extends AbstractJSR250LoaderService implements 
org.apache.avalon.framework.service.ServiceManager{
 
     private final Map<String, Object> servicesByName;
     private final Map<String, String> mappings = new HashMap<String, String>();
@@ -71,7 +61,7 @@
         mappings.put("nntp-repository", 
"org.apache.james.nntpserver.repository.NNTPRepository");
     }
     
-    
+
     public Object get(String name) { 
         Object service = servicesByName.get(mapName(name));
         
@@ -85,45 +75,29 @@
         }
         return newName;
     }
-    private void injectResources(Object resource) {
-        final Method[] methods = resource.getClass().getMethods();
-        for (Method method : methods) {
-            final Resource resourceAnnotation = 
method.getAnnotation(Resource.class);
-            if (resourceAnnotation != null) {
-                final String name = resourceAnnotation.name();
-                if (name == null) {
-                    // Unsupported
-                } else {
-                    // Name indicates a service
-                    final Object service = get(name);
-                    
-                    if (service == null) {
-                   } else {
-                        try {
-                            Object[] args = {service};
-                            method.invoke(resource, args);
-                        } catch (IllegalAccessException e) {
-                            throw new RuntimeException("Injection failed", e);
-                        } catch (IllegalArgumentException e) {
-                            throw new RuntimeException("Injection failed", e);
-                        } catch (InvocationTargetException e) {
-                            throw new RuntimeException("Injection failed", e);
-                        }
-                    }
-                }
-            }
-        }
-    }
+   
 
 
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.avalon.framework.service.ServiceManager#hasService(java.lang.String)
+     */
     public boolean hasService(String name) {
         return servicesByName.containsKey(name);
     }
 
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.avalon.framework.service.ServiceManager#lookup(java.lang.String)
+     */
     public Object lookup(String name) throws ServiceException {
         return servicesByName.get(name);
     }
 
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.avalon.framework.service.ServiceManager#release(java.lang.Object)
+     */
     public void release(Object service) {
     }
 
@@ -132,43 +106,8 @@
     }
 
 
-       public void injectDependencies(Object obj) {
-        injectResources(obj);  
-        try {
-               postConstruct(obj);
-        } catch (Exception e) {
-               throw new RuntimeException(e);
-        }
-       }
-
-
-       public void injectDependenciesWithLifecycle(Object obj, Log logger,
-                       HierarchicalConfiguration config) {
-               if (obj instanceof LogEnabled) {
-                       ((LogEnabled)obj).setLog(logger);
-               }
-               if (obj instanceof Configurable) {
-                       try {
-                               ((Configurable) obj).configure(config);
-                       } catch (ConfigurationException e) {
-                               e.printStackTrace();
-                               throw new RuntimeException(e);
-                       }               
-               }
-               injectDependencies(obj);
-       }
-       
-       private void postConstruct(Object resource) throws 
IllegalAccessException,
-                       InvocationTargetException {
-               Method[] methods = resource.getClass().getMethods();
-               for (Method method : methods) {
-                       PostConstruct postConstructAnnotation = method
-                                       .getAnnotation(PostConstruct.class);
-                       if (postConstructAnnotation != null) {
-                               Object[] args = {};
-                               method.invoke(resource, args);
-
-                       }
-               }
+       @Override
+       protected Object getObjectForName(String name) {
+               return get(name);
        }
 }

Modified: 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/james-config.xml
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/james-config.xml?rev=895586&r1=895585&r2=895586&view=diff
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/james-config.xml
 (original)
+++ 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/james-config.xml
 Mon Jan  4 09:54:57 2010
@@ -1140,7 +1140,7 @@
                   value="org.apache.derby.jdbc.EmbeddedDriver"/>
         <property
                   name="torque.dsfactory.mailboxmanager.connection.url"
-                  
value="jdbc:derby:../apps/james/var/mailboxmanager-derbydb;create=true"/>
+                  
value="jdbc:derby:../var/mailboxmanager-derbydb;create=true"/>
         <property
                   name="torque.dsfactory.mailboxmanager.connection.user"
                   value="app"/>
@@ -1499,7 +1499,7 @@
       <!-- -->
       <data-source name="maildb" 
class="org.apache.james.util.dbcp.JdbcDataSource">
          <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
-         <dburl>jdbc:derby:../apps/james/var/derbydb;create=true</dburl>
+         <dburl>jdbc:derby:../var/derbydb;create=true</dburl>
          <user></user>
          <password></password>
          <poolPreparedStatements>true</poolPreparedStatements>

Modified: 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/log4j.properties
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/log4j.properties?rev=895586&r1=895585&r2=895586&view=diff
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/log4j.properties
 (original)
+++ 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/log4j.properties
 Mon Jan  4 09:54:57 2010
@@ -91,7 +91,7 @@
 log4j.appender.NNTP-REPOSITORY.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} 
| %c | %m%n
 
 log4j.appender.MAILSTORE=org.apache.log4j.DailyRollingFileAppender
-log4j.appender.MAILSTORE=../log/mailstore.log
+log4j.appender.MAILSTORE.File=../log/mailstore.log
 log4j.appender.MAILSTORE.DatePattern='.'yyyy-MM-dd
 log4j.appender.MAILSTORE.layout=org.apache.log4j.PatternLayout
 log4j.appender.MAILSTORE.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | 
%m%n

Modified: 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/spring-beans.xml
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/spring-beans.xml?rev=895586&r1=895585&r2=895586&view=diff
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/spring-beans.xml
 (original)
+++ 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/config/james/spring-beans.xml
 Mon Jan  4 09:54:57 2010
@@ -302,7 +302,7 @@
        -->
 
        <!-- IMAP server Beans -->
-       <bean id="imapserver.protocolhandlerfactory"
+       <bean id="imapserver.protocolhandlerfactory" 
name="org.apache.jsieve.mailet.Poster"
                
class="org.apache.james.imapserver.ImapServerProtocolHandlerFactory" />
 
        <bean id="imapserver.protocolserver" 
class="org.apache.james.socket.AvalonProtocolServer">

Modified: 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/Main.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/Main.java?rev=895586&r1=895585&r2=895586&view=diff
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/Main.java
 (original)
+++ 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/Main.java
 Mon Jan  4 09:54:57 2010
@@ -18,19 +18,16 @@
  ****************************************************************/
 package org.apache.james.container.spring;
 
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * Bootstraps James using a Spring container
  */
 public class Main {    
 
-    public static void main(String[] args) {
-        //JamesApplicationContext.newJamesApplicationContext();
-       
-       ApplicationContext context = new JamesServerApplicationContext(
+    public static void main(String[] args) {           
+       JamesServerApplicationContext context = new 
JamesServerApplicationContext(
                new String[] {"spring-beans.xml"});
+       context.registerShutdownHook();
 
     }
 

Modified: 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/JSR250LoaderService.java
URL: 
http://svn.apache.org/viewvc/james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/JSR250LoaderService.java?rev=895586&r1=895585&r2=895586&view=diff
==============================================================================
--- 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/JSR250LoaderService.java
 (original)
+++ 
james/server/sandbox/active/pure_spring_deployment/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/JSR250LoaderService.java
 Mon Jan  4 09:54:57 2010
@@ -18,18 +18,10 @@
  ****************************************************************/
 package org.apache.james.container.spring.lifecycle;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
-
-import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
+import org.apache.james.api.kernel.AbstractJSR250LoaderService;
 import org.apache.james.api.kernel.LoaderService;
-import org.apache.james.lifecycle.Configurable;
-import org.apache.james.lifecycle.LogEnabled;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -45,66 +37,14 @@
 @SuppressWarnings("serial")
 public class JSR250LoaderService extends CommonAnnotationBeanPostProcessor 
implements LoaderService, ApplicationContextAware {
 
-       private ConfigurableApplicationContext applicationContext;
-
+       private SpringJSR250LoaderService loader;
+       
     /*
         * (non-Javadoc)
         * @see 
org.apache.james.api.kernel.LoaderService#injectDependencies(java.lang.Object)
         */
        public void injectDependencies(Object obj) {
-        try {
-            injectResources(obj);
-            postConstruct(obj);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException("Unable to handle dependency injection 
of object " + obj, e);
-        } catch (InvocationTargetException e) {
-            throw new RuntimeException("Unable to handle dependency injection 
of object " + obj, e);
-        }
-    }
-
-          
-    private void postConstruct(Object resource) throws IllegalAccessException,
-            InvocationTargetException {
-        Method[] methods = resource.getClass().getMethods();
-        for (Method method : methods) {
-            PostConstruct postConstructAnnotation = method
-                    .getAnnotation(PostConstruct.class);
-            if (postConstructAnnotation != null) {
-                Object[] args = {};
-                method.invoke(resource, args);
-
-            }
-        }
-    }
-    
-    private void injectResources(Object resource) {
-        final Method[] methods = resource.getClass().getMethods();
-        for (Method method : methods) {
-            final Resource resourceAnnotation = 
method.getAnnotation(Resource.class);
-            if (resourceAnnotation != null) {
-                final String name = resourceAnnotation.name();
-                if (name == null) {
-                    // Unsupported
-                } else {
-                    // Name indicates a service
-                    final Object service = applicationContext.getBean(name);
-                    
-                    if (service == null) {
-                   } else {
-                        try {
-                            Object[] args = {service};
-                            method.invoke(resource, args);
-                        } catch (IllegalAccessException e) {
-                            throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource " + service, e);
-                        } catch (IllegalArgumentException e) {
-                            throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource " + service, e);
-                        } catch (InvocationTargetException e) {
-                            throw new RuntimeException("Injection failed for 
object " + resource + " on method " + method + " with resource " + service, e);
-                        }
-                    }
-                }
-            }
-        }
+        loader.injectDependencies(obj);
     }
 
        /*
@@ -113,20 +53,28 @@
         */
        public void injectDependenciesWithLifecycle(Object obj, Log logger,
                        HierarchicalConfiguration config) {
-               if (obj instanceof LogEnabled) {
-                       ((LogEnabled) obj).setLog(logger);
-               }
-               if (obj instanceof Configurable) {
-                       try {
-                       ((Configurable) obj).configure(config);
-                       } catch (ConfigurationException ex) {
-                               throw new RuntimeException("Unable to configure 
object " + obj, ex);
-                       }
-               }
-               injectDependencies(obj);
+               loader.injectDependenciesWithLifecycle(obj, logger, config);
        }
 
+       /*
+        * (non-Javadoc)
+        * @see 
org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+        */
     public void setApplicationContext(ApplicationContext applicationContext) 
throws BeansException {
-        this.applicationContext = (ConfigurableApplicationContext) 
applicationContext;
+        loader = new SpringJSR250LoaderService(applicationContext);
+    }
+    
+    private final class SpringJSR250LoaderService extends 
AbstractJSR250LoaderService {
+
+       private ApplicationContext context;
+       
+               public SpringJSR250LoaderService(ApplicationContext context) {
+               this.context = context;
+       }
+               @Override
+               protected Object getObjectForName(String name) {
+                       return context.getBean(name);
+               }
+       
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to