|
Spring LDAP Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.ldap.core.DirContextAdapter
public class DirContextAdapter
Adapter that implements the interesting methods of the DirContext interface.
In particular it contains utility methods for getting and setting attributes.
Using the
DefaultDirObjectFactory
in your
ContextSource
(which is the default) you will receive instances
of this class from searches and lookups. This can be particularly useful when
updating data, since this class implements
AttributeModificationsAware
, providing a
getModificationItems()
method. When in update mode, an object of
this class keeps track of the changes made to its attributes, making them
available as an array of ModificationItem
objects, suitable as
input to LdapTemplate.modifyAttributes(DirContextOperations)
.
Note that this is not a complete implementation of DirContext. Several
methods are not relevant for the intended usage of this class, so they
throw UnsupportOperationException.
setAttributeValue(String, Object)
,
setAttributeValues(String, Object[])
,
getStringAttribute(String)
,
getStringAttributes(String)
,
getObjectAttribute(String)
,
addAttributeValue(String, Object)
,
removeAttributeValue(String, Object)
,
setUpdateMode(boolean)
,
isUpdateMode()
Field Summary |
---|
Fields inherited from interface javax.naming.directory.DirContext |
---|
ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, REPLACE_ATTRIBUTE |
Fields inherited from interface javax.naming.Context |
---|
APPLET, AUTHORITATIVE, BATCHSIZE, DNS_URL, INITIAL_CONTEXT_FACTORY, LANGUAGE, OBJECT_FACTORIES, PROVIDER_URL, REFERRAL, SECURITY_AUTHENTICATION, SECURITY_CREDENTIALS, SECURITY_PRINCIPAL, SECURITY_PROTOCOL, STATE_FACTORIES, URL_PKG_PREFIXES |
Constructor Summary | |
---|---|
|
DirContextAdapter()
Default constructor. |
|
DirContextAdapter(Attributes attrs,
Name dn)
Create a new adapter from the supplied attributes and dn. |
|
DirContextAdapter(Attributes attrs,
Name dn,
Name base)
Create a new adapter from the supplied attributes, dn, and base. |
|
DirContextAdapter(Attributes attrs,
Name dn,
Name base,
String referralUrl)
Create a new adapter from the supplied attributes, dn, base, and referral url. |
protected |
DirContextAdapter(DirContextAdapter master)
Constructor for cloning an existing adapter. |
|
DirContextAdapter(Name dn)
Create a new adapter from the supplied dn. |
|
DirContextAdapter(String dnString)
Create a new DirContextAdapter from the supplied DN String. |
Method Summary | |
---|---|
void |
addAttributeValue(String name,
Object value)
Add a value to the Attribute with the specified name. |
void |
addAttributeValue(String name,
Object value,
boolean addIfDuplicateExists)
Add a value to the Attribute with the specified name. |
Object |
addToEnvironment(String propName,
Object propVal)
|
boolean |
attributeExists(String name)
Check if an Object attribute exists, regardless of whether it has a value or not. |
void |
bind(Name name,
Object obj)
|
void |
bind(Name name,
Object obj,
Attributes attrs)
|
void |
bind(String name,
Object obj)
|
void |
bind(String name,
Object obj,
Attributes attrs)
|
void |
close()
|
Name |
composeName(Name name,
Name prefix)
|
String |
composeName(String name,
String prefix)
|
Context |
createSubcontext(Name name)
|
DirContext |
createSubcontext(Name name,
Attributes attrs)
|
Context |
createSubcontext(String name)
|
DirContext |
createSubcontext(String name,
Attributes attrs)
|
void |
destroySubcontext(Name name)
|
void |
destroySubcontext(String name)
|
boolean |
equals(Object obj)
|
protected boolean |
exists(Attribute attr)
Checks if an entry has a specific attribute. |
protected boolean |
exists(String attrId)
Checks if the attribute exists in this entry, either it was read or it has been added and update() has been called. |
Attributes |
getAttributes()
Get all attributes. |
Attributes |
getAttributes(Name name)
|
Attributes |
getAttributes(Name name,
String[] attrIds)
|
Attributes |
getAttributes(String name)
|
Attributes |
getAttributes(String name,
String[] attrIds)
|
SortedSet |
getAttributeSortedStringSet(String name)
Get all String values of the attribute as a SortedSet . |
Name |
getDn()
Returns the DN relative to the base path. |
Hashtable |
getEnvironment()
|
ModificationItem[] |
getModificationItems()
Creates an array of which attributes have been changed, added or removed since the initialization of this object. |
String |
getNameInNamespace()
|
NameParser |
getNameParser(Name name)
|
NameParser |
getNameParser(String name)
|
String[] |
getNamesOfModifiedAttributes()
Creates a String array of the names of the attributes which have been changed. |
Object |
getObjectAttribute(String name)
Get the value of an Object attribute. |
Object[] |
getObjectAttributes(String name)
Get all values of an Object attribute. |
String |
getReferralUrl()
If this instance results from a referral, this method returns the url of the referred server. |
DirContext |
getSchema(Name name)
|
DirContext |
getSchema(String name)
|
DirContext |
getSchemaClassDefinition(Name name)
|
DirContext |
getSchemaClassDefinition(String name)
|
String |
getStringAttribute(String name)
Get the value of a String attribute. |
String[] |
getStringAttributes(String name)
Get all values of a String attribute. |
int |
hashCode()
|
boolean |
isReferral()
Checks whether this instance results from a referral. |
boolean |
isUpdateMode()
Gets the update mode. |
NamingEnumeration |
list(Name name)
|
NamingEnumeration |
list(String name)
|
NamingEnumeration |
listBindings(Name name)
|
NamingEnumeration |
listBindings(String name)
|
Object |
lookup(Name name)
|
Object |
lookup(String name)
|
Object |
lookupLink(Name name)
|
Object |
lookupLink(String name)
|
void |
modifyAttributes(Name name,
int modOp,
Attributes attrs)
|
void |
modifyAttributes(Name name,
ModificationItem[] mods)
|
void |
modifyAttributes(String name,
int modOp,
Attributes attrs)
|
void |
modifyAttributes(String name,
ModificationItem[] mods)
|
void |
rebind(Name name,
Object obj)
|
void |
rebind(Name name,
Object obj,
Attributes attrs)
|
void |
rebind(String name,
Object obj)
|
void |
rebind(String name,
Object obj,
Attributes attrs)
|
void |
removeAttributeValue(String name,
Object value)
Remove a value from the Attribute with the specified name. |
Object |
removeFromEnvironment(String propName)
|
void |
rename(Name oldName,
Name newName)
|
void |
rename(String oldName,
String newName)
|
NamingEnumeration |
search(Name name,
Attributes matchingAttributes)
|
NamingEnumeration |
search(Name name,
Attributes matchingAttributes,
String[] attributesToReturn)
|
NamingEnumeration |
search(Name name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
|
NamingEnumeration |
search(Name name,
String filter,
SearchControls cons)
|
NamingEnumeration |
search(String name,
Attributes matchingAttributes)
|
NamingEnumeration |
search(String name,
Attributes matchingAttributes,
String[] attributesToReturn)
|
NamingEnumeration |
search(String name,
String filterExpr,
Object[] filterArgs,
SearchControls cons)
|
NamingEnumeration |
search(String name,
String filter,
SearchControls cons)
|
void |
setAttribute(Attribute attribute)
Set the supplied attribute. |
void |
setAttributeValue(String name,
Object value)
Set the with the name name to the value . |
void |
setAttributeValues(String name,
Object[] values)
Sets a multivalue attribute, disregarding the order of the values. |
void |
setAttributeValues(String name,
Object[] values,
boolean orderMatters)
Sets a multivalue attribute. |
void |
setDn(Name dn)
Set the dn of this entry. |
void |
setUpdateMode(boolean mode)
Sets the update mode. |
String |
toString()
|
void |
unbind(Name name)
|
void |
unbind(String name)
|
void |
update()
Update the attributes.This will mean that the getters ( getStringAttribute methods) will return the updated values,
and the modifications will be forgotten (i.e. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public DirContextAdapter()
public DirContextAdapter(String dnString)
dnString
- the DN string. Must be syntactically correct, or an
exception will be thrown.public DirContextAdapter(Name dn)
dn
- the dn.public DirContextAdapter(Attributes attrs, Name dn)
attrs
- the attributes.dn
- the dn.public DirContextAdapter(Attributes attrs, Name dn, Name base)
attrs
- the attributes.dn
- the dn.base
- the base name.public DirContextAdapter(Attributes attrs, Name dn, Name base, String referralUrl)
attrs
- the attributes.dn
- the dn.base
- the base.referralUrl
- the referral url (if this instance results from a
referral).protected DirContextAdapter(DirContextAdapter master)
master
- The adapter to be copied.Method Detail |
---|
public void setUpdateMode(boolean mode)
false
for a
new entry and true
for an existing entry that is being
updated.
mode
- Update mode.public boolean isUpdateMode()
DirContextOperations
AttributeModificationsAware.getModificationItems()
. The update
mode should be true
for a new entry and true
for an existing entry that is being updated.
isUpdateMode
in interface DirContextOperations
public String[] getNamesOfModifiedAttributes()
DirContextOperations
getNamesOfModifiedAttributes
in interface DirContextOperations
public ModificationItem[] getModificationItems()
AttributeModificationsAware
getModificationItems
in interface AttributeModificationsAware
protected final boolean exists(Attribute attr)
attr
- the attribute to check.
protected final boolean exists(String attrId)
attrId
- id of the attribute to check.
public String getStringAttribute(String name)
DirContextOperations
null
will be returned.
getStringAttribute
in interface DirContextOperations
name
- name of the attribute.
null
if
the attribute doesn't exist or if it exists but with no value.public Object getObjectAttribute(String name)
DirContextOperations
null
will be returned.
getObjectAttribute
in interface DirContextOperations
name
- name of the attribute.
null
if the attribute doesn't exist or if it exists but with
no value.public boolean attributeExists(String name)
DirContextOperations
attributeExists
in interface DirContextOperations
name
- name of the attribute
true
if the attribute exists, false
otherwisepublic void setAttributeValue(String name, Object value)
DirContextOperations
name
to the value
.
setAttributeValue
in interface DirContextOperations
name
- name of the attribute.value
- value to set the attribute to.public void addAttributeValue(String name, Object value)
DirContextOperations
addAttributeValue
in interface DirContextOperations
name
- the name of the Attribute to which the specified value should
be added.value
- the Attribute value to add.public void addAttributeValue(String name, Object value, boolean addIfDuplicateExists)
DirContextOperations
addIfDuplicateExists
parameter controls the handling of duplicates. It false
,
this method makes sure that the there will be no duplicates of an added
value - it the value exists it will not be added again.
addAttributeValue
in interface DirContextOperations
name
- the name of the Attribute to which the specified value should
be added.value
- the Attribute value to add.addIfDuplicateExists
- true
will add the value
regardless of whether there is an identical value already, allowing for
duplicate attribute values; false
will not add the value if
it already exists.public void removeAttributeValue(String name, Object value)
DirContextOperations
removeAttributeValue
in interface DirContextOperations
name
- the name of the Attribute from which the specified value
should be removed.value
- the value to remove.public void setAttributeValues(String name, Object[] values)
DirContextOperations
setAttributeValues
in interface DirContextOperations
name
- The id of the attribute.values
- Attribute values.public void setAttributeValues(String name, Object[] values, boolean orderMatters)
DirContextOperations
setAttributeValues
in interface DirContextOperations
name
- The id of the attribute.values
- Attribute values.orderMatters
- If true
, it will be changed even if data
was just reordered.public void update()
DirContextOperations
getStringAttribute
methods) will return the updated values,
and the modifications will be forgotten (i.e.
AttributeModificationsAware.getModificationItems()
will return an
empty array.
update
in interface DirContextOperations
public String[] getStringAttributes(String name)
DirContextOperations
getStringAttributes
in interface DirContextOperations
name
- name of the attribute.
null
otherwise.public Object[] getObjectAttributes(String name)
DirContextOperations
getObjectAttributes
in interface DirContextOperations
name
- name of the attribute.
null
otherwise.public SortedSet getAttributeSortedStringSet(String name)
DirContextOperations
SortedSet
.
getAttributeSortedStringSet
in interface DirContextOperations
name
- name of the attribute.
SortedSet
containing all values of the attribute,
or null
if the attribute does not exist.public void setAttribute(Attribute attribute)
attribute
- the attribute to set.public Attributes getAttributes()
getAttributes
in interface DirContextOperations
public Attributes getAttributes(Name name) throws NamingException
getAttributes
in interface DirContext
NamingException
DirContext.getAttributes(Name)
public Attributes getAttributes(String name) throws NamingException
getAttributes
in interface DirContext
NamingException
DirContext.getAttributes(String)
public Attributes getAttributes(Name name, String[] attrIds) throws NamingException
getAttributes
in interface DirContext
NamingException
DirContext.getAttributes(Name, String[])
public Attributes getAttributes(String name, String[] attrIds) throws NamingException
getAttributes
in interface DirContext
NamingException
DirContext.getAttributes(String, String[])
public void modifyAttributes(Name name, int modOp, Attributes attrs) throws NamingException
modifyAttributes
in interface DirContext
NamingException
DirContext.modifyAttributes(javax.naming.Name,
int, javax.naming.directory.Attributes)
public void modifyAttributes(String name, int modOp, Attributes attrs) throws NamingException
modifyAttributes
in interface DirContext
NamingException
DirContext.modifyAttributes(String, int,
Attributes)
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException
modifyAttributes
in interface DirContext
NamingException
DirContext.modifyAttributes(Name,
ModificationItem[])
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException
modifyAttributes
in interface DirContext
NamingException
DirContext.modifyAttributes(String,
ModificationItem[])
public void bind(Name name, Object obj, Attributes attrs) throws NamingException
bind
in interface DirContext
NamingException
DirContext.bind(Name, Object, Attributes)
public void bind(String name, Object obj, Attributes attrs) throws NamingException
bind
in interface DirContext
NamingException
DirContext.bind(String, Object, Attributes)
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException
rebind
in interface DirContext
NamingException
DirContext.rebind(Name, Object, Attributes)
public void rebind(String name, Object obj, Attributes attrs) throws NamingException
rebind
in interface DirContext
NamingException
DirContext.rebind(String, Object, Attributes)
public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException
createSubcontext
in interface DirContext
NamingException
DirContext.createSubcontext(Name, Attributes)
public DirContext createSubcontext(String name, Attributes attrs) throws NamingException
createSubcontext
in interface DirContext
NamingException
DirContext.createSubcontext(String,
Attributes)
public DirContext getSchema(Name name) throws NamingException
getSchema
in interface DirContext
NamingException
DirContext.getSchema(Name)
public DirContext getSchema(String name) throws NamingException
getSchema
in interface DirContext
NamingException
DirContext.getSchema(String)
public DirContext getSchemaClassDefinition(Name name) throws NamingException
getSchemaClassDefinition
in interface DirContext
NamingException
DirContext.getSchemaClassDefinition(Name)
public DirContext getSchemaClassDefinition(String name) throws NamingException
getSchemaClassDefinition
in interface DirContext
NamingException
DirContext.getSchemaClassDefinition(String)
public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(Name, Attributes, String[])
public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(String, Attributes,
String[])
public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(Name, Attributes)
public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(String, Attributes)
public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(Name, String,
SearchControls)
public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(String, String,
SearchControls)
public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(Name, String, Object[],
SearchControls)
public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException
search
in interface DirContext
NamingException
DirContext.search(String, String, Object[],
SearchControls)
public Object lookup(Name name) throws NamingException
lookup
in interface Context
NamingException
Context.lookup(Name)
public Object lookup(String name) throws NamingException
lookup
in interface Context
NamingException
Context.lookup(String)
public void bind(Name name, Object obj) throws NamingException
bind
in interface Context
NamingException
Context.bind(Name, Object)
public void bind(String name, Object obj) throws NamingException
bind
in interface Context
NamingException
Context.bind(String, Object)
public void rebind(Name name, Object obj) throws NamingException
rebind
in interface Context
NamingException
Context.rebind(Name, Object)
public void rebind(String name, Object obj) throws NamingException
rebind
in interface Context
NamingException
Context.rebind(String, Object)
public void unbind(Name name) throws NamingException
unbind
in interface Context
NamingException
Context.unbind(Name)
public void unbind(String name) throws NamingException
unbind
in interface Context
NamingException
Context.unbind(String)
public void rename(Name oldName, Name newName) throws NamingException
rename
in interface Context
NamingException
Context.rename(Name, Name)
public void rename(String oldName, String newName) throws NamingException
rename
in interface Context
NamingException
Context.rename(String, String)
public NamingEnumeration list(Name name) throws NamingException
list
in interface Context
NamingException
Context.list(Name)
public NamingEnumeration list(String name) throws NamingException
list
in interface Context
NamingException
Context.list(String)
public NamingEnumeration listBindings(Name name) throws NamingException
listBindings
in interface Context
NamingException
Context.listBindings(Name)
public NamingEnumeration listBindings(String name) throws NamingException
listBindings
in interface Context
NamingException
Context.listBindings(String)
public void destroySubcontext(Name name) throws NamingException
destroySubcontext
in interface Context
NamingException
Context.destroySubcontext(Name)
public void destroySubcontext(String name) throws NamingException
destroySubcontext
in interface Context
NamingException
Context.destroySubcontext(String)
public Context createSubcontext(Name name) throws NamingException
createSubcontext
in interface Context
NamingException
Context.createSubcontext(Name)
public Context createSubcontext(String name) throws NamingException
createSubcontext
in interface Context
NamingException
Context.createSubcontext(String)
public Object lookupLink(Name name) throws NamingException
lookupLink
in interface Context
NamingException
Context.lookupLink(Name)
public Object lookupLink(String name) throws NamingException
lookupLink
in interface Context
NamingException
Context.lookupLink(String)
public NameParser getNameParser(Name name) throws NamingException
getNameParser
in interface Context
NamingException
Context.getNameParser(Name)
public NameParser getNameParser(String name) throws NamingException
getNameParser
in interface Context
NamingException
Context.getNameParser(String)
public Name composeName(Name name, Name prefix) throws NamingException
composeName
in interface Context
NamingException
Context.composeName(Name, Name)
public String composeName(String name, String prefix) throws NamingException
composeName
in interface Context
NamingException
Context.composeName(String, String)
public Object addToEnvironment(String propName, Object propVal) throws NamingException
addToEnvironment
in interface Context
NamingException
Context.addToEnvironment(String, Object)
public Object removeFromEnvironment(String propName) throws NamingException
removeFromEnvironment
in interface Context
NamingException
Context.removeFromEnvironment(String)
public Hashtable getEnvironment() throws NamingException
getEnvironment
in interface Context
NamingException
Context.getEnvironment()
public void close() throws NamingException
close
in interface Context
NamingException
Context.close()
public String getNameInNamespace()
getNameInNamespace
in interface Context
getNameInNamespace
in interface DirContextOperations
Context.getNameInNamespace()
public Name getDn()
DirContextOperations
getDn
in interface DirContextOperations
getNameInNamespace()
public final void setDn(Name dn)
DirContextOperations
setDn
in interface DirContextOperations
dn
- the dn.public boolean equals(Object obj)
equals
in class Object
Object.equals(java.lang.Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
public String toString()
toString
in class Object
Object.toString()
public String getReferralUrl()
DirContextOperations
getReferralUrl
in interface DirContextOperations
ldap://localhost:389
, or the empty string if this is not a
referral.public boolean isReferral()
DirContextOperations
isReferral
in interface DirContextOperations
true
if this instance results from a referral,
false
otherwise.
|
Spring LDAP Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |