Java Code Examples for javax.naming.NameClassPair#getName()
The following examples show how to use
javax.naming.NameClassPair#getName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirContextURLConnection.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * List children of this collection. The names given are relative to this * URI's path. The full uri of the children is then : path + "/" + name. */ public Enumeration<String> list() throws IOException { if (!connected) { connect(); } if ((resource == null) && (collection == null)) { throw new FileNotFoundException( getURL() == null ? "null" : getURL().toString()); } Vector<String> result = new Vector<String>(); if (collection != null) { try { NamingEnumeration<NameClassPair> enumeration = collection.list("/"); UEncoder urlEncoder = new UEncoder(UEncoder.SafeCharsSet.WITH_SLASH); while (enumeration.hasMoreElements()) { NameClassPair ncp = enumeration.nextElement(); String s = ncp.getName(); result.addElement( urlEncoder.encodeURL(s, 0, s.length()).toString()); } } catch (NamingException e) { // Unexpected exception throw new FileNotFoundException( getURL() == null ? "null" : getURL().toString()); } } return result.elements(); }
Example 2
Source File: DirContextURLConnection.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * List children of this collection. The names given are relative to this * URI's path. The full uri of the children is then : path + "/" + name. */ public Enumeration<String> list() throws IOException { if (!connected) { connect(); } if ((resource == null) && (collection == null)) { throw new FileNotFoundException( getURL() == null ? "null" : getURL().toString()); } Vector<String> result = new Vector<String>(); if (collection != null) { try { NamingEnumeration<NameClassPair> enumeration = collection.list("/"); UEncoder urlEncoder = new UEncoder(UEncoder.SafeCharsSet.WITH_SLASH); while (enumeration.hasMoreElements()) { NameClassPair ncp = enumeration.nextElement(); String s = ncp.getName(); result.addElement( urlEncoder.encodeURL(s, 0, s.length()).toString()); } } catch (NamingException e) { // Unexpected exception throw new FileNotFoundException( getURL() == null ? "null" : getURL().toString()); } } return result.elements(); }
Example 3
Source File: JdbcWrapperHelper.java From javamelody with Apache License 2.0 | 5 votes |
private static Map<String, DataSource> getJndiDataSourcesAt(String jndiPrefix) throws NamingException { final InitialContext initialContext = new InitialContext(); final Map<String, DataSource> dataSources = new LinkedHashMap<String, DataSource>(2); try { for (final NameClassPair nameClassPair : Collections .list(initialContext.list(jndiPrefix))) { // note: il ne suffit pas de tester // (DataSource.class.isAssignableFrom(Class.forName(nameClassPair.getClassName()))) // car nameClassPair.getClassName() vaut "javax.naming.LinkRef" sous jboss 5.1.0.GA // par exemple, donc on fait le lookup pour voir final String jndiName; if (nameClassPair.getName().startsWith("java:")) { // pour glassfish v3 jndiName = nameClassPair.getName(); } else { jndiName = jndiPrefix + '/' + nameClassPair.getName(); } final Object value = initialContext.lookup(jndiName); if (value instanceof DataSource) { dataSources.put(jndiName, (DataSource) value); } } } catch (final NamingException e) { // le préfixe ("comp/env/jdbc", "/jdbc" ou "java:global/jdbc", etc) n'existe pas dans jndi, // (dans glassfish 3.0.1, c'est une NamingException et non une NameNotFoundException) return dataSources; } initialContext.close(); return dataSources; }
Example 4
Source File: PingsResource.java From ping with Apache License 2.0 | 5 votes |
@GET @Path("/jndi/{namespace}") public JsonObject jndi(@PathParam("namespace") String namespace) throws NamingException { JsonObjectBuilder builder = Json.createObjectBuilder(); InitialContext c = new InitialContext(); NamingEnumeration<NameClassPair> list = c.list(namespace); while (list.hasMoreElements()) { NameClassPair nameClassPair = list.nextElement(); String name = nameClassPair.getName(); String type = nameClassPair.getClassName(); builder.add(name, type); } return builder.build(); }
Example 5
Source File: PingsResource.java From ping with Apache License 2.0 | 5 votes |
@GET @Path("/jndi/{namespace}") public JsonObject jndi(@PathParam("namespace") String namespace) throws NamingException { JsonObjectBuilder builder = Json.createObjectBuilder(); InitialContext c = new InitialContext(); NamingEnumeration<NameClassPair> list = c.list(namespace); while (list.hasMoreElements()) { NameClassPair nameClassPair = list.nextElement(); String name = nameClassPair.getName(); String type = nameClassPair.getClassName(); builder.add(name, type); } return builder.build(); }
Example 6
Source File: VFSDirContext.java From olat with Apache License 2.0 | 4 votes |
@Override public Binding next() throws NamingException { NameClassPair pair = entries.next(); return new Binding(pair.getName(), pair.getClassName(), null); }
Example 7
Source File: VFSDirContext.java From olat with Apache License 2.0 | 4 votes |
@Override public Binding next() throws NamingException { NameClassPair pair = entries.next(); return new Binding(pair.getName(), pair.getClassName(), null); }
Example 8
Source File: JNDIConfiguration.java From commons-configuration with Apache License 2.0 | 4 votes |
/** * This method recursive traverse the JNDI tree, looking for Context objects. * When it finds them, it traverses them as well. Otherwise it just adds the * values to the list of keys found. * * @param keys All the keys that have been found. * @param context The parent context * @param prefix What prefix we are building on. * @param processedCtx a set with the so far processed objects * @throws NamingException If JNDI has an issue. */ private void recursiveGetKeys(final Set<String> keys, final Context context, final String prefix, final Set<Context> processedCtx) throws NamingException { processedCtx.add(context); NamingEnumeration<NameClassPair> elements = null; try { elements = context.list(""); // iterates through the context's elements while (elements.hasMore()) { final NameClassPair nameClassPair = elements.next(); final String name = nameClassPair.getName(); final Object object = context.lookup(name); // build the key final StringBuilder key = new StringBuilder(); key.append(prefix); if (key.length() > 0) { key.append("."); } key.append(name); if (object instanceof Context) { // add the keys of the sub context final Context subcontext = (Context) object; if (!processedCtx.contains(subcontext)) { recursiveGetKeys(keys, subcontext, key.toString(), processedCtx); } } else { // add the key keys.add(key.toString()); } } } finally { // close the enumeration if (elements != null) { elements.close(); } } }
Example 9
Source File: JNDIConfiguration.java From commons-configuration with Apache License 2.0 | 4 votes |
/** * Because JNDI is based on a tree configuration, we need to filter down the * tree, till we find the Context specified by the key to start from. * Otherwise return null. * * @param path the path of keys to traverse in order to find the context * @param context the context to start from * @return The context at that key's location in the JNDI tree, or null if not found * @throws NamingException if JNDI has an issue */ private Context getContext(final List<String> path, final Context context) throws NamingException { // return the current context if the path is empty if (path == null || path.isEmpty()) { return context; } final String key = path.get(0); // search a context matching the key in the context's elements NamingEnumeration<NameClassPair> elements = null; try { elements = context.list(""); while (elements.hasMore()) { final NameClassPair nameClassPair = elements.next(); final String name = nameClassPair.getName(); final Object object = context.lookup(name); if (object instanceof Context && name.equals(key)) { final Context subcontext = (Context) object; // recursive search in the sub context return getContext(path.subList(1, path.size()), subcontext); } } } finally { if (elements != null) { elements.close(); } } return null; }
Example 10
Source File: DefaultNameClassPairMapper.java From spring-ldap with Apache License 2.0 | 3 votes |
/** * Gets the Name from the supplied NameClassPair and returns it as the * result. * * @param nameClassPair * the NameClassPair to transform. * @return the Name string from the NameClassPair. */ @Override public String mapFromNameClassPair(NameClassPair nameClassPair) throws NamingException { return nameClassPair.getName(); }