private void copyProperties()

in extscript-core-root/extscript-spring/src/main/java/org/apache/myfaces/extensions/scripting/spring/bean/CompilationAwareRefreshableBeanFactory.java [219:270]


    private void copyProperties(String beanName, BeanDefinition beanDefinition, Object source, Object target)
    {
        // Definitely we don't want to mess around with properties of
        // any proxy objects, so we'll use its target class here.
        PropertyDescriptor[] targetDescriptors = BeanUtils.getPropertyDescriptors(
                ProxyAopUtils.resolveTargetClass(target));

        for (int i = 0; i < targetDescriptors.length; i++)
        {
            PropertyDescriptor targetDescriptor = targetDescriptors[i];
            if (targetDescriptor.getWriteMethod() != null)
            {
                PropertyDescriptor sourceDescriptor =
                        BeanUtils.getPropertyDescriptor(source.getClass(), targetDescriptor.getName());
                if (sourceDescriptor != null && sourceDescriptor.getReadMethod() != null)
                {
                    try
                    {

                        Object value = invokeMethod(sourceDescriptor.getReadMethod(), source, new Object[0]);
                        if (value instanceof ThrowAwayClassloader)
                        {
                            //spring let spring handle the property assignment for a dynamic class
                            //so that property reloads work
                        } else
                        {
                            invokeMethod(targetDescriptor.getWriteMethod(), target, new Object[]{value});
                        }

                        /*if (getReloadingClassLoader().isOutdated(value.getClass()) &&
                                beanDefinition.getPropertyValues().contains(targetDescriptor.getName())) {
                            // If the currenty property has been injected by Spring already and the
                            // source object returned an outdated object, keep the one that has been
                            // injected by Spring as it's more likely to be the most recent one.

                            if (logger.isWarnEnabled()) {
                                logger.warn(" This factory will not copy the property '" + targetDescriptor.getName() + "' of the bean '" +
                                        beanName + "' as the source object '" + source + "' only returns an outdated object '" + value + "'.");
                            }
                        }
                        else {
                        invokeMethod(targetDescriptor.getWriteMethod(), target, new Object[]{value});
                        /*}*/
                    }
                    catch (Throwable ex)
                    {
                        throw new FatalBeanException("Could not copy properties from source to target", ex);
                    }
                }
            }
        }
    }