public Object getComponent(Object key)
throws ObjectNotFoundException
{
if (key == null)
throw new ObjectNotFoundException("Component key is null");
if (log.isLoggable(Level.FINE)) {
log.fine(L.l("ResinContainerContext.getComponent({0} with type {1})",
key, key.getClass().getName()));
}
if (key instanceof ContainerKeyPair) {
ContainerKeyPair pair = (ContainerKeyPair) key;
// XXX pair.getContainerName() appears to be null most of the time
// ignore it?
key = pair.getKey();
}
if (key instanceof Class) {
Class clazz = (Class) key;
ComponentFactory component = null;
if (log.isLoggable(Level.FINE))
log.fine("Creating new instance from " + clazz);
synchronized (_componentMap) {
component = _componentMap.get(clazz);
if (component == null) {
component = _webBeans.resolveByType(clazz);
if (component == null)
component = _webBeans.createTransient(clazz);
_componentMap.put(clazz, component);
}
}
return component.get();
}
else if (key instanceof String) {
ComponentFactory component = _webBeans.findByName((String) key);
if (component == null) {
throw new ObjectNotFoundException(L.l("Cannot find component with name '{0}'", key));
}
return component.get();
}
else {
throw new ObjectNotFoundException(L.l("Component keys of type {0} are not understood", key.getClass().getName()));
}
}