Search in sources :

Example 1 with Converter

use of org.osgi.service.blueprint.container.Converter in project aries by apache.

the class AggregateConverter method convertWithConverters.

private ConversionResult convertWithConverters(Object source, ReifiedType type) throws Exception {
    Converter converter = selectMatchingConverter(source, type);
    if (converter == null)
        return null;
    Object value = converter.convert(source, type);
    return new ConversionResult(converter, value);
}
Also used : Converter(org.osgi.service.blueprint.container.Converter)

Example 2 with Converter

use of org.osgi.service.blueprint.container.Converter in project aries by apache.

the class BlueprintContainerImpl method processTypeConverters.

private void processTypeConverters() throws Exception {
    List<String> typeConverters = new ArrayList<String>();
    for (Target target : componentDefinitionRegistry.getTypeConverters()) {
        if (target instanceof ComponentMetadata) {
            typeConverters.add(((ComponentMetadata) target).getId());
        } else if (target instanceof RefMetadata) {
            typeConverters.add(((RefMetadata) target).getComponentId());
        } else {
            throw new ComponentDefinitionException("Unexpected metadata for type converter: " + target);
        }
    }
    Map<String, Object> objects = repository.createAll(typeConverters, Arrays.<Class<?>>asList(Converter.class));
    for (String name : typeConverters) {
        Object obj = objects.get(name);
        if (obj instanceof Converter) {
            converter.registerConverter((Converter) obj);
        } else {
            throw new ComponentDefinitionException("Type converter " + obj + " does not implement the " + Converter.class.getName() + " interface");
        }
    }
}
Also used : Target(org.osgi.service.blueprint.reflect.Target) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) ArrayList(java.util.ArrayList) Converter(org.osgi.service.blueprint.container.Converter) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Aggregations

Converter (org.osgi.service.blueprint.container.Converter)2 ArrayList (java.util.ArrayList)1 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)1 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)1 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)1 Target (org.osgi.service.blueprint.reflect.Target)1