directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r169939 - in /directory/network: branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java trunk/src/java/org/apache/mina/protocol/codec/DemuxingProtocolCodecFactory.java
Date Fri, 13 May 2005 05:10:00 GMT
Author: trustin
Date: Thu May 12 22:09:59 2005
New Revision: 169939

URL: http://svn.apache.org/viewcvs?rev=169939&view=rev
Log:
Added DemuxingProtocolCodecFactory.register( Class ) for convenience


Modified:
    directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
    directory/network/trunk/src/java/org/apache/mina/protocol/codec/DemuxingProtocolCodecFactory.java

Modified: directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java?rev=169939&r1=169938&r2=169939&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
(original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java
Thu May 12 22:09:59 2005
@@ -50,6 +50,22 @@
     {
     }
     
+    public void register( Class encoderOrDecoderClass )
+    {
+        if( MessageEncoder.class.isAssignableFrom( encoderOrDecoderClass ) )
+        {
+            register( new DefaultConstructorMessageEncoderFactory( encoderOrDecoderClass
) );
+        }
+        else if( MessageDecoder.class.isAssignableFrom( encoderOrDecoderClass ) )
+        {
+            register( new DefaultConstructorMessageDecoderFactory( encoderOrDecoderClass
) );
+        }
+        else
+        {
+            throw new IllegalArgumentException();
+        }
+    }
+    
     public void register( MessageEncoder encoder )
     {
         register( new SingletonMessageEncoderFactory( encoder ) );
@@ -68,7 +84,7 @@
         this.encoderFactories = newEncoderFactories;
     }
     
-    public void register( final MessageDecoder decoder )
+    public void register( MessageDecoder decoder )
     {
         register( new SingletonMessageDecoderFactory( decoder ) );
     }
@@ -286,6 +302,69 @@
         public MessageDecoder newDecoder()
         {
             return decoder;
+        }
+    }
+
+    
+    private static class DefaultConstructorMessageEncoderFactory implements MessageEncoderFactory
+    {
+        private final Class encoderClass;
+        
+        private DefaultConstructorMessageEncoderFactory( Class encoderClass )
+        {
+            if( encoderClass == null )
+            {
+                throw new NullPointerException( "encoderClass" );
+            }
+            
+            if( !MessageEncoder.class.isAssignableFrom( encoderClass ) )
+            {
+                throw new IllegalArgumentException( "encoderClass is not assignable to MessageEncoder"
);
+            }
+            this.encoderClass = encoderClass;
+        }
+
+        public MessageEncoder newEncoder()
+        {
+            try
+            {
+                return ( MessageEncoder ) encoderClass.newInstance();
+            }
+            catch( Exception e )
+            {
+                throw new RuntimeException( "Failed to create a new instance of " + encoderClass,
e );
+            }
+        }
+    }
+
+    private static class DefaultConstructorMessageDecoderFactory implements MessageDecoderFactory
+    {
+        private final Class decoderClass;
+        
+        private DefaultConstructorMessageDecoderFactory( Class decoderClass )
+        {
+            if( decoderClass == null )
+            {
+                throw new NullPointerException( "decoderClass" );
+            }
+            
+            if( !MessageDecoder.class.isAssignableFrom( decoderClass ) )
+            {
+                throw new IllegalArgumentException( "decoderClass is not assignable to MessageDecoder"
);
+            }
+            this.decoderClass = decoderClass;
+        }
+
+        public MessageDecoder newDecoder()
+        {
+            try
+            {
+                return ( MessageDecoder ) decoderClass.newInstance();
+            }
+            catch( Exception e )
+            {
+                throw new RuntimeException( "Failed to create a new instance of " + decoderClass,
e );
+            }
         }
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/codec/DemuxingProtocolCodecFactory.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/codec/DemuxingProtocolCodecFactory.java?rev=169939&r1=169938&r2=169939&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/codec/DemuxingProtocolCodecFactory.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/codec/DemuxingProtocolCodecFactory.java
Thu May 12 22:09:59 2005
@@ -56,6 +56,22 @@
     {
     }
     
+    public void register( Class encoderOrDecoderClass )
+    {
+        if( MessageEncoder.class.isAssignableFrom( encoderOrDecoderClass ) )
+        {
+            register( new DefaultConstructorMessageEncoderFactory( encoderOrDecoderClass
) );
+        }
+        else if( MessageDecoder.class.isAssignableFrom( encoderOrDecoderClass ) )
+        {
+            register( new DefaultConstructorMessageDecoderFactory( encoderOrDecoderClass
) );
+        }
+        else
+        {
+            throw new IllegalArgumentException();
+        }
+    }
+    
     public void register( MessageEncoder encoder )
     {
         register( new SingletonMessageEncoderFactory( encoder ) );
@@ -74,7 +90,7 @@
         this.encoderFactories = newEncoderFactories;
     }
     
-    public void register( final MessageDecoder decoder )
+    public void register( MessageDecoder decoder )
     {
         register( new SingletonMessageDecoderFactory( decoder ) );
     }
@@ -292,6 +308,68 @@
         public MessageDecoder newDecoder()
         {
             return decoder;
+        }
+    }
+    
+    private static class DefaultConstructorMessageEncoderFactory implements MessageEncoderFactory
+    {
+        private final Class encoderClass;
+        
+        private DefaultConstructorMessageEncoderFactory( Class encoderClass )
+        {
+            if( encoderClass == null )
+            {
+                throw new NullPointerException( "encoderClass" );
+            }
+            
+            if( !MessageEncoder.class.isAssignableFrom( encoderClass ) )
+            {
+                throw new IllegalArgumentException( "encoderClass is not assignable to MessageEncoder"
);
+            }
+            this.encoderClass = encoderClass;
+        }
+
+        public MessageEncoder newEncoder()
+        {
+            try
+            {
+                return ( MessageEncoder ) encoderClass.newInstance();
+            }
+            catch( Exception e )
+            {
+                throw new RuntimeException( "Failed to create a new instance of " + encoderClass,
e );
+            }
+        }
+    }
+
+    private static class DefaultConstructorMessageDecoderFactory implements MessageDecoderFactory
+    {
+        private final Class decoderClass;
+        
+        private DefaultConstructorMessageDecoderFactory( Class decoderClass )
+        {
+            if( decoderClass == null )
+            {
+                throw new NullPointerException( "decoderClass" );
+            }
+            
+            if( !MessageDecoder.class.isAssignableFrom( decoderClass ) )
+            {
+                throw new IllegalArgumentException( "decoderClass is not assignable to MessageDecoder"
);
+            }
+            this.decoderClass = decoderClass;
+        }
+
+        public MessageDecoder newDecoder()
+        {
+            try
+            {
+                return ( MessageDecoder ) decoderClass.newInstance();
+            }
+            catch( Exception e )
+            {
+                throw new RuntimeException( "Failed to create a new instance of " + decoderClass,
e );
+            }
         }
     }
 }



Mime
View raw message