JAXBBeanFactory implements BeanFactory { @Override public Object createBean(Object srcObj, Class<?> srcObjClass, String beanId, BeanContainer beanContainer) { log.debug("createBean(Object, Class, String) - start [{}]", beanId); int indexOf = beanId.indexOf(INNER_CLASS_DELIMITER); while (indexOf > 0) { beanId = beanId.substring(0, indexOf) + beanId.substring(indexOf + 1); log.debug("createBean(Object, Class, String) - HAS BEEN CHANGED TO [{}]", beanId); indexOf = beanId.indexOf(INNER_CLASS_DELIMITER); } Object result; Class<?> objectFactory = MappingUtils.loadClass(beanId.substring(0, beanId.lastIndexOf(".")) + ".ObjectFactory", beanContainer); Object factory = ReflectionUtils.newInstance(objectFactory); Method method = null; try { method = ReflectionUtils.getMethod(objectFactory, "create" + beanId.substring(beanId.lastIndexOf(".") + 1), new Class[] {}); } catch (NoSuchMethodException e) { MappingUtils.throwMappingException(e); } Object returnObject = ReflectionUtils.invoke(method, factory, new Object[] {}); log.debug("createBean(Object, Class, String) - end [{}]", returnObject.getClass().getName()); result = returnObject; return result; }  @Override Object createBean(Object srcObj, Class<?> srcObjClass, String beanId, BeanContainer beanContainer);  }
@Test public void testCreateBeanForSimpleJaxbClass() { Object obj = factory.createBean(null, null, "com.github.dozermapper.core.vo.jaxb.employee.EmployeeType", beanContainer); assertNotNull("Object can not be null", obj); assertEquals("com.github.dozermapper.core.vo.jaxb.employee.EmployeeType", obj.getClass().getName()); }
@Test(expected = MappingException.class) public void testCreateBeanClassNotFoundException() { factory.createBean(null, null, "ve.ve.DE", beanContainer); }
@Test public void testCreateBeanForInnerJaxbClass() { Object obj = factory.createBean(null, null, "com.github.dozermapper.core.vo.jaxb.employee.EmployeeWithInnerClass$Address", beanContainer); assertNotNull(obj); assertEquals("com.github.dozermapper.core.vo.jaxb.employee.EmployeeWithInnerClass$Address", obj.getClass().getName()); }
@Test public void testCreateBeanForNestedInnerJaxbClass() { Object obj = factory.createBean(null, null, "com.github.dozermapper.core.vo.jaxb.employee.EmployeeWithInnerClass$Address$State", beanContainer); assertNotNull(obj); assertEquals("com.github.dozermapper.core.vo.jaxb.employee.EmployeeWithInnerClass$Address$State", obj.getClass().getName()); }