Package ma.glasnost.orika.metadata

Examples of ma.glasnost.orika.metadata.FieldMap


            stack.addAll(0, currentNode.children);
            Node srcNode = null;
            if (currentNode.value != null) {
                srcNode = Node.findFieldMap(currentNode.value, sourceNodes, true);
            } else {
                FieldMap fieldMap = currentNode.getMap();
                if (fieldMap != null) {
                    srcNode = Node.findFieldMap(fieldMap, sourceNodes, true).parent;
                }
            }
           
View Full Code Here


            stack.addAll(0, currentNode.children);
            Node srcNode = null;
            if (currentNode.value != null) {
                srcNode = Node.findFieldMap(currentNode.value, sourceNodes, true);
            } else {
                FieldMap fieldMap = currentNode.getMap();
                if (fieldMap != null) {
                    srcNode = Node.findFieldMap(fieldMap, sourceNodes, true).parent;
                }
            }
       
View Full Code Here

           */
          Set<FieldMap> fields = new HashSet<FieldMap>(classMap.getFieldsMapping());
          for (String arg: declaredParameterNames) {
            Iterator<FieldMap> iter = fields.iterator();
            while(iter.hasNext()) {
              FieldMap fieldMap = iter.next();
              if (!fieldMap.is(aMappingOfTheRequiredClassProperty())) {
                if ( !aToB) {
                  fieldMap = fieldMap.flip();
                }
                if (fieldMap.getSource().getName().equals(arg)) {
                  targetParameters.put(arg, fieldMap);
                  iter.remove();
                }
              }
            }
          }
        } else {
          /*
           * Determine the set of constructor argument names
           * from the field mapping
           */
          for(FieldMap fieldMap: classMap.getFieldsMapping()) {
            if (!fieldMap.is(aMappingOfTheRequiredClassProperty())) {
              if (!aToB) {
                fieldMap = fieldMap.flip();
              }
              targetParameters.put(fieldMap.getDestination().getName(), fieldMap);
            }
          }
         
        }
       
        Constructor<T>[] constructors = (Constructor<T>[]) targetClass.getRawType().getConstructors();
        TreeMap<Integer, ConstructorMapping<T>> constructorsByMatchedParams = new TreeMap<Integer, ConstructorMapping<T>>();
        for (Constructor<T> constructor: constructors) {
          ConstructorMapping<T> constructorMapping = new ConstructorMapping<T>();
          constructorMapping.setDeclaredParameters(declaredParameterNames);
          boolean byDefault = declaredParameterNames == null;
         
          try {
            /*
             * 1) A constructor's parameters are all matched by known parameter names
             * 2) ...
             */
            String[] parameterNames = paranamer.lookupParameterNames(constructor);
            java.lang.reflect.Type[] genericParameterTypes = constructor.getGenericParameterTypes();
            Type<?>[] parameterTypes = new Type[genericParameterTypes.length];
            constructorMapping.setParameterNameInfoAvailable(true);
            if (targetParameters.keySet().containsAll(Arrays.asList(parameterNames))) {
              constructorMapping.setConstructor(constructor);
              for (int i=0; i < parameterNames.length; ++i) {
                String parameterName = parameterNames[i];
                parameterTypes[i] = TypeFactory.valueOf(genericParameterTypes[i]);
                FieldMap existingField = targetParameters.get(parameterName);
                FieldMap argumentMap = mapConstructorArgument(existingField, parameterTypes[i], byDefault);
                constructorMapping.getMappedFields().add(argumentMap);
              }
              constructorMapping.setParameterTypes(parameterTypes);
              constructorsByMatchedParams.put(parameterNames.length*1000, constructorMapping);
            }
          } catch (ParameterNamesNotFoundException e) {
            /*
             * Could not find parameter names of the constructors; attempt to match constructors
             * based on the types of the destination properties
             */
               List<FieldMap> targetTypes = new ArrayList<FieldMap>(targetParameters.values());
             int matchScore = 0;
             int exactMatches = 0;
             java.lang.reflect.Type[] params = constructor.getGenericParameterTypes();
             Type<?>[] parameterTypes = new Type[params.length];
               for (int i=0; i < params.length; ++i) {
                java.lang.reflect.Type param = params[i];
               
                parameterTypes[i] = TypeFactory.valueOf(param);
              for (Iterator<FieldMap> iter = targetTypes.iterator(); iter.hasNext();) {
                FieldMap fieldMap = iter.next();
                Type<?> targetType = fieldMap.getDestination().getType();
                if ((parameterTypes[i].equals(targetType) && ++exactMatches != 0)
                        || parameterTypes[i].isAssignableFrom(targetType) ) {
                  ++matchScore;
                 
                  String parameterName = fieldMap.getDestination().getName();
                    FieldMap existingField = targetParameters.get(parameterName);
                    FieldMap argumentMap = mapConstructorArgument(existingField, parameterTypes[i], byDefault);
                    constructorMapping.getMappedFields().add(argumentMap);
                 
                  iter.remove();
                  break;
                }
View Full Code Here

    Property destProp = new Property.Builder()
            .name(existing.getDestination().getName())
            .getter(existing.getDestination().getName())
            .type(argumentType)
            .build();
    FieldMap fieldMap = new FieldMap(existing.getSource(), destProp, null,
        null, MappingDirection.A_TO_B, false, existing.getConverterId(),
        byDefault, null, null);
    return fieldMap;
  }
View Full Code Here

       
        while (!unprocessed.isEmpty() && !(thisRoundSources.isEmpty() && thisRoundDestinations.isEmpty())) {
           
            Iterator<FieldMap> iter = unprocessed.iterator();
            while (iter.hasNext()) {
                FieldMap f = iter.next();
                boolean containsSource = thisRoundSources.contains(root(f.getSource()).getExpression());
                boolean containsDestination = thisRoundDestinations.contains(root(f.getDestination()).getExpression());
                if (containsSource && containsDestination) {
                    associated.add(f);
                    iter.remove();
                } else if (containsSource) {
                    associated.add(f);
                    iter.remove();
                    nextRoundDestinations.add(f.getDestination().getName());
                } else if (containsDestination) {
                    associated.add(f);
                    iter.remove();
                    nextRoundSources.add(f.getSource().getName());
                }
            }
           
            thisRoundSources = nextRoundSources;
            thisRoundDestinations = nextRoundDestinations;
View Full Code Here

               
              }
              continue;
            }
           
            FieldMap fieldMap = currentFieldMap;
            if (!aToB) {
                fieldMap = fieldMap.flip();
            }
           
            if (code.aggregateSpecsApply(fieldMap)) {
                continue;
            }
           
            if (logDetails != null) {
            logDetails.append(getFieldTag(fieldMap));
          }
           
            if (!fieldMap.isIgnored()) {
                try {
                    mappedFields.add(currentFieldMap);
                    String sourceCode = generateFieldMapCode(code, fieldMap, classMap, destination, logDetails);
                    out.append(sourceCode);
                } catch (final Exception e) {
                    MappingException me = new MappingException(e);
                    me.setSourceProperty(fieldMap.getSource());
                    me.setDestinationProperty(fieldMap.getDestination());
                    me.setSourceType(source.type());
                    me.setDestinationType(destination.type());
                    throw me;
                }
            } else if (logDetails !=null) {
View Full Code Here

       
        for (Node child: children) {
            if (child.value != null) {
               
                int depth = 0;
                FieldMap value = child.value;
                Property prop = isSource ? value.getSource() : value.getDestination();
                while (prop.getContainer() != null) {
                    ++depth;
                    prop = prop.getContainer();
                }
               
View Full Code Here

TOP

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

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.