List of usage examples for javax.naming Context list
public NamingEnumeration<NameClassPair> list(String name) throws NamingException;
From source file:org.apache.directory.studio.connection.core.io.jndi.JNDIConnectionWrapper.java
/** * Retrieves all referrals from the ReferralException and * creates or updates the ReferralsInfo. * // w w w . j a v a 2s . c o m * @param referralException the referral exception * @param initialReferralsInfo the initial referrals info, may be null * * @return the created or updated referrals info * * @throws NamingException if a loop was encountered. */ static ReferralsInfo handleReferralException(ReferralException referralException, ReferralsInfo initialReferralsInfo) throws NamingException { if (initialReferralsInfo == null) { initialReferralsInfo = new ReferralsInfo(true); } Referral referral = handleReferralException(referralException, initialReferralsInfo, null); while (referralException.skipReferral()) { try { Context ctx = referralException.getReferralContext(); ctx.list(StringUtils.EMPTY); //$NON-NLS-1$ } catch (NamingException ne) { if (ne instanceof ReferralException) { if (ne != referralException) { // what a hack: // if the same exception is throw, we have another URL for the same Referral/SearchResultReference // if another exception is throws, we have a new Referral/SearchResultReference // in the latter case we null out the reference, a new one will be created by handleReferral() referral = null; } referralException = (ReferralException) ne; referral = handleReferralException(referralException, initialReferralsInfo, referral); } else { break; } } } return initialReferralsInfo; }
From source file:org.efaps.db.store.VFSStoreResource.java
/** * Method called to initialize this StoreResource. * @param _instance Instance of the object this StoreResource is wanted * for//w w w. j a v a2 s . c om * @param _store Store this resource belongs to * @throws EFapsException on error * @see Resource#initialize(Instance, Map, Compress) */ @Override public void initialize(final Instance _instance, final Store _store) throws EFapsException { super.initialize(_instance, _store); final StringBuilder fileNameTmp = new StringBuilder(); final String useTypeIdStr = getStore().getResourceProperties().get(VFSStoreResource.PROPERTY_USE_TYPE); if ("true".equalsIgnoreCase(useTypeIdStr)) { fileNameTmp.append(getInstance().getType().getId()).append("/"); } final String numberSubDirsStr = getStore().getResourceProperties() .get(VFSStoreResource.PROPERTY_NUMBER_SUBDIRS); if (numberSubDirsStr != null) { final long numberSubDirs = Long.parseLong(numberSubDirsStr); final String pathFormat = "%0" + Math.round(Math.log10(numberSubDirs) + 0.5d) + "d"; fileNameTmp.append(String.format(pathFormat, getInstance().getId() % numberSubDirs)).append("/"); } fileNameTmp.append(getInstance().getType().getId()).append(".").append(getInstance().getId()); this.storeFileName = fileNameTmp.toString(); final String numberBackupStr = getStore().getResourceProperties() .get(VFSStoreResource.PROPERTY_NUMBER_BACKUP); if (numberBackupStr != null) { this.numberBackup = Integer.parseInt(numberBackupStr); } if (this.manager == null) { try { DefaultFileSystemManager tmpMan = null; if (getStore().getResourceProperties().containsKey(Store.PROPERTY_JNDINAME)) { final InitialContext initialContext = new InitialContext(); final Context context = (Context) initialContext.lookup("java:comp/env"); final NamingEnumeration<NameClassPair> nameEnum = context.list(""); while (nameEnum.hasMoreElements()) { final NameClassPair namePair = nameEnum.next(); if (namePair.getName() .equals(getStore().getResourceProperties().get(Store.PROPERTY_JNDINAME))) { tmpMan = (DefaultFileSystemManager) context .lookup(getStore().getResourceProperties().get(Store.PROPERTY_JNDINAME)); break; } } } if (tmpMan == null && this.manager == null) { this.manager = evaluateFileSystemManager(); } } catch (final NamingException e) { throw new EFapsException(VFSStoreResource.class, "initialize.NamingException", e); } } }
From source file:org.netoprise.neo4j.ConnectorTest.java
@Test @Ignore//from w ww . j a v a2 s . com @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.nuxeo.runtime.datasource.DataSourceHelper.java
public static Map<String, DataSource> getDatasources() throws NamingException { String prefix = getDataSourceJNDIPrefix(); Context naming = new InitialContext(); Context jdbc = (Context) naming.lookup(prefix); Enumeration<NameClassPair> namesPair = jdbc.list(""); Map<String, DataSource> datasourcesByName = new HashMap<String, DataSource>(); while (namesPair.hasMoreElements()) { NameClassPair pair = namesPair.nextElement(); String name = pair.getName(); if (pair.isRelative()) { name = prefix + "/" + name; }//w w w. jav a2s.c o m Object ds = naming.lookup(name); if (ds instanceof DataSource) { datasourcesByName.put(name, (DataSource) ds); } } return datasourcesByName; }
From source file:org.saiku.reporting.backend.server.SaikuJndiDatasourceConnectionProvider.java
public void showJndiContext(Context ctx, String name, String space) { if (null == name) name = ""; if (null == space) space = ""; try {/*w w w . ja va2 s.c o m*/ NamingEnumeration<NameClassPair> en = ctx.list(name); while (en != null && en.hasMoreElements()) { String delim = (name.length() > 0) ? "/" : ""; NameClassPair ncp = en.next(); log.debug(space + name + delim + ncp); if (space.length() < 40) showJndiContext(ctx, ncp.getName(), " " + space); } } catch (javax.naming.NamingException ex) { // Normalerweise zu ignorieren } }
From source file:org.scilla.Config.java
/** singleton constructor */ protected Config() { super();//from w w w. j a v a 2s.c o m // defaults put(CACHE_DIR_KEY, System.getProperty("java.io.tmpdir")); // property file data Properties prop = new Properties(); InputStream in = null; try { ClassLoader cl = getClass().getClassLoader(); in = cl.getResourceAsStream(PROPERTY_FILE); if (in != null) { prop.load(in); log.info("properties loaded: " + PROPERTY_FILE); } else { log.fatal("properties not avialable: " + PROPERTY_FILE); } } catch (IOException ex) { log.fatal("can't load properties: " + PROPERTY_FILE, ex); } finally { if (in != null) { try { in.close(); } catch (IOException e) { log.warn(e); } } } putAll(prop); // env-entry data try { Context ctx = new InitialContext(); Context env = (Context) ctx.lookup("java:comp/env"); for (Enumeration en = env.list("scilla"); en.hasMoreElements();) { Object v = en.nextElement(); if (v instanceof NameClassPair) { String key = ((NameClassPair) v).getName(); String val = env.lookup("scilla/" + key).toString(); put(key, val); log.info("env-entry: " + key + "=" + val); } } } catch (NamingException ex) { log.info("no env-entries for scilla available"); } }
From source file:org.viafirma.cliente.util.ConfigUtil.java
/** * Recupera el conjunto de propiedades que utiliza la aplicacin. * @param context/*from w ww.j av a 2s. c o m*/ * @return */ public Properties readConfigPropertes() { Properties properties = new Properties(); Context initCtx; try { // carcamos la configuracin por defecto properties.load(getClass().getResourceAsStream("/viafirmaConfig.properties")); // recuperamos la configuracin almacenada en el contexto de aplicacin 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) { if (propiedad.getName().startsWith("SYSTEM_")) { String valor = (String) temp; String nombre = StringUtils.substringAfter(propiedad.getName(), "SYSTEM_"); System.getProperties().put(nombre, valor); properties.put(nombre, valor); } else { String valor = (String) temp; properties.put(propiedad.getName(), valor); } } } for (Object key : properties.keySet()) { if (((String) key).contains("PASSWORD")) { System.out.println("\t\t\t" + key + "=***"); } else { System.out.println("\t\t\t" + key + "=" + properties.get(key)); } } } catch (Exception e) { log.error("No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible. " + e.getMessage()); //Permitimos el arranque de la aplicacin utilizando la configuracin de los properties. //throw new ExceptionInInitializerError("No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible."+e.getMessage()); } return properties; }
From source file:org.viafirma.util.ConfigUtil.java
/** * Recupera el conjunto de propiedades que utiliza la aplicacin. * @param context//from www . j a v a 2s .co m * @return */ public String readConfigProperty(String property) { 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(); if (property.equalsIgnoreCase(propiedad.getName())) { // propiedad encontrada Object temp = contextInit.lookup(propiedad.getName()); if (temp instanceof String) { String valor = (String) temp; return valor; } } } } catch (Exception e) { throw new ExceptionInInitializerError( "No se pueden recuperar los parametros de configuracin. JNDI parece no estar disponible." + e.getMessage()); } log.fatal("No se pueden recuperar el parametro de configuracin " + property + " de configuracin. JNDI parece no estar disponible."); return null; }
From source file:org.viafirma.util.ConfigUtil.java
/** * Recupera el conjunto de propiedades que utiliza la aplicacin. * @param context//from w w w .j a v a2s .c om * @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 {/*from w w w . j ava 2 s . c o m*/ 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)); } }