Package org.dozer

Examples of org.dozer.BeanFactory


      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;
    }
View Full Code Here


      String factoryBeanId) {

    // By default, use dest object class name for factory bean id
    String beanId = !MappingUtils.isBlankOrNull(factoryBeanId) ? factoryBeanId : destClass.getName();

    BeanFactory factory = storedFactories.get(factoryName);

    if (factory == null) {
      Class<?> factoryClass = MappingUtils.loadClass(factoryName);
      if (!BeanFactory.class.isAssignableFrom(factoryClass)) {
        MappingUtils.throwMappingException("Custom bean factory must implement the BeanFactoryIF interface.");
      }
      factory = (BeanFactory) newInstance(factoryClass);
      // put the created factory in our factory map
      storedFactories.put(factoryName, factory);
    }
    Object rvalue = factory.createBean(srcObject, srcObjectClass, beanId);

    if (log.isDebugEnabled()) {
      log.debug("Bean instance created with custom factory -->" + "\n  Bean Type: " + rvalue.getClass().getName()
              + "\n  Factory Name: " + factoryName);
    }
View Full Code Here

      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;
    }
View Full Code Here

TOP

Related Classes of org.dozer.BeanFactory

Copyright © 2018 www.massapicom. 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.