use of org.apache.openejb.core.ivm.IntraVmProxy in project tomee by apache.
the class IvmContext method lookup.
public Object lookup(final String compositName) throws NamingException {
if (compositName.equals("")) {
return this;
}
final String compoundName;
final int index = compositName.indexOf(":");
if (index > -1) {
final String prefix = compositName.substring(0, index);
String path = compositName.substring(index + 1);
final ParsedName name = new ParsedName(path);
if (prefix.equals("openejb")) {
path = name.path();
return openejbURLContextFactory.getContext().lookup(path);
} else if (prefix.equals("java")) {
if (name.getComponent().equals("openejb")) {
path = name.remaining().path();
return openejbURLContextFactory.getContext().lookup(path);
} else {
path = name.path();
return javaURLContextFactory.getContext().lookup(path);
}
} else {
// we don't know what the prefix means, throw an exception
throw new NamingException("Unknown JNDI name prefix '" + prefix + ":'");
}
} else {
/*
the resolve method always starts with the comparison assuming that the first
component of the name is a context of a peer node or the same node, so we have
to prepend the current context name to the relative lookup path.
*/
compoundName = mynode.getAtomicName() + '/' + compositName;
}
/*
If the object has been resolved in the past from this context and the specified path (name)
it will be in the fastCache which is significantly faster then peruse the Node graph.
80 ms compared to 300 ms for a full node path search.
*/
Object obj = fastCache.get(compoundName);
if (obj == null) {
try {
obj = mynode.resolve(new ParsedName(compoundName), readOnly);
} catch (final NameNotFoundException nnfe) {
obj = federate(compositName);
}
// don't cache proxies
if (!(obj instanceof IntraVmProxy) && !(obj instanceof ContextualJndiReference)) {
fastCache.put(compoundName, obj);
}
}
if (obj == null) {
throw new NameNotFoundException("Name \"" + compositName + "\" not found.");
}
if (obj.getClass() == IvmContext.class) {
((IvmContext) obj).myEnv = myEnv;
} else if (obj instanceof Reference) {
// TODO: JRG - this needs a test
while (obj instanceof Reference) {
obj = ((Reference) obj).getObject();
}
} else if (obj instanceof LinkRef) {
obj = lookup(((LinkRef) obj).getLinkName());
}
return obj;
}
Aggregations