use of javax.naming.NameClassPair in project tomee by apache.
the class JNDIContext method listBindings.
@SuppressWarnings("unchecked")
@Override
public NamingEnumeration<Binding> listBindings(final String name) throws NamingException {
final Object o = lookup(name);
if (o instanceof Context) {
final Context context = (Context) o;
final NamingEnumeration<NameClassPair> enumeration = context.list("");
final List<NameClassPair> bindings = new ArrayList<NameClassPair>();
while (enumeration.hasMoreElements()) {
final NameClassPair pair = enumeration.nextElement();
bindings.add(new LazyBinding(pair.getName(), pair.getClassName(), context));
}
return new NameClassPairEnumeration(bindings);
} else {
return null;
}
}
use of javax.naming.NameClassPair in project tomee by apache.
the class NameClassPairEnumeration method readExternal.
@Override
public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
// future use
final byte version = in.readByte();
int size = in.readInt();
list = new ArrayList<NameClassPair>(size);
for (; size > 0; size--) {
final String name = (String) in.readObject();
final String className = (String) in.readObject();
list.add(new NameClassPair(name, className));
}
iterator = list.iterator();
}
use of javax.naming.NameClassPair in project tomee by apache.
the class JndiRequestHandler method doList.
private void doList(final JNDIRequest req, final JNDIResponse res, final String prefix) {
final String name = req.getRequestString();
try {
final NamingEnumeration<NameClassPair> namingEnumeration = rootContext.list(prefix + name);
if (namingEnumeration == null) {
res.setResponseCode(ResponseCodes.JNDI_OK);
res.setResult(null);
} else {
res.setResponseCode(ResponseCodes.JNDI_ENUMERATION);
final ArrayList<NameClassPair> list = Collections.list(namingEnumeration);
for (final NameClassPair pair : list) {
if (pair.getClassName().equals(IvmContext.class.getName())) {
pair.setClassName(javax.naming.Context.class.getName());
}
}
res.setResult(new NameClassPairEnumeration(list));
}
} catch (NameNotFoundException e) {
res.setResponseCode(ResponseCodes.JNDI_NOT_FOUND);
} catch (NamingException e) {
res.setResponseCode(ResponseCodes.JNDI_NAMING_EXCEPTION);
res.setResult(new ThrowableArtifact(e));
}
}
use of javax.naming.NameClassPair in project tomee by apache.
the class JndiServlet method addBindings.
private void addBindings(final String path, final Map<String, Object> bindings, final Context context) {
try {
for (final NameClassPair pair : Collections.list(context.list(""))) {
final String name = pair.getName();
final String className = pair.getClassName();
if ("org.apache.naming.resources.FileDirContext$FileResource".equals(className)) {
bindings.put(path + name, "<file>");
} else {
try {
final Object value = context.lookup(name);
if (value instanceof Context) {
final Context nextedContext = (Context) value;
bindings.put(path + name, "");
addBindings(path + name + "/", bindings, nextedContext);
} else {
bindings.put(path + name, value);
}
} catch (final NamingException e) {
// lookup failed
bindings.put(path + name, "ERROR: " + e.getMessage());
}
}
}
} catch (final NamingException e) {
bindings.put(path, "ERROR: list bindings threw an exception: " + e.getMessage());
}
}
use of javax.naming.NameClassPair in project deltaspike by apache.
the class JndiUtils method list.
/**
* Resolves an instances for the given naming context.
*
* @param name context name
* @param type target type
* @param <T> type
* @return the found instances, null otherwise
*/
public static <T> Map<String, T> list(String name, Class<T> type) {
Map<String, T> result = new HashMap<String, T>();
try {
NameParser nameParser = initialContext.getNameParser(name);
NamingEnumeration<NameClassPair> enumeration = initialContext.list(name);
while (enumeration.hasMoreElements()) {
try {
NameClassPair binding = enumeration.nextElement();
Name bindingName = nameParser.parse(name).add(binding.getName());
result.put(binding.getName(), lookup(bindingName, type));
} catch (NamingException e) {
if (LOG.isLoggable(Level.FINEST)) {
// this is expected if there is no entry in JNDI for the requested name or type
// so finest level is ok, if devs want to see it they can enable this logger level.
LOG.log(Level.FINEST, "InitialContext#list failed!", e);
}
}
}
} catch (NamingException e) {
// this is fine at this point, since the individual lines will be caught currently.
LOG.log(Level.WARNING, "Problem reading the name of the JNDI location " + name + " or failuring listing pairs.", e);
}
return result;
}
Aggregations