directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nik...@apache.org
Subject svn commit: r428741 - in /directory/trunks/mina/integration-spring/src: main/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBean.java test/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBeanTest.java
Date Fri, 04 Aug 2006 14:48:05 GMT
Author: niklas
Date: Fri Aug  4 07:48:04 2006
New Revision: 428741

URL: http://svn.apache.org/viewvc?rev=428741&view=rev
Log:
Removed setFilterMappings() and changed signature of setFilters() to take a List instead of
an IoFilter array.

Modified:
    directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBean.java
    directory/trunks/mina/integration-spring/src/test/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBeanTest.java

Modified: directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBean.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBean.java?rev=428741&r1=428740&r2=428741&view=diff
==============================================================================
--- directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBean.java
(original)
+++ directory/trunks/mina/integration-spring/src/main/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBean.java
Fri Aug  4 07:48:04 2006
@@ -18,6 +18,8 @@
  */
 package org.apache.mina.integration.spring;
 
+import java.util.List;
+
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoFilter;
 import org.springframework.beans.factory.config.AbstractFactoryBean;
@@ -84,44 +86,46 @@
     }
 
     /**
-     * Sets a number of unnamed filters which will be added to the filter
-     * chain created by this factory bean. The filters will be assigned 
+     * Sets a number of filters which will be added to the filter
+     * chain created by this factory bean. The specified list must contain either
+     * {@link IoFilter} or {@link IoFilterMapping} objects. Filters which
+     * haven't been wrapped in {@link IoFilterMapping} objects will be assigned 
      * automatically generated names (<code>&lt;filterNamePrefix&gt;0</code>,

      * <code>&lt;filterNamePrefix&gt;1</code>, etc).
      * 
-     * @param filters the filters.
+     * @param filters the list of {@link IoFilter} and/or 
+     *        {@link IoFilterMapping} objects.
      * @throws IllegalArgumentException if the specified value is 
-     *         <code>null</code>.
+     *         <code>null</code> or contains objects of the wrong type.
      * @see #setFilterNamePrefix(String)
      */
-    public void setFilters( IoFilter[] filters )
+    public void setFilters( List filters )
     {
         Assert.notNull( filters, "Property 'filters' may not be null" );
-        this.filterMappings = new IoFilterMapping[ filters.length ];
+        IoFilterMapping[] filterMappings = new IoFilterMapping[ filters.size() ];
 
-        for( int i = 0; i < filters.length; i++ )
+        for( int i = 0; i < filterMappings.length; i++ )
         {
-            this.filterMappings[ i ] = new IoFilterMapping();
-            this.filterMappings[ i ].setFilter( filters[ i ] );
+            Object o = filters.get( i );
+            if( o instanceof IoFilterMapping )
+            {
+                filterMappings[ i ] = ( IoFilterMapping ) o;
+            }
+            else if( o instanceof IoFilter )
+            {
+                filterMappings[ i ] = new IoFilterMapping();
+                filterMappings[ i ].setFilter( ( IoFilter ) o );
+            }
+            else
+            {
+                throw new IllegalArgumentException( "List may only contain "
+                        + "IoFilter or IoFilterMapping objects. Found object of "
+                        + "type " + o.getClass().getName() 
+                        + " at position " + i + "." );
+            }
         }
+        
+        this.filterMappings = filterMappings;
     }
 
-    /**
-     * Sets a number of named filters which will be added to the filter
-     * chain created by this factory bean. {@link IoFilterMapping} objects
-     * set using this method which haven't had their name set will be assigned
-     * automatically generated names derived from the prefix set using
-     * {@link #setFilterNamePrefix(String)} and the position in the specified
-     * array (i.e. <code>&lt;filterNamePrefix&gt;&lt;pos&gt;</code>).
-     * 
-     * @param filterMappings the name to filter mappings.
-     * @throws IllegalArgumentException if the specified value is 
-     *         <code>null</code>.
-     * @see #setFilterNamePrefix(String)
-     */
-    public void setFilterMappings( IoFilterMapping[] filterMappings )
-    {
-        Assert.notNull( filterMappings, "Property 'filterMappings' may not be null" );
-        this.filterMappings = filterMappings;
-    }    
 }

Modified: directory/trunks/mina/integration-spring/src/test/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/mina/integration-spring/src/test/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBeanTest.java?rev=428741&r1=428740&r2=428741&view=diff
==============================================================================
--- directory/trunks/mina/integration-spring/src/test/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBeanTest.java
(original)
+++ directory/trunks/mina/integration-spring/src/test/java/org/apache/mina/integration/spring/DefaultIoFilterChainBuilderFactoryBeanTest.java
Fri Aug  4 07:48:04 2006
@@ -18,6 +18,9 @@
  */
 package org.apache.mina.integration.spring;
 
+import java.util.Arrays;
+import java.util.LinkedList;
+
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoFilter;
 import org.apache.mina.common.IoFilterChain;
@@ -60,7 +63,7 @@
         
         DefaultIoFilterChainBuilderFactoryBean factory = 
                                    new DefaultIoFilterChainBuilderFactoryBean();
-        factory.setFilters( filters );
+        factory.setFilters( Arrays.asList( filters ) );
         factory.setFilterNamePrefix( "prefix" );
         DefaultIoFilterChainBuilder builder = 
                              ( DefaultIoFilterChainBuilder) factory.createInstance();
@@ -69,18 +72,29 @@
         mockChain.verify();
     }
     
-    public void testnamedAndUnnamedFilters() throws Exception
+    public void testIllegalObjectsInFilterList() throws Exception
+    {
+        LinkedList mappings = new LinkedList();
+        mappings.add( new IoFilterMapping( "f0", filters[ 0 ] ) );
+        mappings.add( new Object() );
+        DefaultIoFilterChainBuilderFactoryBean factory = 
+            new DefaultIoFilterChainBuilderFactoryBean();
+        try
+        {
+            factory.setFilters( mappings );
+            fail( "Illegal object in list of filters. IllegalArgumentException expected."
);
+        }
+        catch( IllegalArgumentException iae )
+        {
+        }
+    }
+    
+    public void testNamedAndUnnamedFilters() throws Exception
     {
-        IoFilterMapping[] mappings = new IoFilterMapping[] {
-                new IoFilterMapping(),
-                new IoFilterMapping(),
-                new IoFilterMapping()
-        };
-        mappings[ 0 ].setFilter( filters[ 0 ] );
-        mappings[ 0 ].setName( "f0" );
-        mappings[ 1 ].setFilter( filters[ 1 ] );
-        mappings[ 2 ].setFilter( filters[ 2 ] );
-        mappings[ 2 ].setName( "f2" );
+        LinkedList mappings = new LinkedList();
+        mappings.add( new IoFilterMapping( "f0", filters[ 0 ] ) );
+        mappings.add( filters[ 1 ] );
+        mappings.add( new IoFilterMapping( "f2", filters[ 2 ] ) );
         
         chain.addLast( "f0", filters[ 0 ] );
         chain.addLast( "filter1", filters[ 1 ] );
@@ -90,7 +104,7 @@
         
         DefaultIoFilterChainBuilderFactoryBean factory = 
                                    new DefaultIoFilterChainBuilderFactoryBean();
-        factory.setFilterMappings( mappings );
+        factory.setFilters( mappings );
         DefaultIoFilterChainBuilder builder = 
                              ( DefaultIoFilterChainBuilder) factory.createInstance();
         builder.buildFilterChain( chain );



Mime
View raw message