Search in sources :

Example 6 with BeanProperty

use of org.osgi.service.blueprint.reflect.BeanProperty 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);
        }
    }
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 7 with BeanProperty

use of org.osgi.service.blueprint.reflect.BeanProperty in project aries by apache.

the class RecipeBuilder method createBeanRecipe.

private BeanRecipe createBeanRecipe(BeanMetadata beanMetadata) {
    BeanRecipe recipe = new BeanRecipe(getName(beanMetadata.getId()), blueprintContainer, getBeanClass(beanMetadata), allowsFieldInjection(beanMetadata));
    // Create refs for explicit dependencies
    recipe.setExplicitDependencies(getDependencies(beanMetadata));
    recipe.setPrototype(MetadataUtil.isPrototypeScope(beanMetadata) || MetadataUtil.isCustomScope(beanMetadata));
    recipe.setInitMethod(beanMetadata.getInitMethod());
    recipe.setDestroyMethod(beanMetadata.getDestroyMethod());
    recipe.setInterceptorLookupKey(beanMetadata);
    List<BeanArgument> beanArguments = beanMetadata.getArguments();
    if (beanArguments != null && !beanArguments.isEmpty()) {
        boolean hasIndex = (beanArguments.get(0).getIndex() >= 0);
        if (hasIndex) {
            List<BeanArgument> beanArgumentsCopy = new ArrayList<BeanArgument>(beanArguments);
            Collections.sort(beanArgumentsCopy, MetadataUtil.BEAN_COMPARATOR);
            beanArguments = beanArgumentsCopy;
        }
        List<Object> arguments = new ArrayList<Object>();
        List<String> argTypes = new ArrayList<String>();
        for (BeanArgument argument : beanArguments) {
            Recipe value = getValue(argument.getValue(), null);
            arguments.add(value);
            argTypes.add(argument.getValueType());
        }
        recipe.setArguments(arguments);
        recipe.setArgTypes(argTypes);
        recipe.setReorderArguments(!hasIndex);
    }
    recipe.setFactoryMethod(beanMetadata.getFactoryMethod());
    if (beanMetadata.getFactoryComponent() != null) {
        recipe.setFactoryComponent(getValue(beanMetadata.getFactoryComponent(), null));
    }
    for (BeanProperty property : beanMetadata.getProperties()) {
        Recipe value = getValue(property.getValue(), null);
        recipe.setProperty(property.getName(), value);
    }
    return recipe;
}
Also used : BeanArgument(org.osgi.service.blueprint.reflect.BeanArgument) DependentComponentFactoryRecipe(org.apache.aries.blueprint.di.DependentComponentFactoryRecipe) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) ComponentFactoryRecipe(org.apache.aries.blueprint.di.ComponentFactoryRecipe) MapRecipe(org.apache.aries.blueprint.di.MapRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) PassThroughRecipe(org.apache.aries.blueprint.di.PassThroughRecipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) ArrayRecipe(org.apache.aries.blueprint.di.ArrayRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) ValueRecipe(org.apache.aries.blueprint.di.ValueRecipe) ArrayList(java.util.ArrayList) BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Example 8 with BeanProperty

use of org.osgi.service.blueprint.reflect.BeanProperty in project aries by apache.

the class BeanMetadataImpl method addProperty.

public BeanProperty addProperty(String name, Metadata value) {
    BeanProperty prop = new BeanPropertyImpl(name, value);
    addProperty(prop);
    return prop;
}
Also used : BeanProperty(org.osgi.service.blueprint.reflect.BeanProperty)

Aggregations

BeanProperty (org.osgi.service.blueprint.reflect.BeanProperty)8 BeanArgument (org.osgi.service.blueprint.reflect.BeanArgument)4 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)3 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)2 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)2 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)2 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)2 Metadata (org.osgi.service.blueprint.reflect.Metadata)2 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)2 ReferenceListener (org.osgi.service.blueprint.reflect.ReferenceListener)2 RegistrationListener (org.osgi.service.blueprint.reflect.RegistrationListener)2 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)2 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 WrappedServiceMetadata (org.apache.aries.application.modelling.WrappedServiceMetadata)1 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)1 ArrayRecipe (org.apache.aries.blueprint.di.ArrayRecipe)1