use of javax.naming.RefAddr in project tomee by apache.
the class TomcatEjbFactory method getObjectInstance.
@SuppressWarnings("unchecked")
@Override
public Object getObjectInstance(final Object obj, final Name name, final Context nameCtx, final Hashtable environment) throws Exception {
Object beanObj = null;
final Class ejbRefClass = Class.forName("org.apache.naming.EjbRef");
if (ejbRefClass.isAssignableFrom(obj.getClass())) {
RefAddr refAddr;
String addrType;
final Properties env = new Properties();
String bean = null;
final Reference ref = (Reference) obj;
final Enumeration addresses = ref.getAll();
while (addresses.hasMoreElements()) {
refAddr = (RefAddr) addresses.nextElement();
addrType = refAddr.getType();
if (addrType.startsWith(OPENEJB_PREFIX)) {
final String value = refAddr.getContent().toString();
if (addrType.equals(OPENEJB_EJB_LINK)) {
bean = value;
continue;
}
String key = addrType.substring(OPENEJB_PREFIX_LENGTH);
key = JAVA_PREFIX + key;
env.put(key, value);
}
}
if (bean != null) {
beanObj = (new InitialContext(env)).lookup(bean);
}
}
return beanObj;
}
use of javax.naming.RefAddr in project tomee by apache.
the class NamingUtil method getProperty.
public static String getProperty(final Reference ref, final String name) {
final RefAddr addr = ref.get(name);
if (addr == null) {
return null;
}
final Object value = addr.getContent();
return (String) value;
}
use of javax.naming.RefAddr in project tomee by apache.
the class TomcatJndiBuilder method normalize.
/**
* LinkRef addresses need to be prefixed with java: or they won't resolve
*
* OpenEJB is fine with this, but Tomcat needs them
*
* @param value
* @return
*/
private static Object normalize(final Object value) {
try {
if (!(value instanceof LinkRef)) {
return value;
}
final LinkRef ref = (LinkRef) value;
final RefAddr refAddr = ref.getAll().nextElement();
final String address = refAddr.getContent().toString();
if (address.startsWith("openejb:")) {
return value;
}
if (!address.startsWith("java:")) {
return new LinkRef("java:" + address);
}
} catch (final Exception e) {
// no-op
}
return value;
}
Aggregations