use of org.apache.aries.blueprint.services.ExtendedBlueprintContainer 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.services.ExtendedBlueprintContainer in project aries by apache.
the class BlueprintNamespaceHandler method getOrCreateParserContext.
private org.springframework.beans.factory.xml.ParserContext getOrCreateParserContext(ParserContext parserContext) {
ComponentDefinitionRegistry registry = parserContext.getComponentDefinitionRegistry();
ExtendedBlueprintContainer container = getBlueprintContainer(parserContext);
// Create spring application context
SpringApplicationContext applicationContext = getPassThrough(parserContext, SPRING_APPLICATION_CONTEXT_ID, SpringApplicationContext.class);
if (applicationContext == null) {
applicationContext = new SpringApplicationContext(container);
registry.registerComponentDefinition(createPassThrough(parserContext, SPRING_APPLICATION_CONTEXT_ID, applicationContext, "destroy"));
}
// Create registry
DefaultListableBeanFactory beanFactory = getPassThrough(parserContext, SPRING_BEAN_FACTORY_ID, DefaultListableBeanFactory.class);
if (beanFactory == null) {
beanFactory = applicationContext.getBeanFactory();
registry.registerComponentDefinition(createPassThrough(parserContext, SPRING_BEAN_FACTORY_ID, beanFactory));
}
// Create spring parser context
org.springframework.beans.factory.xml.ParserContext springParserContext = getPassThrough(parserContext, SPRING_CONTEXT_ID, org.springframework.beans.factory.xml.ParserContext.class);
if (springParserContext == null) {
// Create spring context
springParserContext = createSpringParserContext(parserContext, beanFactory);
registry.registerComponentDefinition(createPassThrough(parserContext, SPRING_CONTEXT_ID, springParserContext));
}
// Create processor
if (!parserContext.getComponentDefinitionRegistry().containsComponentDefinition(SPRING_BEAN_PROCESSOR_ID)) {
MutableBeanMetadata bm = parserContext.createMetadata(MutableBeanMetadata.class);
bm.setId(SPRING_BEAN_PROCESSOR_ID);
bm.setProcessor(true);
bm.setScope(BeanMetadata.SCOPE_SINGLETON);
bm.setRuntimeClass(SpringBeanProcessor.class);
bm.setActivation(BeanMetadata.ACTIVATION_EAGER);
bm.addArgument(createRef(parserContext, "blueprintBundleContext"), null, 0);
bm.addArgument(createRef(parserContext, "blueprintContainer"), null, 0);
bm.addArgument(createRef(parserContext, SPRING_APPLICATION_CONTEXT_ID), null, 0);
registry.registerComponentDefinition(bm);
}
// Add the namespace handler's bundle to the application context classloader
applicationContext.addSourceBundle(bundle);
return springParserContext;
}
Aggregations