directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r344069 [1/2] - in /directory/network/trunk: ./ src/java/org/apache/mina/integration/ src/java/org/apache/mina/integration/spring/ src/java/org/apache/mina/integration/spring/support/ src/java/org/apache/mina/transport/socket/nio/ src/test/...
Date Mon, 14 Nov 2005 07:38:00 GMT
Author: trustin
Date: Sun Nov 13 23:37:37 2005
New Revision: 344069

URL: http://svn.apache.org/viewcvs?rev=344069&view=rev
Log:
Resolved issue: DIRMINA-28 Spring framework integration
* Applied Niklas's Spring framework integration patch.

Added:
    directory/network/trunk/src/java/org/apache/mina/integration/
    directory/network/trunk/src/java/org/apache/mina/integration/spring/
    directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramAcceptorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramConnectorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/InetAddressEditor.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/IoFilterMapping.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketAcceptorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketConnectorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeConnectorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/package.html   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/support/
    directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java   (with props)
    directory/network/trunk/src/java/org/apache/mina/integration/spring/support/package.html   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/
    directory/network/trunk/src/test/org/apache/mina/integration/spring/
    directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramAcceptorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramConnectorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/InetAddressEditorTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/IoFilterMappingTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketAcceptorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketConnectorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeConnectorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/support/
    directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBeanTest.java   (with props)
    directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBeanTest.java   (with props)
Modified:
    directory/network/trunk/project.xml
    directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java

Modified: directory/network/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/network/trunk/project.xml?rev=344069&r1=344068&r2=344069&view=diff
==============================================================================
--- directory/network/trunk/project.xml (original)
+++ directory/network/trunk/project.xml Sun Nov 13 23:37:37 2005
@@ -97,6 +97,20 @@
       <url>http://www.slf4j.org/</url>
     </dependency>
 
+    <dependency>
+      <groupId>springframework</groupId>
+      <artifactId>spring-core</artifactId>
+      <version>1.2.5</version>
+      <url>http://www.springframework.org/</url>
+    </dependency>
+
+    <dependency>
+      <groupId>springframework</groupId>
+      <artifactId>spring-beans</artifactId>
+      <version>1.2.5</version>
+      <url>http://www.springframework.org/</url>
+    </dependency>
+
     <!-- ========================================================= -->
     <!-- Dependencies required for running test cases and examples -->
     <!-- ========================================================= -->
@@ -109,13 +123,34 @@
     </dependency>
 
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <url>http://junit.org/</url>
+      <groupId>easymock</groupId>
+      <artifactId>easymock</artifactId>
+      <version>1.2_Java1.3</version>
+      <url>http://www.easymock.org/</url>
+    </dependency>
+    
+    <dependency>
+      <groupId>easymock</groupId>
+      <artifactId>easymockclassextension</artifactId>
+      <version>1.2</version>
+      <url>http://www.easymock.org/</url>
+    </dependency>
+    
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib-nodep</artifactId>
+      <version>2.1</version>
+      <url>http://cglib.sourceforge.net/</url>
     </dependency>
 
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>jcl104-over-slf4j</artifactId>
+      <version>1.0-beta9</version>
+      <url>http://www.slf4j.org/</url>
+    </dependency>
+    
+    <dependency>
       <groupId>emma</groupId>
       <artifactId>emma</artifactId>
       <version>2.0.latest</version>
@@ -123,13 +158,20 @@
     </dependency>
 
     <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <url>http://junit.org/</url>
+    </dependency>
+
+    <dependency>
       <groupId>emma</groupId>
       <artifactId>maven-emma-plugin</artifactId>
       <version>0.4</version>
       <url>http://emma.sourceforge.net/</url>
       <type>plugin</type>
     </dependency>
-
+    
     <dependency>
       <artifactId>maven-site-plugin</artifactId>
       <groupId>maven</groupId>

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramAcceptorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramAcceptorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramAcceptorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramAcceptorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,75 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.integration.spring.support.AbstractIoAcceptorFactoryBean;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+
+/**
+ * {@link AbstractIoAcceptorFactoryBean} implementation which allows for easy
+ * configuration of {@link DatagramAcceptor} instances using Spring. Example of
+ * usage:
+ * <p>
+ * 
+ * <pre>
+ *   &lt;!-- My IoHandler implementation--&gt;
+ *   &lt;bean id=&quot;myHandler&quot; class=&quot;com.foo.bar.MyHandler&quot;&gt;
+ *       ...
+ *   
+ *   &lt;!-- Create a thread pool filter --&gt;
+ *   &lt;bean id=&quot;threadPoolFilter&quot; 
+ *         class=&quot;org.apache.mina.filter.ThreadPoolFilter&quot;&gt;
+ *       &lt;!-- Threads will be named IoWorker-1, IoWorker-2, etc --&gt;
+ *       &lt;constructor-arg value=&quot;IoWorker&quot;/&gt;
+ *       &lt;property name=&quot;maximumPoolSize&quot; value=&quot;10&quot;/&gt;
+ *   &lt;/bean&gt;
+ *   
+ *   &lt;!-- Create the DatagramAcceptor --&gt;
+ *   &lt;bean id=&quot;datagramAcceptor&quot; 
+ *        class=&quot;org.apache.mina.spring.DatagramAcceptorFactoryBean&quot;&gt;
+ *    &lt;property name=&quot;filters&quot;&gt;
+ *      &lt;list&gt;
+ *         &lt;ref local=&quot;threadPoolFilter&quot;/&gt;
+ *      &lt;/list&gt;
+ *    &lt;/property&gt;
+ *    &lt;property name=&quot;bindings&quot;&gt;
+ *      &lt;map&gt;
+ *        &lt;entry key=&quot;:9287&quot; value-ref=&quot;myHandler&quot;/&gt;
+ *        &lt;entry key=&quot;192.168.0.1:6273&quot; value-ref=&quot;myHandler&quot;/&gt;
+ *      &lt;/map&gt;
+ *    &lt;/property&gt;
+ *  &lt;/bean&gt;
+ * </pre>
+ * 
+ * </p>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DatagramAcceptorFactoryBean extends
+        InetSocketAddressBindingIoAcceptorFactoryBean
+{
+
+    protected IoAcceptor createIoAcceptor() throws Exception
+    {
+        return new DatagramAcceptor();
+    }
+
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramAcceptorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramConnectorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramConnectorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramConnectorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramConnectorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,41 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.integration.spring.support.AbstractIoConnectorFactoryBean;
+import org.apache.mina.transport.socket.nio.DatagramConnector;
+
+/**
+ * {@link AbstractIoConnectorFactoryBean} implementation which allows for easy
+ * configuration of {@link DatagramConnector} instances using Spring.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DatagramConnectorFactoryBean extends
+        AbstractIoConnectorFactoryBean
+{
+
+    protected IoConnector createIoConnector() throws Exception
+    {
+        return new DatagramConnector();
+    }
+
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/DatagramConnectorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/InetAddressEditor.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/InetAddressEditor.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/InetAddressEditor.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/InetAddressEditor.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,56 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import java.beans.PropertyEditorSupport;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * Java Bean PropertyEditor which converts Strings into InetAddress objects.
+ * This may be used together with Spring to be able to set InetAddress bean
+ * properties, e.g.
+ * {@link org.apache.mina.filter.BlacklistFilter#setBlacklist(InetAddress[])}.
+ * Simply calls {@link java.net.InetAddress#getByName(java.lang.String)} when
+ * converting from a String.
+ * <p>
+ * Use Spring's CustomEditorConfigurer to use this property editor in a Spring
+ * context. See chapter 3.14 of the Spring Reference Documentation for more
+ * info.
+ * </p>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Revision$, $Date$
+ * 
+ * @see java.net.InetAddress
+ */
+public class InetAddressEditor extends PropertyEditorSupport
+{
+    public void setAsText( String text ) throws IllegalArgumentException
+    {
+        try
+        {
+            setValue( InetAddress.getByName( text ) );
+        }
+        catch( UnknownHostException uhe )
+        {
+            throw new IllegalArgumentException( uhe );
+        }
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/InetAddressEditor.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,88 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+
+import org.apache.mina.integration.spring.support.AbstractIoAcceptorFactoryBean;
+import org.springframework.util.Assert;
+
+/**
+ * Common base class for factory beans creating IoAcceptor instances which bind
+ * to InetSocketAddress addresses.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class InetSocketAddressBindingIoAcceptorFactoryBean extends
+        AbstractIoAcceptorFactoryBean
+{
+
+    /**
+     * Parses the specified string and returns a corresponding
+     * InetSocketAddress. E.g.: <code>google.com:80</code>, <code>:22</code>,
+     * <code>192.168.0.1:110</code>.
+     * 
+     * @param s
+     *            the string to parse. An optional host or ip address followed
+     *            by a colon and a port number (<em>[host|ip]:port</em>).
+     * @return the SocketAddress.
+     */
+    protected SocketAddress parseSocketAddress( String s )
+    {
+        Assert.notNull( s, "null SocketAddress string" );
+        s = s.trim();
+        int colonIndex = s.indexOf( ":" );
+        if( colonIndex > 0 )
+        {
+            String host = s.substring( 0, colonIndex );
+            int port = parsePort( s.substring( colonIndex + 1 ) );
+            return new InetSocketAddress( host, port );
+        }
+        else
+        {
+            int port = parsePort( s.substring( colonIndex + 1 ) );
+            return new InetSocketAddress( port );
+        }
+    }
+
+    /**
+     * Parses a port number by calling
+     * {@link Integer#parseInt(java.lang.String)}.
+     * 
+     * @param s
+     *            the textual representation of the port.
+     * @return the port number.
+     * @throws IllegalArgumentException
+     *             if {@link Integer#parseInt(java.lang.String)} throws a
+     *             NumberFormatException.
+     */
+    protected int parsePort( String s )
+    {
+        try
+        {
+            return Integer.parseInt( s );
+        }
+        catch( NumberFormatException nfe )
+        {
+            throw new IllegalArgumentException( "Illegal port number: " + s );
+        }
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/IoFilterMapping.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/IoFilterMapping.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/IoFilterMapping.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/IoFilterMapping.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,78 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.integration.spring.support.AbstractIoSessionManagerFactoryBean;
+import org.springframework.util.Assert;
+
+/**
+ * Associates a name with an IoFilter. The name will be used in the call to
+ * {@link org.apache.mina.common.IoFilterChain#addLast(String, IoFilter)} when
+ * an IoSessionManager is configured by using any of the Spring FactoryBean
+ * implementations extending {@link AbstractIoSessionManagerFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoFilterMapping
+{
+    private String name = null;
+
+    private IoFilter filter = null;
+
+    /**
+     * Creates a new mapping which associates the specified name with the
+     * specified filter.
+     * 
+     * @param name
+     *            the name.
+     * @param filter
+     *            the filter.
+     * @throws IllegalArgumentException
+     *             if any of the parameters are <code>null</code>.
+     */
+    public IoFilterMapping( String name, IoFilter filter )
+    {
+        Assert.notNull( name, "Argument 'name' may not be null" );
+        Assert.notNull( filter, "Argument 'filter' may not be null" );
+        this.name = name;
+        this.filter = filter;
+    }
+
+    /**
+     * Gets the filter of this mapping.
+     * 
+     * @return the filter.
+     */
+    public IoFilter getFilter()
+    {
+        return filter;
+    }
+
+    /**
+     * Gets the name associated with the filter.
+     * 
+     * @return the name.
+     */
+    public String getName()
+    {
+        return name;
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/IoFilterMapping.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketAcceptorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketAcceptorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketAcceptorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketAcceptorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,135 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.integration.spring.support.AbstractIoAcceptorFactoryBean;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+
+/**
+ * {@link AbstractIoAcceptorFactoryBean} implementation which allows for easy
+ * configuration of {@link SocketAcceptor} instances using Spring. Example of
+ * usage:
+ * <p>
+ * 
+ * <pre>
+ *   &lt;!-- POP3 server IoHandler implementation--&gt;
+ *   &lt;bean id=&quot;pop3Handler&quot; class=&quot;com.foo.bar.MyPop3Handler&quot;&gt;
+ *       ...
+ *   &lt;!-- IMAP server IoHandler implementation --&gt;
+ *   &lt;bean id=&quot;imapHandler&quot; class=&quot;com.foo.bar.MyImapHandler&quot;&gt;
+ *       ...
+ *   &lt;/bean&gt;
+ *   &lt;!-- Telnet based admin console handler. Should only be 
+ *        accessible from localhost --&gt;
+ *   &lt;bean id=&quot;adminHandler&quot; class=&quot;com.foo.bar.MyAdminHandler&quot;&gt;
+ *       ...
+ *   &lt;/bean&gt;
+ *   
+ *   &lt;!-- Create a thread pool filter --&gt;
+ *   &lt;bean id=&quot;threadPoolFilter&quot; 
+ *         class=&quot;org.apache.mina.filter.ThreadPoolFilter&quot;&gt;
+ *       &lt;!-- Threads will be named IoWorker-1, IoWorker-2, etc --&gt;
+ *       &lt;constructor-arg value=&quot;IoWorker&quot;/&gt;
+ *       &lt;property name=&quot;maximumPoolSize&quot; value=&quot;10&quot;/&gt;
+ *   &lt;/bean&gt;
+ *   
+ *   &lt;!-- Create the SocketAcceptor --&gt;
+ *  &lt;bean id=&quot;socketAcceptor&quot; 
+ *        class=&quot;org.apache.mina.spring.SocketAcceptorFactoryBean&quot;&gt;
+ *    &lt;property name=&quot;filters&quot;&gt;
+ *      &lt;list&gt;
+ *         &lt;ref local=&quot;threadPoolFilter&quot;/&gt;
+ *      &lt;/list&gt;
+ *    &lt;/property&gt;
+ *    &lt;property name=&quot;bindings&quot;&gt;
+ *      &lt;map&gt;
+ *        &lt;entry key=&quot;:110&quot; value-ref=&quot;pop3Handler&quot;/&gt;
+ *        &lt;entry key=&quot;:143&quot; value-ref=&quot;imapHandler&quot;/&gt;
+ *        &lt;entry key=&quot;127.0.0.1:60987&quot; value-ref=&quot;adminHandler&quot;/&gt;
+ *      &lt;/map&gt;
+ *    &lt;/property&gt;
+ *  &lt;/bean&gt;
+ * </pre>
+ * 
+ * </p>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SocketAcceptorFactoryBean extends
+        InetSocketAddressBindingIoAcceptorFactoryBean
+{
+
+    private boolean reuseAddress = false;
+
+    private int backlog = 50;
+
+    private int receiveBufferSize = -1;
+
+    protected IoAcceptor createIoAcceptor() throws Exception
+    {
+        SocketAcceptor acceptor = new SocketAcceptor();
+
+        acceptor.setBacklog( backlog );
+        acceptor.setReceiveBufferSize( receiveBufferSize );
+        acceptor.setReuseAddress( reuseAddress );
+
+        return acceptor;
+    }
+
+    /**
+     * Sets the <code>backlog</code> property of the {@link SocketAcceptor}
+     * this factory bean will create.
+     * 
+     * @param backlog
+     *            the property value.
+     * @see SocketAcceptor#setBacklog(int)
+     */
+    public void setBacklog( int backlog )
+    {
+        this.backlog = backlog;
+    }
+
+    /**
+     * Sets the <code>receiveBufferSize</code> property of the
+     * {@link SocketAcceptor} this factory bean will create.
+     * 
+     * @param receiveBufferSize
+     *            the property value.
+     * @see SocketAcceptor#setReceiveBufferSize(int)
+     */
+    public void setReceiveBufferSize( int receiveBufferSize )
+    {
+        this.receiveBufferSize = receiveBufferSize;
+    }
+
+    /**
+     * Sets the <code>reuseAddress</code> property of the
+     * {@link SocketAcceptor} this factory bean will create.
+     * 
+     * @param reuseAddress
+     *            the property value.
+     * @see SocketAcceptor#setReuseAddress(boolean)
+     */
+    public void setReuseAddress( boolean reuseAddress )
+    {
+        this.reuseAddress = reuseAddress;
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketAcceptorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketConnectorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketConnectorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketConnectorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketConnectorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,40 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.integration.spring.support.AbstractIoConnectorFactoryBean;
+import org.apache.mina.transport.socket.nio.SocketConnector;
+
+/**
+ * {@link AbstractIoConnectorFactoryBean} implementation which allows for easy
+ * configuration of {@link SocketConnector} instances using Spring.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SocketConnectorFactoryBean extends AbstractIoConnectorFactoryBean
+{
+
+    protected IoConnector createIoConnector() throws Exception
+    {
+        return new SocketConnector();
+    }
+
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/SocketConnectorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,95 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import java.net.SocketAddress;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.integration.spring.support.AbstractIoAcceptorFactoryBean;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+import org.springframework.util.Assert;
+
+/**
+ * {@link AbstractIoAcceptorFactoryBean} implementation which allows for easy
+ * configuration of {@link VmPipeAcceptor} instances using Spring. Example of
+ * usage:
+ * <p>
+ * 
+ * <pre>
+ *   &lt;!-- My IoHandler implementation--&gt;
+ *   &lt;bean id=&quot;myHandler&quot; class=&quot;com.foo.bar.MyHandler&quot;&gt;
+ *       ...
+ *   
+ *   &lt;!-- Create a thread pool filter --&gt;
+ *   &lt;bean id=&quot;threadPoolFilter&quot; 
+ *         class=&quot;org.apache.mina.filter.ThreadPoolFilter&quot;&gt;
+ *       &lt;!-- Threads will be named IoWorker-1, IoWorker-2, etc --&gt;
+ *       &lt;constructor-arg value=&quot;IoWorker&quot;/&gt;
+ *       &lt;property name=&quot;maximumPoolSize&quot; value=&quot;10&quot;/&gt;
+ *   &lt;/bean&gt;
+ *   
+ *   &lt;!-- Create the DatagramAcceptor --&gt;
+ *   &lt;bean id=&quot;vmPipeAcceptor&quot; 
+ *        class=&quot;org.apache.mina.spring.VmPipeAcceptorFactoryBean&quot;&gt;
+ *    &lt;property name=&quot;filters&quot;&gt;
+ *      &lt;list&gt;
+ *         &lt;ref local=&quot;threadPoolFilter&quot;/&gt;
+ *      &lt;/list&gt;
+ *    &lt;/property&gt;
+ *    &lt;property name=&quot;bindings&quot;&gt;
+ *      &lt;map&gt;
+ *        &lt;entry key=&quot;:9287&quot; value-ref=&quot;myHandler&quot;/&gt;
+ *        &lt;entry key=&quot;:6273&quot; value-ref=&quot;myHandler&quot;/&gt;
+ *      &lt;/map&gt;
+ *    &lt;/property&gt;
+ *  &lt;/bean&gt;
+ * </pre>
+ * 
+ * </p>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAcceptorFactoryBean extends AbstractIoAcceptorFactoryBean
+{
+
+    protected IoAcceptor createIoAcceptor() throws Exception
+    {
+        return new VmPipeAcceptor();
+    }
+
+    protected SocketAddress parseSocketAddress( String s )
+    {
+        Assert.notNull( s, "null SocketAddress string" );
+        s = s.trim();
+        if( s.startsWith( ":" ) )
+        {
+            s = s.substring( 1 );
+        }
+        try
+        {
+            return new VmPipeAddress( Integer.parseInt( s.trim() ) );
+        }
+        catch( NumberFormatException nfe )
+        {
+            throw new IllegalArgumentException( "Illegal vm pipe address: " + s );
+        }
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeConnectorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeConnectorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeConnectorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeConnectorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,40 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.integration.spring.support.AbstractIoConnectorFactoryBean;
+import org.apache.mina.transport.vmpipe.VmPipeConnector;
+
+/**
+ * {@link AbstractIoConnectorFactoryBean} implementation which allows for easy
+ * configuration of {@link VmPipeConnector} instances using Spring.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeConnectorFactoryBean extends AbstractIoConnectorFactoryBean
+{
+
+    protected IoConnector createIoConnector() throws Exception
+    {
+        return new VmPipeConnector();
+    }
+
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/VmPipeConnectorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/package.html
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/package.html?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/package.html (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/package.html Sun Nov 13 23:37:37 2005
@@ -0,0 +1,9 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+</head>
+<body>
+<a href="http://www.springframework.org/">SpringFramework</a>-specific classes
+for integration
+</body>
+</html>

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/package.html
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,188 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring.support;
+
+import java.net.SocketAddress;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSessionManager;
+import org.springframework.util.Assert;
+
+/**
+ * Abstract Spring FactoryBean which creates IoAcceptor instances and enables
+ * their bindings and filter chain to be configured using Spring.
+ * <p>
+ * NOTE: Do NOT call {@link IoAcceptor#bind(SocketAddress, IoHandler)} on the
+ * created IoAcceptor. If you do add additional bindings that way
+ * {@link #destroyInstance(Object)} will not be able to unbind all bindings of
+ * the IoAcceptor and it will not be fully shut down when the Spring BeanFactory
+ * is closed.
+ * </p>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractIoAcceptorFactoryBean extends
+        AbstractIoSessionManagerFactoryBean
+{
+
+    protected Map bindings = Collections.EMPTY_MAP;
+
+    /**
+     * Creates the IoAcceptor configured by this factory bean.
+     * 
+     * @return the IoAcceptor.
+     * @throws Exception
+     *             on errors.
+     */
+    protected abstract IoAcceptor createIoAcceptor() throws Exception;
+
+    /**
+     * Creates a new IoAcceptor. Calls {@link #createIoAcceptor()} to get the
+     * new IoAcceptor instance and then calls
+     * {@link AbstractIoSessionManagerFactoryBean#initIoSessionManager(IoSessionManager)}
+     * followed by {@link #initIoAcceptor(IoAcceptor)}.
+     * 
+     * @return the IoAcceptor instance.
+     */
+    protected Object createInstance() throws Exception
+    {
+        IoAcceptor acceptor = createIoAcceptor();
+
+        initIoSessionManager( acceptor );
+        initIoAcceptor( acceptor );
+
+        return acceptor;
+    }
+
+    /**
+     * Initializes an IoAcceptor configured by this factory bean.
+     * 
+     * @param acceptor
+     *            the IoAcceptor.
+     * @throws Exception
+     *             on errors.
+     */
+    protected void initIoAcceptor( IoAcceptor acceptor ) throws Exception
+    {
+
+        /*
+         * Bind all.
+         */
+        for( Iterator it = bindings.keySet().iterator(); it.hasNext(); )
+        {
+            SocketAddress address = ( SocketAddress ) it.next();
+            IoHandler handler = ( IoHandler ) bindings.get( address );
+            acceptor.bind( address, handler );
+        }
+    }
+
+    /**
+     * Destroys an IoAcceptor created by the factory bean by calling
+     * {@link #destroyIoAcceptor(IoAcceptor)} and then
+     * {@link AbstractIoSessionManagerFactoryBean#destroyIoSessionManager(IoSessionManager)}.
+     * This method may be overridden by extending classes if additional calls
+     * are necessary to shutdown the IoAcceptor or if the sequence of calls
+     * should be different.
+     * <p>
+     * This method will be called by Spring when the BeanFactory creating this
+     * instance is closed. Spring will NOT call this method if this factory bean
+     * has been configured for non-singleton use.
+     * </p>
+     * 
+     * @param instance
+     *            the IoAcceptor instance to be destroyed.
+     */
+    protected void destroyInstance( Object instance ) throws Exception
+    {
+        IoAcceptor acceptor = ( IoAcceptor ) instance;
+        destroyIoAcceptor( acceptor );
+        destroyIoSessionManager( acceptor );
+    }
+
+    /**
+     * Destroys an IoAcceptor created by the factory bean by unbinding all
+     * bindings set through {@link #setBindings(Map)}.
+     * 
+     * @param acceptor
+     *            the IoAcceptor instance to be destroyed.
+     */
+    protected void destroyIoAcceptor( IoAcceptor acceptor ) throws Exception
+    {
+        /*
+         * Unbind all.
+         */
+        for( Iterator it = bindings.keySet().iterator(); it.hasNext(); )
+        {
+            SocketAddress address = ( SocketAddress ) it.next();
+            try
+            {
+                acceptor.unbind( address );
+            }
+            catch( Exception ignored )
+            {
+            }
+        }
+    }
+
+    public Class getObjectType()
+    {
+        return IoAcceptor.class;
+    }
+
+    /**
+     * Sets the bindings to be used by the IoAcceptor created by this factory
+     * bean. The specified map maps a String representation of the SocketAddress
+     * implementation supported by the concrete implementation of this class to
+     * an IoHandler instance.
+     * 
+     * @param bindings
+     *            the
+     * @throws IllegalArgumentException
+     *             if the specified value is <code>null</code>.
+     * @see IoAcceptor#bind(SocketAddress, IoHandler)
+     * @see #parseSocketAddress(String)
+     */
+    public void setBindings( Map bindings )
+    {
+        Assert.notNull( bindings, "Property 'bindings' may not be null" );
+        this.bindings = new HashMap();
+
+        for( Iterator it = bindings.keySet().iterator(); it.hasNext(); )
+        {
+            String address = ( String ) it.next();
+            IoHandler handler = ( IoHandler ) bindings.get( address );
+            this.bindings.put( parseSocketAddress( address ), handler );
+        }
+    }
+
+    /**
+     * Parses the specified string and returns the corresponding SocketAddress.
+     * 
+     * @param s
+     *            the string to parse.
+     * @return the SocketAddress.
+     */
+    protected abstract SocketAddress parseSocketAddress( String s );
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,111 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring.support;
+
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoSessionManager;
+
+/**
+ * Abstract Spring FactoryBean which creates {@link IoConnector} instances and
+ * enables their filter chain to be configured using Spring.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractIoConnectorFactoryBean extends
+        AbstractIoSessionManagerFactoryBean
+{
+
+    private int connectTimeout = 60;
+
+    /**
+     * Creates the {@link IoConnector} configured by this factory bean.
+     * 
+     * @return the new instance
+     * @throws Exception on errors.
+     */
+    protected abstract IoConnector createIoConnector() throws Exception;
+
+    /**
+     * Creates a new {@link IoConnector}. Calls {@link #createIoConnector()} to
+     * get the new instance and then calls {@link AbstractIoSessionManagerFactoryBean#initIoSessionManager(IoSessionManager)}
+     * followed by {@link #initIoConnector(IoConnector)}.
+     * 
+     * @return the new instance
+     */
+    protected Object createInstance() throws Exception
+    {
+        IoConnector connector = createIoConnector();
+
+        initIoSessionManager( connector );
+        initIoConnector( connector );
+
+        return connector;
+    }
+
+    /**
+     * Initializes the specified <code>connector</code> configured by this
+     * factory bean.
+     * 
+     * @throws Exception on errors.
+     */
+    protected void initIoConnector( IoConnector connector ) throws Exception
+    {
+        connector.setConnectTimeout( connectTimeout );
+    }
+
+    /**
+     * Destroys an IoConnector created by the factory bean by calling
+     * {@link AbstractIoSessionManagerFactoryBean#destroyIoSessionManager(IoSessionManager)}.
+     * This method may be overridden by extending classes if additional calls
+     * are necessary to shutdown the IoConnector or if the sequence of calls
+     * should be different.
+     * <p>
+     * This method will be called by Spring when the BeanFactory creating this
+     * instance is closed. Spring will NOT call this method if this factory bean
+     * has been configured for non-singleton use.
+     * </p>
+     * 
+     * @param instance
+     *            the IoAcceptor instance to be destroyed.
+     */
+    protected void destroyInstance( Object instance ) throws Exception
+    {
+        IoConnector connector = ( IoConnector ) instance;
+        destroyIoSessionManager( connector );
+    }
+
+    public Class getObjectType()
+    {
+        return IoConnector.class;
+    }
+
+    /**
+     * Sets the <code>connectTimeout</code> property of the
+     * {@link IoConnector} this factory bean will create.
+     * 
+     * @param connectTimeout
+     *            the property value.
+     * @see IoConnector#setConnectTimeout(int)
+     */
+    public void setConnectTimeout( int connectTimeout )
+    {
+        this.connectTimeout = connectTimeout;
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoConnectorFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,154 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring.support;
+
+import org.apache.mina.common.ExceptionMonitor;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoSessionManager;
+import org.apache.mina.integration.spring.IoFilterMapping;
+import org.springframework.beans.factory.config.AbstractFactoryBean;
+import org.springframework.util.Assert;
+
+/**
+ * Abstract Spring FactoryBean which creates IoSessionManager instances and
+ * enables their filter chain to be configured using Spring.
+ * <p>
+ * A IoFilterChain may be set up in two ways. By creating
+ * {@link IoFilterMapping} objects which associate a name with an IoFilter
+ * instance and set them using {@link #setFilterMappings(IoFilterMapping[])} or
+ * by using {@link #setFilters(IoFilter[])} directly which assigns automatically
+ * generated names to each IoFilter.
+ * </p>
+ * <p>
+ * NOTE: Instances of this class should NOT be condigured as non-singletons.
+ * This will prevent Spring from calling the <code>destroyInstance()</code>
+ * method on BeanFactory shut down.
+ * </p>
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractIoSessionManagerFactoryBean extends
+        AbstractFactoryBean
+{
+    private ExceptionMonitor exceptionMonitor = null;
+
+    private IoFilterMapping[] filterMappings = new IoFilterMapping[ 0 ];
+
+    /**
+     * Initializes an IoSessionManager configured by this factory bean.
+     * 
+     * @param sessionManager
+     *            the IoSessionManager.
+     * @throws Exception
+     *             on errors.
+     */
+    protected void initIoSessionManager( IoSessionManager sessionManager )
+            throws Exception
+    {
+
+        if( exceptionMonitor != null )
+        {
+            sessionManager.setExceptionMonitor( exceptionMonitor );
+        }
+
+        /*
+         * Add filters to the end of the filter chain.
+         */
+        IoFilterChain filterChain = sessionManager.getFilterChain();
+        for( int i = 0; i < filterMappings.length; i++ )
+        {
+            filterChain.addLast( filterMappings[ i ].getName(),
+                    filterMappings[ i ].getFilter() );
+        }
+    }
+
+    /**
+     * Destroys an IoSessionManager created by the factory bean by clearing its
+     * IoFilterChain.
+     * 
+     * @param sessionManager
+     *            the IoSessionManager instance to be destroyed.
+     */
+    protected void destroyIoSessionManager( IoSessionManager sessionManager )
+            throws Exception
+    {
+
+        /*
+         * Remove all filters.
+         */
+        IoFilterChain filterChain = sessionManager.getFilterChain();
+        filterChain.clear();
+    }
+
+    /**
+     * Sets a number of unnamed filters which will be used to create the filter
+     * chain for the IoSessionManager created by this factory bean. The filters
+     * will be assigned automatically generated names (<code>filter0</code>,
+     * <code>filter1</code>, etc).
+     * 
+     * @param filters
+     *            the filters.
+     * @throws IllegalArgumentException
+     *             if the specified value is <code>null</code>.
+     */
+    public void setFilters( IoFilter[] filters )
+    {
+        Assert.notNull( filters, "Property 'filters' may not be null" );
+        this.filterMappings = new IoFilterMapping[ filters.length ];
+
+        for( int i = 0; i < filters.length; i++ )
+        {
+            this.filterMappings[ i ] = new IoFilterMapping( "filter" + i,
+                    filters[ i ] );
+        }
+    }
+
+    /**
+     * Sets a number of named filters which will be used to create the filter
+     * chain for the IoSessionManager created by this factory bean.
+     * 
+     * @param filterMappings
+     *            the name to filter mappings.
+     * @throws IllegalArgumentException
+     *             if the specified value is <code>null</code>.
+     */
+    public void setFilterMappings( IoFilterMapping[] filterMappings )
+    {
+        Assert.notNull( filterMappings,
+                "Property 'filterMappings' may not be null" );
+        this.filterMappings = filterMappings;
+    }
+
+    /**
+     * Sets the {@link ExceptionMonitor} to be used by the IoSessionManager
+     * created by this factory bean. If this isn't specified a default one will
+     * be used.
+     * 
+     * @param exceptionMonitor
+     *            the monitor.
+     */
+    public void setExceptionMonitor( ExceptionMonitor exceptionMonitor )
+    {
+        Assert.notNull( exceptionMonitor,
+                "Property 'exceptionMonitor' may not be null" );
+        this.exceptionMonitor = exceptionMonitor;
+    }
+}

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/AbstractIoSessionManagerFactoryBean.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/package.html
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/integration/spring/support/package.html?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/integration/spring/support/package.html (added)
+++ directory/network/trunk/src/java/org/apache/mina/integration/spring/support/package.html Sun Nov 13 23:37:37 2005
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+</head>
+<body>
+Internal classes used by <tt>org.apache.mina.integration.spring</tt> package.
+</body>
+</html>

Propchange: directory/network/trunk/src/java/org/apache/mina/integration/spring/support/package.html
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Modified: directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java?rev=344069&r1=344068&r2=344069&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java Sun Nov 13 23:37:37 2005
@@ -20,7 +20,6 @@
 
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.support.DelegatedIoConnector;
-import org.apache.mina.transport.socket.nio.support.SocketAcceptorDelegate;
 import org.apache.mina.transport.socket.nio.support.SocketConnectorDelegate;
 
 /**

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramAcceptorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramAcceptorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramAcceptorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramAcceptorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,41 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.DatagramAcceptorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DatagramAcceptorFactoryBeanTest extends TestCase
+{
+
+    public void testCreateIoAcceptor() throws Exception
+    {
+        DatagramAcceptorFactoryBean factory = new DatagramAcceptorFactoryBean();
+
+        assertTrue( factory.createIoAcceptor() instanceof DatagramAcceptor );
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramAcceptorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramConnectorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramConnectorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramConnectorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramConnectorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,39 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.transport.socket.nio.DatagramConnector;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.DatagramConnectorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DatagramConnectorFactoryBeanTest extends TestCase
+{
+    public void testCreateIoConnector() throws Exception
+    {
+        DatagramConnectorFactoryBean factory = new DatagramConnectorFactoryBean();
+
+        assertTrue( factory.createIoConnector() instanceof DatagramConnector );
+    }
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/DatagramConnectorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/InetAddressEditorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/InetAddressEditorTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/InetAddressEditorTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/InetAddressEditorTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,53 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import java.net.InetAddress;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.InetAddressEditor}. NOTE:
+ * This test does DNS queries so it needs network access to succeed.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class InetAddressEditorTest extends TestCase
+{
+    InetAddressEditor editor;
+
+    protected void setUp() throws Exception
+    {
+        editor = new InetAddressEditor();
+    }
+
+    public void testSetAsTextWithHostName() throws Exception
+    {
+        editor.setAsText( "www.google.com" );
+        assertEquals( InetAddress.getByName( "www.google.com" ), editor
+                .getValue() );
+    }
+
+    public void testSetAsTextWithIpAddress() throws Exception
+    {
+        editor.setAsText( "127.0.0.1" );
+        assertEquals( InetAddress.getByName( "127.0.0.1" ), editor.getValue() );
+    }
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/InetAddressEditorTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,90 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import java.net.InetSocketAddress;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoAcceptor;
+
+/**
+ * Tests {@link InetSocketAddressBindingIoAcceptorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class InetSocketAddressBindingIoAcceptorFactoryBeanTest extends TestCase
+{
+
+    public void testParseSocketAddress() throws Exception
+    {
+        InetSocketAddressBindingIoAcceptorFactoryBean factory = new InetSocketAddressBindingIoAcceptorFactoryBean()
+        {
+            protected IoAcceptor createIoAcceptor() throws Exception
+            {
+                // Don't care. This will never be called.
+                return null;
+            }
+        };
+
+        assertEquals( new InetSocketAddress( 1 ), factory
+                .parseSocketAddress( "1" ) );
+        assertEquals( new InetSocketAddress( 10 ), factory
+                .parseSocketAddress( ":10" ) );
+        assertEquals( new InetSocketAddress( "foo.bar.com", 100 ), factory
+                .parseSocketAddress( "foo.bar.com:100" ) );
+        assertEquals( new InetSocketAddress( "192.168.0.1", 1000 ), factory
+                .parseSocketAddress( "192.168.0.1:1000" ) );
+
+        try
+        {
+            factory.parseSocketAddress( null );
+            fail( "null string. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+        try
+        {
+            factory.parseSocketAddress( "bar" );
+            fail( "Illegal port number. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+        try
+        {
+            factory.parseSocketAddress( ":foo" );
+            fail( "Illegal port number. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+        try
+        {
+            factory.parseSocketAddress( "www.foo.com:yada" );
+            fail( "Illegal port number. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/InetSocketAddressBindingIoAcceptorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/IoFilterMappingTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/IoFilterMappingTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/IoFilterMappingTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/IoFilterMappingTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,60 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoFilter;
+import org.easymock.MockControl;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.IoFilterMapping}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoFilterMappingTest extends TestCase
+{
+    public void testConstructor() throws Exception
+    {
+        IoFilter filter = ( IoFilter ) MockControl.createControl(
+                IoFilter.class ).getMock();
+
+        try
+        {
+            new IoFilterMapping( null, filter );
+            fail( "null name. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+        try
+        {
+            new IoFilterMapping( "name", null );
+            fail( "null filter. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+
+        IoFilterMapping mapping = new IoFilterMapping( "name", filter );
+        assertEquals( "name", mapping.getName() );
+        assertSame( filter, mapping.getFilter() );
+    }
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/IoFilterMappingTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketAcceptorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketAcceptorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketAcceptorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketAcceptorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,57 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.SocketAcceptorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SocketAcceptorFactoryBeanTest extends TestCase
+{
+
+    public void testCreateIoAcceptorWithDefaults() throws Exception
+    {
+        SocketAcceptorFactoryBean factory = new SocketAcceptorFactoryBean();
+
+        SocketAcceptor acceptor = ( SocketAcceptor ) factory.createIoAcceptor();
+        assertEquals( 50, acceptor.getBacklog() );
+        assertEquals( -1, acceptor.getReceiveBufferSize() );
+        assertFalse( acceptor.isReuseAddress() );
+    }
+
+    public void testCreateIoAcceptorWithNonDefaults() throws Exception
+    {
+        SocketAcceptorFactoryBean factory = new SocketAcceptorFactoryBean();
+
+        factory.setBacklog( 10000 );
+        factory.setReceiveBufferSize( 1024 * 1024 );
+        factory.setReuseAddress( true );
+
+        SocketAcceptor acceptor = ( SocketAcceptor ) factory.createIoAcceptor();
+        assertEquals( 10000, acceptor.getBacklog() );
+        assertEquals( 1024 * 1024, acceptor.getReceiveBufferSize() );
+        assertTrue( acceptor.isReuseAddress() );
+    }
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketAcceptorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketConnectorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketConnectorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketConnectorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketConnectorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,41 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.transport.socket.nio.SocketConnector;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.SocketConnectorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class SocketConnectorFactoryBeanTest extends TestCase
+{
+
+    public void testCreateIoConnector() throws Exception
+    {
+        SocketConnectorFactoryBean factory = new SocketConnectorFactoryBean();
+
+        assertTrue( factory.createIoConnector() instanceof SocketConnector );
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/SocketConnectorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,78 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.VmPipeAcceptorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAcceptorFactoryBeanTest extends TestCase
+{
+
+    public void testParseSocketAddress() throws Exception
+    {
+        VmPipeAcceptorFactoryBean factory = new VmPipeAcceptorFactoryBean()
+        {
+            protected IoAcceptor createIoAcceptor() throws Exception
+            {
+                // Don't care. This will never be called.
+                return null;
+            }
+        };
+
+        assertEquals( new VmPipeAddress( 1 ), factory.parseSocketAddress( "1" ) );
+        assertEquals( new VmPipeAddress( 10 ), factory
+                .parseSocketAddress( ":10" ) );
+        assertEquals( new VmPipeAddress( 100 ), factory
+                .parseSocketAddress( " :100 " ) );
+
+        try
+        {
+            factory.parseSocketAddress( null );
+            fail( "null string. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+        try
+        {
+            factory.parseSocketAddress( "bar" );
+            fail( "Illegal port number. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+        try
+        {
+            factory.parseSocketAddress( ":foo" );
+            fail( "Illegal port number. IllegalArgumentException expected." );
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeAcceptorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeConnectorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeConnectorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeConnectorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeConnectorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,41 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.transport.vmpipe.VmPipeConnector;
+
+/**
+ * Tests {@link org.apache.mina.integration.spring.VmPipeConnectorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeConnectorFactoryBeanTest extends TestCase
+{
+
+    public void testCreateIoConnector() throws Exception
+    {
+        VmPipeConnectorFactoryBean factory = new VmPipeConnectorFactoryBean();
+
+        assertTrue( factory.createIoConnector() instanceof VmPipeConnector );
+    }
+
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/integration/spring/VmPipeConnectorFactoryBeanTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBeanTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBeanTest.java?rev=344069&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBeanTest.java (added)
+++ directory/network/trunk/src/test/org/apache/mina/integration/spring/support/AbstractIoAcceptorFactoryBeanTest.java Sun Nov 13 23:37:37 2005
@@ -0,0 +1,209 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.mina.integration.spring.support;
+
+import java.lang.reflect.Method;
+import java.net.SocketAddress;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSessionManager;
+import org.easymock.MockControl;
+import org.easymock.classextension.MockClassControl;
+
+/**
+ * Tests
+ * {@link org.apache.mina.integration.spring.support.AbstractIoAcceptorFactoryBean}.
+ * 
+ * @author The Apache Directory Project (dev@directory.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class AbstractIoAcceptorFactoryBeanTest extends TestCase
+{
+    MockControl mockFactory;
+    AbstractIoAcceptorFactoryBean factory;
+    MockControl mockIoAcceptor;
+    IoAcceptor ioAcceptor;
+    Map bindings;
+    IoHandler popHandler;
+    IoHandler sshHandler;
+    IoHandler httpHandler;
+
+    protected void setUp() throws Exception
+    {
+        /*
+         * Create the object to be tested. We're using EasyMock to mock some of
+         * the methods in the super class since we're already testing those in
+         * AbstractIoSessionManagerFactoryBeanTest and we don't want to test
+         * them in this test again.
+         */
+        mockFactory = MockClassControl
+                .createNiceControl(
+                        TestIoAcceptorFactoryBean.class,
+                        new Method[] {
+                                TestIoAcceptorFactoryBean.class
+                                        .getDeclaredMethod( "createIoAcceptor",
+                                                new Class[ 0 ] ),
+                                AbstractIoSessionManagerFactoryBean.class
+                                        .getDeclaredMethod(
+                                                "initIoSessionManager",
+                                                new Class[] { IoSessionManager.class } ),
+                                AbstractIoSessionManagerFactoryBean.class
+                                        .getDeclaredMethod(
+                                                "destroyIoSessionManager",
+                                                new Class[] { IoSessionManager.class } ) } );
+
+        factory = ( AbstractIoAcceptorFactoryBean ) mockFactory.getMock();
+
+        /*
+         * Create other EasyMock mocks.
+         */
+        mockIoAcceptor = MockControl.createControl( IoAcceptor.class );
+        ioAcceptor = ( IoAcceptor ) mockIoAcceptor.getMock();
+
+        /*
+         * Create some IoHandlers.
+         */
+        popHandler = ( IoHandler ) MockControl.createControl( IoHandler.class )
+                .getMock();
+        sshHandler = ( IoHandler ) MockControl.createControl( IoHandler.class )
+                .getMock();
+        httpHandler = ( IoHandler ) MockControl.createControl( IoHandler.class )
+                .getMock();
+
+        /*
+         * Create the map of bindings to use.
+         */
+        bindings = new LinkedHashMap();
+        bindings.put( ":110", popHandler );
+        bindings.put( "127.0.0.1:22", sshHandler );
+        bindings.put( "192.168.0.1:80", httpHandler );
+    }
+
+    public void testCreateInstance() throws Exception
+    {
+        /*
+         * Record expectations.
+         */
+        factory.createIoAcceptor();
+        mockFactory.setReturnValue( ioAcceptor );
+        factory.initIoSessionManager( ioAcceptor );
+        ioAcceptor.bind( new DummySocketAddress( ":110" ), popHandler );
+        ioAcceptor.bind( new DummySocketAddress( "127.0.0.1:22" ), sshHandler );
+        ioAcceptor.bind( new DummySocketAddress( "192.168.0.1:80" ),
+                httpHandler );
+
+        /*
+         * Replay.
+         */
+        mockIoAcceptor.replay();
+        mockFactory.replay();
+
+        factory.setBindings( bindings );
+        Object o = factory.createInstance();
+
+        /*
+         * Verify.
+         */
+        mockIoAcceptor.verify();
+        mockFactory.verify();
+
+        assertSame( ioAcceptor, o );
+    }
+
+    public void testDestroyInstance() throws Exception
+    {
+
+        /*
+         * Record expectations.
+         */
+        ioAcceptor.unbind( new DummySocketAddress( ":110" ) );
+        ioAcceptor.unbind( new DummySocketAddress( "127.0.0.1:22" ) );
+        // Make this unbind call throw an exception. The exception should be
+        // ignored.
+        mockIoAcceptor.setThrowable( new NullPointerException() );
+        ioAcceptor.unbind( new DummySocketAddress( "192.168.0.1:80" ) );
+        factory.destroyIoSessionManager( ioAcceptor );
+
+        /*
+         * Replay.
+         */
+        mockIoAcceptor.replay();
+        mockFactory.replay();
+
+        factory.setBindings( bindings );
+        factory.destroyInstance( ioAcceptor );
+
+        /*
+         * Verify.
+         */
+        mockIoAcceptor.verify();
+        mockFactory.verify();
+    }
+
+    public void testGetObjectType() throws Exception
+    {
+        AbstractIoAcceptorFactoryBean factory = new TestIoAcceptorFactoryBean();
+        assertSame( IoAcceptor.class, factory.getObjectType() );
+    }
+
+    /*
+     * We need a concrete class to test.
+     */
+    public static class TestIoAcceptorFactoryBean extends
+            AbstractIoAcceptorFactoryBean
+    {
+        protected IoAcceptor createIoAcceptor() throws Exception
+        {
+            // Don't care. This method will be mocked.
+            return null;
+        }
+
+        protected SocketAddress parseSocketAddress( String s )
+        {
+            return new DummySocketAddress( s );
+        }
+    }
+
+    public static class DummySocketAddress extends SocketAddress
+    {
+        private static final long serialVersionUID = -4369202604535464701L;
+
+        private String s = null;
+
+        public DummySocketAddress( String s )
+        {
+            this.s = s;
+        }
+
+        public boolean equals( Object o )
+        {
+            if( !( o instanceof DummySocketAddress ) )
+            {
+                return false;
+            }
+            DummySocketAddress that = ( DummySocketAddress ) o;
+            return this.s.equals( that.s );
+        }
+    }
+}



Mime
View raw message