Search in sources :

Example 1 with ExtendedBeanMetadata

use of org.apache.aries.blueprint.ExtendedBeanMetadata in project camel by apache.

the class BlueprintPropertiesParser method lookupPropertyPlaceholderIds.

/**
     * Lookup the ids of the Blueprint property placeholder services in the
     * Blueprint container.
     *
     * @return the ids, will be an empty array if none found.
     */
public String[] lookupPropertyPlaceholderIds() {
    List<String> ids = new ArrayList<String>();
    for (Object componentId : container.getComponentIds()) {
        String id = (String) componentId;
        ComponentMetadata meta = container.getComponentMetadata(id);
        if (meta instanceof ExtendedBeanMetadata) {
            Class<?> clazz = ((ExtendedBeanMetadata) meta).getRuntimeClass();
            if (clazz != null && AbstractPropertyPlaceholder.class.isAssignableFrom(clazz)) {
                ids.add(id);
            }
        }
    }
    return ids.toArray(new String[ids.size()]);
}
Also used : ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) ArrayList(java.util.ArrayList) AbstractPropertyPlaceholder(org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 2 with ExtendedBeanMetadata

use of org.apache.aries.blueprint.ExtendedBeanMetadata in project aries by apache.

the class BlueprintContainerImpl method processProcessors.

private void processProcessors() throws Exception {
    // Instantiate ComponentDefinitionRegistryProcessor and BeanProcessor
    for (BeanMetadata bean : getMetadata(BeanMetadata.class)) {
        if (bean instanceof ExtendedBeanMetadata && !((ExtendedBeanMetadata) bean).isProcessor()) {
            continue;
        }
        Class clazz = null;
        if (bean instanceof ExtendedBeanMetadata) {
            clazz = ((ExtendedBeanMetadata) bean).getRuntimeClass();
        }
        if (clazz == null && bean.getClassName() != null) {
            clazz = loadClass(bean.getClassName());
        }
        if (clazz == null) {
            continue;
        }
        if (ComponentDefinitionRegistryProcessor.class.isAssignableFrom(clazz)) {
            Object obj = repository.create(bean.getId(), Arrays.<Class<?>>asList(ComponentDefinitionRegistryProcessor.class));
            ((ComponentDefinitionRegistryProcessor) obj).process(componentDefinitionRegistry);
        } else if (Processor.class.isAssignableFrom(clazz)) {
            Object obj = repository.create(bean.getId(), Arrays.<Class<?>>asList(Processor.class));
            this.processors.add((Processor) obj);
        } else {
            continue;
        }
        updateUninstantiatedRecipes();
    }
}
Also used : ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) Processor(org.apache.aries.blueprint.Processor) ComponentDefinitionRegistryProcessor(org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentDefinitionRegistryProcessor(org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor)

Example 3 with ExtendedBeanMetadata

use of org.apache.aries.blueprint.ExtendedBeanMetadata in project aries by apache.

the class PlaceholdersUtils method validatePlaceholder.

public static void validatePlaceholder(MutableBeanMetadata metadata, ComponentDefinitionRegistry registry) {
    String prefix = getPlaceholderProperty(metadata, "placeholderPrefix");
    String suffix = getPlaceholderProperty(metadata, "placeholderSuffix");
    for (String id : registry.getComponentDefinitionNames()) {
        ComponentMetadata component = registry.getComponentDefinition(id);
        if (component instanceof ExtendedBeanMetadata) {
            ExtendedBeanMetadata bean = (ExtendedBeanMetadata) component;
            if (bean.getRuntimeClass() != null && AbstractPropertyPlaceholderExt.class.isAssignableFrom(bean.getRuntimeClass())) {
                String otherPrefix = getPlaceholderProperty(bean, "placeholderPrefix");
                String otherSuffix = getPlaceholderProperty(bean, "placeholderSuffix");
                if (prefix.equals(otherPrefix) && suffix.equals(otherSuffix)) {
                    throw new ComponentDefinitionException("Multiple placeholders with the same prefix and suffix are not allowed");
                }
            }
        }
    }
}
Also used : ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Example 4 with ExtendedBeanMetadata

use of org.apache.aries.blueprint.ExtendedBeanMetadata in project aries by apache.

the class SpringBeanProcessor method getProcessors.

private <T> List<T> getProcessors(Class<T> type) {
    List<T> processors = new ArrayList<T>();
    if (!creatingProcessor) {
        creatingProcessor = true;
        for (BeanMetadata bean : blueprintContainer.getMetadata(BeanMetadata.class)) {
            Class clazz = null;
            if (bean instanceof ExtendedBeanMetadata) {
                clazz = ((ExtendedBeanMetadata) bean).getRuntimeClass();
            }
            if (clazz == null && bean.getClassName() != null) {
                try {
                    clazz = bundleContext.getBundle().loadClass(bean.getClassName());
                } catch (ClassNotFoundException e) {
                }
            }
            if (clazz == null) {
                continue;
            }
            if (type.isAssignableFrom(clazz)) {
                Object p = blueprintContainer.getComponentInstance(bean.getId());
                processors.add(type.cast(p));
            }
        }
        creatingProcessor = false;
    }
    return processors;
}
Also used : ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) ExtendedBeanMetadata(org.apache.aries.blueprint.ExtendedBeanMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ArrayList(java.util.ArrayList)

Aggregations

ExtendedBeanMetadata (org.apache.aries.blueprint.ExtendedBeanMetadata)4 ArrayList (java.util.ArrayList)2 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)2 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)2 ComponentDefinitionRegistryProcessor (org.apache.aries.blueprint.ComponentDefinitionRegistryProcessor)1 Processor (org.apache.aries.blueprint.Processor)1 AbstractPropertyPlaceholder (org.apache.aries.blueprint.ext.AbstractPropertyPlaceholder)1 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)1