directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1073629 - 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 08:10:14 GMT
Author: akarasulu
Date: Wed Feb 23 08:10:13 2011
New Revision: 1073629

URL: http://svn.apache.org/viewvc?rev=1073629&view=rev
Log:
DIRSHARED-86: implementing some method stubs in codec service implementations

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/LdapCodecService.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/util/src/main/java/org/apache/directory/shared/ldap/util/JndiUtils.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=1073629&r1=1073628&r2=1073629&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 08:10:13 2011
@@ -29,6 +29,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.naming.NamingException;
+
 import org.apache.directory.shared.asn1.DecoderException;
 import org.apache.directory.shared.asn1.EncoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Container;
@@ -37,6 +39,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.api.ControlFactory;
 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.ExtendedResponseDecorator;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
 import org.apache.directory.shared.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.api.MessageDecorator;
@@ -52,6 +55,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 import org.apache.directory.shared.ldap.model.message.ExtendedRequestImpl;
 import org.apache.directory.shared.ldap.model.message.ExtendedResponse;
+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.exception.NotImplementedException;
@@ -790,8 +794,9 @@ public class StandaloneLdapCodecService 
      */
     public ExtendedRequest<?> fromJndi( javax.naming.ldap.ExtendedRequest jndiRequest
) throws DecoderException
     {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
+        ExtendedRequestDecorator<?,?> decorator =
+            ( ExtendedRequestDecorator<?, ?> ) newExtendedRequest( jndiRequest.getID(),
jndiRequest.getEncodedValue() );
+        return decorator;
     }
 
 
@@ -800,18 +805,70 @@ public class StandaloneLdapCodecService 
      */
     public javax.naming.ldap.ExtendedRequest toJndi( ExtendedRequest<?> modelRequest
) throws EncoderException
     {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
+        final String oid = modelRequest.getRequestName();
+        final byte[] value;
+        
+        if ( modelRequest instanceof ExtendedRequestDecorator )
+        {
+            ExtendedRequestDecorator<?, ?> decorator = ( ExtendedRequestDecorator<?,
?> ) modelRequest;
+            value = decorator.getRequestValue();
+        }
+        else
+        {
+            // have to ask the factory to decorate for us - can't do it ourselves
+            throw new NotImplementedException( "need to decorate the request" );
+        }
+        
+        
+        javax.naming.ldap.ExtendedRequest jndiRequest = new javax.naming.ldap.ExtendedRequest()
+        {
+            private static final long serialVersionUID = -4160980385909987475L;
+
+            public String getID()
+            {
+                return oid;
+            }
+
+            public byte[] getEncodedValue()
+            {
+                return value;
+            }
+
+            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"
);
+            }
+            
+        };
+
+        return jndiRequest;
     }
 
 
     /**
      * {@inheritDoc}
+     * @throws DecoderException 
      */
-    public <E extends ExtendedResponse> E newExtendedResponse( ExtendedRequest<E>
req, byte[] serializedResponse )
+    @SuppressWarnings("unchecked")
+    public <E extends ExtendedResponse> E newExtendedResponse( ExtendedRequest<E>
req, byte[] serializedResponse ) throws DecoderException
     {
-        // TODO Auto-generated method stub
-        return null;
+        ExtendedResponseDecorator<ExtendedResponse> resp;
+        
+        ExtendedRequestFactory<?,?> extendedRequestFactory = extReqFactories.get( req.getRequestName()
);
+        if ( extendedRequestFactory != null )
+        {
+            resp = ( ExtendedResponseDecorator<ExtendedResponse> ) extendedRequestFactory.newResponse(
serializedResponse );
+        }
+        else
+        {
+            resp = new ExtendedResponseDecorator<ExtendedResponse>( this, 
+                new ExtendedResponseImpl( req.getRequestName() ) );
+            resp.setResponseValue( serializedResponse );
+            resp.setResponseName( req.getRequestName() );
+        }
+        
+        return ( E ) resp;
     }
 
 

Modified: directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecService.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecService.java?rev=1073629&r1=1073628&r2=1073629&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecService.java
(original)
+++ directory/shared/branches/akarasulu/ldap-codec/src/main/java/org/apache/directory/shared/ldap/codec/api/LdapCodecService.java
Wed Feb 23 08:10:13 2011
@@ -248,7 +248,7 @@ public interface LdapCodecService
     Asn1Container newMessageContainer();
 
 
-    <E extends ExtendedResponse> E newExtendedResponse( ExtendedRequest<E> req,
byte[] serializedResponse );
+    <E extends ExtendedResponse> E newExtendedResponse( ExtendedRequest<E> req,
byte[] serializedResponse ) throws DecoderException;
 
 
     /**

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=1073629&r1=1073628&r2=1073629&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 08:10:13 2011
@@ -25,6 +25,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.Asn1Container;
 import org.apache.directory.shared.ldap.codec.BasicControlDecorator;
 import org.apache.directory.shared.ldap.codec.api.ExtendedRequestDecorator;
+import org.apache.directory.shared.ldap.codec.api.ExtendedResponseDecorator;
 import org.apache.directory.shared.ldap.codec.api.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.api.CodecControl;
 import org.apache.directory.shared.ldap.codec.api.ControlFactory;
@@ -43,6 +44,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 import org.apache.directory.shared.ldap.model.message.ExtendedRequestImpl;
 import org.apache.directory.shared.ldap.model.message.ExtendedResponse;
+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.exception.NotImplementedException;
@@ -56,6 +58,8 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.naming.NamingException;
+
 
 /**
  * The default {@link LdapCodecService} implementation.
@@ -390,8 +394,9 @@ public class DefaultLdapCodecService imp
      */
     public ExtendedRequest<?> fromJndi( javax.naming.ldap.ExtendedRequest jndiRequest
) throws DecoderException
     {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
+        ExtendedRequestDecorator<?,?> decorator =
+            ( ExtendedRequestDecorator<?, ?> ) newExtendedRequest( jndiRequest.getID(),
jndiRequest.getEncodedValue() );
+        return decorator;
     }
 
 
@@ -400,18 +405,73 @@ public class DefaultLdapCodecService imp
      */
     public javax.naming.ldap.ExtendedRequest toJndi( ExtendedRequest<?> modelRequest
) throws EncoderException
     {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
+        final String oid = modelRequest.getRequestName();
+        final byte[] value;
+        
+        if ( modelRequest instanceof ExtendedRequestDecorator )
+        {
+            ExtendedRequestDecorator<?, ?> decorator = ( ExtendedRequestDecorator<?,
?> ) modelRequest;
+            value = decorator.getRequestValue();
+        }
+        else
+        {
+            // have to ask the factory to decorate for us - can't do it ourselves
+            throw new NotImplementedException( "need to decorate the request" );
+        }
+        
+        
+        javax.naming.ldap.ExtendedRequest jndiRequest = new javax.naming.ldap.ExtendedRequest()
+        {
+            private static final long serialVersionUID = -4160980385909987475L;
+
+            public String getID()
+            {
+                return oid;
+            }
+
+            public byte[] getEncodedValue()
+            {
+                return value;
+            }
+
+            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"
);
+            }
+            
+        };
+
+        return jndiRequest;
     }
 
 
     /**
      * {@inheritDoc}
      */
-    public <E extends ExtendedResponse> E newExtendedResponse( ExtendedRequest<E>
req, byte[] serializedResponse )
+    /**
+     * {@inheritDoc}
+     * @throws DecoderException 
+     */
+    @SuppressWarnings("unchecked")
+    public <E extends ExtendedResponse> E newExtendedResponse( ExtendedRequest<E>
req, byte[] serializedResponse ) throws DecoderException
     {
-        // TODO Auto-generated method stub
-        throw new NotImplementedException();
+        ExtendedResponseDecorator<ExtendedResponse> resp;
+        
+        ExtendedRequestFactory<?,?> extendedRequestFactory = extReqFactories.get( req.getRequestName()
);
+        if ( extendedRequestFactory != null )
+        {
+            resp = ( ExtendedResponseDecorator<ExtendedResponse> ) extendedRequestFactory.newResponse(
serializedResponse );
+        }
+        else
+        {
+            resp = new ExtendedResponseDecorator<ExtendedResponse>( this, 
+                new ExtendedResponseImpl( req.getRequestName() ) );
+            resp.setResponseValue( serializedResponse );
+            resp.setResponseName( req.getRequestName() );
+        }
+        
+        return ( E ) resp;
     }
 
 

Modified: directory/shared/branches/akarasulu/ldap-extras/util/src/main/java/org/apache/directory/shared/ldap/util/JndiUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/util/src/main/java/org/apache/directory/shared/ldap/util/JndiUtils.java?rev=1073629&r1=1073628&r2=1073629&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/util/src/main/java/org/apache/directory/shared/ldap/util/JndiUtils.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/util/src/main/java/org/apache/directory/shared/ldap/util/JndiUtils.java
Wed Feb 23 08:10:13 2011
@@ -21,7 +21,6 @@ package org.apache.directory.shared.ldap
 
 
 import java.util.Hashtable;
-import java.util.Map;
 
 import javax.naming.AuthenticationException;
 import javax.naming.AuthenticationNotSupportedException;
@@ -45,7 +44,6 @@ import javax.naming.directory.InvalidAtt
 import javax.naming.directory.InvalidSearchFilterException;
 import javax.naming.directory.NoSuchAttributeException;
 import javax.naming.directory.SchemaViolationException;
-import javax.naming.ldap.ExtendedResponse;
 import javax.naming.ldap.LdapName;
 
 import org.apache.directory.shared.asn1.DecoderException;
@@ -76,10 +74,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.exception.LdapServiceUnavailableException;
 import org.apache.directory.shared.ldap.model.exception.LdapTimeLimitExceededException;
 import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
-import org.apache.directory.shared.ldap.model.exception.MessageException;
 import org.apache.directory.shared.ldap.model.message.Control;
-import org.apache.directory.shared.ldap.model.message.LdapResult;
-import org.apache.directory.shared.ldap.model.message.MessageTypeEnum;
 import org.apache.directory.shared.ldap.model.name.Dn;
 
 
@@ -160,135 +155,6 @@ public final class JndiUtils
     }
 
 
-    /**
-     * TODO toJndiExtendedResponse. This is NOT correct ATM
-     *
-     * @param request
-     * @return
-     */
-    public static org.apache.directory.shared.ldap.model.message.ExtendedResponse fromJndiExtendedResponse(
-        final ExtendedResponse response )
-    {
-        class ServerExtendedResponse implements org.apache.directory.shared.ldap.model.message.ExtendedResponse
-        {
-            private static final long serialVersionUID = 1L;
-
-            public String getResponseName()
-            {
-                return response.getID();
-            }
-
-
-            public void setResponseName( String oid )
-            {
-            }
-
-
-            public LdapResult getLdapResult()
-            {
-                return null;
-            }
-
-
-            public void addAllControls( Control[] controls ) throws MessageException
-            {
-            }
-
-
-            public void addControl( Control control ) throws MessageException
-            {
-            }
-
-
-            public Object get( Object key )
-            {
-                return null;
-            }
-
-
-            public Control getControl( String oid )
-            {
-                return null;
-            }
-
-
-            public Map<String, Control> getControls()
-            {
-                return null;
-            }
-
-
-            @SuppressWarnings("unused")
-            public int getControlsLength()
-            {
-                return 0;
-            }
-
-
-            @SuppressWarnings("unused")
-            public Control getCurrentControl()
-            {
-                return null;
-            }
-
-
-            public int getMessageId()
-            {
-                return 0;
-            }
-
-
-            @SuppressWarnings("unused")
-            public int getMessageLength()
-            {
-                return 0;
-            }
-
-
-            public MessageTypeEnum getType()
-            {
-                return null;
-            }
-
-
-            public boolean hasControl( String oid )
-            {
-                return false;
-            }
-
-
-            public Object put( Object key, Object value )
-            {
-                return null;
-            }
-
-
-            public void removeControl( Control control ) throws MessageException
-            {
-            }
-
-
-            @SuppressWarnings("unused")
-            public void setControlsLength( int controlsLength )
-            {
-            }
-
-
-            public void setMessageId( int messageId )
-            {
-            }
-
-
-            @SuppressWarnings("unused")
-            public void setMessageLength( int messageLength )
-            {
-            }
-        }
-
-        return new ServerExtendedResponse();
-    }
-
-
     public static void wrap( Throwable t ) throws NamingException
     {
         if ( t instanceof NamingException )



Mime
View raw message