Search in sources :

Example 1 with DTO

use of org.osgi.dto.DTO in project felix by apache.

the class SchemaBasedConverter method convertMap.

@SuppressWarnings("unchecked")
private T convertMap(Map<?, ?> map, Schema s, String contextPath) {
    Node node = s.nodeAtPath(contextPath);
    Class<?> cls = Util.rawClassOf(node.type());
    if (!asDTO(cls))
        return handleInvalid();
    if (!contextPath.endsWith("/"))
        contextPath = contextPath + "/";
    return (T) convertToDTO((Class<? extends DTO>) cls, map, s, contextPath);
}
Also used : Node(org.apache.felix.schematizer.Node) Util.asDTO(org.apache.felix.schematizer.impl.Util.asDTO) DTO(org.osgi.dto.DTO)

Example 2 with DTO

use of org.osgi.dto.DTO in project felix by apache.

the class SchemaBasedConverter method convertToCollection.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <U, V extends Collection<U>> V convertToCollection(Class<U> targetCls, Class<V> collectionClass, Collection sourceCollection, Schema schema, String path) {
    try {
        V targetCollection = instantiateCollection(collectionClass);
        sourceCollection.stream().map(obj -> convertCollectionItemToObject(obj, targetCls, schema, path)).forEach(u -> targetCollection.add((U) u));
        return targetCollection;
    } catch (Exception e) {
        throw new ConversionException("Cannot create DTO " + targetCls, e);
    }
}
Also used : Util.asDTO(org.apache.felix.schematizer.impl.Util.asDTO) Converter(org.osgi.util.converter.Converter) ConverterFunction(org.osgi.util.converter.ConverterFunction) TargetRule(org.osgi.util.converter.TargetRule) Collection(java.util.Collection) TypeReference(org.osgi.util.converter.TypeReference) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) Schema(org.apache.felix.schematizer.Schema) ConversionException(org.osgi.util.converter.ConversionException) List(java.util.List) Node(org.apache.felix.schematizer.Node) DTO(org.osgi.dto.DTO) Type(java.lang.reflect.Type) Map(java.util.Map) Converters(org.osgi.util.converter.Converters) Util.rawClassOf(org.apache.felix.schematizer.impl.Util.rawClassOf) ConversionException(org.osgi.util.converter.ConversionException) ConversionException(org.osgi.util.converter.ConversionException)

Aggregations

Node (org.apache.felix.schematizer.Node)2 Util.asDTO (org.apache.felix.schematizer.impl.Util.asDTO)2 DTO (org.osgi.dto.DTO)2 Field (java.lang.reflect.Field)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Schema (org.apache.felix.schematizer.Schema)1 Util.rawClassOf (org.apache.felix.schematizer.impl.Util.rawClassOf)1 ConversionException (org.osgi.util.converter.ConversionException)1 Converter (org.osgi.util.converter.Converter)1 ConverterFunction (org.osgi.util.converter.ConverterFunction)1 Converters (org.osgi.util.converter.Converters)1 TargetRule (org.osgi.util.converter.TargetRule)1 TypeReference (org.osgi.util.converter.TypeReference)1