List of usage examples for javax.naming NameClassPair getName
public String getName()
From source file:org.viafirma.util.ConfigUtil.java
/** * Recupera el conjunto de propiedades que utiliza la aplicacin. * @param context/*from w ww . j av a 2 s. co m*/ * @return */ public Properties readConfigPropertes() { Properties properties = new Properties(); Context initCtx; try { initCtx = new InitialContext(); Context contextInit = (Context) initCtx.lookup("java:comp/env"); // recuperamos ahora todos los parametros JNDI que estan en el raiz de la aplicacin NamingEnumeration<NameClassPair> propiedadesJDNI = contextInit.list(""); while (propiedadesJDNI.hasMoreElements()) { NameClassPair propiedad = propiedadesJDNI.nextElement(); Object temp = contextInit.lookup(propiedad.getName()); if (temp instanceof String) { String valor = (String) temp; System.out.println("\t\t\t" + propiedad.getName() + "=" + valor); properties.put(propiedad.getName(), valor); } } } catch (Exception e) { log.fatal("No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible.", e); throw new ExceptionInInitializerError( "No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible." + e.getMessage()); } return properties; }
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 w w . j a v a 2 s. com 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)); } }