public LoadMappingsResult load(List<MappingFileData> mappings) { Configuration globalConfiguration = findConfiguration(mappings); ClassMappings customMappings = new ClassMappings(); // Decorate the raw ClassMap objects and create ClassMap "prime" instances for (MappingFileData mappingFileData : mappings) { List<ClassMap> classMaps = mappingFileData.getClassMaps(); ClassMappings customMappingsPrime = mappingsParser.processMappings(classMaps, globalConfiguration); customMappings.addAll(customMappingsPrime); } // Add default mappings using matching property names if wildcard policy // is true. The addDefaultFieldMappings will check the wildcard policy of each classmap ClassMapBuilder.addDefaultFieldMappings(customMappings, globalConfiguration); Set<CustomConverterDescription> customConverterDescriptions = new LinkedHashSet<CustomConverterDescription>(); // build up custom converter description objects if (globalConfiguration.getCustomConverters() != null && globalConfiguration.getCustomConverters().getConverters() != null) { for (CustomConverterDescription cc : globalConfiguration.getCustomConverters().getConverters()) { customConverterDescriptions.add(cc); } } // iterate through the classmaps and set all of the custom converters on them for (Entry<CacheKeyFactory.CacheKey, ClassMap> entry : customMappings.getAll().entrySet()) { ClassMap classMap = entry.getValue(); if (classMap.getCustomConverters() != null) { classMap .getCustomConverters() .setConverters(new ArrayList<CustomConverterDescription>(customConverterDescriptions)); } else { classMap.setCustomConverters(new CustomConverterContainer()); classMap .getCustomConverters() .setConverters(new ArrayList<CustomConverterDescription>(customConverterDescriptions)); } } addDefaultCustomConverters(globalConfiguration); return new LoadMappingsResult(customMappings, globalConfiguration); }
public static void addGenericMapping( ClassMap classMap, Configuration configuration, String srcName, String destName, CustomMapping mapping, Boolean isField) { FieldMap fieldMap = new GenericFieldMap(classMap); DozerField sourceField = new DozerField(srcName, null); DozerField destField = new DozerField(destName, null); if (isField.booleanValue()) { sourceField.setAccessible(true); destField.setAccessible(true); } // Add mapping fieldMap.setSrcField(sourceField); fieldMap.setDestField(destField); // Add relationship-type fieldMap.setRelationshipType(RelationshipType.valueOf(mapping.relationshipType().trim())); // Add remove orphan fieldMap.setRemoveOrphans(mapping.removeOrphans()); // add CopyByReferences per defect #1728159 MappingUtils.applyGlobalCopyByReference(configuration, fieldMap, classMap); classMap.addFieldMapping(fieldMap); }