📄 dsmlcontext.java
字号:
* Called by DsmlCtxFactory / also used for testing
*
* @param env the environment to use for this connection...
*/
DsmlContext(Hashtable env)
{
environment = (env == null) ? new Hashtable() : env;
log.fine("Created DsmlContext");
}
/**
* Retrieves all of the attributes associated with a named object.
* See {@link #getAttributes(javax.naming.Name)} for details.
*
* @param name the name of the object from which to retrieve attributes
* @return the set of attributes associated with <code>name</code>
* @throws javax.naming.NamingException if a naming exception is encountered
*/
public Attributes getAttributes(String name) throws NamingException
{
return getAttributes(name, null);
}
/**
* Modifies the attributes associated with a named object.
* See {@link #modifyAttributes(javax.naming.Name, int, javax.naming.directory.Attributes)} for details.
*
* @param name the name of the object whose attributes will be updated
* @param mod_op the modification operation, one of:
* <code>ADD_ATTRIBUTE</code>,
* <code>REPLACE_ATTRIBUTE</code>,
* <code>REMOVE_ATTRIBUTE</code>.
* @param attrs the attributes to be used for the modification; map not be null
* @throws javax.naming.directory.AttributeModificationException if the modification cannot
* be completed successfully
* @throws javax.naming.NamingException if a naming exception is encountered
*/
public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException
{
ModificationItem[] mods = new ModificationItem[attrs.size()];
Enumeration attObjects = attrs.getAll();
int i = 0;
while (attObjects.hasMoreElements())
{
mods[i++] = new ModificationItem(mod_op, (Attribute) attObjects.nextElement());
}
modifyAttributes(name, mods);
}
/**
* Retrieves all of the attributes associated with a named object.
* See the class description regarding attribute models, attribute
* type names, and operational attributes.
*
* @param name the name of the object from which to retrieve attributes
* @return the set of attributes associated with <code>name</code>.
* Returns an empty attribute set if name has no attributes;
* never null.
* @throws javax.naming.NamingException if a naming exception is encountered
* @see #getAttributes(String)
* @see #getAttributes(javax.naming.Name, String[])
*/
public Attributes getAttributes(Name name) throws NamingException
{
return getAttributes(name, null);
}
/**
* Modifies the attributes associated with a named object.
* The order of the modifications is not specified. Where
* possible, the modifications are performed atomically.
*
* @param name the name of the object whose attributes will be updated
* @param mod_op the modification operation, one of:
* <code>ADD_ATTRIBUTE</code>,
* <code>REPLACE_ATTRIBUTE</code>,
* <code>REMOVE_ATTRIBUTE</code>.
* @param attrs the attributes to be used for the modification; may not be null
* @throws javax.naming.directory.AttributeModificationException if the modification cannot
* be completed successfully
* @throws javax.naming.NamingException if a naming exception is encountered
* @see #modifyAttributes(javax.naming.Name, javax.naming.directory.ModificationItem[])
*/
public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException
{
modifyAttributes(name.toString(), mod_op, attrs);
}
/**
* Retrieves the schema associated with the named object.
* See {@link #getSchema(javax.naming.Name)} for details.
*
* @param name the name of the object whose schema is to be retrieved
* @return the schema associated with the context; never null
* @throws javax.naming.OperationNotSupportedException if schema not supported
* @throws javax.naming.NamingException if a naming exception is encountered
* @deprecated not yet implemented
*/
public DirContext getSchema(String name) throws NamingException
{
throw new OperationNotSupportedException("DsmlContext does not support reading schema (yet)");
}
/**
* Retrieves a context containing the schema objects of the
* named object's class definitions.
* See {@link #getSchemaClassDefinition(javax.naming.Name)} for details.
*
* @param name the name of the object whose object class
* definition is to be retrieved
* @return the <tt>DirContext</tt> containing the named
* object's class definitions; never null
* @throws javax.naming.OperationNotSupportedException if schema not supported
* @throws javax.naming.NamingException if a naming exception is encountered
* @deprecated not yet implemented
*/
public DirContext getSchemaClassDefinition(String name) throws NamingException
{
throw new OperationNotSupportedException("DsmlContext does not support reading schema (yet)");
}
/**
* Retrieves the schema associated with the named object.
* The schema describes rules regarding the structure of the namespace
* and the attributes stored within it. The schema
* specifies what types of objects can be added to the directory and where
* they can be added; what mandatory and optional attributes an object
* can have. The range of support for schemas is directory-specific.
* <p/>
* <p> This method returns the root of the schema information tree
* that is applicable to the named object. Several named objects
* (or even an entire directory) might share the same schema.
* <p/>
* <p> Issues such as structure and contents of the schema tree,
* permission to modify to the contents of the schema
* tree, and the effect of such modifications on the directory
* are dependent on the underlying directory.
*
* @param name the name of the object whose schema is to be retrieved
* @return the schema associated with the context; never null
* @throws javax.naming.OperationNotSupportedException if schema not supported
* @throws javax.naming.NamingException if a naming exception is encountered
* @deprecated not yet implemented
*/
public DirContext getSchema(Name name) throws NamingException
{
throw new OperationNotSupportedException("DsmlContext does not support reading schema (yet)");
}
/**
* Retrieves a context containing the schema objects of the
* named object's class definitions.
* <p/>
* One category of information found in directory schemas is
* <em>class definitions</em>. An "object class" definition
* specifies the object's <em>type</em> and what attributes (mandatory
* and optional) the object must/can have. Note that the term
* "object class" being referred to here is in the directory sense
* rather than in the Java sense.
* For example, if the named object is a directory object of
* "Person" class, <tt>getSchemaClassDefinition()</tt> would return a
* <tt>DirContext</tt> representing the (directory's) object class
* definition of "Person".
* <p/>
* The information that can be retrieved from an object class definition
* is directory-dependent.
* <p/>
* Prior to JNDI 1.2, this method
* returned a single schema object representing the class definition of
* the named object.
* Since JNDI 1.2, this method returns a <tt>DirContext</tt> containing
* all of the named object's class definitions.
*
* @param name the name of the object whose object class
* definition is to be retrieved
* @return the <tt>DirContext</tt> containing the named
* object's class definitions; never null
* @throws javax.naming.OperationNotSupportedException if schema not supported
* @throws javax.naming.NamingException if a naming exception is encountered
* @deprecated not yet implemented
*/
public DirContext getSchemaClassDefinition(Name name) throws NamingException
{
throw new OperationNotSupportedException("DsmlContext does not support reading schema (yet)");
}
/**
* Modifies the attributes associated with a named object using
* an ordered list of modifications.
* See {@link #modifyAttributes(javax.naming.Name, javax.naming.directory.ModificationItem[])} for details.
*
* @param name the name of the object whose attributes will be updated
* @param mods an ordered sequence of modifications to be performed;
* may not be null
* @throws javax.naming.directory.AttributeModificationException if the modifications
* cannot be completed successfully
* @throws javax.naming.NamingException if a naming exception is encountered
*/
public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException
{
log.finest("modify Atts of (" + name + ")");
// construct XML
StringBuffer modRequestBuffer = constructModRequest(name, mods);
// send XML to server
String response = sendDSMLRequest(modRequestBuffer);
// parse response XML
parseModResponse(response);
}
private StringBuffer constructModRequest(String name, ModificationItem[] mods)
throws NamingException
{
StringBuffer message = new StringBuffer(200);
message.append(STANDARDHEADER);
getModRequestElement(message, name, mods);
message.append(STANDARDFOOTER);
return message;
}
/**
* @param message
* @param name
* @param mods
*/
/*
" <dsml:modifyRequest dn=\"cn=Alana SHORE,ou=Infrastructure,ou=Support,o=DEMOCORP,c=AU\">" +
" <dsml:modification name=\"favoriteDrink\" operation=\"add\">" +
" <dsml:value>japanese slipper</dsml:value>" +
" </dsml:modification>" +
" <dsml:modification name=\"address\" operation=\"delete\">\n" +
" <dsml:value>21 Jump Street$New York$90210</dsml:value>\n" +
" </dsml:modification>\n" +
" <dsml:modification name=\"userPassword\" operation=\"replace\">" +
" <dsml:value xsi:type=\"xsd:base64Binary\">c2VjcmV0IHBhc3N3b3Jk</dsml:value>" +
" </dsml:modification>" +
" </dsml:modifyRequest>" +
*/
static void getModRequestElement(StringBuffer message, String name, ModificationItem[] mods)
throws NamingException
{
message.append(TAB4).append("<dsml:modifyRequest dn=\"").append(escapeName(name)).append("\">\n");
for (int i = 0; i < mods.length; i++)
{
Attribute att = mods[i].getAttribute();
NamingEnumeration values = att.getAll();
switch (mods[i].getModificationOp())
{
case ADD_ATTRIBUTE:
message.append(TAB5).append("<dsml:modification name=\"").append(att.getID()).append("\" operation=\"add\">\n");
while (values.hasMore())
createDsmlValueElement(values.next(), message);
message.append(TAB5).append("</dsml:modification>\n");
break;
case REPLACE_ATTRIBUTE:
message.append(TAB5).append("<dsml:modification name=\"").append(att.getID()).append("\" operation=\"replace\">\n");
while (values.hasMore())
createDsmlValueElement(values.next(), message);
message.append(TAB5).append("</dsml:modification>\n");
break;
case REMOVE_ATTRIBUTE:
message.append(TAB5).append("<dsml:modification name=\"").append(att.getID()).append("\" operation=\"delete\">\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -