本文整理匯總了Java中javax.naming.NamingEnumeration.hasMore方法的典型用法代碼示例。如果您正苦於以下問題:Java NamingEnumeration.hasMore方法的具體用法?Java NamingEnumeration.hasMore怎麽用?Java NamingEnumeration.hasMore使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.naming.NamingEnumeration
的用法示例。
在下文中一共展示了NamingEnumeration.hasMore方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGet
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain;UTF-8");
PrintWriter out = resp.getWriter();
try {
Context ctx = new InitialContext();
NamingEnumeration<Binding> enm =
ctx.listBindings("java:comp/env/list");
while (enm.hasMore()) {
Binding b = enm.next();
out.print(b.getObject().getClass().getName());
}
} catch (NamingException ne) {
ne.printStackTrace(out);
}
}
示例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: getAllAttributesSorted
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* @param dn
* @return
* @throws NamingException
*/
public TreeMap getAllAttributesSorted(String dn) throws NamingException
{
NamingEnumeration enumAll = getAllAttributes(dn);
TreeMap<String, Object> tree = new TreeMap<String, Object>();
while (enumAll.hasMore())
{
Attribute a = (Attribute)enumAll.next();
tree.put(new String(a.getID()), a.get());
}
for (Iterator it = tree.keySet().iterator(); it.hasNext();)
{
String key = (String)it.next();
Log.logDebug(key+" = "+tree.get(key));
}
return tree;
}
示例4: 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;
}
示例5: equals
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* Determines whether this {@code BasicAttributes} is equal to another
* {@code Attributes}
* Two {@code Attributes} are equal if they are both instances of
* {@code Attributes},
* treat the case of attribute IDs the same way, and contain the
* same attributes. Each {@code Attribute} in this {@code BasicAttributes}
* is checked for equality using {@code Object.equals()}, which may have
* be overridden by implementations of {@code Attribute}).
* If a subclass overrides {@code equals()},
* it should override {@code hashCode()}
* as well so that two {@code Attributes} 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;
}
示例6: printResources
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* List the resources of the given context.
*/
protected void printResources(PrintWriter writer, String prefix, javax.naming.Context namingContext, String type,
Class<?> clazz, StringManager smClient) {
try {
NamingEnumeration<Binding> items = namingContext.listBindings("");
while (items.hasMore()) {
Binding item = items.next();
if (item.getObject() instanceof javax.naming.Context) {
printResources(writer, prefix + item.getName() + "/", (javax.naming.Context) item.getObject(), type,
clazz, smClient);
} else {
if ((clazz != null) && (!(clazz.isInstance(item.getObject())))) {
continue;
}
writer.print(prefix + item.getName());
writer.print(':');
writer.print(item.getClassName());
// Do we want a description if available?
writer.println();
}
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.resources[" + type + "]", t);
writer.println(smClient.getString("managerServlet.exception", t.toString()));
}
}
示例7: findUserDn
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* Finds a distinguished name(DN) of a user by querying the active directory LDAP context for the
* specified username.
*/
protected String findUserDn(LdapContextFactory ldapContextFactory, String username) throws NamingException {
LdapContext ctx = null;
try {
// Binds using the system username and password.
ctx = ldapContextFactory.getSystemLdapContext();
final SearchControls ctrl = new SearchControls();
ctrl.setCountLimit(1);
ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctrl.setTimeLimit(searchTimeoutMillis);
final String filter =
searchFilter != null ? USERNAME_PLACEHOLDER.matcher(searchFilter)
.replaceAll(username)
: username;
final NamingEnumeration<SearchResult> result = ctx.search(searchBase, filter, ctrl);
try {
if (!result.hasMore()) {
throw new AuthenticationException("No username: " + username);
}
return result.next().getNameInNamespace();
} finally {
result.close();
}
} finally {
LdapUtils.closeContext(ctx);
}
}
示例8: printResources
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* List the resources of the given context.
*/
protected void printResources(PrintWriter writer, String prefix,
javax.naming.Context namingContext,
String type, Class<?> clazz,
StringManager smClient) {
try {
NamingEnumeration<Binding> items = namingContext.listBindings("");
while (items.hasMore()) {
Binding item = items.next();
if (item.getObject() instanceof javax.naming.Context) {
printResources
(writer, prefix + item.getName() + "/",
(javax.naming.Context) item.getObject(), type, clazz,
smClient);
} else {
if ((clazz != null) &&
(!(clazz.isInstance(item.getObject())))) {
continue;
}
writer.print(prefix + item.getName());
writer.print(':');
writer.print(item.getClassName());
// Do we want a description if available?
writer.println();
}
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
log("ManagerServlet.resources[" + type + "]", t);
writer.println(smClient.getString("managerServlet.exception",
t.toString()));
}
}
示例9: getSomeAttributes
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* @param dn
* @param attributeNames
* @return
* @throws NamingException
*/
public NamingEnumeration getSomeAttributes(String dn, String[] attributeNames) throws NamingException
{
Attributes attrs = m_ctx.getAttributes(dn, attributeNames);
NamingEnumeration enumSome = attrs.getAll();
while (enumSome.hasMore())
{
Attribute a = (Attribute)enumSome.next();
Log.logDebug(a.getID()+" = "+a.get());
}
return enumSome;
}
示例10: getHeaderField
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* Returns the name of the specified header field.
*/
public String getHeaderField(String name) {
if (!connected) {
// Try to connect (silently)
try {
connect();
} catch (IOException e) {
}
}
if (attributes == null)
return (null);
NamingEnumeration attributeEnum = attributes.getIDs();
try {
while (attributeEnum.hasMore()) {
String attributeID = (String)attributeEnum.next();
if (attributeID.equalsIgnoreCase(name)) {
Attribute attribute = attributes.get(attributeID);
if (attribute == null) return null;
return getHeaderValueAsString(attribute.get(attribute.size()-1));
}
}
} catch (NamingException ne) {
// Shouldn't happen
}
return (null);
}
示例11: enumerate
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
public static boolean enumerate(Context _ctx, NamingEnumeration e, String string,String __dbtype) throws NamingException {
while (e.hasMore()) {
Binding binding = (Binding) e.next();
Common.debugingLine2D("DataSource binding Name: " + binding.getName());
// System.out.println("Type: " + binding.getClassName());
// System.out.println("Value: " + binding.getObject());
if(binding.getName().endsWith(__dbtype))
{
DataSource _ds1 = (DataSource) _ctx.lookup("jdbc/" + binding.getName());
addDs(binding.getName(), _ds1);
}
}
return !_m_conn.isEmpty();
}
示例12: hasMoreEnum
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
private boolean hasMoreEnum(NamingEnumeration<SearchResult> namingEnum)
throws NamingException {
boolean hasMore = true;
try {
if (!namingEnum.hasMore()) {
hasMore = false;
}
} catch (PartialResultException e) {
hasMore = false;
logger.logWarn(Log4jLogger.SYSTEM_LOG, e,
LogMessageIdentifier.WARN_LDAP_PARTIAL_EXCEPTION);
}
return hasMore;
}
示例13: search
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
/**
* @return null if there are zero results
*/
private NamingEnumeration<SearchResult> search(DirContext ctx, Name base, String[] returnAttributes, Filter filter,
boolean recurse)
{
SearchControls ctls = new SearchControls();
ctls.setCountLimit(filter.getLimit());
ctls.setReturningAttributes(returnAttributes);
ctls.setSearchScope(recurse ? SearchControls.SUBTREE_SCOPE : SearchControls.ONELEVEL_SCOPE);
try
{
// Search for objects using the filter
String query = filter.toFilter();
if( LOGGER.isDebugEnabled() )
{
LOGGER.debug("Query:" + query + " Base:" + base);
}
NamingEnumeration<SearchResult> ne = ctx.search(base, query, ctls);
if( ne.hasMore() )
{
return ne;
}
}
catch( PartialResultException pre )
{
LOGGER.info(pre);
}
catch( SizeLimitExceededException slee )
{
LOGGER.info(slee);
}
catch( Exception e )
{
LOGGER.warn(e);
}
return null;
}
示例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: getLDAPGroupNames
import javax.naming.NamingEnumeration; //導入方法依賴的package包/類
private Collection<Name> getLDAPGroupNames(DirContext ctx, Attributes useratt)
{
Set<Name> foundGroups = new HashSet<Name>();
if( !Check.isEmpty(memberOfField) )
{
Attribute attribute = useratt.get(memberOfField);
try
{
NameParser parser = ctx.getNameParser(""); //$NON-NLS-1$
if( attribute != null )
{
NamingEnumeration<?> enumeration = attribute.getAll();
while( enumeration != null && enumeration.hasMore() )
{
String role = (String) enumeration.next();
Name compound = parser.parse(role);
foundGroups.add(compound);
}
}
}
catch( NamingException e )
{
throw new RuntimeException("Couldn't get memberField", e);
}
}
return foundGroups;
}