下面列出了怎么用javax.naming.directory.AttributeInUseException的API类实例代码及写法,或者点击链接到github查看源代码。
private void bindServer() throws UnknownHostException, AttributeInUseException {
if (Namespace.exists(getDefaultNamespaceName())) {
LOG.error("EmissaryServer already bound to namespace. This should NEVER happen.");
throw new AttributeInUseException("EmissaryServer was already bound to the namespace using serverName: " + DEFAULT_NAMESPACE_NAME);
}
LOG.debug("Binding {} ", DEFAULT_NAMESPACE_NAME);
Namespace.bind(getDefaultNamespaceName(), this);
}
public void assignUser(String username, String groupName) throws NamingException {
try {
ModificationItem[] mods = new ModificationItem[1];
Attribute mod = new BasicAttribute("member", getUserDN(username));
mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE, mod);
context.modifyAttributes(getGroupDN(groupName), mods);
} catch (AttributeInUseException e) {
// If user is already added, ignore exception
}
}