|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--netscape.ldap.LDAPControl | +--netscape.ldap.controls.LDAPVirtualListControl
Represents control data for returning paged results from a search. Example of usage, with JFC:
// Call this to initialize the list box, whenever the search
// conditions change.
// "filter" may be "objectclass=person", for example
void initListBox( String host, int port, String base, String filter ) {
// Create list box if not already done
if ( _dataList == null ) {
_dataList = new JList();
JScrollPane scrollPane = new JScrollPane(_dataList);
add( scrollPane );
}
// Create a virtual data model
vlistModel model = new vlistModel( host, port, base, filter );
// Keep a buffer of one page before and one after
model.setPageSize( getScrollVisibleSize() );
_dataList.setModel( model );
}
// Data model to supply buffer list data
class vlistModel extends AbstractListModel {
vlistModel( String host, int port, String base, String filter ) {
_base = base;
_filter = filter;
// Connect to the server
try {
_ldc = new LDAPConnection();
System.out.println( "Connecting to " + host +
":" + port );
_ldc.connect( host, port );
} catch ( LDAPException e ) {
System.out.println( e );
_ldc = null;
}
}
// Called by JList to get virtual list size
public int getSize() {
if ( !_initialized ) {
_initialized = true;
_pageControls = new LDAPControl[2];
// Paged results also require a sort control
_pageControls[0] =
new LDAPSortControl( new LDAPSortKey("cn"),
true );
// Do an initial search to get the virtual list size
// Keep one page before and one page after the start
_beforeCount = _pageSize;
_afterCount = _pageSize;
// Create the initial paged results control
LDAPVirtualListControl cont =
new LDAPVirtualListControl( "A",
_beforeCount,
_afterCount );
_pageControls[1] = cont;
_vlc = (LDAPVirtualListControl)_pageControls[1];
getPage( 0 );
}
return _size;
}
// Get a page starting at first (although we may also fetch
// some preceding entries)
boolean getPage( int first ) {
_vlc.setRange( first, _beforeCount, _afterCount );
return getPage();
}
boolean getEntries() {
// Specify necessary controls for vlv
if ( _pageControls != null ) {
try {
_ldc.setOption( _ldc.SERVERCONTROLS, _pageControls );
} catch ( LDAPException e ) {
System.out.println( e + ", setting vlv control" );
}
}
// Empty the buffer
_entries.removeAllElements();
// Do a search
try {
String[] attrs = { "cn" };
LDAPSearchResults result =
_ldc.search( _base,
LDAPConnection.SCOPE_SUB,
_filter,
attrs, false );
while ( result.hasMoreElements() ) {
LDAPEntry entry = (LDAPEntry)result.nextElement();
LDAPAttribute attr = entry.getAttribute( attrs[0] );
if ( attr != null ) {
Enumeration en = attr.getStringValues();
while( en.hasMoreElements() ) {
String name = (String)en.nextElement();
_entries.addElement( name );
}
}
}
} catch ( LDAPException e ) {
System.out.println( e + ", searching" );
return false;
}
return true;
}
// Fetch a buffer
boolean getPage() {
// Get the actual entries
if ( !getEntries() )
return false;
// Check if we have a control returned
LDAPControl[] c = _ldc.getResponseControls();
LDAPVirtualListResponse nextCont = null;
for ( int i = 0; i < c.length; i++ ) {
if ( c[i] instanceof LDAPVirtualListResponse ) {
nextCont = (LDAPVirtualListResponse)c[i];
break;
}
}
if ( nextCont != null ) {
_selectedIndex = nextCont.getFirstPosition() - 1;
_top = Math.max( 0, _selectedIndex - _beforeCount );
// Now we know the total size of the virtual list box
_size = nextCont.getContentCount();
_vlc.setListSize( _size );
} else {
System.out.println( "Null response control" );
}
return true;
}
// Called by JList to fetch data to paint a single list item
public Object getElementAt(int index) {
if ( (index < _top) || (index >= _top + _entries.size()) ) {
getPage( index );
}
int offset = index - _top;
if ( (offset < 0) || (offset >= _entries.size()) )
return new String( "No entry at " + index );
else
return _entries.elementAt( offset );
}
// Called by application to find out the virutal selected index
public int getSelectedIndex() {
return _selectedIndex;
}
// Called by application to find out the top of the buffer
public int getFirstIndex() {
return _top;
}
public void setPageSize( int size ) {
_pageSize = size;
}
Vector _entries = new Vector();
protected boolean _initialized = false;
private int _top = 0;
protected int _beforeCount;
protected int _afterCount;
private int _pageSize = 10;
private int _selectedIndex = 0;
protected LDAPControl[] _pageControls = null;
protected LDAPVirtualListControl _vlc = null;
protected int _size = -1;
private String _base;
private String _filter;
private LDAPConnection _ldc;
}
VirtualListViewRequest ::= SEQUENCE { beforeCount INTEGER (0 .. maxInt), afterCount INTEGER (0 .. maxInt), CHOICE { byIndex [0] SEQUENCE { index INTEGER, contentCount INTEGER } byFilter [1] jumpTo Substring }, contextID OCTET STRING OPTIONAL }
Field Summary | |
static java.lang.String |
VIRTUALLIST
|
Fields inherited from class netscape.ldap.LDAPControl |
m_critical,
m_value,
MANAGEDSAIT,
PWEXPIRED,
PWEXPIRING |
Constructor Summary | |
LDAPVirtualListControl(int startIndex,
int beforeCount,
int afterCount,
int contentCount)
Constructs a new LDAPVirtualListControl object. |
|
LDAPVirtualListControl(int startIndex,
int beforeCount,
int afterCount,
int contentCount,
java.lang.String context)
|
|
LDAPVirtualListControl(java.lang.String jumpTo,
int beforeCount,
int afterCount)
Constructs a new LDAPVirtualListControl object. |
|
LDAPVirtualListControl(java.lang.String jumpTo,
int beforeCount,
int afterCount,
java.lang.String context)
|
Method Summary | |
int |
getAfterCount()
Gets the number of results after the top/center to return per page. |
int |
getBeforeCount()
Gets the number of results before the top/center to return per page. |
java.lang.String |
getContext()
Gets the optional context cookie. |
int |
getIndex()
Gets the size of the virtual result set. |
int |
getListSize()
Gets the size of the virtual result set. |
void |
setContext(java.lang.String context)
Sets the optional context cookie. |
void |
setListSize(int listSize)
Sets the size of the virtual result set. |
void |
setRange(int startIndex,
int beforeCount,
int afterCount)
Sets the starting index, and the number of entries before and after to return. |
void |
setRange(java.lang.String jumpTo,
int beforeCount,
int afterCount)
Sets the search expression, and the number of entries before and after to return. |
java.lang.String |
toString()
Return a string representation of the control for debugging |
Methods inherited from class netscape.ldap.LDAPControl |
clone,
createControl,
flattenBER,
getID,
getValue,
isCritical,
lookupControlClass,
newInstance,
register |
Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public static final java.lang.String VIRTUALLIST
Constructor Detail |
public LDAPVirtualListControl(java.lang.String jumpTo, int beforeCount, int afterCount)
LDAPVirtualListControl
object. Use this
constructor on an initial search operation, specifying the first
entry to be matched, or the initial part of it.jumpTo
- an LDAP search expression defining the result setbeforeCount
- the number of results before the top/center to
return per pageafterCount
- the number of results after the top/center to
return per pageLDAPControl
public LDAPVirtualListControl(java.lang.String jumpTo, int beforeCount, int afterCount, java.lang.String context)
public LDAPVirtualListControl(int startIndex, int beforeCount, int afterCount, int contentCount)
LDAPVirtualListControl
object. Use this
constructor on a subsquent search operation, after we know the
size of the virtual list, to fetch a subset.startIndex
- the index into the virtual list of an entry to
returnbeforeCount
- the number of results before the top/center to
return per pageafterCount
- the number of results after the top/center to
return per pageLDAPControl
public LDAPVirtualListControl(int startIndex, int beforeCount, int afterCount, int contentCount, java.lang.String context)
Method Detail |
public void setRange(int startIndex, int beforeCount, int afterCount)
startIndex
- the index into the virtual list of an entry to
returnbeforeCount
- the number of results before startIndex to
return per pageafterCount
- the number of results after startIndex to
return per pageLDAPControl
public void setRange(java.lang.String jumpTo, int beforeCount, int afterCount)
jumpTo
- an LDAP search expression defining the result set
return.beforeCount
- the number of results before startIndex to
return per pageafterCount
- the number of results after startIndex to
return per pageLDAPControl
public int getIndex()
public int getListSize()
public void setListSize(int listSize)
listSize
- the virtual result set sizepublic int getBeforeCount()
public int getAfterCount()
public java.lang.String getContext()
public void setContext(java.lang.String context)
context
- the optional context cookiepublic java.lang.String toString()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |