本文整理匯總了Java中javax.naming.NamingEnumeration類的典型用法代碼示例。如果您正苦於以下問題:Java NamingEnumeration類的具體用法?Java NamingEnumeration怎麽用?Java NamingEnumeration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NamingEnumeration類屬於javax.naming包,在下文中一共展示了NamingEnumeration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mockSearchResults
import javax.naming.NamingEnumeration; //導入依賴的package包/類
private NamingEnumeration<SearchResult> mockSearchResults(String password)
throws NamingException {
@SuppressWarnings("unchecked")
NamingEnumeration<SearchResult> searchResults =
EasyMock.createNiceMock(NamingEnumeration.class);
EasyMock.expect(Boolean.valueOf(searchResults.hasMore()))
.andReturn(Boolean.TRUE)
.andReturn(Boolean.FALSE)
.andReturn(Boolean.TRUE)
.andReturn(Boolean.FALSE);
EasyMock.expect(searchResults.next())
.andReturn(new SearchResult("ANY RESULT", "",
new BasicAttributes(USER_PASSWORD_ATTR, password)))
.times(2);
EasyMock.replay(searchResults);
return searchResults;
}
示例2: getRangeRestrictedAttribute
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Gets the values of a repeating attribute that may have range restriction options. If an attribute is range
* restricted, it will appear in the attribute set with a ";range=i-j" option, where i and j indicate the start and
* end index, and j is '*' if it is at the end.
*
* @param attributes
* the attributes
* @param attributeName
* the attribute name
* @return the range restricted attribute
* @throws NamingException
* the naming exception
*/
private Attribute getRangeRestrictedAttribute(Attributes attributes, String attributeName) throws NamingException
{
Attribute unrestricted = attributes.get(attributeName);
if (unrestricted != null)
{
return unrestricted;
}
NamingEnumeration<? extends Attribute> i = attributes.getAll();
String searchString = attributeName.toLowerCase() + ';';
while (i.hasMore())
{
Attribute attribute = i.next();
if (attribute.getID().toLowerCase().startsWith(searchString))
{
return attribute;
}
}
return null;
}
示例3: listBindings
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Enumerates the names bound in the named context, along with the objects
* bound to them. The contents of any subcontexts are not included.
* <p>
* If a binding is added to or removed from this context, its effect on an
* enumeration previously returned is undefined.
*
* @param name
* the name of the context to list
* @return an enumeration of the bindings in this context. Each element of
* the enumeration is of type Binding.
* @exception NamingException
* if a naming exception is encountered
*/
@Override
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
示例4: Rdn
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Constructs an Rdn from the given attribute set. See
* {@link javax.naming.directory.Attributes Attributes}.
* <p>
* The string attribute values are not interpreted as
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
* formatted RDN strings. That is, the values are used
* literally (not parsed) and assumed to be unescaped.
*
* @param attrSet The non-null and non-empty attributes containing
* type/value mappings.
* @throws InvalidNameException If contents of {@code attrSet} cannot
* be used to construct a valid RDN.
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
entries = new ArrayList<>(attrSet.size());
NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
InvalidNameException e2 = new InvalidNameException(
e.getMessage());
e2.initCause(e);
throw e2;
}
sort(); // arrange entries for comparison
}
示例5: list
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them. The contents of any subcontexts are
* not included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
public NamingEnumeration list(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextEnumeration(bindings.elements());
}
NamingEntry entry = (NamingEntry) bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).list(name.getSuffix(1));
}
示例6: Rdn
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Constructs an Rdn from the given attribute set. See
* {@link javax.naming.directory.Attributes Attributes}.
* <p>
* The string attribute values are not interpreted as
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a>
* formatted RDN strings. That is, the values are used
* literally (not parsed) and assumed to be unescaped.
*
* @param attrSet The non-null and non-empty attributes containing
* type/value mappings.
* @throws InvalidNameException If contents of <tt>attrSet</tt> cannot
* be used to construct a valid RDN.
*/
public Rdn(Attributes attrSet) throws InvalidNameException {
if (attrSet.size() == 0) {
throw new InvalidNameException("Attributes cannot be empty");
}
entries = new ArrayList<>(attrSet.size());
NamingEnumeration<? extends Attribute> attrs = attrSet.getAll();
try {
for (int nEntries = 0; attrs.hasMore(); nEntries++) {
RdnEntry entry = new RdnEntry();
Attribute attr = attrs.next();
entry.type = attr.getID();
entry.value = attr.get();
entries.add(nEntries, entry);
}
} catch (NamingException e) {
InvalidNameException e2 = new InvalidNameException(
e.getMessage());
e2.initCause(e);
throw e2;
}
sort(); // arrange entries for comparison
}
示例7: listBindings
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them. The contents of any subcontexts are not
* included.
* <p>
* If a binding is added to or removed from this context, its effect on
* an enumeration previously returned is undefined.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<Binding> listBindings(Name name)
throws NamingException {
// Removing empty parts
while ((!name.isEmpty()) && (name.get(0).length() == 0))
name = name.getSuffix(1);
if (name.isEmpty()) {
return new NamingContextBindingsEnumeration(bindings.values().iterator(), this);
}
NamingEntry entry = bindings.get(name.get(0));
if (entry == null) {
throw new NameNotFoundException
(sm.getString("namingContext.nameNotBound", name, name.get(0)));
}
if (entry.type != NamingEntry.CONTEXT) {
throw new NamingException
(sm.getString("namingContext.contextExpected"));
}
return ((Context) entry.value).listBindings(name.getSuffix(1));
}
示例8: getUserAttributes
import javax.naming.NamingEnumeration; //導入依賴的package包/類
public static Map<String, String> getUserAttributes(DirContext ctx, String searchBase, String userName,
String principalDomain, String... attributeNames)
throws NamingException {
if (StringUtils.isBlank(userName)) {
throw new IllegalArgumentException("Username and password can not be blank.");
}
if (attributeNames.length == 0) {
return Collections.emptyMap();
}
Attributes matchAttr = new BasicAttributes(true);
BasicAttribute basicAttr = new BasicAttribute("userPrincipalName", userName + principalDomain);
matchAttr.put(basicAttr);
NamingEnumeration<? extends SearchResult> searchResult = ctx.search(searchBase, matchAttr, attributeNames);
if (ctx != null) {
ctx.close();
}
Map<String, String> result = new HashMap<>();
if (searchResult.hasMore()) {
NamingEnumeration<? extends Attribute> attributes = searchResult.next().getAttributes().getAll();
while (attributes.hasMore()) {
Attribute attr = attributes.next();
String attrId = attr.getID();
String attrValue = (String) attr.get();
result.put(attrId, attrValue);
}
}
return result;
}
示例9: listBindings
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Enumerates the names bound in the named context, along with the
* objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the bindings in this context.
* Each element of the enumeration is of type Binding.
* @exception NamingException if a naming exception is encountered
*/
@Override
public final NamingEnumeration<Binding> listBindings(String name)
throws NamingException {
if (!aliases.isEmpty()) {
AliasResult result = findAlias(name);
if (result.dirContext != null) {
return result.dirContext.listBindings(result.aliasName);
}
}
// Next do a standard lookup
List<NamingEntry> bindings = doListBindings(name);
// Check the alternate locations
List<NamingEntry> altBindings = null;
String resourceName = "/META-INF/resources" + name;
for (DirContext altDirContext : altDirContexts) {
if (altDirContext instanceof BaseDirContext) {
altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName);
}
if (altBindings != null) {
if (bindings == null) {
bindings = altBindings;
} else {
bindings.addAll(altBindings);
}
}
}
if (bindings != null) {
return new NamingContextBindingsEnumeration(bindings.iterator(),
this);
}
// Really not found
throw new NameNotFoundException(
sm.getString("resources.notFound", name));
}
示例10: addAttributeValues
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Add values of a specified attribute to a list
*
* @param attrId Attribute name
* @param attrs Attributes containing the new values
* @param values ArrayList containing values found so far
*
* @exception NamingException if a directory server error occurs
*/
private ArrayList<String> addAttributeValues(String attrId,
Attributes attrs,
ArrayList<String> values)
throws NamingException{
if (containerLog.isTraceEnabled())
containerLog.trace(" retrieving values for attribute " + attrId);
if (attrId == null || attrs == null)
return values;
if (values == null)
values = new ArrayList<String>();
Attribute attr = attrs.get(attrId);
if (attr == null)
return values;
NamingEnumeration<?> e = attr.getAll();
try {
while(e.hasMore()) {
String value = (String)e.next();
values.add(value);
}
} catch (PartialResultException ex) {
if (!adCompat)
throw ex;
} finally {
e.close();
}
return values;
}
示例11: list
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(String name)
throws NamingException {
if (log.isDebugEnabled()) {
log.debug(sm.getString("selectorContext.methodUsingString", "list",
name));
}
return getBoundContext().list(parseName(name));
}
示例12: list
import javax.naming.NamingEnumeration; //導入依賴的package包/類
@Override
public NamingEnumeration list(Name name) throws NamingException {
if (name.isEmpty())
return new ListOfNames(iBindings.keys());
Object target = lookup(name);
if (target instanceof Context)
return ((Context) target).list("");
throw new NotContextException(name + " cannot be listed");
}
示例13: list
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Enumerates the names bound in the named context, along with the class
* names of objects bound to them.
*
* @param name the name of the context to list
* @return an enumeration of the names and class names of the bindings in
* this context. Each element of the enumeration is of type NameClassPair.
* @exception NamingException if a naming exception is encountered
*/
@Override
public NamingEnumeration<NameClassPair> list(String name)
throws NamingException {
if (!aliases.isEmpty()) {
AliasResult result = findAlias(name);
if (result.dirContext != null) {
return result.dirContext.list(result.aliasName);
}
}
// Next do a standard lookup
List<NamingEntry> bindings = doListBindings(name);
// Check the alternate locations
List<NamingEntry> altBindings = null;
String resourceName = "/META-INF/resources" + name;
for (DirContext altDirContext : altDirContexts) {
if (altDirContext instanceof BaseDirContext) {
altBindings = ((BaseDirContext) altDirContext).doListBindings(resourceName);
}
if (altBindings != null) {
if (bindings == null) {
bindings = altBindings;
} else {
bindings.addAll(altBindings);
}
}
}
if (bindings != null) {
return new NamingContextEnumeration(bindings.iterator());
}
// Really not found
throw new NameNotFoundException(
sm.getString("resources.notFound", name));
}
示例14: equals
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* Determines whether this <tt>BasicAttributes</tt> is equal to another
* <tt>Attributes</tt>
* Two <tt>Attributes</tt> are equal if they are both instances of
* <tt>Attributes</tt>,
* treat the case of attribute IDs the same way, and contain the
* same attributes. Each <tt>Attribute</tt> in this <tt>BasicAttributes</tt>
* is checked for equality using <tt>Object.equals()</tt>, which may have
* be overridden by implementations of <tt>Attribute</tt>).
* If a subclass overrides <tt>equals()</tt>,
* it should override <tt>hashCode()</tt>
* as well so that two <tt>Attributes</tt> instances that are equal
* have the same hash code.
* @param obj the possibly null object to compare against.
*
* @return true If obj is equal to this BasicAttributes.
* @see #hashCode
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof Attributes)) {
Attributes target = (Attributes)obj;
// Check case first
if (ignoreCase != target.isCaseIgnored()) {
return false;
}
if (size() == target.size()) {
Attribute their, mine;
try {
NamingEnumeration<?> theirs = target.getAll();
while (theirs.hasMore()) {
their = (Attribute)theirs.next();
mine = get(their.getID());
if (!their.equals(mine)) {
return false;
}
}
} catch (NamingException e) {
return false;
}
return true;
}
}
return false;
}
示例15: searchChildren
import javax.naming.NamingEnumeration; //導入依賴的package包/類
/**
* @param dn
* @param filter
* @return
* @throws NamingException
*/
public NamingEnumeration searchChildren(String dn, String filter) throws NamingException
{
SearchControls constraints = new SearchControls();
constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
return m_ctx.search(dn, filter, constraints);
}