in src/java/org/apache/fulcrum/yaafi/framework/container/ServiceContainerImpl.java [610:670]
public Object lookup(String name) throws ServiceException {
Validate.notEmpty(name, "name");
Object result = null;
ServiceComponent serviceManagerComponent;
if (this.isAlreadyDisposed()) {
String msg = "The container is disposed an no services are available";
this.getLogger().error(msg);
throw new ServiceException(name, msg);
}
try {
synchronized (this) {
// 1) check our local services
serviceManagerComponent = this.getLocalServiceComponent(name);
if (serviceManagerComponent != null) {
result = serviceManagerComponent.getInstance();
if (result != null && this.getLogger().isDebugEnabled()) {
String msg = "Located the service '" + name + "' in the local container";
this.getLogger().debug(msg);
}
}
// 2) look at fallback service managers
if (result == null) {
result = this.getFallbackService(name);
}
}
} catch (ServiceException e) {
String msg = "Failed to lookup a service " + name;
this.getLogger().error(msg, e);
throw e;
} catch (Throwable t) {
String msg = "Failed to lookup a service " + name;
this.getLogger().error(msg, t);
throw new ServiceException(name, msg, t);
}
// 3) if we haven't found anything ask the parent ServiceManager
if (result == null && this.hasParentServiceManager()) {
result = this.getParentServiceManager().lookup(name);
if (result != null && this.getLogger().isDebugEnabled()) {
String msg = "Located the service '" + name + "' using the parent service manager";
this.getLogger().debug(msg);
}
}
// if we still haven't found anything then complain
if (result == null) {
String msg = "The following component does not exist : " + name;
this.getLogger().error(msg);
throw new ServiceException(AvalonYaafiConstants.AVALON_CONTAINER_YAAFI, name);
}
return result;
}