* @return
* @throws IllegalArgumentException If no ResourceProvider found for Type
* @throws RuntimeException If ResourceProvider return null
*/
private Object lookup(Class<?> type, ContainerResource resource, Annotation... qualifiers) {
final Container container;
final List<Container> containers = containerRegistry.get().getContainers();
if (resource.value().isEmpty()) {
if (containers.size() > 1) {
throw new RuntimeException("@ContainerResource did not specify a server and more than one server exists in the deployment");
}
container = containers.get(0);
} else {
container = containerRegistry.get().getContainer(resource.value());
if (container == null) {
throw new RuntimeException("@ContainerResource specified non existent server " + resource.value());
}
}
try {
containerContext.get().activate(container.getName());
if (Context.class.isAssignableFrom(type)) {
return lookupContext(type, resource, qualifiers);
} else if (ManagementClient.class.isAssignableFrom(type)) {
return managementClient.get();
} else {