Search in sources :

Example 1 with CollectionRecipe

use of org.apache.aries.blueprint.di.CollectionRecipe 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 CollectionRecipe

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

the class RecipeBuilder method createReferenceListRecipe.

private Recipe createReferenceListRecipe(ReferenceListMetadata metadata) {
    ValueRecipe filterRecipe = null;
    if (metadata instanceof ExtendedReferenceMetadata) {
        ValueMetadata filterMetadata = ((ExtendedServiceReferenceMetadata) metadata).getExtendedFilter();
        if (filterMetadata != null) {
            filterRecipe = (ValueRecipe) getValue(filterMetadata, null);
        }
    }
    CollectionRecipe listenersRecipe = null;
    if (metadata.getReferenceListeners() != null) {
        listenersRecipe = new CollectionRecipe(getName(null), ArrayList.class, Object.class.getName());
        for (ReferenceListener listener : metadata.getReferenceListeners()) {
            listenersRecipe.add(createRecipe(listener));
        }
    }
    ReferenceListRecipe recipe = new ReferenceListRecipe(getName(metadata.getId()), blueprintContainer, metadata, filterRecipe, listenersRecipe, getDependencies(metadata));
    return recipe;
}
Also used : ExtendedReferenceMetadata(org.apache.aries.blueprint.ExtendedReferenceMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ArrayList(java.util.ArrayList) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) ExtendedServiceReferenceMetadata(org.apache.aries.blueprint.ExtendedServiceReferenceMetadata) ValueRecipe(org.apache.aries.blueprint.di.ValueRecipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe)

Example 3 with CollectionRecipe

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

the class RecipeBuilder method createServiceRecipe.

private Recipe createServiceRecipe(ServiceMetadata serviceExport) {
    CollectionRecipe listenersRecipe = new CollectionRecipe(getName(null), ArrayList.class, Object.class.getName());
    if (serviceExport.getRegistrationListeners() != null) {
        for (RegistrationListener listener : serviceExport.getRegistrationListeners()) {
            listenersRecipe.add(createRecipe(listener));
        }
    }
    ServiceRecipe recipe = new ServiceRecipe(getName(serviceExport.getId()), blueprintContainer, serviceExport, getValue(serviceExport.getServiceComponent(), null), listenersRecipe, getServicePropertiesRecipe(serviceExport), getDependencies(serviceExport));
    return recipe;
}
Also used : RegistrationListener(org.osgi.service.blueprint.reflect.RegistrationListener) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe)

Example 4 with CollectionRecipe

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

the class RecipeBuilder method createReferenceRecipe.

private ReferenceRecipe createReferenceRecipe(ReferenceMetadata metadata) {
    ValueRecipe filterRecipe = null;
    if (metadata instanceof ExtendedReferenceMetadata) {
        ValueMetadata filterMetadata = ((ExtendedServiceReferenceMetadata) metadata).getExtendedFilter();
        if (filterMetadata != null) {
            filterRecipe = (ValueRecipe) getValue(filterMetadata, null);
        }
    }
    CollectionRecipe listenersRecipe = null;
    if (metadata.getReferenceListeners() != null) {
        listenersRecipe = new CollectionRecipe(getName(null), ArrayList.class, Object.class.getName());
        for (ReferenceListener listener : metadata.getReferenceListeners()) {
            listenersRecipe.add(createRecipe(listener));
        }
    }
    ReferenceRecipe recipe = new ReferenceRecipe(getName(metadata.getId()), blueprintContainer, metadata, filterRecipe, listenersRecipe, getDependencies(metadata));
    return recipe;
}
Also used : ExtendedReferenceMetadata(org.apache.aries.blueprint.ExtendedReferenceMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ArrayList(java.util.ArrayList) ReferenceListener(org.osgi.service.blueprint.reflect.ReferenceListener) ExtendedServiceReferenceMetadata(org.apache.aries.blueprint.ExtendedServiceReferenceMetadata) ValueRecipe(org.apache.aries.blueprint.di.ValueRecipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe)

Example 5 with CollectionRecipe

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

the class BlueprintRepository method validate.

public void validate() {
    for (Recipe recipe : getAllRecipes()) {
        // Check that references are satisfied
        String ref = null;
        if (recipe instanceof RefRecipe) {
            ref = ((RefRecipe) recipe).getIdRef();
        } else if (recipe instanceof IdRefRecipe) {
            ref = ((IdRefRecipe) recipe).getIdRef();
        }
        if (ref != null && getRecipe(ref) == null) {
            throw new ComponentDefinitionException("Unresolved ref/idref to component: " + ref);
        }
        // Check service
        if (recipe instanceof ServiceRecipe) {
            Recipe r = ((ServiceRecipe) recipe).getServiceRecipe();
            if (r instanceof RefRecipe) {
                r = getRecipe(((RefRecipe) r).getIdRef());
            }
            if (r instanceof ServiceRecipe) {
                throw new ComponentDefinitionException("The target for a <service> element must not be <service> element");
            }
            if (r instanceof ReferenceListRecipe) {
                throw new ComponentDefinitionException("The target for a <service> element must not be <reference-list> element");
            }
            CollectionRecipe listeners = ((ServiceRecipe) recipe).getListenersRecipe();
            for (Recipe lr : listeners.getDependencies()) {
                // The listener recipe is a bean recipe with the listener being set in a property
                for (Recipe l : lr.getDependencies()) {
                    if (l instanceof RefRecipe) {
                        l = getRecipe(((RefRecipe) l).getIdRef());
                    }
                    if (l instanceof ServiceRecipe) {
                        throw new ComponentDefinitionException("The target for a <registration-listener> element must not be <service> element");
                    }
                    if (l instanceof ReferenceListRecipe) {
                        throw new ComponentDefinitionException("The target for a <registration-listener> element must not be <reference-list> element");
                    }
                }
            }
        }
        // Check references
        if (recipe instanceof AbstractServiceReferenceRecipe) {
            CollectionRecipe listeners = ((AbstractServiceReferenceRecipe) recipe).getListenersRecipe();
            for (Recipe lr : listeners.getDependencies()) {
                // The listener recipe is a bean recipe with the listener being set in a property
                for (Recipe l : lr.getDependencies()) {
                    if (l instanceof RefRecipe) {
                        l = getRecipe(((RefRecipe) l).getIdRef());
                    }
                    if (l instanceof ServiceRecipe) {
                        throw new ComponentDefinitionException("The target for a <reference-listener> element must not be <service> element");
                    }
                    if (l instanceof ReferenceListRecipe) {
                        throw new ComponentDefinitionException("The target for a <reference-listener> element must not be <reference-list> element");
                    }
                }
            }
        }
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) 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) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) IdRefRecipe(org.apache.aries.blueprint.di.IdRefRecipe) RefRecipe(org.apache.aries.blueprint.di.RefRecipe) CollectionRecipe(org.apache.aries.blueprint.di.CollectionRecipe)

Aggregations

CollectionRecipe (org.apache.aries.blueprint.di.CollectionRecipe)5 ArrayList (java.util.ArrayList)3 ExtendedReferenceMetadata (org.apache.aries.blueprint.ExtendedReferenceMetadata)3 ExtendedServiceReferenceMetadata (org.apache.aries.blueprint.ExtendedServiceReferenceMetadata)3 ValueRecipe (org.apache.aries.blueprint.di.ValueRecipe)3 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)3 IdRefRecipe (org.apache.aries.blueprint.di.IdRefRecipe)2 Recipe (org.apache.aries.blueprint.di.Recipe)2 RefRecipe (org.apache.aries.blueprint.di.RefRecipe)2 ReferenceListener (org.osgi.service.blueprint.reflect.ReferenceListener)2 ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)1 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)1 ArrayRecipe (org.apache.aries.blueprint.di.ArrayRecipe)1 ComponentFactoryRecipe (org.apache.aries.blueprint.di.ComponentFactoryRecipe)1 DependentComponentFactoryRecipe (org.apache.aries.blueprint.di.DependentComponentFactoryRecipe)1 MapRecipe (org.apache.aries.blueprint.di.MapRecipe)1 PassThroughRecipe (org.apache.aries.blueprint.di.PassThroughRecipe)1 ComponentFactoryMetadata (org.apache.aries.blueprint.ext.ComponentFactoryMetadata)1 DependentComponentFactoryMetadata (org.apache.aries.blueprint.ext.DependentComponentFactoryMetadata)1 MutableMapMetadata (org.apache.aries.blueprint.mutable.MutableMapMetadata)1