Hi Norman,

I made a first approach making SpringConfigurationRegistry abstract with 2 implementations (SpringFileConfigurationRegistry and SpringClasspathConfigurationRegistry). I first wanted to use composition, but this would have asked too much refactoring, so I used inheritance.

The classpath loader still does not work, as there is at least 3 file://conf definitions in spring-beans.xml. We could ask the administrator to change these, but I find that tedious. This is why I would rather think to a global setting in James.xml or spring-beans.xml that would define the resource loading type. In this case, the attached patch can be forgotten.

Tks in advance for your comments on the attached patch (will be removed from the james list, so I copied you).

Eric


On 05/08/2010 05:28 AM, Norman Maurer wrote:

Hi Eric,

I like your idea about loading every config from classpath. I think
you are right, we should change it. About the proposed fallback
strategy I'm not sure. I think we should not try to mix up things to
much. Just let use add two different ConfigurationRegistry
implementations. One for classpath and one for file, so if someone
needs to load things from files he could just swap them out.

Bye,
Norman


2010/5/5 Eric Charles<[email protected]>:
>  Hi,
>
>  To run james in my ide (eclipse), I copied config files from
>  server/spring-deployment/src/main/config/james to a directory called conf a
>  level upon the root of my project.
>  The resource loading via thefile://conf  was ok.
>
>  After, I wanted to load via classpath to have smoother intergration in my
>  ide and also thinking to later integration with 3rd parties (simply using
>  james jars with embedded resources).
>
>  I changed all neededfile://conf/  to classpath: in the xml files
>  (spring-beans,...).
>  I also had to change in SpringConfigurationRegistry.getForComponent line 56
>  from
>              Resource r =oader.getResource("file://conf/"  + name + ".xml");
>  to
>              Resource r =oader.getResource("classpath:" + name + ".xml");
>
>  I looked for a system-wide configuration (in James.xml or whatever) that
>  would allow to define the way resources are loaded (file or classpath) but
>  didn't find anything.
>
>  One way to tackle this would be first try onfile://conf  and rather than
>  throwing directly the RegistryException, still give a try to classpath.
>  In case of duplicate config present (file + classpath), the file would take
>  the precedence, discarding the classpath.
>  You could have a default classpath config, and simply override some via
>  file.
>
>  On pom.xml, we could also add the following (direct ide setup after mvn
>  eclipse:eclipse).
>
>  <build>
>  <resources>
>  <resource>
>  <directory>src/main/resources</directory>
>  </resource>
>  </resources>
>  ....
>
>  In a first instance, for mvn package, everything could remain as such (all
>  files copied to conf).
>
>  Any comment?
>  Tks,
>
>  Eric
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail:[email protected]
For additional commands, e-mail:[email protected]



Index: src/main/java/org/apache/james/container/spring/lifecycle/SpringClasspathConfigurationRegistry.java
===================================================================
--- src/main/java/org/apache/james/container/spring/lifecycle/SpringClasspathConfigurationRegistry.java	(revision 0)
+++ src/main/java/org/apache/james/container/spring/lifecycle/SpringClasspathConfigurationRegistry.java	(revision 0)
@@ -0,0 +1,12 @@
+package org.apache.james.container.spring.lifecycle;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+
+public class SpringClasspathConfigurationRegistry extends SpringConfigurationRegistry {
+
+	public HierarchicalConfiguration getForComponent(String componentname)
+			throws org.apache.james.container.spring.Registry.RegistryException {
+		return getForComponent(componentname, SpringConfigurationRegistry.SpringLoadType.CLASSPATH);
+	}
+
+}
Index: src/main/java/org/apache/james/container/spring/lifecycle/SpringFileConfigurationRegistry.java
===================================================================
--- src/main/java/org/apache/james/container/spring/lifecycle/SpringFileConfigurationRegistry.java	(revision 0)
+++ src/main/java/org/apache/james/container/spring/lifecycle/SpringFileConfigurationRegistry.java	(revision 0)
@@ -0,0 +1,12 @@
+package org.apache.james.container.spring.lifecycle;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+
+public class SpringFileConfigurationRegistry extends SpringConfigurationRegistry {
+
+	public HierarchicalConfiguration getForComponent(String componentname)
+			throws org.apache.james.container.spring.Registry.RegistryException {
+		return getForComponent(componentname, SpringConfigurationRegistry.SpringLoadType.FILE);
+	}
+
+}
Index: src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
===================================================================
--- src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java	(revision 942302)
+++ src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java	(working copy)
@@ -37,23 +37,31 @@
  * 
  *
  */
-public class SpringConfigurationRegistry implements Registry<HierarchicalConfiguration>, ResourceLoaderAware, InitializingBean {
+public abstract class SpringConfigurationRegistry implements Registry<HierarchicalConfiguration>, ResourceLoaderAware, InitializingBean {
 
 	private ResourceLoader loader;
 	private Map<String,HierarchicalConfiguration> confMap = new HashMap<String,HierarchicalConfiguration>();
     private Map<String,String> resources;
+    protected enum SpringLoadType {
+    	CLASSPATH("classpath:"),
+    	FILE("file://conf/");
+    	private final String loadType;
+    	SpringLoadType(String loadType) {
+    		this.loadType = loadType;
+    	}
+    }
 
 	/*
 	 * (non-Javadoc)
 	 * @see org.apache.james.container.spring.Registry#getForComponent(java.lang.String)
 	 */
-	public HierarchicalConfiguration getForComponent(String name)
+	public HierarchicalConfiguration getForComponent(String name, SpringLoadType springLoadType)
 			throws RegistryException {
 	    HierarchicalConfiguration conf = confMap.get(name);
 	    if (conf != null) {
 	        return conf;
 	    } else {
-	        Resource r = loader.getResource("file://conf/" + name + ".xml");
+	        Resource r = loader.getResource(springLoadType.loadType + name + ".xml");
 	        if (r.exists()) {
 	            try {
                     return getConfig(r);
Index: src/main/config/james/spring-beans.xml
===================================================================
--- src/main/config/james/spring-beans.xml	(revision 942302)
+++ src/main/config/james/spring-beans.xml	(working copy)
@@ -71,8 +71,14 @@
         <property name="configurationRegistry" ref="configurationRegistry" />
         <property name="order" value="1" />
     </bean>
+    
+    <!-- To load configuraiton from file (in conf directory,
+         use org.apache.james.container.spring.lifecycle.SpringFileConfigurationRegistry 
+         To load configuraiton from classpath
+         use org.apache.james.container.spring.lifecycle.SpringClasspathConfigurationRegistry 
+     -->
 
-    <bean id="configurationRegistry" class="org.apache.james.container.spring.lifecycle.SpringConfigurationRegistry">
+    <bean id="configurationRegistry" class="org.apache.james.container.spring.lifecycle.SpringClasspathConfigurationRegistry">
         <property name="configurationMappings">
             <map>
                 <entry key="mailboxmanager" value="imapserver" />
@@ -238,14 +244,18 @@
     </bean>
 
     <!--This is needed to link the smtpserver to the local user repository
-        LocalJamesUsersRepository is used for backward compatibility with
-        James 2.3.0
-        If backward compatibility is not need the LocalUsersRepository
-        implementation
+        org.apache.james.impl.jamesuser.LocalJamesUsersRepository can be used for
+        backward compatibility with James 2.3.0
+        If backward compatibility is not needed, org.apache.james.impl.user.LocalUsersRepository
+        implementation is used by default.
     -->
-    <!-- could be safely used -->
+
+    <!-- uncomment this for james 2.3.0 backward compatibility 
     <bean id="localusersrepository" class="org.apache.james.impl.jamesuser.LocalJamesUsersRepository" />
+	-->
 
+    <!-- this is the default implementation for the localusersrepository - not james 2.3.0 backward compatible -->
+    <bean id="localusersrepository" class="org.apache.james.impl.user.LocalUsersRepository" />
 
     <!-- The context FileSystem implementation -->
     <bean id="filesystem" class="org.apache.james.container.spring.SpringFileSystem" />
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to