use of org.osgi.service.blueprint.container.ReifiedType in project aries by apache.
the class CollectionRecipe method internalCreate.
protected Object internalCreate() throws ComponentDefinitionException {
Class type = getCollection(collectionTypeClass);
if (!ReflectionUtils.hasDefaultConstructor(type)) {
throw new ComponentDefinitionException("Type does not have a default constructor " + type.getName());
}
// create collection instance
Object o;
try {
o = type.newInstance();
} catch (Exception e) {
throw new ComponentDefinitionException("Error while creating collection instance: " + type.getName());
}
if (!(o instanceof Collection)) {
throw new ComponentDefinitionException("Specified collection type does not implement the Collection interface: " + type.getName());
}
Collection instance = (Collection) o;
ReifiedType defaultConversionType = loadType(defaultValueType);
Type conversionType = null;
for (Recipe recipe : list) {
Object value;
if (recipe != null) {
try {
conversionType = defaultConversionType.getRawClass();
if (recipe instanceof ValueRecipe) {
conversionType = ((ValueRecipe) recipe).getValueType();
}
value = convert(recipe.create(), conversionType);
} catch (Exception e) {
throw new ComponentDefinitionException("Unable to convert value " + recipe + " to type " + conversionType, e);
}
} else {
value = null;
}
instance.add(value);
}
return instance;
}
Aggregations