You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2008/09/09 22:25:10 UTC

svn commit: r693590 - in /mina/ftpserver/trunk: ./ core/ core/src/main/java/org/apache/ftpserver/main/ core/src/test/java/org/apache/ftpserver/config/spring/ core/src/test/resources/spring-config/ distribution/

Author: ngn
Date: Tue Sep  9 13:25:10 2008
New Revision: 693590

URL: http://svn.apache.org/viewvc?rev=693590&view=rev
Log:
Adding support for using ApplicationContext, for example to support property placeholders (FTPSERVER-173

Added:
    mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/PropertyPlaceholderTest.java   (with props)
    mina/ftpserver/trunk/core/src/test/resources/spring-config/config-property-placeholder.xml   (with props)
    mina/ftpserver/trunk/core/src/test/resources/spring-config/placeholder.properties   (with props)
Modified:
    mina/ftpserver/trunk/core/pom.xml
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java
    mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java
    mina/ftpserver/trunk/distribution/pom.xml
    mina/ftpserver/trunk/pom.xml

Modified: mina/ftpserver/trunk/core/pom.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/pom.xml?rev=693590&r1=693589&r2=693590&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/pom.xml (original)
+++ mina/ftpserver/trunk/core/pom.xml Tue Sep  9 13:25:10 2008
@@ -93,7 +93,7 @@
 
     <dependency>
       <groupId>org.springframework</groupId>
-      <artifactId>spring-beans</artifactId>
+      <artifactId>spring-context</artifactId>
       <optional>true</optional>
     </dependency>
     

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java?rev=693590&r1=693589&r2=693590&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java Tue Sep  9 13:25:10 2008
@@ -20,8 +20,7 @@
 package org.apache.ftpserver.main;
 
 import org.apache.ftpserver.FtpServer;
-import org.springframework.beans.factory.xml.XmlBeanFactory;
-import org.springframework.core.io.FileSystemResource;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
 
 /**
  * This class is the starting point for the FtpServer when it is started using
@@ -129,24 +128,24 @@
         } else if (args.length == 1) {
             System.out.println("Using XML configuration file " + args[0]
                     + "...");
-            XmlBeanFactory bf = new XmlBeanFactory(new FileSystemResource(
-                    args[0]));
-            if (bf.containsBean("server")) {
-                server = (FtpServer) bf.getBean("server");
+            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
+                    args[0]);
+
+            if (ctx.containsBean("server")) {
+                server = (FtpServer) ctx.getBean("server");
             } else {
-                String[] beanNames = bf.getBeanNamesForType(FtpServer.class);
+                String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
                 if (beanNames.length == 1) {
-                    server = (FtpServer) bf.getBean(beanNames[0]);
+                    server = (FtpServer) ctx.getBean(beanNames[0]);
                 } else if (beanNames.length > 1) {
                     System.out
                             .println("Using the first server defined in the configuration, named "
                                     + beanNames[0]);
-                    server = (FtpServer) bf.getBean(beanNames[0]);
+                    server = (FtpServer) ctx.getBean(beanNames[0]);
                 } else {
                     System.err
                             .println("XML configuration does not contain a server configuration");
                 }
-
             }
         } else {
             usage();

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java?rev=693590&r1=693589&r2=693590&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java Tue Sep  9 13:25:10 2008
@@ -24,6 +24,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
 import org.springframework.core.io.FileSystemResource;
 
 /**
@@ -97,19 +98,20 @@
             server = new FtpServer();
         } else if (args.length == 2) {
             LOG.info("Using xml configuration file " + args[1] + "...");
-            XmlBeanFactory bf = new XmlBeanFactory(new FileSystemResource(
-                    args[1]));
-            if (bf.containsBean("server")) {
-                server = (FtpServer) bf.getBean("server");
+            FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
+                    args[1]);
+
+            if (ctx.containsBean("server")) {
+                server = (FtpServer) ctx.getBean("server");
             } else {
-                String[] beanNames = bf.getBeanNamesForType(FtpServer.class);
+                String[] beanNames = ctx.getBeanNamesForType(FtpServer.class);
                 if (beanNames.length == 1) {
-                    server = (FtpServer) bf.getBean(beanNames[0]);
+                    server = (FtpServer) ctx.getBean(beanNames[0]);
                 } else if (beanNames.length > 1) {
                     System.out
                             .println("Using the first server defined in the configuration, named "
                                     + beanNames[0]);
-                    server = (FtpServer) bf.getBean(beanNames[0]);
+                    server = (FtpServer) ctx.getBean(beanNames[0]);
                 } else {
                     System.err
                             .println("XML configuration does not contain a server configuration");

Added: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/PropertyPlaceholderTest.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/PropertyPlaceholderTest.java?rev=693590&view=auto
==============================================================================
--- mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/PropertyPlaceholderTest.java (added)
+++ mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/PropertyPlaceholderTest.java Tue Sep  9 13:25:10 2008
@@ -0,0 +1,46 @@
+/*
+ * 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.ftpserver.config.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.ftpserver.FtpServer;
+import org.springframework.context.support.FileSystemXmlApplicationContext;
+
+/**
+*
+* @author The Apache MINA Project (dev@mina.apache.org)
+* @version $Rev$, $Date$
+*
+*/
+public class PropertyPlaceholderTest extends TestCase {
+
+    public void test() throws Throwable {
+        System.setProperty("port2", "3333");
+        
+        FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(
+                "src/test/resources/spring-config/config-property-placeholder.xml");
+
+        FtpServer server = (FtpServer) ctx.getBean("server");
+
+        assertEquals(2222, server.getListener("listener0").getPort());
+        assertEquals(3333, server.getListener("listener1").getPort());
+    }
+}

Propchange: mina/ftpserver/trunk/core/src/test/java/org/apache/ftpserver/config/spring/PropertyPlaceholderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: mina/ftpserver/trunk/core/src/test/resources/spring-config/config-property-placeholder.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/resources/spring-config/config-property-placeholder.xml?rev=693590&view=auto
==============================================================================
--- mina/ftpserver/trunk/core/src/test/resources/spring-config/config-property-placeholder.xml (added)
+++ mina/ftpserver/trunk/core/src/test/resources/spring-config/config-property-placeholder.xml Tue Sep  9 13:25:10 2008
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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. -->  
+
+<beans:beans xmlns="http://mina.apache.org/ftpserver/spring/v1"
+    xmlns:beans="http://www.springframework.org/schema/beans"
+    xmlns:context="http://www.springframework.org/schema/context"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
+       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+       http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd    
+       ">
+    <context:property-placeholder location="src/test/resources/spring-config/placeholder.properties"/>
+    
+    <server id="server">
+		<listeners>
+			<listener name="listener0">
+                <beans:bean class="org.apache.ftpserver.listener.nio.NioListener">
+                    <beans:property name="port" value="${port1}"/>
+                </beans:bean>
+			</listener>
+            <listener name="listener1">
+                <beans:bean class="org.apache.ftpserver.listener.nio.NioListener">
+                    <beans:property name="port" value="${port2}"/>
+                </beans:bean>
+            </listener>
+        </listeners>
+	</server>
+</beans:beans>

Propchange: mina/ftpserver/trunk/core/src/test/resources/spring-config/config-property-placeholder.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: mina/ftpserver/trunk/core/src/test/resources/spring-config/placeholder.properties
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/test/resources/spring-config/placeholder.properties?rev=693590&view=auto
==============================================================================
--- mina/ftpserver/trunk/core/src/test/resources/spring-config/placeholder.properties (added)
+++ mina/ftpserver/trunk/core/src/test/resources/spring-config/placeholder.properties Tue Sep  9 13:25:10 2008
@@ -0,0 +1 @@
+port1=2222
\ No newline at end of file

Propchange: mina/ftpserver/trunk/core/src/test/resources/spring-config/placeholder.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: mina/ftpserver/trunk/distribution/pom.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/distribution/pom.xml?rev=693590&r1=693589&r2=693590&view=diff
==============================================================================
--- mina/ftpserver/trunk/distribution/pom.xml (original)
+++ mina/ftpserver/trunk/distribution/pom.xml Tue Sep  9 13:25:10 2008
@@ -102,7 +102,7 @@
     </dependency>
         <dependency>
       <groupId>org.springframework</groupId>
-      <artifactId>spring-beans</artifactId>
+      <artifactId>spring-context</artifactId>
     </dependency>
     <!-- Use as Spring uses JCL -->
     <dependency>

Modified: mina/ftpserver/trunk/pom.xml
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/pom.xml?rev=693590&r1=693589&r2=693590&view=diff
==============================================================================
--- mina/ftpserver/trunk/pom.xml (original)
+++ mina/ftpserver/trunk/pom.xml Tue Sep  9 13:25:10 2008
@@ -161,7 +161,7 @@
 
     <dependency>
       <groupId>org.springframework</groupId>
-      <artifactId>spring-beans</artifactId>
+      <artifactId>spring-context</artifactId>
       <version>2.5.5</version>
         <exclusions>
             <exclusion>
@@ -171,6 +171,7 @@
 	</exclusions>
     </dependency>
 
+
       <!-- Logging -->
       <dependency>
         <groupId>org.slf4j</groupId>