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


Java Context.listBindings方法代碼示例

本文整理匯總了Java中javax.naming.Context.listBindings方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.listBindings方法的具體用法?Java Context.listBindings怎麽用?Java Context.listBindings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.Context的用法示例。


在下文中一共展示了Context.listBindings方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import javax.naming.Context; //導入方法依賴的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:liaokailin,項目名稱:tomcat7,代碼行數:20,代碼來源:TestNamingContext.java

示例2: createMBeans

import javax.naming.Context; //導入方法依賴的package包/類
/**
 * Create the MBeans for the interesting global JNDI resources in
 * the specified naming context.
 *
 * @param prefix Prefix for complete object name paths
 * @param context Context to be scanned
 *
 * @exception NamingException if a JNDI exception occurs
 */
protected void createMBeans(String prefix, Context context)
    throws NamingException {

    if (debug >= 1) {
        log("Creating MBeans for Global JNDI Resources in Context '" +
            prefix + "'");
    }

    NamingEnumeration bindings = context.listBindings("");
    while (bindings.hasMore()) {
        Binding binding = (Binding) bindings.next();
        String name = prefix + binding.getName();
        Object value = context.lookup(binding.getName());
        if (debug >= 2) {
            log("Checking resource " + name);
        }
        if (value instanceof Context) {
            createMBeans(name + "/", (Context) value);
        } else if (value instanceof UserDatabase) {
            try {
                createMBeans(name, (UserDatabase) value);
            } catch (Exception e) {
                log("Exception creating UserDatabase MBeans for " + name,
                    e);
            }
        }
    }

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:39,代碼來源:GlobalResourcesLifecycleListener.java

示例3: clearContext

import javax.naming.Context; //導入方法依賴的package包/類
/**
 * Removes all entries from the specified context, including subcontexts.
 * 
 * @param context context to clear
 */
private void clearContext(Context context) throws NamingException {
  for (NamingEnumeration e = context.listBindings(""); e.hasMoreElements();) {
    Binding binding = (Binding) e.nextElement();
    if (binding.getObject() instanceof Context) {
      clearContext((Context) binding.getObject());
    }
    context.unbind(binding.getName());
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:15,代碼來源:ContextJUnitTest.java

示例4: verifyListBindings

import javax.naming.Context; //導入方法依賴的package包/類
private void verifyListBindings(Context c, String name, Object obj1, Object obj2)
    throws NamingException {
  boolean datasourceFoundFlg = false;
  boolean o2FoundFlg = false;
  boolean datasourceO1FoundFlg = false;
  boolean datasourceNullFoundFlg = false;

  // List bindings for the specified context
  for (NamingEnumeration en = c.listBindings(name); en.hasMore();) {
    Binding b = (Binding) en.next();
    if (b.getName().equals("datasource")) {
      assertEquals(b.getObject(), dataSourceContext);
      datasourceFoundFlg = true;

      Context nextCon = (Context) b.getObject();
      for (NamingEnumeration en1 = nextCon.listBindings(""); en1.hasMore();) {
        Binding b1 = (Binding) en1.next();
        if (b1.getName().equals("sub41")) {
          assertEquals(b1.getObject(), obj1);
          datasourceO1FoundFlg = true;
        } else if (b1.getName().equals("sub43")) {
          // check for null object
          assertNull(b1.getObject());
          datasourceNullFoundFlg = true;
        }
      }
    } else if (b.getName().equals("sub42")) {
      assertEquals(b.getObject(), obj2);
      o2FoundFlg = true;
    }
  }
  if (!(datasourceFoundFlg && o2FoundFlg && datasourceO1FoundFlg && datasourceNullFoundFlg)) {
    fail();
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:36,代碼來源:ContextJUnitTest.java


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