org.apache.directory.server.core.filtering
Class BaseEntryFilteringCursor

java.lang.Object
  extended by org.apache.directory.server.core.filtering.BaseEntryFilteringCursor
All Implemented Interfaces:
java.lang.Iterable<ClonedServerEntry>, Cursor<ClonedServerEntry>, EntryFilteringCursor

public class BaseEntryFilteringCursor
extends java.lang.Object
implements EntryFilteringCursor

A Cursor which uses a list of filters to selectively return entries and/or modify the contents of entries. Uses lazy pre-fetching on positioning operations which means adding filters after creation will not miss candidate entries.

Version:
$Rev$, $Date$
Author:
Apache Directory Project

Constructor Summary
BaseEntryFilteringCursor(Cursor<ServerEntry> wrapped, SearchingOperationContext operationContext)
          Creates a new entry filtering Cursor over an existing Cursor using a no filter initially: more can be added later after creation.
BaseEntryFilteringCursor(Cursor<ServerEntry> wrapped, SearchingOperationContext operationContext, EntryFilter filter)
          Creates a new entry filtering Cursor over an existing Cursor using a single filter initially: more can be added later after creation.
BaseEntryFilteringCursor(Cursor<ServerEntry> wrapped, SearchingOperationContext operationContext, java.util.List<EntryFilter> filters)
          Creates a new entry filtering Cursor over an existing Cursor using a list of filters initially: more can be added later after creation.
 
Method Summary
 boolean addEntryFilter(EntryFilter filter)
          Adds an entry filter to this BaseEntryFilteringCursor at the very end of the filter list.
 void after(ClonedServerEntry element)
          Prepares this Cursor, so a subsequent call to Cursor#previous() with a true return value, will have positioned the Cursor on a dataset element equal to or less than the element argument but not greater.
 void afterLast()
          Positions this Curser after the last element.
 boolean available()
          Determines whether or not a call to get() will succeed.
 void before(ClonedServerEntry element)
          Prepares this Cursor, so a subsequent call to Cursor#next() with a true return value, will have positioned the Cursor on a dataset element equal to or less than the element argument but not greater.
 void beforeFirst()
          Positions this Curser before the first element.
 void close()
          Closes this Cursor and frees any resources it my have allocated.
 void close(java.lang.Exception reason)
          Closes this Cursor and frees any resources it my have allocated.
 boolean first()
          Positions this Curser at the first element.
 ClonedServerEntry get()
          Gets the object at the current position.
 java.util.List<EntryFilter> getEntryFilters()
          Gets an unmodifiable list of EntryFilters applied.
 SearchingOperationContext getOperationContext()
           
 boolean isAbandoned()
          Gets whether or not this BaseEntryFilteringCursor has been abandoned.
 boolean isClosed()
          Checks if this Curser is closed.
 boolean isElementReused()
          Gets whether or not this Cursor will return the same element object instance on get() operations for any position of this Cursor.
 java.util.Iterator<ClonedServerEntry> iterator()
           
 boolean last()
          Positions this Curser at the last element.
 boolean next()
          Advances this Cursor to the next position.
 boolean previous()
          Advances this Cursor to the previous position.
 boolean removeEntryFilter(EntryFilter filter)
          Removes an entry filter to this BaseEntryFilteringCursor at the very end of the filter list.
 void setAbandoned(boolean abandoned)
          Sets whether this BaseEntryFilteringCursor has been abandoned.
 void setClosureMonitor(ClosureMonitor monitor)
          Sets a non-null closure monitor to associate with this Cursor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseEntryFilteringCursor

public BaseEntryFilteringCursor(Cursor<ServerEntry> wrapped,
                                SearchingOperationContext operationContext,
                                EntryFilter filter)
Creates a new entry filtering Cursor over an existing Cursor using a single filter initially: more can be added later after creation.

Parameters:
wrapped - the underlying wrapped Cursor whose entries are filtered
searchControls - the controls of search that created this Cursor
invocation - the search operation invocation creating this Cursor
filter - a single filter to be used

BaseEntryFilteringCursor

public BaseEntryFilteringCursor(Cursor<ServerEntry> wrapped,
                                SearchingOperationContext operationContext)
Creates a new entry filtering Cursor over an existing Cursor using a no filter initially: more can be added later after creation.

Parameters:
wrapped - the underlying wrapped Cursor whose entries are filtered
searchControls - the controls of search that created this Cursor
invocation - the search operation invocation creating this Cursor
filter - a single filter to be used

BaseEntryFilteringCursor

public BaseEntryFilteringCursor(Cursor<ServerEntry> wrapped,
                                SearchingOperationContext operationContext,
                                java.util.List<EntryFilter> filters)
Creates a new entry filtering Cursor over an existing Cursor using a list of filters initially: more can be added later after creation.

Parameters:
wrapped - the underlying wrapped Cursor whose entries are filtered
operationContext - the operation context that created this Cursor
invocation - the search operation invocation creating this Cursor
filters - a list of filters to be used
Method Detail

isAbandoned

public boolean isAbandoned()
Description copied from interface: EntryFilteringCursor
Gets whether or not this BaseEntryFilteringCursor has been abandoned.

Specified by:
isAbandoned in interface EntryFilteringCursor
Returns:
true if abandoned, false if not

setAbandoned

public void setAbandoned(boolean abandoned)
Description copied from interface: EntryFilteringCursor
Sets whether this BaseEntryFilteringCursor has been abandoned.

Specified by:
setAbandoned in interface EntryFilteringCursor
Parameters:
abandoned - true if abandoned, false if not

addEntryFilter

public boolean addEntryFilter(EntryFilter filter)
Description copied from interface: EntryFilteringCursor
Adds an entry filter to this BaseEntryFilteringCursor at the very end of the filter list. EntryFilters are applied in the order of addition.

Specified by:
addEntryFilter in interface EntryFilteringCursor
Parameters:
filter - a filter to apply to the entries
Returns:
the result of List.add(Object)

removeEntryFilter

public boolean removeEntryFilter(EntryFilter filter)
Description copied from interface: EntryFilteringCursor
Removes an entry filter to this BaseEntryFilteringCursor at the very end of the filter list.

Specified by:
removeEntryFilter in interface EntryFilteringCursor
Parameters:
filter - a filter to remove from the filter list
Returns:
the result of List.remove(Object)

getEntryFilters

public java.util.List<EntryFilter> getEntryFilters()
Description copied from interface: EntryFilteringCursor
Gets an unmodifiable list of EntryFilters applied.

Specified by:
getEntryFilters in interface EntryFilteringCursor
Returns:
an unmodifiable list of EntryFilters applied

getOperationContext

public SearchingOperationContext getOperationContext()
Specified by:
getOperationContext in interface EntryFilteringCursor
Returns:
the operationContext

after

public void after(ClonedServerEntry element)
           throws java.lang.Exception
Description copied from interface: Cursor
Prepares this Cursor, so a subsequent call to Cursor#previous() with a true return value, will have positioned the Cursor on a dataset element equal to or less than the element argument but not greater. A call to Cursor#next() with a true return value will position the Cursor on a dataset element greater than the argument. If Cursor#next() returns false then the Cursor is past the last element and so all values in the dataset are less than or equal to the argument. If Cursor#previous() returns false then the Cursor is positioned before the first element and all elements in the dataset are greater than the argument.

Specified by:
after in interface Cursor<ClonedServerEntry>
Parameters:
element - the element to be positioned after
Throws:
java.lang.Exception - if there are problems positioning this cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

afterLast

public void afterLast()
               throws java.lang.Exception
Description copied from interface: Cursor
Positions this Curser after the last element.

Specified by:
afterLast in interface Cursor<ClonedServerEntry>
Throws:
java.lang.Exception - if there are problems positioning this Cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

available

public boolean available()
Description copied from interface: Cursor
Determines whether or not a call to get() will succeed.

Specified by:
available in interface Cursor<ClonedServerEntry>
Returns:
true if the cursor is valid get() will succeed, false otherwise

before

public void before(ClonedServerEntry element)
            throws java.lang.Exception
Description copied from interface: Cursor
Prepares this Cursor, so a subsequent call to Cursor#next() with a true return value, will have positioned the Cursor on a dataset element equal to or less than the element argument but not greater. A call to Cursor#previous() with a true return value will position the Cursor on a dataset element less than the argument. If Cursor#next() returns false then the Cursor is past the last element and so all values in the dataset are less than the argument. If Cursor#previous() returns false then the Cursor is positioned before the first element and all elements in the dataset are greater than the argument.

Specified by:
before in interface Cursor<ClonedServerEntry>
Parameters:
element - the element to be positioned before
Throws:
java.lang.Exception - with problems accessing the underlying btree
java.lang.UnsupportedOperationException - if this method is not supported

beforeFirst

public void beforeFirst()
                 throws java.lang.Exception
Description copied from interface: Cursor
Positions this Curser before the first element.

Specified by:
beforeFirst in interface Cursor<ClonedServerEntry>
Throws:
java.lang.Exception - if there are problems positioning this cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

close

public void close()
           throws java.lang.Exception
Description copied from interface: Cursor
Closes this Cursor and frees any resources it my have allocated. Repeated calls to this method after this Cursor has already been called should not fail with exceptions.

Specified by:
close in interface Cursor<ClonedServerEntry>
Throws:
java.lang.Exception - if for some reason this Cursor could not be closed

close

public void close(java.lang.Exception reason)
           throws java.lang.Exception
Description copied from interface: Cursor
Closes this Cursor and frees any resources it my have allocated. Repeated calls to this method after this Cursor has already been called should not fail with exceptions. The reason argument is the Exception instance thrown instead of the standard CursorClosedException.

Specified by:
close in interface Cursor<ClonedServerEntry>
Parameters:
reason - exception thrown when this Cursor is accessed after close
Throws:
java.lang.Exception - if for some reason this Cursor could not be closed

setClosureMonitor

public final void setClosureMonitor(ClosureMonitor monitor)
Description copied from interface: Cursor
Sets a non-null closure monitor to associate with this Cursor.

Specified by:
setClosureMonitor in interface Cursor<ClonedServerEntry>
Parameters:
monitor - the monitor to use for detecting Cursor close events

first

public boolean first()
              throws java.lang.Exception
Description copied from interface: Cursor
Positions this Curser at the first element.

Specified by:
first in interface Cursor<ClonedServerEntry>
Returns:
true if the position has been successfully changed to the first element, false otherwise
Throws:
java.lang.Exception - if there are problems positioning this Cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

get

public ClonedServerEntry get()
                      throws java.lang.Exception
Description copied from interface: Cursor
Gets the object at the current position. Cursor implementations may choose to reuse element objects by re-populating them on advances instead of creating new objects on each advance.

Specified by:
get in interface Cursor<ClonedServerEntry>
Returns:
the object at the current position
Throws:
java.lang.Exception - if the object at this Cursor's current position cannot be retrieved, or if this Cursor is closed

isClosed

public boolean isClosed()
                 throws java.lang.Exception
Description copied from interface: Cursor
Checks if this Curser is closed. Calls to this operation should not fail with exceptions if and only if the cursor is in the closed state.

Specified by:
isClosed in interface Cursor<ClonedServerEntry>
Returns:
true if this Cursor is closed, false otherwise
Throws:
java.lang.Exception - if there are problems determining the cursor's closed state
java.lang.UnsupportedOperationException - if this method is not supported

isElementReused

public boolean isElementReused()
Description copied from interface: Cursor
Gets whether or not this Cursor will return the same element object instance on get() operations for any position of this Cursor. Some Cursor implementations may reuse the same element copying values into it for every position rather than creating and emiting new element objects on each advance. Some Cursor implementations may return different elements for each position yet the same element instance is returned for the same position. In these cases this method should return true.

Specified by:
isElementReused in interface Cursor<ClonedServerEntry>
Returns:
true if elements are reused by this Cursor

last

public boolean last()
             throws java.lang.Exception
Description copied from interface: Cursor
Positions this Curser at the last element.

Specified by:
last in interface Cursor<ClonedServerEntry>
Returns:
true if the position has been successfully changed to the last element, false otherwise
Throws:
java.lang.Exception - if there are problems positioning this Cursor or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

next

public boolean next()
             throws java.lang.Exception
Description copied from interface: Cursor
Advances this Cursor to the next position. If called before explicitly positioning this Cursor, the position is presumed to be before the first element and this method moves the cursor forward to the first element.

Specified by:
next in interface Cursor<ClonedServerEntry>
Returns:
true if the advance succeeded, false otherwise
Throws:
java.lang.Exception - if there are problems advancing to this Cursor to the next position, or if this Cursor is closed
java.lang.UnsupportedOperationException - if this method is not supported

previous

public boolean previous()
                 throws java.lang.Exception
Description copied from interface: Cursor
Advances this Cursor to the previous position. If called before explicitly positioning this Cursor, the position is presumed to be after the last element and this method moves the cursor back to the last element.

Specified by:
previous in interface Cursor<ClonedServerEntry>
Returns:
true if the advance succeeded, false otherwise
Throws:
java.lang.Exception - if there are problems advancing to the next position
java.lang.UnsupportedOperationException - if this method is not supported

iterator

public java.util.Iterator<ClonedServerEntry> iterator()
Specified by:
iterator in interface java.lang.Iterable<ClonedServerEntry>


Copyright © 2003-2009 Apache Software Foundation. All Rights Reserved.