Examples of ClassMap


Examples of org.dozer.classmap.ClassMap

    Object result = null;
    // in case of iterate feature new objects are created in any case
    if (!DozerConstants.ITERATE.equals(fieldMap.getDestFieldType())) {
      result = getExistingValue(fieldMap, destObj, destFieldType);
    }
    ClassMap classMap = null;
    // if the field is not null than we don't want a new instance
    if (result == null) {
      // first check to see if this plain old field map has hints to the actual
      // type.
      if (fieldMap.getDestHintContainer() != null) {
        Class<?> destHintType = fieldMap.getDestHintType(srcFieldValue.getClass());
        // if the destType is null this means that there was more than one hint.
        // we must have already set the destType then.
        if (destHintType != null) {
          destFieldType = destHintType;
        }
      }
      // Check to see if explicit map-id has been specified for the field
      // mapping
      String mapId = fieldMap.getMapId();

      Class<? extends Object> targetClass;
      if (fieldMap.getDestHintContainer() != null && fieldMap.getDestHintContainer().getHint() != null) {
        targetClass = fieldMap.getDestHintContainer().getHint();
      } else {
        targetClass = destFieldType;
      }
      classMap = getClassMap(srcFieldValue.getClass(), targetClass, mapId);

      result = DestBeanCreator.create(
          new BeanCreationDirective(srcFieldValue, classMap.getSrcClassToMap(), classMap.getDestClassToMap(),
              destFieldType, classMap.getDestClassBeanFactory(), classMap.getDestClassBeanFactoryId(),
              fieldMap.getDestFieldCreateMethod() != null ? fieldMap.getDestFieldCreateMethod() : classMap.getDestClassCreateMethod()));
    }

    map(classMap, srcFieldValue, result, false, fieldMap.getMapId());

    return result;
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    return superClasses;
  }

  private void checkForClassMapping(Class<?> srcClass, List<ClassMap> superClasses, Class<?> superDestClass) {
    ClassMap srcClassMap = classMappings.find(srcClass, superDestClass);
    if (srcClassMap != null) {
      superClasses.add(srcClassMap);
    }
  }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    }
    return result;
  }

  private ClassMap getClassMap(Class<?> srcClass, Class<?> destClass, String mapId) {
    ClassMap mapping = classMappings.find(srcClass, destClass, mapId);

    if (mapping == null) {
      // If mapping not found in existing custom mapping collection, create
      // default as an explicit mapping must not
      // exist. The create default class map method will also add all default
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    return new ConfigurationBuilder(configuration);
  }

  public MappingBuilder mapping() {
    Configuration configuration = data.getConfiguration();
    ClassMap classMap = new ClassMap(configuration);
    data.getClassMaps().add(classMap);
    MappingBuilder mappingDefinitionBuilder = new MappingBuilder(classMap);
    mappingBuilders.add(mappingDefinitionBuilder);
    return mappingDefinitionBuilder;
  }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

      return new FieldDefinitionBuilder(field);
    }


    public void build() {
      ClassMap classMap = fieldMap.getClassMap();
      classMap.addFieldMapping(fieldMap);
    }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

  @Override
  @Before
  public void setUp() throws Exception {
    globalConfiguration = new Configuration();
    classMap = new ClassMap(globalConfiguration);
  }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    classMap = new ClassMap(globalConfiguration);
  }

  @Test
  public void testAddFieldMappings() throws Exception {
    ClassMap cm = new ClassMap(null);
    GenericFieldMap fm = new GenericFieldMap(cm);

    cm.addFieldMapping(fm);

    assertNotNull(cm.getFieldMaps());
    assertTrue(cm.getFieldMaps().size() == 1);
    assertEquals(cm.getFieldMaps().get(0), fm);
  }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    assertEquals(cm.getFieldMaps().get(0), fm);
  }

  @Test
  public void testSetFieldMappings() throws Exception {
    ClassMap cm = new ClassMap(null);
    GenericFieldMap fm = new GenericFieldMap(cm);
    List<FieldMap> fmList = new ArrayList<FieldMap>();
    fmList.add(fm);

    cm.setFieldMaps(fmList);

    assertNotNull(cm.getFieldMaps());
    assertTrue(cm.getFieldMaps().size() == fmList.size());
    assertEquals(cm.getFieldMaps().get(0), fmList.get(0));
  }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

    } else {
      destType = destClass;
      result = null;
    }

    ClassMap classMap = null;
    try {
      Class<?> srcRealClass = MappingUtils.getRealClass(srcObj.getClass());
      classMap = getClassMap(srcRealClass, destType, mapId);

      eventMgr.fireEvent(new DozerEvent(DozerEventType.MAPPING_STARTED, classMap, null, srcObj, result, null));

      // TODO Check if any proxy issues are here
      // Check to see if custom converter has been specified for this mapping
      // combination. If so, just use it.
      Class<?> converterClass = MappingUtils.findCustomConverter(converterByDestTypeCache, classMap.getCustomConverters(), srcObj
          .getClass(), destType);

      if (converterClass != null) {
        return (T) mapUsingCustomConverter(converterClass, srcObj.getClass(), srcObj, destType, result, null, true);
      }

      if (result == null) {
        result = (T) DestBeanCreator.create(srcObj, classMap.getSrcClassToMap(), classMap.getDestClassToMap(), destType, classMap
            .getDestClassBeanFactory(), classMap.getDestClassBeanFactoryId(), classMap.getDestClassCreateMethod());
      }
      map(classMap, srcObj, result, false, null);
    } catch (Throwable e) {
      MappingUtils.throwMappingException(e);
    }
View Full Code Here

Examples of org.dozer.classmap.ClassMap

  private Object mapCustomObject(FieldMap fieldMap, Object destObj, Class<?> destFieldType, Object srcFieldValue) {
    // Custom java bean. Need to make sure that the destination object is not
    // already instantiated.
    Object result = getExistingValue(fieldMap, destObj, destFieldType);
    ClassMap classMap = null;
    // if the field is not null than we don't want a new instance
    if (result == null) {
      // first check to see if this plain old field map has hints to the actual
      // type.
      if (fieldMap.getDestHintContainer() != null) {
        Class<?> destHintType = fieldMap.getDestHintType(srcFieldValue.getClass());
        // if the destType is null this means that there was more than one hint.
        // we must have already set the destType then.
        if (destHintType != null) {
          destFieldType = destHintType;
        }
      }
      // Check to see if explicit map-id has been specified for the field
      // mapping
      String mapId = fieldMap.getMapId();
      classMap = getClassMap(srcFieldValue.getClass(), destFieldType, mapId);

      result = DestBeanCreator.create(srcFieldValue, classMap.getSrcClassToMap(),
          fieldMap.getDestHintContainer() != null ? fieldMap.getDestHintContainer().getHint() : classMap.getDestClassToMap(),
          destFieldType, classMap.getDestClassBeanFactory(), classMap.getDestClassBeanFactoryId(), fieldMap
              .getDestFieldCreateMethod() != null ? fieldMap.getDestFieldCreateMethod() : classMap.getDestClassCreateMethod());
    }

    map(classMap, srcFieldValue, result, false, fieldMap.getMapId());

    return result;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.