use of org.apache.aries.blueprint.di.ExecutionContext in project aries by apache.
the class GenericType method parse.
public static GenericType parse(String rawType, final Object loader) throws ClassNotFoundException, IllegalArgumentException {
final String type = rawType.trim();
// Check if this is an array
if (type.endsWith("[]")) {
GenericType t = parse(type.substring(0, type.length() - 2), loader);
return new GenericType(Array.newInstance(t.getRawClass(), 0).getClass(), t);
}
// Check if this is a generic
int genericIndex = type.indexOf('<');
if (genericIndex > 0) {
if (!type.endsWith(">")) {
throw new IllegalArgumentException("Can not load type: " + type);
}
GenericType base = parse(type.substring(0, genericIndex), loader);
String[] params = type.substring(genericIndex + 1, type.length() - 1).split(",");
GenericType[] types = new GenericType[params.length];
for (int i = 0; i < params.length; i++) {
types[i] = parse(params[i], loader);
}
return new GenericType(base.getRawClass(), types);
}
// Primitive
if (primitiveClasses.containsKey(type)) {
return new GenericType(primitiveClasses.get(type));
}
// Extends
if (type.startsWith("? extends ")) {
String raw = type.substring("? extends ".length());
return new GenericType(((ClassLoader) loader).loadClass(raw), BoundType.Extends);
}
// Super
if (type.startsWith("? super ")) {
String raw = type.substring("? extends ".length());
return new GenericType(((ClassLoader) loader).loadClass(raw), BoundType.Super);
}
// Class
if (loader instanceof ClassLoader) {
return new GenericType(((ClassLoader) loader).loadClass(type));
} else if (loader instanceof Bundle) {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<GenericType>() {
public GenericType run() throws ClassNotFoundException {
return new GenericType(((Bundle) loader).loadClass(type));
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof ClassNotFoundException)
throw (ClassNotFoundException) e;
else
throw (RuntimeException) e;
}
} else if (loader instanceof ExecutionContext) {
return new GenericType(((ExecutionContext) loader).loadClass(type));
} else if (loader instanceof ExtendedBlueprintContainer) {
return new GenericType(((ExtendedBlueprintContainer) loader).loadClass(type));
} else {
throw new IllegalArgumentException("Unsupported loader: " + loader);
}
}
use of org.apache.aries.blueprint.di.ExecutionContext in project aries by apache.
the class BlueprintRepository method createAll.
public Map<String, Object> createAll(Collection<String> names, Collection<Class<?>> proxyInterfaces) throws ComponentDefinitionException {
ExecutionContext oldContext = ExecutionContext.Holder.setContext(this);
try {
Map<String, Object> instances = createInstances(names);
for (String name : instances.keySet()) {
Object obj = instances.get(name);
if (obj instanceof UnwrapperedBeanHolder)
obj = BeanRecipe.wrap((UnwrapperedBeanHolder) obj, proxyInterfaces);
instances.put(name, convert(name, obj));
}
return instances;
} finally {
ExecutionContext.Holder.setContext(oldContext);
}
}
Aggregations