You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/05/10 00:48:57 UTC
svn commit: r1101258 - in /directory/shared/trunk/ldap:
client/api/src/main/java/org/apache/directory/ldap/client/api/
model/src/main/java/org/apache/directory/shared/ldap/model/cursor/
model/src/main/java/org/apache/directory/shared/ldap/model/message/
Author: elecharny
Date: Mon May 9 22:48:56 2011
New Revision: 1101258
URL: http://svn.apache.org/viewvc?rev=1101258&view=rev
Log:
o Modified the LdapConection interface so that the simple methods return void (except compare)
o Added a processResponse method in the AbstractResponse class, to generate the correct exception from the ResutCode
o Added the EntryCursor interface
Added:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java
Modified:
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AbstractResponse.java
Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java?rev=1101258&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java (added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/EntryCursorImpl.java Mon May 9 22:48:56 2011
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.ldap.client.api;
+
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.directory.ldap.client.api.future.SearchFuture;
+import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.model.cursor.AbstractCursor;
+import org.apache.directory.shared.ldap.model.cursor.EntryCursor;
+import org.apache.directory.shared.ldap.model.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapReferralException;
+import org.apache.directory.shared.ldap.model.message.Response;
+import org.apache.directory.shared.ldap.model.message.SearchResultDone;
+import org.apache.directory.shared.ldap.model.message.SearchResultEntry;
+import org.apache.directory.shared.ldap.model.message.SearchResultReference;
+
+
+/**
+ * An implementation of Cursor based on the underlying SearchFuture instance.
+ *
+ * Note: This is a forward only cursor hence the only valid operations are next(), get() and close()
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class EntryCursorImpl extends AbstractCursor<Entry> implements EntryCursor
+{
+ /** the search future */
+ private SearchFuture future;
+
+ /** wait time while polling for a SearchResponse */
+ private long timeout;
+
+ /** time units of timeout value */
+ private TimeUnit timeUnit;
+
+ /** a reference to hold the retrieved SearchResponse object from SearchFuture */
+ private Response response;
+
+ /** the done flag */
+ private boolean done;
+
+ /** a reference to hold the SearchResultDone response */
+ private SearchResultDone searchDoneResp;
+
+
+ /**
+ * Instantiates a new search cursor.
+ *
+ * @param future the future
+ * @param timeout the timeout
+ * @param timeUnit the time unit
+ */
+ public EntryCursorImpl( SearchFuture future, long timeout, TimeUnit timeUnit )
+ {
+ this.future = future;
+ this.timeout = timeout;
+ this.timeUnit = timeUnit;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean next() throws Exception
+ {
+ if ( done )
+ {
+ return false;
+ }
+
+ try
+ {
+ if ( future.isCancelled() )
+ {
+ response = null;
+ done = true;
+ return false;
+ }
+
+ response = future.get( timeout, timeUnit );
+ }
+ catch ( Exception e )
+ {
+ LdapException ldapException = new LdapException( LdapNetworkConnection.NO_RESPONSE_ERROR );
+ ldapException.initCause( e );
+
+ // Send an abandon request
+ if ( !future.isCancelled() )
+ {
+ future.cancel( true );
+ }
+
+ // close the cursor
+ close( ldapException );
+
+ throw ldapException;
+ }
+
+ if ( response == null )
+ {
+ future.cancel( true );
+
+ throw new LdapException( LdapNetworkConnection.TIME_OUT_ERROR );
+ }
+
+ done = ( response instanceof SearchResultDone );
+
+ if ( done )
+ {
+ searchDoneResp = ( SearchResultDone ) response;
+ response = null;
+ }
+
+ return !done;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public Entry get() throws Exception
+ {
+ if ( !available() )
+ {
+ throw new InvalidCursorPositionException();
+ }
+
+ if ( response instanceof SearchResultEntry )
+ {
+ return ((SearchResultEntry)response).getEntry();
+ }
+
+ SearchResultReference referral = ((SearchResultReference)response);
+ throw new LdapReferralException( referral.getReferral().getLdapUrls() );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public SearchResultDone getSearchResultDone()
+ {
+ return searchDoneResp;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isElementReused()
+ {
+ return true;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean available()
+ {
+ return response != null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close() throws Exception
+ {
+ close( null );
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void close( Exception cause ) throws Exception
+ {
+ if ( done )
+ {
+ super.close();
+ return;
+ }
+
+ if ( !future.isCancelled() )
+ {
+ future.cancel( true );
+ }
+
+ if ( cause != null )
+ {
+ super.close( cause );
+ }
+ else
+ {
+ super.close();
+ }
+ }
+
+
+ // rest of all operations will throw UnsupportedOperationException
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public void after( Entry element ) throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "after( Response element )" ) ) );
+ }
+
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public void afterLast() throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "afterLast()" ) ) );
+ }
+
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public void before( Entry element ) throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "before( Response element )" ) ) );
+ }
+
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public void beforeFirst() throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "beforeFirst()" ) ) );
+ }
+
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public boolean first() throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "first()" ) ) );
+ }
+
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public boolean last() throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "last()" ) ) );
+ }
+
+
+ /**
+ * This operation is not supported in SearchCursor.
+ * {@inheritDoc}
+ */
+ public boolean previous() throws Exception
+ {
+ throw new UnsupportedOperationException( I18n.err( I18n.ERR_02014_UNSUPPORTED_OPERATION, getClass().getName()
+ .concat( "." ).concat( "previous()" ) ) );
+ }
+}
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=1101258&r1=1101257&r2=1101258&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java Mon May 9 22:48:56 2011
@@ -107,7 +107,7 @@ public interface LdapConnection
* @return the add operation's response
* @throws LdapException if some error occurred
*/
- AddResponse add( Entry entry ) throws LdapException;
+ void add( Entry entry ) throws LdapException;
/**
@@ -148,7 +148,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @throws IOException if an I/O exception occurred
*/
- BindResponse bind() throws LdapException, IOException;
+ void bind() throws LdapException, IOException;
/**
@@ -160,7 +160,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @throws IOException if an I/O exception occurred
*/
- BindResponse bind( String name ) throws LdapException, IOException;
+ void bind( String name ) throws LdapException, IOException;
/**
@@ -173,7 +173,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @throws IOException if an I/O exception occurred
*/
- BindResponse bind( String name, String credentials ) throws LdapException, IOException;
+ void bind( String name, String credentials ) throws LdapException, IOException;
/**
@@ -185,7 +185,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @throws IOException if an I/O exception occurred
*/
- BindResponse bind( Dn name ) throws LdapException, IOException;
+ void bind( Dn name ) throws LdapException, IOException;
/**
@@ -198,7 +198,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @throws IOException if an I/O exception occurred
*/
- BindResponse bind( Dn name, String credentials ) throws LdapException, IOException;
+ void bind( Dn name, String credentials ) throws LdapException, IOException;
/**
@@ -296,7 +296,7 @@ public interface LdapConnection
* @return the modify operation's response
* @throws LdapException in case of modify operation failure or timeout happens
*/
- ModifyResponse modify( Dn dn, Modification... modifications ) throws LdapException;
+ void modify( Dn dn, Modification... modifications ) throws LdapException;
/**
@@ -307,7 +307,7 @@ public interface LdapConnection
* @return the modify operation's response
* @throws LdapException in case of modify operation failure or timeout happens
*/
- ModifyResponse modify( String dn, Modification... modifications ) throws LdapException;
+ void modify( String dn, Modification... modifications ) throws LdapException;
/**
@@ -318,7 +318,7 @@ public interface LdapConnection
* @return the modify operation's response
* @throws LdapException in case of modify operation failure or timeout happens
*/
- ModifyResponse modify( Entry entry, ModificationOperation modOp ) throws LdapException;
+ void modify( Entry entry, ModificationOperation modOp ) throws LdapException;
/**
@@ -341,7 +341,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @see #rename(String, String, boolean)
*/
- ModifyDnResponse rename( String entryDn, String newRdn ) throws LdapException;
+ void rename( String entryDn, String newRdn ) throws LdapException;
/**
@@ -353,7 +353,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @see #rename(org.apache.directory.shared.ldap.model.name.Dn, org.apache.directory.shared.ldap.model.name.Rdn, boolean)
*/
- ModifyDnResponse rename( Dn entryDn, Rdn newRdn ) throws LdapException;
+ void rename( Dn entryDn, Rdn newRdn ) throws LdapException;
/**
@@ -367,7 +367,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @see #rename(org.apache.directory.shared.ldap.model.name.Dn, org.apache.directory.shared.ldap.model.name.Rdn, boolean)
*/
- ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn ) throws LdapException;
+ void rename( String entryDn, String newRdn, boolean deleteOldRdn ) throws LdapException;
/**
@@ -380,7 +380,7 @@ public interface LdapConnection
* @return modifyDn operation's response
* @throws LdapException if some error occurred
*/
- ModifyDnResponse rename( Dn entryDn, Rdn newRdn, boolean deleteOldRdn ) throws LdapException;
+ void rename( Dn entryDn, Rdn newRdn, boolean deleteOldRdn ) throws LdapException;
/**
@@ -392,7 +392,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @see #move(org.apache.directory.shared.ldap.model.name.Dn, org.apache.directory.shared.ldap.model.name.Dn)
*/
- ModifyDnResponse move( String entryDn, String newSuperiorDn ) throws LdapException;
+ void move( String entryDn, String newSuperiorDn ) throws LdapException;
/**
@@ -403,7 +403,7 @@ public interface LdapConnection
* @return modifyDn operation's response
* @throws LdapException if some error occurred
*/
- ModifyDnResponse move( Dn entryDn, Dn newSuperiorDn ) throws LdapException;
+ void move( Dn entryDn, Dn newSuperiorDn ) throws LdapException;
/**
@@ -415,7 +415,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @see #moveAndRename(org.apache.directory.shared.ldap.model.name.Dn, org.apache.directory.shared.ldap.model.name.Dn, boolean)
*/
- ModifyDnResponse moveAndRename( Dn entryDn, Dn newDn ) throws LdapException;
+ void moveAndRename( Dn entryDn, Dn newDn ) throws LdapException;
/**
@@ -427,7 +427,7 @@ public interface LdapConnection
* @throws LdapException if some error occurred
* @see #moveAndRename(org.apache.directory.shared.ldap.model.name.Dn, org.apache.directory.shared.ldap.model.name.Dn, boolean)
*/
- ModifyDnResponse moveAndRename( String entryDn, String newDn ) throws LdapException;
+ void moveAndRename( String entryDn, String newDn ) throws LdapException;
/**
@@ -439,7 +439,7 @@ public interface LdapConnection
* @return modifyDn operations response
* @throws LdapException if some error occurred
*/
- ModifyDnResponse moveAndRename( Dn entryDn, Dn newDn, boolean deleteOldRdn ) throws LdapException;
+ void moveAndRename( Dn entryDn, Dn newDn, boolean deleteOldRdn ) throws LdapException;
/**
@@ -451,7 +451,7 @@ public interface LdapConnection
* @return modifyDn operation's response
* @throws LdapException if some error occurred
*/
- ModifyDnResponse moveAndRename( String entryDn, String newDn, boolean deleteOldRdn )
+ void moveAndRename( String entryDn, String newDn, boolean deleteOldRdn )
throws LdapException;
@@ -472,7 +472,7 @@ public interface LdapConnection
* @return the delete operation's response
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
- DeleteResponse delete( String dn ) throws LdapException;
+ void delete( String dn ) throws LdapException;
/**
@@ -482,7 +482,7 @@ public interface LdapConnection
* @return the delete operation's response
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
- DeleteResponse delete( Dn dn ) throws LdapException;
+ void delete( Dn dn ) throws LdapException;
/**
@@ -505,7 +505,7 @@ public interface LdapConnection
* @return compare operation's response
* @throws LdapException if some error occurred
*/
- CompareResponse compare( String dn, String attributeName, String value ) throws LdapException;
+ boolean compare( String dn, String attributeName, String value ) throws LdapException;
/**
@@ -518,7 +518,7 @@ public interface LdapConnection
* @return compare operation's response
* @throws LdapException if some error occurred
*/
- CompareResponse compare( String dn, String attributeName, byte[] value ) throws LdapException;
+ boolean compare( String dn, String attributeName, byte[] value ) throws LdapException;
/**
@@ -531,7 +531,7 @@ public interface LdapConnection
* @return compare operation's response
* @throws LdapException if some error occurred
*/
- CompareResponse compare( String dn, String attributeName, Value<?> value ) throws LdapException;
+ boolean compare( String dn, String attributeName, Value<?> value ) throws LdapException;
/**
@@ -544,7 +544,7 @@ public interface LdapConnection
* @return compare operation's response
* @throws LdapException if some error occurred
*/
- CompareResponse compare( Dn dn, String attributeName, String value ) throws LdapException;
+ boolean compare( Dn dn, String attributeName, String value ) throws LdapException;
/**
@@ -557,7 +557,7 @@ public interface LdapConnection
* @return compare operation's response
* @throws LdapException if some error occurred
*/
- CompareResponse compare( Dn dn, String attributeName, byte[] value ) throws LdapException;
+ boolean compare( Dn dn, String attributeName, byte[] value ) throws LdapException;
/**
@@ -570,7 +570,7 @@ public interface LdapConnection
* @return compare operation's response
* @throws LdapException if some error occurred
*/
- CompareResponse compare( Dn dn, String attributeName, Value<?> value ) throws LdapException;
+ boolean compare( Dn dn, String attributeName, Value<?> value ) throws LdapException;
/**
Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=1101258&r1=1101257&r2=1101258&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java (original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java Mon May 9 22:48:56 2011
@@ -20,6 +20,8 @@
package org.apache.directory.ldap.client.api;
+import static org.apache.directory.shared.ldap.model.message.AbstractResponse.processResponse;
+
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@@ -473,7 +475,7 @@ public class LdapNetworkConnection exten
messageId = new AtomicInteger();
}
-
+
//-------------------------- The methods ---------------------------//
/**
* {@inheritDoc}
@@ -653,7 +655,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public AddResponse add( Entry entry ) throws LdapException
+ public void add( Entry entry ) throws LdapException
{
if ( entry == null )
{
@@ -665,7 +667,9 @@ public class LdapNetworkConnection exten
AddRequest addRequest = new AddRequestImpl();
addRequest.setEntry( entry );
- return add( addRequest );
+ AddResponse addResponse = add( addRequest );
+
+ processResponse( addResponse );
}
@@ -888,14 +892,16 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public BindResponse bind() throws LdapException, IOException
+ public void bind() throws LdapException, IOException
{
LOG.debug( "Anonymous Bind request" );
// Create the BindRequest
BindRequest bindRequest = createBindRequest( StringConstants.EMPTY, StringConstants.EMPTY_BYTES );
- return bind( bindRequest );
+ BindResponse bindResponse = bind( bindRequest );
+
+ processResponse( bindResponse );
}
@@ -916,21 +922,23 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public BindResponse bind( String name ) throws LdapException, IOException
+ public void bind( String name ) throws LdapException, IOException
{
LOG.debug( "Bind request : {}", name );
// Create the BindRequest
BindRequest bindRequest = createBindRequest( name, StringConstants.EMPTY_BYTES );
- return bind( bindRequest );
+ BindResponse bindResponse = bind( bindRequest );
+
+ processResponse( bindResponse );
}
/**
* {@inheritDoc}
*/
- public BindResponse bind( String name, String credentials ) throws LdapException, IOException
+ public void bind( String name, String credentials ) throws LdapException, IOException
{
LOG.debug( "Bind request : {}", name );
@@ -944,7 +952,9 @@ public class LdapNetworkConnection exten
// Create the BindRequest
BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ) );
- return bind( bindRequest );
+ BindResponse bindResponse = bind( bindRequest );
+
+ processResponse( bindResponse );
}
@@ -992,21 +1002,23 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public BindResponse bind( Dn name ) throws LdapException, IOException
+ public void bind( Dn name ) throws LdapException, IOException
{
LOG.debug( "Unauthenticated authentication Bind request : {}", name );
// Create the BindRequest
BindRequest bindRequest = createBindRequest( name, StringConstants.EMPTY_BYTES, null );
- return bind( bindRequest );
+ BindResponse bindResponse = bind( bindRequest );
+
+ processResponse( bindResponse );
}
/**
* {@inheritDoc}
*/
- public BindResponse bind( Dn name, String credentials ) throws LdapException, IOException
+ public void bind( Dn name, String credentials ) throws LdapException, IOException
{
LOG.debug( "Bind request : {}", name );
@@ -1020,7 +1032,9 @@ public class LdapNetworkConnection exten
// Create the BindRequest
BindRequest bindRequest = createBindRequest( name, Strings.getBytesUtf8( credentials ), null );
- return bind( bindRequest );
+ BindResponse bindResponse = bind( bindRequest );
+
+ processResponse( bindResponse );
}
@@ -2145,7 +2159,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public ModifyResponse modify( Entry entry, ModificationOperation modOp ) throws LdapException
+ public void modify( Entry entry, ModificationOperation modOp ) throws LdapException
{
if ( entry == null )
{
@@ -2162,14 +2176,16 @@ public class LdapNetworkConnection exten
modReq.addModification( itr.next(), modOp );
}
- return modify( modReq );
+ ModifyResponse modifyResponse = modify( modReq );
+
+ processResponse( modifyResponse );
}
/**
* {@inheritDoc}
*/
- public ModifyResponse modify( Dn dn, Modification... modifications ) throws LdapException
+ public void modify( Dn dn, Modification... modifications ) throws LdapException
{
if ( dn == null )
{
@@ -2192,16 +2208,18 @@ public class LdapNetworkConnection exten
modReq.addModification( modification );
}
- return modify( modReq );
+ ModifyResponse modifyResponse = modify( modReq );
+
+ processResponse( modifyResponse );
}
/**
* {@inheritDoc}
*/
- public ModifyResponse modify( String dn, Modification... modifications ) throws LdapException
+ public void modify( String dn, Modification... modifications ) throws LdapException
{
- return modify( new Dn( dn ), modifications );
+ modify( new Dn( dn ), modifications );
}
@@ -2322,25 +2340,25 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public ModifyDnResponse rename( String entryDn, String newRdn ) throws LdapException
+ public void rename( String entryDn, String newRdn ) throws LdapException
{
- return rename( entryDn, newRdn, true );
+ rename( entryDn, newRdn, true );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse rename( Dn entryDn, Rdn newRdn ) throws LdapException
+ public void rename( Dn entryDn, Rdn newRdn ) throws LdapException
{
- return rename( entryDn, newRdn, true );
+ rename( entryDn, newRdn, true );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse rename( String entryDn, String newRdn, boolean deleteOldRdn ) throws LdapException
+ public void rename( String entryDn, String newRdn, boolean deleteOldRdn ) throws LdapException
{
if ( entryDn == null )
{
@@ -2358,7 +2376,7 @@ public class LdapNetworkConnection exten
try
{
- return rename( new Dn( entryDn ), new Rdn( newRdn ), deleteOldRdn );
+ rename( new Dn( entryDn ), new Rdn( newRdn ), deleteOldRdn );
}
catch ( LdapInvalidDnException e )
{
@@ -2371,7 +2389,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public ModifyDnResponse rename( Dn entryDn, Rdn newRdn, boolean deleteOldRdn ) throws LdapException
+ public void rename( Dn entryDn, Rdn newRdn, boolean deleteOldRdn ) throws LdapException
{
if ( entryDn == null )
{
@@ -2392,14 +2410,16 @@ public class LdapNetworkConnection exten
modDnRequest.setNewRdn( newRdn );
modDnRequest.setDeleteOldRdn( deleteOldRdn );
- return modifyDn( modDnRequest );
+ ModifyDnResponse modifyDnResponse = modifyDn( modDnRequest );
+
+ processResponse( modifyDnResponse );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse move( String entryDn, String newSuperiorDn ) throws LdapException
+ public void move( String entryDn, String newSuperiorDn ) throws LdapException
{
if ( entryDn == null )
{
@@ -2417,7 +2437,7 @@ public class LdapNetworkConnection exten
try
{
- return move( new Dn( entryDn ), new Dn( newSuperiorDn ) );
+ move( new Dn( entryDn ), new Dn( newSuperiorDn ) );
}
catch ( LdapInvalidDnException e )
{
@@ -2430,7 +2450,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public ModifyDnResponse move( Dn entryDn, Dn newSuperiorDn ) throws LdapException
+ public void move( Dn entryDn, Dn newSuperiorDn ) throws LdapException
{
if ( entryDn == null )
{
@@ -2453,32 +2473,34 @@ public class LdapNetworkConnection exten
//TODO not setting the below value is resulting in error
modDnRequest.setNewRdn( entryDn.getRdn() );
- return modifyDn( modDnRequest );
+ ModifyDnResponse modifyDnResponse = modifyDn( modDnRequest );
+
+ processResponse( modifyDnResponse );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse moveAndRename( Dn entryDn, Dn newDn ) throws LdapException
+ public void moveAndRename( Dn entryDn, Dn newDn ) throws LdapException
{
- return moveAndRename( entryDn, newDn, true );
+ moveAndRename( entryDn, newDn, true );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse moveAndRename( String entryDn, String newDn ) throws LdapException
+ public void moveAndRename( String entryDn, String newDn ) throws LdapException
{
- return moveAndRename( new Dn( entryDn ), new Dn( newDn ), true );
+ moveAndRename( new Dn( entryDn ), new Dn( newDn ), true );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse moveAndRename( Dn entryDn, Dn newDn, boolean deleteOldRdn ) throws LdapException
+ public void moveAndRename( Dn entryDn, Dn newDn, boolean deleteOldRdn ) throws LdapException
{
// Check the parameters first
if ( entryDn == null )
@@ -2508,16 +2530,18 @@ public class LdapNetworkConnection exten
modDnRequest.setNewSuperior( newDn.getParent() );
modDnRequest.setDeleteOldRdn( deleteOldRdn );
- return modifyDn( modDnRequest );
+ ModifyDnResponse modifyDnResponse = modifyDn( modDnRequest );
+
+ processResponse( modifyDnResponse );
}
/**
* {@inheritDoc}
*/
- public ModifyDnResponse moveAndRename( String entryDn, String newDn, boolean deleteOldRdn ) throws LdapException
+ public void moveAndRename( String entryDn, String newDn, boolean deleteOldRdn ) throws LdapException
{
- return moveAndRename( new Dn( entryDn ), new Dn( newDn ), true );
+ moveAndRename( new Dn( entryDn ), new Dn( newDn ), true );
}
@@ -2632,21 +2656,23 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public DeleteResponse delete( String dn ) throws LdapException
+ public void delete( String dn ) throws LdapException
{
- return delete( new Dn( dn ) );
+ delete( new Dn( dn ) );
}
/**
* {@inheritDoc}
*/
- public DeleteResponse delete( Dn dn ) throws LdapException
+ public void delete( Dn dn ) throws LdapException
{
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName( dn );
- return delete( deleteRequest );
+ DeleteResponse deleteResponse = delete( deleteRequest );
+
+ processResponse( deleteResponse );
}
@@ -2657,7 +2683,7 @@ public class LdapNetworkConnection exten
* @return operation's response
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
- public DeleteResponse deleteTree( Dn dn ) throws LdapException
+ public void deleteTree( Dn dn ) throws LdapException
{
String treeDeleteOid = "1.2.840.113556.1.4.805";
@@ -2666,7 +2692,9 @@ public class LdapNetworkConnection exten
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName( dn );
deleteRequest.addControl( new OpaqueControl( treeDeleteOid ) );
- return delete( deleteRequest );
+ DeleteResponse deleteResponse = delete( deleteRequest );
+
+ processResponse( deleteResponse );
}
else
{
@@ -2685,7 +2713,7 @@ public class LdapNetworkConnection exten
* @return operation's response
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
- public DeleteResponse deleteTree( String dn ) throws LdapException
+ public void deleteTree( String dn ) throws LdapException
{
try
{
@@ -2697,7 +2725,9 @@ public class LdapNetworkConnection exten
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName( newDn );
deleteRequest.addControl( new OpaqueControl( treeDeleteOid ) );
- return delete( deleteRequest );
+ DeleteResponse deleteResponse = delete( deleteRequest );
+
+ processResponse( deleteResponse );
}
else
{
@@ -2827,7 +2857,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public CompareResponse compare( String dn, String attributeName, String value ) throws LdapException
+ public boolean compare( String dn, String attributeName, String value ) throws LdapException
{
return compare( new Dn( dn ), attributeName, value );
}
@@ -2836,7 +2866,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public CompareResponse compare( String dn, String attributeName, byte[] value ) throws LdapException
+ public boolean compare( String dn, String attributeName, byte[] value ) throws LdapException
{
return compare( new Dn( dn ), attributeName, value );
}
@@ -2845,7 +2875,7 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public CompareResponse compare( String dn, String attributeName, Value<?> value ) throws LdapException
+ public boolean compare( String dn, String attributeName, Value<?> value ) throws LdapException
{
return compare( new Dn( dn ), attributeName, value );
}
@@ -2854,35 +2884,39 @@ public class LdapNetworkConnection exten
/**
* {@inheritDoc}
*/
- public CompareResponse compare( Dn dn, String attributeName, String value ) throws LdapException
+ public boolean compare( Dn dn, String attributeName, String value ) throws LdapException
{
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName( dn );
compareRequest.setAttributeId( attributeName );
compareRequest.setAssertionValue( value );
- return compare( compareRequest );
+ CompareResponse compareResponse = compare( compareRequest );
+
+ return processResponse( compareResponse );
}
/**
* {@inheritDoc}
*/
- public CompareResponse compare( Dn dn, String attributeName, byte[] value ) throws LdapException
+ public boolean compare( Dn dn, String attributeName, byte[] value ) throws LdapException
{
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName( dn );
compareRequest.setAttributeId( attributeName );
compareRequest.setAssertionValue( value );
- return compare( compareRequest );
+ CompareResponse compareResponse = compare( compareRequest );
+
+ return processResponse( compareResponse );
}
/**
* {@inheritDoc}
*/
- public CompareResponse compare( Dn dn, String attributeName, Value<?> value ) throws LdapException
+ public boolean compare( Dn dn, String attributeName, Value<?> value ) throws LdapException
{
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName( dn );
@@ -2897,7 +2931,9 @@ public class LdapNetworkConnection exten
compareRequest.setAssertionValue( value.getBytes() );
}
- return compare( compareRequest );
+ CompareResponse compareResponse = compare( compareRequest );
+
+ return processResponse( compareResponse );
}
Added: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java?rev=1101258&view=auto
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java (added)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/cursor/EntryCursor.java Mon May 9 22:48:56 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.shared.ldap.model.cursor;
+
+
+import org.apache.directory.shared.ldap.model.entry.Entry;
+import org.apache.directory.shared.ldap.model.message.SearchResultDone;
+
+
+/**
+ * An extension of Cursor which returns only Entry objects and includes the retrieval of the SearchResultDone.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public interface EntryCursor extends Cursor<Entry>
+{
+ /**
+ * gives the SearchResultDone message received at the end of search results
+ *
+ * @return the SearchResultDone message, null if the search operation fails for any reason
+ */
+ public SearchResultDone getSearchResultDone();
+}
Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AbstractResponse.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AbstractResponse.java?rev=1101258&r1=1101257&r2=1101258&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AbstractResponse.java (original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/message/AbstractResponse.java Mon May 9 22:48:56 2011
@@ -19,6 +19,19 @@
*/
package org.apache.directory.shared.ldap.model.message;
+import org.apache.directory.shared.ldap.model.exception.LdapAliasException;
+import org.apache.directory.shared.ldap.model.exception.LdapAttributeInUseException;
+import org.apache.directory.shared.ldap.model.exception.LdapAuthenticationException;
+import org.apache.directory.shared.ldap.model.exception.LdapContextNotEmptyException;
+import org.apache.directory.shared.ldap.model.exception.LdapEntryAlreadyExistsException;
+import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapNoPermissionException;
+import org.apache.directory.shared.ldap.model.exception.LdapNoSuchAttributeException;
+import org.apache.directory.shared.ldap.model.exception.LdapNoSuchObjectException;
+import org.apache.directory.shared.ldap.model.exception.LdapOperationException;
+import org.apache.directory.shared.ldap.model.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
+
/**
* Abstract base for a Response message.
@@ -42,4 +55,102 @@ public abstract class AbstractResponse e
{
super( id, type );
}
+
+
+ /**
+ * Process the response, throwing the associated exception if needed. If the result
+ * was SUCCESS, does not return anything but true.
+ *
+ * @param response The response to process
+ * @return For the COMPARE_TRUE or COMPARE_FALSE results, return true or false
+ * @throws LdapException The associated exception
+ */
+ public static boolean processResponse( ResultResponse response ) throws LdapException
+ {
+ LdapResult ldapResult = response.getLdapResult();
+
+ switch ( ldapResult.getResultCode() )
+ {
+ case SUCCESS :
+ return true;
+
+ case COMPARE_TRUE :
+ return true;
+
+ case COMPARE_FALSE :
+ return false;
+
+ case INVALID_CREDENTIALS :
+ LdapAuthenticationException authenticationException = new LdapAuthenticationException( ldapResult.getDiagnosticMessage() );
+ authenticationException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw authenticationException;
+
+ case UNWILLING_TO_PERFORM :
+ LdapUnwillingToPerformException unwillingToPerformException = new LdapUnwillingToPerformException( ldapResult.getDiagnosticMessage() );
+ unwillingToPerformException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw unwillingToPerformException;
+
+ case INSUFFICIENT_ACCESS_RIGHTS :
+ LdapNoPermissionException ldapNoPermissionException = new LdapNoPermissionException( ldapResult.getDiagnosticMessage() );
+ ldapNoPermissionException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapNoPermissionException;
+
+ case NOT_ALLOWED_ON_NON_LEAF :
+ LdapContextNotEmptyException ldapContextNotEmptyException = new LdapContextNotEmptyException( ldapResult.getDiagnosticMessage() );
+ ldapContextNotEmptyException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapContextNotEmptyException;
+
+ case NO_SUCH_OBJECT :
+ LdapNoSuchObjectException ldapNoSuchObjectException = new LdapNoSuchObjectException( ldapResult.getDiagnosticMessage() );
+ ldapNoSuchObjectException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapNoSuchObjectException;
+
+ case NO_SUCH_ATTRIBUTE :
+ LdapNoSuchAttributeException ldapNoSuchAttributeException = new LdapNoSuchAttributeException( ldapResult.getDiagnosticMessage() );
+ ldapNoSuchAttributeException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapNoSuchAttributeException;
+
+ case ATTRIBUTE_OR_VALUE_EXISTS :
+ LdapAttributeInUseException ldapAttributeInUseException = new LdapAttributeInUseException( ldapResult.getDiagnosticMessage() );
+ ldapAttributeInUseException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapAttributeInUseException;
+
+ case ENTRY_ALREADY_EXISTS :
+ LdapEntryAlreadyExistsException ldapEntryAlreadyExistsException = new LdapEntryAlreadyExistsException( ldapResult.getDiagnosticMessage() );
+ ldapEntryAlreadyExistsException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapEntryAlreadyExistsException;
+
+ case OBJECT_CLASS_VIOLATION :
+ case NOT_ALLOWED_ON_RDN :
+ case OBJECT_CLASS_MODS_PROHIBITED :
+ LdapSchemaViolationException ldapSchemaViolationException =
+ new LdapSchemaViolationException( ldapResult.getResultCode() , ldapResult.getDiagnosticMessage() );
+ ldapSchemaViolationException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapSchemaViolationException;
+
+ case ALIAS_PROBLEM :
+ LdapAliasException ldapAliasException = new LdapAliasException( ldapResult.getDiagnosticMessage() );
+ ldapAliasException.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw ldapAliasException;
+
+ case REFERRAL :
+ // TODO
+
+ default :
+ LdapOperationException exception = new LdapOperationException( ldapResult.getResultCode(), ldapResult.getDiagnosticMessage() );
+ exception.setResolvedDn( ldapResult.getMatchedDn() );
+
+ throw exception;
+ }
+ }
}