Search in sources :

Example 1 with Recipe

use of org.apache.aries.blueprint.di.Recipe in project aries by apache.

the class RecipeBuilder method getValue.

private Recipe getValue(Metadata v, Object groupingType) {
    if (v instanceof NullMetadata) {
        return null;
    } else if (v instanceof ComponentMetadata) {
        return createRecipe((ComponentMetadata) v);
    } else if (v instanceof ValueMetadata) {
        ValueMetadata stringValue = (ValueMetadata) v;
        Object type = stringValue.getType();
        type = (type == null) ? groupingType : type;
        ValueRecipe vr = new ValueRecipe(getName(null), stringValue, type);
        return vr;
    } else if (v instanceof RefMetadata) {
        // TODO: make it work with property-placeholders?
        String componentName = ((RefMetadata) v).getComponentId();
        RefRecipe rr = new RefRecipe(getName(null), componentName);
        return rr;
    } else if (v instanceof CollectionMetadata) {
        CollectionMetadata collectionMetadata = (CollectionMetadata) v;
        Class<?> cl = collectionMetadata.getCollectionClass();
        String type = collectionMetadata.getValueType();
        if (cl == Object[].class) {
            ArrayRecipe ar = new ArrayRecipe(getName(null), type);
            for (Metadata lv : collectionMetadata.getValues()) {
                ar.add(getValue(lv, type));
            }
            return ar;
        } else {
            CollectionRecipe cr = new CollectionRecipe(getName(null), cl != null ? cl : ArrayList.class, type);
            for (Metadata lv : collectionMetadata.getValues()) {
                cr.add(getValue(lv, type));
            }
            return cr;
        }
    } else if (v instanceof MapMetadata) {
        return createMapRecipe((MapMetadata) v);
    } else if (v instanceof PropsMetadata) {
        PropsMetadata mapValue = (PropsMetadata) v;
        MapRecipe mr = new MapRecipe(getName(null), Properties.class, String.class, String.class);
        for (MapEntry entry : mapValue.getEntries()) {
            Recipe key = getValue(entry.getKey(), String.class);
            Recipe val = getValue(entry.getValue(), String.class);
            mr.put(key, val);
        }
        return mr;
    } else if (v instanceof IdRefMetadata) {
        // TODO: make it work with property-placeholders?
        String componentName = ((IdRefMetadata) v).getComponentId();
        IdRefRecipe rnr = new IdRefRecipe(getName(null), componentName);
        return rnr;
    } else {
        throw new IllegalStateException("Unsupported value: " + (v != null ? v.getClass().getName() : "null"));
    }
}
Also used : PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) 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) MapRecipe(org.apache.aries.blueprint.di.MapRecipe) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PropsMetadata(org.osgi.service.blueprint.reflect.PropsMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata) ExtendedReferenceMetadata(org.apache.aries.blueprint.ExtendedReferenceMetadata) ComponentFactoryMetadata(org.apache.aries.blueprint.ext.ComponentFactoryMetadata) DependentComponentFactoryMetadata(org.apache.aries.blueprint.ext.DependentComponentFactoryMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) ExtendedServiceReferenceMetadata(org.apache.aries.blueprint.ExtendedServiceReferenceMetadata) ArrayList(java.util.ArrayList) ArrayRecipe(org.apache.aries.blueprint.di.ArrayRecipe) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ValueRecipe(org.apache.aries.blueprint.di.ValueRecipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata) NullMetadata(org.osgi.service.blueprint.reflect.NullMetadata)

Example 2 with Recipe

use of org.apache.aries.blueprint.di.Recipe in project aries by apache.

the class RecipeBuilder method createMapRecipe.

private MapRecipe createMapRecipe(MapMetadata mapValue) {
    String keyType = mapValue.getKeyType();
    String valueType = mapValue.getValueType();
    MapRecipe mr = new MapRecipe(getName(null), HashMap.class, keyType, valueType);
    for (MapEntry entry : mapValue.getEntries()) {
        Recipe key = getValue(entry.getKey(), keyType);
        Recipe val = getValue(entry.getValue(), valueType);
        mr.put(key, val);
    }
    return mr;
}
Also used : MapEntry(org.osgi.service.blueprint.reflect.MapEntry) 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) MapRecipe(org.apache.aries.blueprint.di.MapRecipe)

Example 3 with Recipe

use of org.apache.aries.blueprint.di.Recipe in project aries by apache.

the class ReferenceRecipe method internalCreate.

@Override
protected Object internalCreate() throws ComponentDefinitionException {
    try {
        if (explicitDependencies != null) {
            for (Recipe recipe : explicitDependencies) {
                recipe.create();
            }
        }
        // Create the proxy
        Set<Class<?>> interfaces = new HashSet<Class<?>>();
        Class<?> clz = getInterfaceClass();
        if (clz != null)
            interfaces.add(clz);
        if (metadata instanceof ExtendedReferenceMetadata) {
            interfaces.addAll(loadAllClasses(((ExtendedReferenceMetadata) metadata).getExtraInterfaces()));
        }
        proxy = createProxy(new ServiceDispatcher(), interfaces);
        // Add partially created proxy to the context
        ServiceProxyWrapper wrapper = new ServiceProxyWrapper();
        addPartialObject(wrapper);
        // Handle initial references
        createListeners();
        updateListeners();
        // Return a ServiceProxy that can injection of references or proxies can be done correctly
        return wrapper;
    } catch (ComponentDefinitionException e) {
        throw e;
    } catch (Throwable t) {
        throw new ComponentDefinitionException(t);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) ValueRecipe(org.apache.aries.blueprint.di.ValueRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) ExtendedReferenceMetadata(org.apache.aries.blueprint.ExtendedReferenceMetadata) HashSet(java.util.HashSet)

Example 4 with Recipe

use of org.apache.aries.blueprint.di.Recipe in project aries by apache.

the class BlueprintRepository method destroy.

public void destroy() {
    // destroy objects in reverse creation order
    List<String> order = new ArrayList<String>(creationOrder);
    Collections.reverse(order);
    for (String name : order) {
        Recipe recipe = recipes.get(name);
        if (recipe != null) {
            recipe.destroy(getInstance(name));
        }
    }
    instances.clear();
    creationOrder.clear();
}
Also used : IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 5 with Recipe

use of org.apache.aries.blueprint.di.Recipe in project aries by apache.

the class BlueprintRepository method getAllRecipes.

public Set<Recipe> getAllRecipes(String... names) {
    ExecutionContext oldContext = ExecutionContext.Holder.setContext(this);
    try {
        Set<Recipe> allRecipes = new HashSet<Recipe>();
        Collection<String> topLevel = names != null && names.length > 0 ? Arrays.asList(names) : recipes.keySet();
        for (String name : topLevel) {
            internalGetAllRecipes(allRecipes, getRecipe(name));
        }
        return allRecipes;
    } finally {
        ExecutionContext.Holder.setContext(oldContext);
    }
}
Also used : ExecutionContext(org.apache.aries.blueprint.di.ExecutionContext) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) Recipe(org.apache.aries.blueprint.di.Recipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) HashSet(java.util.HashSet)

Aggregations

Recipe (org.apache.aries.blueprint.di.Recipe)21 RefRecipe (org.apache.aries.blueprint.di.RefRecipe)12 CollectionRecipe (org.apache.aries.blueprint.di.CollectionRecipe)11 ArrayList (java.util.ArrayList)10 IdRefRecipe (org.apache.aries.blueprint.di.IdRefRecipe)9 ValueRecipe (org.apache.aries.blueprint.di.ValueRecipe)6 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)6 MapRecipe (org.apache.aries.blueprint.di.MapRecipe)5 ArrayRecipe (org.apache.aries.blueprint.di.ArrayRecipe)4 ComponentFactoryRecipe (org.apache.aries.blueprint.di.ComponentFactoryRecipe)4 DependentComponentFactoryRecipe (org.apache.aries.blueprint.di.DependentComponentFactoryRecipe)4 PassThroughRecipe (org.apache.aries.blueprint.di.PassThroughRecipe)4 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Map (java.util.Map)3 AbstractRecipe (org.apache.aries.blueprint.di.AbstractRecipe)3 CircularDependencyException (org.apache.aries.blueprint.di.CircularDependencyException)3