📄 dsmlcontext.java
字号:
while (values.hasMore())
createDsmlValueElement(values.next(), message);
message.append(TAB5).append("</dsml:modification>\n");
break;
}
}
message.append(TAB4).append("</dsml:modifyRequest>\n");
}
void parseModResponse(String response)
throws NamingException
{
// check for a dsml error
checkForError(response);
// quick check that it really was a modify response...
if (response.indexOf("modifyResponse>") == -1)
throw new NamingException("Unexpected DSML Response to Modify Request:\n " + response);
}
//private static Pattern searchResultEntry = Pattern.compile("<searchResultEntry.*?dn=\"(.*?)\">(.*?)</searchResultEntry>", Pattern.DOTALL);
//TODO: tighten up...
private static Pattern errorResult = Pattern.compile("errorResponse.*?type=\"(.*?)\"", Pattern.DOTALL);
private static Pattern errorMessage = Pattern.compile("message>(.*?)</", Pattern.DOTALL);
private static Pattern errorDetail = Pattern.compile("detail>(.*?)</", Pattern.DOTALL);
private static Pattern ldapResultCode = Pattern.compile("code=\"(.*?)\"", Pattern.DOTALL);
private static Pattern ldapResultDesc = Pattern.compile("resultCode.*?descr=\"(.*?)\"", Pattern.DOTALL);
private static Pattern ldapResultMsg = Pattern.compile("errorMessage>(.*?)</", Pattern.DOTALL);
static void checkForError(String response)
throws NamingException
{
Matcher error = errorResult.matcher(response);
if (error.find())
{
String errorMsg = "Error Processing DSML Request: " + error.group(1);
Matcher message = errorMessage.matcher(response);
if (message.find())
errorMsg = errorMsg + "\n" + message.group(1);
Matcher detail = errorDetail.matcher(response);
if (detail.find())
errorMsg = errorMsg + "\n" + detail.group(1);
throw new NamingException(errorMsg);
}
else
{
try
{
Matcher resultMatcher = ldapResultCode.matcher(response);
resultMatcher.find();
String resultCode = resultMatcher.group(1);
int i = Integer.parseInt(resultCode);
if (i == 0)
return; // all good here.
Matcher descMatcher = ldapResultDesc.matcher(response);
String desc = "";
if (descMatcher.find())
desc = descMatcher.group(1);
Matcher msgMatcher = ldapResultMsg.matcher(response);
String msg = "";
if (msgMatcher.find())
msg = msgMatcher.group(1);
throw new NamingException(desc + " Exception (LDAP " + resultCode + ")\n" + msg);
}
catch (NumberFormatException e)
{
throw new NamingException("Unable to parse result code in DSML Response\n" + response);
}
catch (IllegalStateException e)
{
throw new NamingException("Unable to find result code in DSML Response\n" + response);
}
}
}
/**
* Modifies the attributes associated with a named object using
* an ordered list of modifications.
* The modifications are performed
* in the order specified. Each modification specifies a
* modification operation code and an attribute on which to
* operate. Where possible, the modifications are
* performed atomically.
*
* @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
* @see #modifyAttributes(javax.naming.Name, int, javax.naming.directory.Attributes)
* @see javax.naming.directory.ModificationItem
*/
public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException
{
modifyAttributes(name.toString(), mods);
}
/**
* Searches in a single context for objects that contain a
* specified set of attributes.
* See {@link #search(javax.naming.Name, javax.naming.directory.Attributes)} for details.
*
* @param name the name of the context to search
* @param matchingAttributes the attributes to search for
* @return an enumeration of <tt>SearchResult</tt> objects
* @throws javax.naming.NamingException if a naming exception is encountered
*/
public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException
{
return search(name, matchingAttributes, null);
}
/**
* Searches in a single context for objects that contain a
* specified set of attributes.
* This method returns all the attributes of such objects.
* It is equivalent to supplying null as
* the <tt>atributesToReturn</tt> parameter to the method
* <code>search(Name, Attributes, String[])</code>, i.e. search(name, matchingAttributes, null)
* <br>
* See {@link #search(javax.naming.Name, javax.naming.directory.Attributes, String[])} for a full description.
*
* @param name the name of the context to search
* @param matchingAttributes the attributes to search for
* @return an enumeration of <tt>SearchResult</tt> objects
* @throws javax.naming.NamingException if a naming exception is encountered
* @see #search(javax.naming.Name, javax.naming.directory.Attributes, String[])
*/
public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException
{
return search(name, matchingAttributes, null);
}
/**
* Binds a name to an object, along with associated attributes.
* See {@link #bind(javax.naming.Name, Object, javax.naming.directory.Attributes)} for details.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @param attrs the attributes to associate with the binding
* @throws javax.naming.NameAlreadyBoundException if name is already bound
* @throws javax.naming.directory.InvalidAttributesException if some "mandatory" attributes
* of the binding are not supplied
* @throws javax.naming.NamingException if a naming exception is encountered
* @deprecated this method will not be implemented
*/
public void bind(String name, Object obj, Attributes attrs) throws NamingException
{
throw new OperationNotSupportedException("binding of java objects is not supported by the DsmlContext");
}
/**
* Binds a name to an object, along with associated attributes,
* overwriting any existing binding.
* See {@link #rebind(javax.naming.Name, Object, javax.naming.directory.Attributes)} for details.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @param attrs the attributes to associate with the binding
* @throws javax.naming.directory.InvalidAttributesException if some "mandatory" attributes
* of the binding are not supplied
* @throws javax.naming.NamingException if a naming exception is encountered
* @deprecated this method will not be implemented
*/
public void rebind(String name, Object obj, Attributes attrs) throws NamingException
{
throw new OperationNotSupportedException("binding of java objects is not supported by the DsmlContext");
}
/**
* Binds a name to an object, along with associated attributes.
* If <tt>attrs</tt> is null, the resulting binding will have
* the attributes associated with <tt>obj</tt> if <tt>obj</tt> is a
* <tt>DirContext</tt>, and no attributes otherwise.
* If <tt>attrs</tt> is non-null, the resulting binding will have
* <tt>attrs</tt> as its attributes; any attributes associated with
* <tt>obj</tt> are ignored.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @param attrs the attributes to associate with the binding
* @throws javax.naming.NameAlreadyBoundException if name is already bound
* @throws javax.naming.directory.InvalidAttributesException if some "mandatory" attributes
* of the binding are not supplied
* @throws javax.naming.NamingException if a naming exception is encountered
* @see javax.naming.Context#bind(javax.naming.Name, Object)
* @see #rebind(javax.naming.Name, Object, javax.naming.directory.Attributes)
* @deprecated this method will not be implemented
*/
public void bind(Name name, Object obj, Attributes attrs) throws NamingException
{
throw new OperationNotSupportedException("binding of java objects is not supported by the DsmlContext");
}
/**
* Binds a name to an object, along with associated attributes,
* overwriting any existing binding.
* If <tt>attrs</tt> is null and <tt>obj</tt> is a <tt>DirContext</tt>,
* the attributes from <tt>obj</tt> are used.
* If <tt>attrs</tt> is null and <tt>obj</tt> is not a <tt>DirContext</tt>,
* any existing attributes associated with the object already bound
* in the directory remain unchanged.
* If <tt>attrs</tt> is non-null, any existing attributes associated with
* the object already bound in the directory are removed and <tt>attrs</tt>
* is associated with the named object. If <tt>obj</tt> is a
* <tt>DirContext</tt> and <tt>attrs</tt> is non-null, the attributes
* of <tt>obj</tt> are ignored.
*
* @param name the name to bind; may not be empty
* @param obj the object to bind; possibly null
* @param attrs the attributes to associate with the binding
* @throws javax.naming.directory.InvalidAttributesException if some "mandatory" attributes
* of the binding are not supplied
* @throws javax.naming.NamingException if a naming exception is encountered
* @see javax.naming.Context#bind(javax.naming.Name, Object)
* @see #bind(javax.naming.Name, Object, javax.naming.directory.Attributes)
* @deprecated this method will not be implemented
*/
public void rebind(Name name, Object obj, Attributes attrs) throws NamingException
{
throw new OperationNotSupportedException("binding of java objects is not supported by the DsmlContext");
}
/**
* Retrieves selected attributes associated with a named object.
* See {@link #getAttributes(javax.naming.Name, String[])} for details.
*
* @param name The name of the object from which to retrieve attributes
* @param attrIds the identifiers of the attributes to retrieve.
* null indicates that all attributes should be retrieved;
* an empty array indicates that none should be retrieved.
* @return the requested attributes; never null
* @throws javax.naming.NamingException if a naming exception is encountered
*/
public Attributes getAttributes(String name, String[] attrIds) throws NamingException
{
log.finest("getAttributes (" + name.toString() + ")");
NamingEnumeration en = doDsmlSearch(name.toString(), BASEOBJECT, SEARCHING, 0, 0, false, "(objectClass=*)", attrIds);
if (en.hasMoreElements() == false)
return new BasicAttributes(); // return empty attributes object for 'virtual' nodes (e.g. router entries, base DN RDNs)
SearchResult result = (SearchResult) en.next();
return result.getAttributes();
//return getTestAttributes(name.toString()); //To change body of implemented methods use File | Settings | File Templates.
}
/**
* Retrieves selected attributes associated with a named object.
* See the class description regarding attribute models, attribute
* type names, and operational attributes.
* <p/>
* <p> If the object does not have an attribute
* specified, the directory will ignore the nonexistent attribute
* and return those requested attributes that the object does have.
* <p/>
* <p> A directory might return more attributes than was requested
* (see <strong>Attribute Type Names</strong> in the class description),
* but is not allowed to return arbitrary, unrelated attributes.
* <p/>
* <p> See also <strong>Operational Attributes</strong> in the class
* description.
*
* @param name the name of the object from which to retrieve attributes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -