當前位置: 首頁>>代碼示例>>Java>>正文


Java NamingEnumeration.hasMore方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:20,代碼來源:TestNamingContext.java

示例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;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:33,代碼來源:LDAPUserRegistry.java

示例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;
   }
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:22,代碼來源:LdapUtil.java

示例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;
}
 
開發者ID:SirAeroWN,項目名稱:premier-wherehows,代碼行數:37,代碼來源:AuthenticationManager.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:47,代碼來源:BasicAttributes.java

示例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()));
	}

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:32,代碼來源:ManagerServlet.java

示例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);
    }
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:33,代碼來源:SearchFirstActiveDirectoryRealm.java

示例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()));
    }

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:38,代碼來源:ManagerServlet.java

示例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;
   }
 
開發者ID:costea7,項目名稱:ChronoBike,代碼行數:18,代碼來源:LdapUtil.java

示例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);
    
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:DirContextURLConnection.java

示例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();
}
 
開發者ID:dimasalomatine,項目名稱:sdirobot,代碼行數:16,代碼來源:CManagerMap.java

示例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;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:15,代碼來源:LdapAccessServiceBean.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:41,代碼來源:LDAP.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:47,代碼來源:BasicAttributes.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:28,代碼來源:MemberOfGroupSearch.java


注:本文中的javax.naming.NamingEnumeration.hasMore方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。