directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r385254 - in /directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec: ProtocolCodecFactory.java ProtocolCodecFilter.java demux/DemuxingProtocolCodecFactory.java demux/MessageDecoderFactory.java demux/MessageEncoderFactory.java
Date Sun, 12 Mar 2006 06:08:15 GMT
Author: trustin
Date: Sat Mar 11 22:08:14 2006
New Revision: 385254

URL: http://svn.apache.org/viewcvs?rev=385254&view=rev
Log:
* Added more constructor methods in ProtocolCodecFilter
* All methods in ProtocolCodecFactory and Message(En|De)coderFactory now can throw any exceptions.
* Renamed newEncoder() to getEncoder()
* Renamed newDecoder() to getDecoder()

Modified:
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
    directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java?rev=385254&r1=385253&r2=385254&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java
Sat Mar 11 22:08:14 2006
@@ -35,11 +35,11 @@
      * Returns a new (or reusable) instance of {@link ProtocolEncoder} which
      * encodes message objects into binary or protocol-specific data.
      */
-    ProtocolEncoder getEncoder();
+    ProtocolEncoder getEncoder() throws Exception;
 
     /**
      * Returns a new (or reusable) instance of {@link ProtocolDecoder} which
      * decodes binary or protocol-specific data into message objects.
      */
-    ProtocolDecoder getDecoder();
+    ProtocolDecoder getDecoder() throws Exception;
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java?rev=385254&r1=385253&r2=385254&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java
Sat Mar 11 22:08:14 2006
@@ -18,6 +18,8 @@
     public static final String ENCODER_OUT = ProtocolCodecFilter.class.getName() + ".encoderOutput";
     public static final String DECODER_OUT = ProtocolCodecFilter.class.getName() + ".decoderOutput";
     
+    private static final Class[] EMPTY_PARAMS = new Class[0];
+
     private final ProtocolCodecFactory factory;
     
     public ProtocolCodecFilter( ProtocolCodecFactory factory )
@@ -29,6 +31,80 @@
         this.factory = factory;
     }
     
+    public ProtocolCodecFilter( final ProtocolEncoder encoder, final ProtocolDecoder decoder
)
+    {
+        if( encoder == null )
+        {
+            throw new NullPointerException( "encoder" );
+        }
+        if( decoder == null )
+        {
+            throw new NullPointerException( "decoder" );
+        }
+        
+        this.factory = new ProtocolCodecFactory()
+        {
+            public ProtocolEncoder getEncoder()
+            {
+                return encoder;
+            }
+
+            public ProtocolDecoder getDecoder()
+            {
+                return decoder;
+            }
+        };
+    }
+    
+    public ProtocolCodecFilter( final Class encoderClass, final Class decoderClass )
+    {
+        if( encoderClass == null )
+        {
+            throw new NullPointerException( "encoderClass" );
+        }
+        if( decoderClass == null )
+        {
+            throw new NullPointerException( "decoderClass" );
+        }
+        if( !ProtocolEncoder.class.isAssignableFrom( encoderClass ) )
+        {
+            throw new IllegalArgumentException( "encoderClass: " + encoderClass.getName()
);
+        }
+        if( !ProtocolDecoder.class.isAssignableFrom( decoderClass ) )
+        {
+            throw new IllegalArgumentException( "decoderClass: " + decoderClass.getName()
);
+        }
+        try
+        {
+            encoderClass.getConstructor( EMPTY_PARAMS );
+        }
+        catch( NoSuchMethodException e )
+        {
+            throw new IllegalArgumentException( "encoderClass doesn't have a public default
constructor." );
+        }
+        try
+        {
+            decoderClass.getConstructor( EMPTY_PARAMS );
+        }
+        catch( NoSuchMethodException e )
+        {
+            throw new IllegalArgumentException( "decoderClass doesn't have a public default
constructor." );
+        }
+        
+        this.factory = new ProtocolCodecFactory()
+        {
+            public ProtocolEncoder getEncoder() throws Exception
+            {
+                return ( ProtocolEncoder ) encoderClass.newInstance();
+            }
+
+            public ProtocolDecoder getDecoder() throws Exception
+            {
+                return ( ProtocolDecoder ) decoderClass.newInstance();
+            }
+        };
+    }
+
     public void onPreAdd( IoFilterChain parent, String name, NextFilter nextFilter ) throws
Exception
     {
         if( parent.contains( ProtocolCodecFilter.class ) )
@@ -165,7 +241,7 @@
         nextFilter.sessionClosed( session );
     }
 
-    private ProtocolEncoder getEncoder( IoSession session )
+    private ProtocolEncoder getEncoder( IoSession session ) throws Exception
     {
         ProtocolEncoder encoder = ( ProtocolEncoder ) session.getAttribute( ENCODER );
         if( encoder == null )
@@ -187,7 +263,7 @@
         return out;
     }
     
-    private ProtocolDecoder getDecoder( IoSession session )
+    private ProtocolDecoder getDecoder( IoSession session ) throws Exception
     {
         ProtocolDecoder decoder = ( ProtocolDecoder ) session.getAttribute( DECODER );
         if( decoder == null )

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java?rev=385254&r1=385253&r2=385254&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/DemuxingProtocolCodecFactory.java
Sat Mar 11 22:08:14 2006
@@ -63,6 +63,8 @@
     private MessageDecoderFactory[] decoderFactories = new MessageDecoderFactory[0];
     private MessageEncoderFactory[] encoderFactories = new MessageEncoderFactory[0];
     
+    private static final Class[] EMPTY_PARAMS = new Class[0];
+
     public DemuxingProtocolCodecFactory()
     {
     }
@@ -73,6 +75,15 @@
         {
             throw new NullPointerException( "encoderOrDecoderClass" );
         }
+        
+        try
+        {
+            encoderOrDecoderClass.getConstructor( EMPTY_PARAMS );
+        }
+        catch( NoSuchMethodException e )
+        {
+            throw new IllegalArgumentException( "The specifiec class doesn't have a public
default constructor." );
+        }
 
         boolean registered = false;
         if( MessageEncoder.class.isAssignableFrom( encoderOrDecoderClass ) )
@@ -130,11 +141,11 @@
         this.decoderFactories = newDecoderFactories;
     }
     
-    public ProtocolEncoder getEncoder() {
+    public ProtocolEncoder getEncoder() throws Exception {
         return new ProtocolEncoderImpl();
     }
 
-    public ProtocolDecoder getDecoder() {
+    public ProtocolDecoder getDecoder() throws Exception {
         return new ProtocolDecoderImpl();
     }
     
@@ -157,12 +168,12 @@
     {
         private final Map encoders = new IdentityHashMap();
         
-        private ProtocolEncoderImpl()
+        private ProtocolEncoderImpl() throws Exception
         {
             MessageEncoderFactory[] encoderFactories = DemuxingProtocolCodecFactory.this.encoderFactories;
             for( int i = encoderFactories.length - 1; i >= 0; i-- )
             {
-                MessageEncoder encoder = encoderFactories[ i ].newEncoder();
+                MessageEncoder encoder = encoderFactories[ i ].getEncoder();
                 Iterator it = encoder.getMessageTypes().iterator();
                 while( it.hasNext() )
                 {
@@ -236,7 +247,7 @@
         private final MessageDecoder[] decoders;
         private MessageDecoder currentDecoder;
 
-        protected ProtocolDecoderImpl()
+        protected ProtocolDecoderImpl() throws Exception
         {
             super( 16 );
             
@@ -244,7 +255,7 @@
             decoders = new MessageDecoder[ decoderFactories.length ];
             for( int i = decoderFactories.length - 1; i >= 0; i-- )
             {
-                decoders[ i ] = decoderFactories[ i ].newDecoder();
+                decoders[ i ] = decoderFactories[ i ].getDecoder();
             }
         }
 
@@ -344,7 +355,7 @@
             this.encoder = encoder;
         }
 
-        public MessageEncoder newEncoder()
+        public MessageEncoder getEncoder()
         {
             return encoder;
         }
@@ -363,7 +374,7 @@
             this.decoder = decoder;
         }
 
-        public MessageDecoder newDecoder()
+        public MessageDecoder getDecoder()
         {
             return decoder;
         }
@@ -388,16 +399,9 @@
             this.encoderClass = encoderClass;
         }
 
-        public MessageEncoder newEncoder()
+        public MessageEncoder getEncoder() throws Exception
         {
-            try
-            {
-                return ( MessageEncoder ) encoderClass.newInstance();
-            }
-            catch( Exception e )
-            {
-                throw new RuntimeException( "Failed to create a new instance of " + encoderClass,
e );
-            }
+            return ( MessageEncoder ) encoderClass.newInstance();
         }
     }
 
@@ -419,16 +423,9 @@
             this.decoderClass = decoderClass;
         }
 
-        public MessageDecoder newDecoder()
+        public MessageDecoder getDecoder() throws Exception
         {
-            try
-            {
-                return ( MessageDecoder ) decoderClass.newInstance();
-            }
-            catch( Exception e )
-            {
-                throw new RuntimeException( "Failed to create a new instance of " + decoderClass,
e );
-            }
+            return ( MessageDecoder ) decoderClass.newInstance();
         }
     }
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java?rev=385254&r1=385253&r2=385254&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageDecoderFactory.java
Sat Mar 11 22:08:14 2006
@@ -31,5 +31,5 @@
     /**
      * Creates a new message decoder.
      */
-    MessageDecoder newDecoder();
+    MessageDecoder getDecoder() throws Exception;
 }

Modified: directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java?rev=385254&r1=385253&r2=385254&view=diff
==============================================================================
--- directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java
(original)
+++ directory/trunks/mina/core/src/main/java/org/apache/mina/filter/codec/demux/MessageEncoderFactory.java
Sat Mar 11 22:08:14 2006
@@ -31,5 +31,5 @@
     /**
      * Creates a new message encoder.
      */
-    MessageEncoder newEncoder();
+    MessageEncoder getEncoder() throws Exception;
 }



Mime
View raw message