public static boolean shouldIgnoreField(String fieldName, Class<?> srcType, Class<?> destType) { if (CLASS.equals(fieldName)) { return true; } if ((CALLBACK.equals(fieldName) || CALLBACKS.equals(fieldName)) && (MappingUtils.isProxy(srcType) || MappingUtils.isProxy(destType))) { return true; } return false; }
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); }
public Object create(BeanCreationDirective directive) { Class<?> classToCreate = directive.getActualClass(); String factoryBeanId = directive.getFactoryId(); String beanId = !MappingUtils.isBlankOrNull(factoryBeanId) ? factoryBeanId : classToCreate.getName(); return xmlBeanFactory.createBean(directive.getSrcObject(), directive.getSrcClass(), beanId); }
private Method findMethod(Class<?> actualClass, String createMethod) { Method method = null; try { method = ReflectionUtils.getMethod(actualClass, createMethod, null); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } return method; }
public Object create(BeanCreationDirective directive) { Class<?> classToCreate = directive.getActualClass(); String factoryName = directive.getFactoryName(); String factoryBeanId = directive.getFactoryId(); // By default, use dest object class name for factory bean id String beanId = !MappingUtils.isBlankOrNull(factoryBeanId) ? factoryBeanId : classToCreate.getName(); BeanFactory factory = factoryCache.get(factoryName); if (factory == null) { Class<?> factoryClass = MappingUtils.loadClass(factoryName); if (!BeanFactory.class.isAssignableFrom(factoryClass)) { MappingUtils.throwMappingException( "Custom bean factory must implement " + BeanFactory.class.getName() + " interface : " + factoryClass); } factory = (BeanFactory) ReflectionUtils.newInstance(factoryClass); // put the created factory in our factory map factoryCache.put(factoryName, factory); } Object result = factory.createBean(directive.getSrcObject(), directive.getSrcClass(), beanId); log.debug( "Bean instance created with custom factory -->\n Bean Type: {}\n Factory Name: {}", result.getClass().getName(), factoryName); if (!classToCreate.isAssignableFrom(result.getClass())) { MappingUtils.throwMappingException( "Custom bean factory (" + factory.getClass() + ") did not return correct type of destination data object. Expected : " + classToCreate + ", Actual : " + result.getClass()); } return result; }
public Object create(BeanCreationDirective directive) { Class<?> classToCreate = directive.getActualClass(); try { return newInstance(classToCreate); } catch (Exception e) { if (directive.getAlternateClass() != null) { return newInstance(directive.getAlternateClass()); } else { MappingUtils.throwMappingException(e); } } return null; }
private Configuration findConfiguration(List<MappingFileData> mappingFileDataList) { Configuration globalConfiguration = null; for (MappingFileData mappingFileData : mappingFileDataList) { if (mappingFileData.getConfiguration() != null) { // Only allow 1 global configuration if (globalConfiguration != null) { MappingUtils.throwMappingException( "More than one global configuration found. " + "Only one global configuration block (<configuration></configuration>) can be specified across all mapping files. " + "You need to consolidate all global configuration blocks into a single one."); } globalConfiguration = mappingFileData.getConfiguration(); } } // If global configuration was not specified, use defaults if (globalConfiguration == null) { globalConfiguration = new Configuration(); } return globalConfiguration; }
private static <T> T newInstance(Class<T> clazz) { // Create using public or private no-arg constructor Constructor<T> constructor = null; try { constructor = clazz.getDeclaredConstructor(null); } catch (SecurityException e) { MappingUtils.throwMappingException(e); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } if (constructor == null) { MappingUtils.throwMappingException( "Could not create a new instance of the dest object: " + clazz + ". Could not find a no-arg constructor for this class."); } // If private, make it accessible if (!constructor.isAccessible()) { constructor.setAccessible(true); } T result = null; try { result = constructor.newInstance(null); } catch (IllegalArgumentException e) { MappingUtils.throwMappingException(e); } catch (InstantiationException e) { MappingUtils.throwMappingException(e); } catch (IllegalAccessException e) { MappingUtils.throwMappingException(e); } catch (InvocationTargetException e) { MappingUtils.throwMappingException(e); } return result; }
public boolean isApplicable(BeanCreationDirective directive) { String factoryName = directive.getFactoryName(); return !MappingUtils.isBlankOrNull(factoryName); }
public boolean isApplicable(BeanCreationDirective directive) { String createMethod = directive.getCreateMethod(); return !MappingUtils.isBlankOrNull(createMethod); }