use of org.osgi.service.blueprint.reflect.BeanArgument in project aries by apache.
the class BeanMetadataImpl method addArgument.
public BeanArgument addArgument(Metadata value, String valueType, int index) {
BeanArgument arg = new BeanArgumentImpl(value, valueType, index);
addArgument(arg);
return arg;
}
use of org.osgi.service.blueprint.reflect.BeanArgument in project aries by apache.
the class ParserTest method testParseComponent.
public void testParseComponent() throws Exception {
ComponentDefinitionRegistry registry = parse("/test-simple-component.xml");
assertNotNull(registry);
ComponentMetadata component = registry.getComponentDefinition("pojoA");
assertNotNull(component);
assertEquals("pojoA", component.getId());
assertTrue(component instanceof BeanMetadata);
BeanMetadata local = (BeanMetadata) component;
List<String> deps = local.getDependsOn();
assertNotNull(deps);
assertEquals(2, deps.size());
assertTrue(deps.contains("pojoB"));
assertTrue(deps.contains("pojoC"));
assertEquals("org.apache.aries.blueprint.pojos.PojoA", local.getClassName());
List<BeanArgument> params = local.getArguments();
assertNotNull(params);
assertEquals(6, params.size());
BeanArgument param = params.get(0);
assertNotNull(param);
assertEquals(-1, param.getIndex());
assertNull(param.getValueType());
assertNotNull(param.getValue());
assertTrue(param.getValue() instanceof ValueMetadata);
assertEquals("val0", ((ValueMetadata) param.getValue()).getStringValue());
assertNull(((ValueMetadata) param.getValue()).getType());
param = params.get(1);
assertNotNull(param);
assertEquals(-1, param.getIndex());
assertNull(param.getValueType());
assertNotNull(param.getValue());
assertTrue(param.getValue() instanceof RefMetadata);
assertEquals("val1", ((RefMetadata) param.getValue()).getComponentId());
param = params.get(2);
assertNotNull(param);
assertEquals(-1, param.getIndex());
assertNull(param.getValueType());
assertNotNull(param.getValue());
assertTrue(param.getValue() instanceof NullMetadata);
param = params.get(3);
assertNotNull(param);
assertEquals(-1, param.getIndex());
assertEquals("java.lang.String", param.getValueType());
assertNotNull(param.getValue());
assertTrue(param.getValue() instanceof ValueMetadata);
assertEquals("val3", ((ValueMetadata) param.getValue()).getStringValue());
assertNull(((ValueMetadata) param.getValue()).getType());
param = params.get(4);
assertNotNull(param);
assertEquals(-1, param.getIndex());
assertNull(param.getValueType());
assertNotNull(param.getValue());
assertTrue(param.getValue() instanceof CollectionMetadata);
CollectionMetadata array = (CollectionMetadata) param.getValue();
assertNull(array.getValueType());
assertNotNull(array.getValues());
assertEquals(3, array.getValues().size());
assertTrue(array.getValues().get(0) instanceof ValueMetadata);
assertTrue(array.getValues().get(1) instanceof ComponentMetadata);
assertTrue(array.getValues().get(2) instanceof NullMetadata);
param = params.get(5);
assertNotNull(param);
assertEquals(-1, param.getIndex());
assertNull(param.getValueType());
assertNotNull(param.getValue());
assertTrue(param.getValue() instanceof RefMetadata);
assertEquals("pojoB", ((RefMetadata) param.getValue()).getComponentId());
assertEquals(null, local.getInitMethod());
assertEquals(null, local.getDestroyMethod());
// test pojoB
ComponentMetadata pojoB = registry.getComponentDefinition("pojoB");
assertNotNull(pojoB);
assertEquals("pojoB", pojoB.getId());
assertTrue(pojoB instanceof BeanMetadata);
BeanMetadata pojoBLocal = (BeanMetadata) pojoB;
assertEquals("initPojo", pojoBLocal.getInitMethod());
// assertEquals("", pojoBLocal.getDestroyMethod());
params = pojoBLocal.getArguments();
assertNotNull(params);
assertEquals(2, params.size());
param = params.get(0);
assertNotNull(param);
assertEquals(1, param.getIndex());
param = params.get(1);
assertNotNull(param);
assertEquals(0, param.getIndex());
}
use of org.osgi.service.blueprint.reflect.BeanArgument in project aries by apache.
the class BlueprintContainerImpl method getMetadata.
private <T extends ComponentMetadata> void getMetadata(Class<T> clazz, Metadata component, Collection<T> metadatas) {
if (component == null) {
return;
}
if (clazz.isInstance(component)) {
metadatas.add(clazz.cast(component));
}
if (component instanceof BeanMetadata) {
getMetadata(clazz, ((BeanMetadata) component).getFactoryComponent(), metadatas);
for (BeanArgument arg : ((BeanMetadata) component).getArguments()) {
getMetadata(clazz, arg.getValue(), metadatas);
}
for (BeanProperty prop : ((BeanMetadata) component).getProperties()) {
getMetadata(clazz, prop.getValue(), metadatas);
}
}
if (component instanceof CollectionMetadata) {
for (Metadata m : ((CollectionMetadata) component).getValues()) {
getMetadata(clazz, m, metadatas);
}
}
if (component instanceof MapMetadata) {
for (MapEntry m : ((MapMetadata) component).getEntries()) {
getMetadata(clazz, m.getKey(), metadatas);
getMetadata(clazz, m.getValue(), metadatas);
}
}
if (component instanceof PropsMetadata) {
for (MapEntry m : ((PropsMetadata) component).getEntries()) {
getMetadata(clazz, m.getKey(), metadatas);
getMetadata(clazz, m.getValue(), metadatas);
}
}
if (component instanceof ServiceReferenceMetadata) {
for (ReferenceListener l : ((ServiceReferenceMetadata) component).getReferenceListeners()) {
getMetadata(clazz, l.getListenerComponent(), metadatas);
}
}
if (component instanceof ServiceMetadata) {
getMetadata(clazz, ((ServiceMetadata) component).getServiceComponent(), metadatas);
for (MapEntry m : ((ServiceMetadata) component).getServiceProperties()) {
getMetadata(clazz, m.getKey(), metadatas);
getMetadata(clazz, m.getValue(), metadatas);
}
for (RegistrationListener l : ((ServiceMetadata) component).getRegistrationListeners()) {
getMetadata(clazz, l.getListenerComponent(), metadatas);
}
}
}
use of org.osgi.service.blueprint.reflect.BeanArgument in project aries by apache.
the class AbstractPropertyPlaceholder method processBeanMetadata.
protected Metadata processBeanMetadata(BeanMetadata component) {
for (BeanArgument arg : component.getArguments()) {
try {
processingStack.add("Argument index " + arg.getIndex() + " and value type " + arg.getValueType() + "->");
if (arg instanceof MutableBeanArgument) {
((MutableBeanArgument) arg).setValue(processMetadata(arg.getValue()));
} else {
//Say that we can't change this argument, but continue processing
//If the value is mutable then we may be ok!
printWarning(arg, "Constructor Argument");
processMetadata(arg.getValue());
}
} finally {
processingStack.removeLast();
}
}
for (BeanProperty prop : component.getProperties()) {
try {
processingStack.add("Property named " + prop.getName() + "->");
if (prop instanceof MutableBeanProperty) {
((MutableBeanProperty) prop).setValue(processMetadata(prop.getValue()));
} else {
//Say that we can't change this property, but continue processing
//If the value is mutable then we may be ok!
printWarning(prop, "Injection Property");
processMetadata(prop.getValue());
}
} finally {
processingStack.removeLast();
}
}
Target factoryComponent = component.getFactoryComponent();
if (factoryComponent != null) {
try {
if (component instanceof MutableBeanMetadata) {
processingStack.add("Factory Component->");
((MutableBeanMetadata) component).setFactoryComponent((Target) processMetadata(factoryComponent));
} else {
printWarning(component, "Factory Component");
processingStack.add("Factory Component->");
processMetadata(factoryComponent);
}
} finally {
processingStack.removeLast();
}
}
return component;
}
use of org.osgi.service.blueprint.reflect.BeanArgument in project aries by apache.
the class AbstractParserProxy method traverseComponent.
/**
* Traverse {@link ComponentMetadata} instances to find all nested {@link ComponentMetadata} instances
* @param component
* @param output
*/
private void traverseComponent(ComponentMetadata component, Set<ComponentMetadata> output) {
if (!!!output.add(component))
return;
if (component instanceof BeanMetadata) {
BeanMetadata bean = (BeanMetadata) component;
traverse(bean.getFactoryComponent(), output);
for (BeanArgument argument : bean.getArguments()) {
traverse(argument.getValue(), output);
}
for (BeanProperty property : bean.getProperties()) {
traverse(property.getValue(), output);
}
} else if (component instanceof ServiceMetadata) {
ServiceMetadata service = (ServiceMetadata) component;
traverse(service.getServiceComponent(), output);
for (RegistrationListener listener : service.getRegistrationListeners()) {
traverse(listener.getListenerComponent(), output);
}
for (MapEntry e : service.getServiceProperties()) {
traverse(e.getKey(), output);
traverse(e.getValue(), output);
}
} else if (component instanceof ServiceReferenceMetadata) {
ServiceReferenceMetadata reference = (ServiceReferenceMetadata) component;
for (ReferenceListener listener : reference.getReferenceListeners()) {
traverse(listener.getListenerComponent(), output);
}
}
}
Aggregations