Package ma.glasnost.orika.metadata

Examples of ma.glasnost.orika.metadata.MapperKey


            if (srcNode.parent != null
                    && srcNode.parent.elementRef != null
                    && currentNode.parent != null
                    && currentNode.parent.elementRef != null) {
               
                MapperKey key = new MapperKey(srcNode.parent.elementRef.type(), currentNode.parent.elementRef.type());
                if (!ClassUtil.isImmutable(key.getAType())
                        && !ClassUtil.isImmutable(key.getBType())
                        && !mapperFactory.existsRegisteredMapper(key.getAType(), key.getBType(), true)) {
                    ClassMapBuilder<?,?> builder = builders.get(key);
                    if (builder == null) {
                        builder = mapperFactory.classMap(key.getAType(), key.getBType());
                        builders.put(key, builder);
                    }
                    Property sp = innermostElement(currentNode.value.getSource());
                    Property dp = innermostElement(currentNode.value.getDestination());
                    builder.fieldMap(sp.getExpression(), dp.getExpression()).add();
View Full Code Here


     */
    public String currentElementComparator(Node source, Node dest, NodeList srcNodes, NodeList destNodes) {
       
        StringBuilder comparator = new StringBuilder();
       
        MapperKey key = new MapperKey(source.elementRef.type(), dest.elementRef.type());
        ClassMap<?,?> classMap = mapperFactory.getClassMap(key);
        if (classMap == null) {
            classMap = mapperFactory.classMap(key.getAType(), key.getBType()).byDefault().toClassMap();
        }
       
        String or = "";
        Set<FieldMap> fieldMaps = new HashSet<FieldMap>(classMap.getFieldsMapping());
        for (Node node: source.children) {
            if (node.value != null) {
                fieldMaps.add(node.value);
            }
        }
        for (Node node: dest.children) {
            if (node.value != null) {
                fieldMaps.add(node.value);
            }
        }
       
        Set<String> comparisons = new HashSet<String>();
       
        for (FieldMap fieldMap: fieldMaps) {
            if (!(fieldMap.is(aMultiOccurrenceElementMap()) && fieldMap.isByDefault())
                    && !fieldMap.isExcluded()
                    && !fieldMap.isIgnored()) {
           
                Node srcNode = Node.findFieldMap(fieldMap, srcNodes, true);
                if (srcNode != null && srcNode.parent != null) {
                    srcNode = srcNode.parent;
                } else {
                    srcNode = source;
                }
               
                Node destNode = Node.findFieldMap(fieldMap, destNodes, false);
                if (destNode != null && destNode.parent != null) {
                    destNode = destNode.parent;
                } else {
                    destNode = dest;
                }
               
                Type<?> sourceType = source.elementRef.type();
                Type<?> destType = dest.elementRef.type();
               
                try {
                    propertyResolver.getProperty(sourceType, fieldMap.getSource().getName());
                    propertyResolver.getProperty(destType, fieldMap.getDestination().getName());
                   
                    VariableRef s = new VariableRef(fieldMap.getSource(), srcNode.elementRef);
                    VariableRef d = new VariableRef(fieldMap.getDestination(), destNode.elementRef);
                    String code = this.compareFields(fieldMap, s, d, key.getBType(), null);
                    if (!"".equals(code) && comparisons.add(code)) {
                        comparator.append(or + "!(" + code + ")");
                        or = " || ";
                    }
                } catch (Exception e) {
View Full Code Here

            }
        }
    }
   
    Mapper<Object, Object> resolveMapper(Type<?> sourceType, Type<?> destinationType) {
        final MapperKey mapperKey = new MapperKey(sourceType, destinationType);
        Mapper<Object, Object> mapper = mapperFactory.lookupMapper(mapperKey);
       
        if (mapper == null) {
            throw new IllegalStateException(String.format("Cannot create a mapper for classes : %s, %s", destinationType, sourceType));
        }
View Full Code Here

        return mappedFields;
    }
   
    private boolean isAlreadyExistsInUsedMappers(FieldMap fieldMap, ClassMap<?, ?> classMap) {
       
        Set<ClassMap<Object, Object>> usedClassMapSet = mapperFactory.lookupUsedClassMap(new MapperKey(classMap.getAType(),
                classMap.getBType()));
       
        if (!fieldMap.isByDefault()) {
          return false;
        }
View Full Code Here

        code.addMethod(out.toString());
    }
   
    private String addSourceClassConstructor(SourceCodeContext code, Type<?> type, Type<?> sourceType, MappingContext mappingContext, StringBuilder logDetails) {
       
        MapperKey mapperKey = new MapperKey(type,sourceType);
        ClassMap<Object, Object>  classMap = mapperFactory.getClassMap(mapperKey);
       
        if (classMap==null) {
          classMap = mapperFactory.getClassMap(new MapperKey(sourceType,type));
        }
       
        StringBuilder out = new StringBuilder();
       
        if (type.isArray()) {
View Full Code Here

        return concreteType;
    }
   
    @SuppressWarnings("unchecked")
    public <A, B> void registerClassMap(ClassMap<A, B> classMap) {
        classMapRegistry.put(new MapperKey(classMap.getAType(), classMap.getBType()), (ClassMap<Object, Object>) classMap);
        if (isBuilding || isBuilt) {
           
            MappingContext context = contextFactory.getContext();
            try {
                buildMapper(classMap, /** isAutoGenerated == **/isBuilding, context);
View Full Code Here

        Map<MapperKey, ClassMap<Object, Object>> classMapsDictionary = new HashMap<MapperKey, ClassMap<Object, Object>>();
       
        Set<ClassMap<Object, Object>> classMaps = new HashSet<ClassMap<Object, Object>>(classMapRegistry.values());
       
        for (final ClassMap<Object, Object> classMap : classMaps) {
            classMapsDictionary.put(new MapperKey(classMap.getAType(), classMap.getBType()), classMap);
        }
       
        for (final ClassMap<?, ?> classMap : classMaps) {
            MapperKey key = new MapperKey(classMap.getAType(), classMap.getBType());
           
            Set<ClassMap<Object, Object>> usedClassMapSet = new HashSet<ClassMap<Object, Object>>();
           
            for (final MapperKey parentMapperKey : classMap.getUsedMappers()) {
                ClassMap<Object, Object> usedClassMap = classMapsDictionary.get(parentMapperKey);
View Full Code Here

    }
   
    @SuppressWarnings("unchecked")
    private void initializeUsedMappers(ClassMap<?, ?> classMap) {
       
        Mapper<Object, Object> mapper = lookupMapper(new MapperKey(classMap.getAType(), classMap.getBType()));
       
        List<Mapper<Object, Object>> parentMappers = new ArrayList<Mapper<Object, Object>>();
       
        if (!classMap.getUsedMappers().isEmpty()) {
            for (MapperKey parentMapperKey : classMap.getUsedMappers()) {
                collectUsedMappers(classMap, parentMappers, parentMapperKey);
            }
        } else {
            /*
             * Attempt to auto-determine used mappers for this classmap;
             * however, we should only add the most-specific of the available
             * mappers to avoid calling the same mapper multiple times during a
             * single map request;
             */
            SortedCollection<MapperKey> usedMappers = new SortedCollection<MapperKey>(Comparators.MAPPER_KEY);
            for (MapperKey key : this.classMapRegistry.keySet()) {
                if (!key.getAType().equals(classMap.getAType()) || !key.getBType().equals(classMap.getBType())) {
                    if (key.getAType().isAssignableFrom(classMap.getAType()) && key.getBType().isAssignableFrom(classMap.getBType())) {
                        usedMappers.add(key);
                    }
                }
            }
            if (!usedMappers.isEmpty()) {
                MapperKey parentKey = usedMappers.first();
                collectUsedMappers(classMap, parentMappers, parentKey);
            }
        }
       
        /*
 
View Full Code Here

        parentMappers.add(parentMapper);
       
        Set<ClassMap<Object, Object>> usedClassMapSet = usedMapperMetadataRegistry.get(parentMapperKey);
        if (usedClassMapSet != null) {
            for (ClassMap<Object, Object> cm : usedClassMapSet) {
                collectUsedMappers(cm, parentMappers, new MapperKey(cm.getAType(), cm.getBType()));
            }
        }
    }
View Full Code Here

    private GeneratedMapperBase buildMapper(ClassMap<?, ?> classMap, boolean isAutoGenerated, MappingContext context) {
       
        register(classMap.getAType(), classMap.getBType());
        register(classMap.getBType(), classMap.getAType());
       
        final MapperKey mapperKey = new MapperKey(classMap.getAType(), classMap.getBType());
        final GeneratedMapperBase mapper = this.mapperGenerator.build(classMap, context);
        mapper.setMapperFacade(mapperFacade);
        mapper.setFromAutoMapping(isAutoGenerated);
        if (classMap.getCustomizedMapper() != null) {
            final Mapper<Object, Object> customizedMapper = (Mapper<Object, Object>) classMap.getCustomizedMapper();
View Full Code Here

TOP

Related Classes of ma.glasnost.orika.metadata.MapperKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.