james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1005763 - in /james/server/trunk: spring-common/src/main/java/org/apache/james/container/spring/ spring-deployment/src/main/config/james/ spring-deployment/src/main/java/org/apache/james/container/spring/
Date Fri, 08 Oct 2010 10:19:45 GMT
Author: norman
Date: Fri Oct  8 10:19:44 2010
New Revision: 1005763

URL: http://svn.apache.org/viewvc?rev=1005763&view=rev
Log:
Use a BeanFactoryPostProcessor implementation to resolve filesystem urls in spring-beans.xml.
This allows us to be sure that all the directories in spring-beans.xml use the same "parent".

Added:
    james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/FileSystemResolver.java
Removed:
    james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/FileSystemUtils.java
Modified:
    james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml

Added: james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/FileSystemResolver.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/FileSystemResolver.java?rev=1005763&view=auto
==============================================================================
--- james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/FileSystemResolver.java
(added)
+++ james/server/trunk/spring-common/src/main/java/org/apache/james/container/spring/FileSystemResolver.java
Fri Oct  8 10:19:44 2010
@@ -0,0 +1,80 @@
+/****************************************************************
+ * 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.container.spring;
+
+import java.io.FileNotFoundException;
+
+import org.apache.james.services.FileSystem;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.FatalBeanException;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.beans.factory.config.BeanDefinitionVisitor;
+import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
+import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+/**
+ * 
+ *  {@link BeanFactoryPostProcessor} implementation which parse the spring configuration
and search for property values which are
+ *  prefixed with {@link #FS_PREFIX}. If such a property is found it will try to resolve
the given path via the {@link FileSystem} service
+ *  and replace it.
+ */
+public class FileSystemResolver implements BeanFactoryPostProcessor{
+
+    private static final String FS_PREFIX ="filesystem=";
+
+    private final FileSystemVisitor visitor = new FileSystemVisitor();
+    
+    private FileSystem fs;
+
+    public void setFileSystem(FileSystem fs) {
+        this.fs = fs;
+    }
+    
+    
+    /*
+     * (non-Javadoc)
+     * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
+     */
+    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException
{
+        String names[] = factory.getBeanDefinitionNames();
+        for (int i = 0; i < names.length; i++) {
+            BeanDefinition def = factory.getBeanDefinition(names[i]);
+            visitor.visitBeanDefinition(def);
+           
+        }
+    }
+    
+    
+    private final class FileSystemVisitor extends BeanDefinitionVisitor {
+
+        @Override
+        protected String resolveStringValue(String strVal) throws BeansException {
+            if (strVal.startsWith(FS_PREFIX)) {
+                try {
+                    return fs.getFile(strVal.substring(FS_PREFIX.length())).toString();
+                } catch (FileNotFoundException e) {
+                    throw new FatalBeanException("Unable to convert value with filesystem
service", e);
+                }
+            }
+            return strVal;
+        }
+        
+    }
+
+}

Modified: james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=1005763&r1=1005762&r2=1005763&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml (original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml Fri Oct  8
10:19:44 2010
@@ -89,6 +89,11 @@
         </property>
     </bean>
 
+    <!-- Take care of resolve filesystem= property values -->
+    <bean class="org.apache.james.container.spring.FileSystemResolver">
+        <property name="fileSystem" ref="filesystem" />
+    </bean>
+    
     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name = "location" value="file://conf/database.properties"/>
     </bean>
@@ -129,7 +134,7 @@
     </camel:camelContext>
 
     <!--  lets create an embedded ActiveMQ Broker -->
-    <amq:broker useJmx="false" persistent="true" dataDirectory="../var/activemq-data/"
schedulerSupport="true" id="broker">
+    <amq:broker useJmx="false" persistent="true" dataDirectory="filesystem=file://var/activemq-data/"
schedulerSupport="true" id="broker">
         <amq:destinationPolicy>
             <amq:policyMap>
                 <amq:policyEntries>
@@ -445,18 +450,8 @@
     
     <!-- Jackrabbit config -->
     <bean id="config" class="org.apache.jackrabbit.core.config.RepositoryConfig" factory-method="create">
-        <constructor-arg index="0">
-            <bean class="org.apache.james.container.spring.FileSystemUtils" factory-method="getFileNameFromUrl">
-                <constructor-arg index="0" ref="filesystem"/>
-                <constructor-arg index="1" value="file://conf/jcr-repository.xml" />
-            </bean>
-        </constructor-arg>
-        <constructor-arg index="1">
-            <bean class="org.apache.james.container.spring.FileSystemUtils" factory-method="getFileNameFromUrl">
-                <constructor-arg index="0" ref="filesystem"/>
-                <constructor-arg index="1" value="file://var/jackrabbit" />
-            </bean>
-        </constructor-arg>
+        <constructor-arg index="0" value="filesystem=file://conf/jcr-repository.xml"/>
+        <constructor-arg index="1" value="filesystem=file://var/jackrabbit" />
     </bean>
 
     <!-- #################################################################### -->



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


Mime
View raw message