List of usage examples for javax.naming NameClassPair getClassName
public String getClassName()
From source file:com.funambol.server.db.DataSourceContextHelperTest.java
/** * Usefull method for troubleshooting/*from w ww . jav a 2s .c o m*/ * @throws java.lang.Exception */ private static void printContext(String contextName) throws Exception { System.out.println("---------- Listing '" + contextName + "' ------------"); InitialContext initialContext = new InitialContext(); NamingEnumeration<NameClassPair> nameEnum = initialContext.list(contextName); if (nameEnum != null) { while (nameEnum.hasMore()) { NameClassPair name = nameEnum.next(); String nameInSpace = name.getName(); String className = name.getClassName(); System.out.println("NameInSpace: " + nameInSpace + ", class: " + className); } } System.out.println("--------------------------------------------"); }
From source file:com.flexive.shared.EJBLookup.java
/** * Discover which lookup strategy works for the given class * * @param appName EJB application name * @param environment properties passed to the initial context * @param type the class// w w w . j a va 2 s .co m * @return appName (may have changed) */ private static <T> String discoverStrategy(String appName, final Hashtable<String, String> environment, Class<T> type) { InitialContext ctx = null; for (STRATEGY strat : STRATEGY.values()) { if (strat == STRATEGY.UNKNOWN) continue; used_strategy = strat; try { final Hashtable<String, String> env = environment != null ? new Hashtable<String, String>(environment) : new Hashtable<String, String>(); prepareEnvironment(strat, env); ctx = new InitialContext(env); ctx.lookup(buildName(appName, type)); if (used_strategy == STRATEGY.EJB31_MODULE) { // we need to resolve all interfaces required by non-web components (stream server, scheduler), // since they run outside the module context resolveKnownInterfaces(); } return appName; } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("Strategy " + strat + " failed: " + e.getMessage(), e); } //ignore and try next } } //houston, we have a problem - try locale and remote with appname again iterating through all "root" ctx bindings //this can happen if the ear is not named flexive.ear try { if (ctx == null) ctx = new InitialContext(environment); NamingEnumeration<NameClassPair> ncpe = ctx.list(""); while (ncpe.hasMore()) { NameClassPair ncp = ncpe.next(); if (ncp.getClassName().endsWith("NamingContext")) { appName = ncp.getName(); try { used_strategy = STRATEGY.APP_SIMPLENAME_LOCAL; ctx.lookup(buildName(ncp.getName(), type)); APPNAME = ncp.getName(); LOG.info("Using application name [" + appName + "] for lookups!"); return APPNAME; } catch (Exception e) { //ignore and try remote } try { used_strategy = STRATEGY.APP_SIMPLENAME_REMOTE; ctx.lookup(buildName(ncp.getName(), type)); APPNAME = ncp.getName(); LOG.info("Using application name [" + appName + "] for lookups!"); return APPNAME; } catch (Exception e) { //ignore and try remote } } } } catch (Exception e) { LOG.warn(e); } used_strategy = null; return appName; }
From source file:com.egt.core.util.Utils.java
public static void traceContext(Context c, String name) { NameClassPair ncp; NamingEnumeration<NameClassPair> ncpenum; try {/*from www. j a v a 2 s . c om*/ ncpenum = c.list(name); while (ncpenum.hasMore()) { ncp = ncpenum.next(); if (ncp.getClassName().endsWith("javaURLContext")) { traceContext(c, ncp.getName()); } else { Bitacora.logTrace(ncp.getName() + " = " + ncp.getClassName()); } } } catch (NamingException ex) { Bitacora.logFatal(ThrowableUtils.getString(ex)); } }
From source file:net.chrisrichardson.foodToGo.ejb3.facadeWithSpringDI.PlaceOrderFacadeUsingIntegratedDependencyInjectImpl.java
private void listContext(InitialContext initialContext, String root) throws NamingException { Enumeration<NameClassPair> enumeration = initialContext.list(root); while (enumeration.hasMoreElements()) { NameClassPair nc = enumeration.nextElement(); logger.debug("Name=" + root + "/" + nc.getName()); if (nc.getClassName().endsWith("NamingContext")) listContext(initialContext, root + "/" + nc.getName()); }//from w ww. j a va 2 s . c om }
From source file:org.netoprise.neo4j.ConnectorTest.java
@Test @Ignore//from w ww .j av a 2 s . co m @OperateOnDeployment("test") public void listJNDI() { try { Context context = new InitialContext(); System.out.println("Context namespace: " + context.getNameInNamespace()); NamingEnumeration<NameClassPair> content = context.list("comp"); while (content.hasMoreElements()) { NameClassPair nameClassPair = (NameClassPair) content.nextElement(); System.out .println("Name :" + nameClassPair.getName() + " with type:" + nameClassPair.getClassName()); } } catch (NamingException e) { throw new RuntimeException(e); } }
From source file:org.zanata.ZanataInit.java
private static void list(Context ctx, String indent, StringBuffer buffer, boolean verbose) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try {/* w ww .j a v a 2s. c om*/ NamingEnumeration<NameClassPair> ne = ctx.list(""); while (ne.hasMore()) { NameClassPair pair = ne.next(); String name = pair.getName(); String className = pair.getClassName(); boolean recursive = false; boolean isLinkRef = false; boolean isProxy = false; Class<?> c = null; try { c = loader.loadClass(className); if (Context.class.isAssignableFrom(c)) { recursive = true; } if (LinkRef.class.isAssignableFrom(c)) { isLinkRef = true; } isProxy = Proxy.isProxyClass(c); } catch (ClassNotFoundException cnfe) { // If this is a $Proxy* class its a proxy if (className.startsWith("$Proxy")) { isProxy = true; // We have to get the class from the binding try { Object p = ctx.lookup(name); c = p.getClass(); } catch (NamingException e) { Throwable t = e.getRootCause(); if (t instanceof ClassNotFoundException) { // Get the class name from the exception msg String msg = t.getMessage(); if (msg != null) { // Reset the class name to the CNFE class className = msg; } } } } } buffer.append(indent).append(" +- ").append(name); // Display reference targets if (isLinkRef) { // Get the try { Object obj = ctx.lookupLink(name); LinkRef link = (LinkRef) obj; buffer.append("[link -> "); buffer.append(link.getLinkName()); buffer.append(']'); } catch (Throwable t) { buffer.append("invalid]"); } } // Display proxy interfaces if (isProxy) { buffer.append(" (proxy: ").append(pair.getClassName()); if (c != null) { Class<?>[] ifaces = c.getInterfaces(); buffer.append(" implements "); for (Class<?> iface : ifaces) { buffer.append(iface); buffer.append(','); } buffer.setCharAt(buffer.length() - 1, ')'); } else { buffer.append(" implements ").append(className).append(")"); } } else if (verbose) { buffer.append(" (class: ").append(pair.getClassName()).append(")"); } buffer.append('\n'); if (recursive) { try { Object value = ctx.lookup(name); if (value instanceof Context) { Context subctx = (Context) value; list(subctx, indent + " | ", buffer, verbose); } else { buffer.append(indent).append(" | NonContext: ").append(value); buffer.append('\n'); } } catch (Throwable t) { buffer.append("Failed to lookup: ").append(name).append(", errmsg=").append(t.getMessage()); buffer.append('\n'); } } } ne.close(); } catch (NamingException ne) { buffer.append("error while listing context ").append(ctx.toString()).append(": ") .append(ne.toString(true)); } }