Object result = null;
while (addresses.hasMoreElements()) {
RefAddr address = addresses.nextElement();
if (address instanceof StringRefAddr && "URL".equals(address.getType())) {
String urlScheme = getUrlScheme( (String) address.getContent() );
DirObjectFactory factory = null;
ServiceReference ref = null;
try {
ServiceReference[] services = callerContext.getServiceReferences(DirObjectFactory.class.getName(),
"(&(" + JNDIConstants.JNDI_URLSCHEME + "=" + urlScheme + "))");
if (services != null && services.length > 0) {
ref = services[0];
}
} catch (InvalidSyntaxException e) {
// should not happen
throw new RuntimeException("Invalid filter", e);
}
if (ref != null) {
factory = (DirObjectFactory) callerContext.getService(ref);
String value = (String) address.getContent();
try {
result = factory.getObjectInstance(value, name, nameCtx, environment, attrs);
} finally {
callerContext.ungetService(ref);
}
// if the result comes back and is not null and not the reference