コード例 #1
0
 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);
 }
コード例 #2
0
 public Object create(BeanCreationDirective directive) {
   JAXBElementConverter jaxbElementConverter =
       new JAXBElementConverter(
           (directive.getDestObj() != null)
               ? directive.getDestObj().getClass().getCanonicalName()
               : directive.getActualClass().getCanonicalName(),
           directive.getFieldName(),
           null);
   String beanId = jaxbElementConverter.getBeanId();
   Object destValue =
       jaxbBeanFactory.createBean(directive.getSrcObject(), directive.getSrcClass(), beanId);
   return jaxbElementConverter.convert(
       jaxbObjectType, (destValue != null) ? destValue : directive.getSrcObject());
 }
コード例 #3
0
    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;
    }