directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1073646 - in /directory/shared/branches/akarasulu: ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/ ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/ ldap-codec/src/main/java/org/apa...
Date Wed, 23 Feb 2011 09:05:20 GMT
Author: akarasulu
Date: Wed Feb 23 09:05:20 2011
New Revision: 1073646

URL: http://svn.apache.org/viewvc?rev=1073646&view=rev
Log:
DIRSHARED-86: adding new method to decorate undecorated requests

Modified:
    directory/shared/branches/akarasulu/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java
    directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/ExtendedRequestFactory.java
    directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultLdapCodecService.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CancelFactory.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CertGenerationFactory.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/GracefulShutdownFactory.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java

Modified: directory/shared/branches/akarasulu/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java
(original)
+++ directory/shared/branches/akarasulu/ldap-codec-standalone/src/main/java/org/apache/directory/shared/ldap/codec/standalone/StandaloneLdapCodecService.java
Wed Feb 23 09:05:20 2011
@@ -58,6 +58,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.ExtendedResponseImpl;
 import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.ldap.model.message.controls.OpaqueControl;
+import org.apache.directory.shared.util.Strings;
 import org.apache.directory.shared.util.exception.NotImplementedException;
 import org.apache.felix.framework.Felix;
 import org.apache.felix.framework.util.FelixConstants;
@@ -803,7 +804,7 @@ public class StandaloneLdapCodecService 
     /**
      * {@inheritDoc}
      */
-    public javax.naming.ldap.ExtendedRequest toJndi( ExtendedRequest<?> modelRequest
) throws EncoderException
+    public javax.naming.ldap.ExtendedRequest toJndi( final ExtendedRequest<?> modelRequest
) throws EncoderException
     {
         final String oid = modelRequest.getRequestName();
         final byte[] value;
@@ -816,7 +817,9 @@ public class StandaloneLdapCodecService 
         else
         {
             // have to ask the factory to decorate for us - can't do it ourselves
-            throw new NotImplementedException( "need to decorate the request" );
+            ExtendedRequestFactory<?,?> extendedRequestFactory = extReqFactories.get(
modelRequest.getRequestName() );
+            ExtendedRequestDecorator<?, ?> decorator = extendedRequestFactory.decorate(
modelRequest );
+            value = decorator.getRequestValue();
         }
         
         
@@ -837,9 +840,36 @@ public class StandaloneLdapCodecService 
             public javax.naming.ldap.ExtendedResponse createExtendedResponse( String id,
byte[] berValue, int offset,
                 int length ) throws NamingException
             {
-                throw new NotImplementedException( "need to create new extended response"
);
+                ExtendedRequestFactory<?,?> factory = extReqFactories.get( modelRequest.getRequestName()
);
+                
+                try
+                {
+                    final ExtendedResponseDecorator<?> resp = ( ExtendedResponseDecorator<?>
) factory.newResponse( berValue );
+                    javax.naming.ldap.ExtendedResponse jndiResponse = new javax.naming.ldap.ExtendedResponse()
+                    {
+                        private static final long serialVersionUID = -7686354122066100703L;
+
+                        public String getID()
+                        {
+                            return oid;
+                        }
+
+                        public byte[] getEncodedValue()
+                        {
+                            return resp.getResponseValue();
+                        }
+                    };
+                    
+                    return jndiResponse;
+                }
+                catch ( DecoderException e )
+                {
+                    NamingException ne = new NamingException( "Unable to decode encoded response
value: " + 
+                        Strings.dumpBytes( berValue ) );
+                    ne.setRootCause( e );
+                    throw ne;
+                }
             }
-            
         };
 
         return jndiRequest;

Modified: directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/ExtendedRequestFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/ExtendedRequestFactory.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/ExtendedRequestFactory.java
(original)
+++ directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/ExtendedRequestFactory.java
Wed Feb 23 09:05:20 2011
@@ -58,6 +58,15 @@ public interface ExtendedRequestFactory<
     
     
     /**
+     * Decorates a non-decorated request.
+     *
+     * @param modelRequest the non decorated model request
+     * @return the decorated model request
+     */
+    ExtendedRequestDecorator<Q, P> decorate( ExtendedRequest<?> modelRequest
);
+    
+    
+    /**
      * Creates a new ExtendedResponse, for the ExtendedRequest with a specific
      * encoded value.
      * 

Modified: directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultLdapCodecService.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultLdapCodecService.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultLdapCodecService.java
(original)
+++ directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/osgi/DefaultLdapCodecService.java
Wed Feb 23 09:05:20 2011
@@ -47,6 +47,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.ExtendedResponseImpl;
 import org.apache.directory.shared.ldap.model.message.Message;
 import org.apache.directory.shared.ldap.model.message.controls.OpaqueControl;
+import org.apache.directory.shared.util.Strings;
 import org.apache.directory.shared.util.exception.NotImplementedException;
 import org.apache.mina.filter.codec.ProtocolCodecFactory;
 import org.slf4j.Logger;
@@ -403,7 +404,7 @@ public class DefaultLdapCodecService imp
     /**
      * {@inheritDoc}
      */
-    public javax.naming.ldap.ExtendedRequest toJndi( ExtendedRequest<?> modelRequest
) throws EncoderException
+    public javax.naming.ldap.ExtendedRequest toJndi( final ExtendedRequest<?> modelRequest
) throws EncoderException
     {
         final String oid = modelRequest.getRequestName();
         final byte[] value;
@@ -416,7 +417,9 @@ public class DefaultLdapCodecService imp
         else
         {
             // have to ask the factory to decorate for us - can't do it ourselves
-            throw new NotImplementedException( "need to decorate the request" );
+            ExtendedRequestFactory<?,?> extendedRequestFactory = extReqFactories.get(
modelRequest.getRequestName() );
+            ExtendedRequestDecorator<?, ?> decorator = extendedRequestFactory.decorate(
modelRequest );
+            value = decorator.getRequestValue();
         }
         
         
@@ -437,9 +440,36 @@ public class DefaultLdapCodecService imp
             public javax.naming.ldap.ExtendedResponse createExtendedResponse( String id,
byte[] berValue, int offset,
                 int length ) throws NamingException
             {
-                throw new NotImplementedException( "need to create new extended response"
);
+                ExtendedRequestFactory<?,?> factory = extReqFactories.get( modelRequest.getRequestName()
);
+                
+                try
+                {
+                    final ExtendedResponseDecorator<?> resp = ( ExtendedResponseDecorator<?>
) factory.newResponse( berValue );
+                    javax.naming.ldap.ExtendedResponse jndiResponse = new javax.naming.ldap.ExtendedResponse()
+                    {
+                        private static final long serialVersionUID = -7686354122066100703L;
+
+                        public String getID()
+                        {
+                            return oid;
+                        }
+
+                        public byte[] getEncodedValue()
+                        {
+                            return resp.getResponseValue();
+                        }
+                    };
+                    
+                    return jndiResponse;
+                }
+                catch ( DecoderException e )
+                {
+                    NamingException ne = new NamingException( "Unable to decode encoded response
value: " + 
+                        Strings.dumpBytes( berValue ) );
+                    ne.setRootCause( e );
+                    throw ne;
+                }
             }
-            
         };
 
         return jndiRequest;

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CancelFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CancelFactory.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CancelFactory.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CancelFactory.java
Wed Feb 23 09:05:20 2011
@@ -21,12 +21,14 @@ package org.apache.directory.shared.ldap
 
 
 import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.shared.ldap.codec.api.ExtendedRequestFactory;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
 import org.apache.directory.shared.ldap.extras.extended.CancelRequestImpl;
 import org.apache.directory.shared.ldap.extras.extended.CancelResponseImpl;
 import org.apache.directory.shared.ldap.extras.extended.CancelRequest;
 import org.apache.directory.shared.ldap.extras.extended.CancelResponse;
+import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 
 
 /**
@@ -75,10 +77,31 @@ public class CancelFactory implements Ex
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     public CancelRequest newRequest( byte[] value )
     {
         CancelRequestDecorator req = new CancelRequestDecorator( codec, new CancelRequestImpl()
);
         req.setRequestValue( value );
         return req;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ExtendedRequestDecorator<CancelRequest, CancelResponse> decorate( ExtendedRequest<?>
modelRequest )
+    {
+        if ( modelRequest instanceof CancelRequestDecorator )
+        {
+            return ( CancelRequestDecorator ) modelRequest;
+        }
+        else if ( modelRequest instanceof CancelRequest )
+        {
+            return new CancelRequestDecorator( codec, ( CancelRequest ) modelRequest );
+        }
+        
+        return ( CancelRequestDecorator ) newRequest();
+    }
 }

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CertGenerationFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CertGenerationFactory.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CertGenerationFactory.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/CertGenerationFactory.java
Wed Feb 23 09:05:20 2011
@@ -21,12 +21,15 @@ package org.apache.directory.shared.ldap
 
 
 import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.shared.ldap.codec.api.ExtendedRequestFactory;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
+import org.apache.directory.shared.ldap.extras.extended.CancelRequest;
 import org.apache.directory.shared.ldap.extras.extended.CertGenerationRequestImpl;
 import org.apache.directory.shared.ldap.extras.extended.CertGenerationResponseImpl;
 import org.apache.directory.shared.ldap.extras.extended.CertGenerationRequest;
 import org.apache.directory.shared.ldap.extras.extended.CertGenerationResponse;
+import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 
 
 /**
@@ -85,4 +88,22 @@ public class CertGenerationFactory 
         req.setRequestValue( value );
         return req;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ExtendedRequestDecorator<CertGenerationRequest, CertGenerationResponse>
decorate( ExtendedRequest<?> modelRequest )
+    {
+        if ( modelRequest instanceof CertGenerationRequestDecorator )
+        {
+            return ( CertGenerationRequestDecorator ) modelRequest;
+        }
+        else if ( modelRequest instanceof CancelRequest )
+        {
+            return new CertGenerationRequestDecorator( codec, ( CertGenerationRequest ) modelRequest
);
+        }
+        
+        return ( CertGenerationRequestDecorator ) newRequest();
+    }
 }

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/GracefulShutdownFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/GracefulShutdownFactory.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/GracefulShutdownFactory.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/GracefulShutdownFactory.java
Wed Feb 23 09:05:20 2011
@@ -21,12 +21,14 @@ package org.apache.directory.shared.ldap
 
 
 import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.shared.ldap.codec.api.ExtendedRequestFactory;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
 import org.apache.directory.shared.ldap.extras.extended.GracefulShutdownRequestImpl;
 import org.apache.directory.shared.ldap.extras.extended.GracefulShutdownResponseImpl;
 import org.apache.directory.shared.ldap.extras.extended.GracefulShutdownRequest;
 import org.apache.directory.shared.ldap.extras.extended.GracefulShutdownResponse;
+import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 
 
 /**
@@ -86,4 +88,23 @@ public class GracefulShutdownFactory 
         req.setRequestValue( value );
         return req;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ExtendedRequestDecorator<GracefulShutdownRequest, GracefulShutdownResponse>
decorate(
+        ExtendedRequest<?> modelRequest )
+    {
+        if ( modelRequest instanceof GracefulShutdownRequestDecorator )
+        {
+            return ( GracefulShutdownRequestDecorator ) modelRequest;
+        }
+        else if ( modelRequest instanceof GracefulShutdownRequest )
+        {
+            return new GracefulShutdownRequestDecorator( codec, ( GracefulShutdownRequest
) modelRequest );
+        }
+        
+        return ( GracefulShutdownRequestDecorator ) newRequest();
+    }
 }

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java?rev=1073646&r1=1073645&r2=1073646&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
Wed Feb 23 09:05:20 2011
@@ -20,13 +20,15 @@
 package org.apache.directory.shared.ldap.extras.extended.ads_impl;
 
 
-import org.apache.directory.shared.asn1.DecoderException;
+import org.apache.directory.shared.asn1.DecoderException; 
+import org.apache.directory.shared.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.shared.ldap.codec.api.ExtendedRequestFactory;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequest;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureResponse;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequestImpl;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureResponseImpl;
+import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 
 
 /**
@@ -89,4 +91,23 @@ public class StoredProcedureFactory impl
         req.setRequestValue( value );
         return req;
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public ExtendedRequestDecorator<StoredProcedureRequest, StoredProcedureResponse>
decorate(
+        ExtendedRequest<?> modelRequest )
+    {
+        if ( modelRequest instanceof StoredProcedureRequestDecorator )
+        {
+            return ( StoredProcedureRequestDecorator ) modelRequest;
+        }
+        else if ( modelRequest instanceof StoredProcedureRequest )
+        {
+            return new StoredProcedureRequestDecorator( codec, ( StoredProcedureRequest )
modelRequest );
+        }
+        
+        return ( StoredProcedureRequestDecorator ) newRequest();
+    }
 }



Mime
View raw message