@@ -0,0 +1,3307 @@
+package org.aksw.spring.bean.util;%0A%0Aimport java.beans.PropertyDescriptor;%0Aimport java.util.Map;%0A%0Aimport org.springframework.aop.scope.ScopedProxyUtils;%0Aimport org.springframework.beans.BeanWrapperImpl;%0Aimport org.springframework.beans.MutablePropertyValues;%0Aimport org.springframework.beans.factory.BeanFactory;%0Aimport org.springframework.beans.factory.config.BeanDefinitionHolder;%0Aimport org.springframework.beans.factory.support.BeanDefinitionReaderUtils;%0Aimport org.springframework.beans.factory.support.DefaultListableBeanFactory;%0Aimport org.springframework.beans.factory.support.RootBeanDefinition;%0Aimport org.springframework.context.ConfigurableApplicationContext;%0A%0Apublic class BeanDefinitionProxyUtils %7B%0A    /**%0A     * Take an existing bean (pojo), and use it as a template for creating a corresponding%0A     * bean definition (based on its properties and values) and register it%0A     * with the specfied scope at the given registry.%0A     *%0A     *%0A     * @param ctx%0A     * @param bean%0A     * @param scopeName%0A     * @param propertyToSpel Spel expression to evaluate on the scope%0A     * @return%0A     */%0A    public static %3CT%3E T createScopedProxy(BeanFactory ctx, T bean, String scopeName, Map%3CString, Object%3E propertyToSpel) %7B%0A        DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)((ConfigurableApplicationContext)ctx).getBeanFactory();%0A        //BeanDefinitionRegistry registry = (BeanDefinitionRegistry)ctx; // ConfigurableApplicationContext%0A%0A        Class%3C?%3E beanClazz = bean.getClass();%0A%0A        RootBeanDefinition beanDef = new RootBeanDefinition(beanClazz);%0A        BeanWrapperImpl beanWrapper = new BeanWrapperImpl(bean);%0A        MutablePropertyValues propertyValues = beanDef.getPropertyValues();%0A%0A        for(PropertyDescriptor pd : beanWrapper.getPropertyDescriptors()) %7B%0A            String propertyName = pd.getName();%0A            boolean isReadable = beanWrapper.isReadableProperty(propertyName);%0A            boolean isWritable = beanWrapper.isWritableProperty(propertyName);%0A            if(isReadable && isWritable) %7B%0A                Object value = beanWrapper.getPropertyValue(propertyName);%0A%0A                // TODO Make this configurable%0A                if(value != null && value instanceof String) %7B%0A                    String text = (String)value;%0A                    if(text.startsWith(%22##%22)) %7B%0A                        value = %22#%7B %22 + text.substring(2) + %22 %7D%22;%0A                    %7D%0A                %7D%0A%0A                propertyValues.add(propertyName, value);%0A            %7D%0A        %7D%0A        beanDef.setScope(scopeName);%0A%0A        //DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)((ConfigurableApplicationContext)ctx).getBeanFactory();%0A        //String rootName = BeanDefinitionReaderUtils.generateBeanName(beanDef, beanFactory);%0A        String beanName = BeanDefinitionReaderUtils.registerWithGeneratedName(beanDef, beanFactory);%0A%0A        BeanDefinitionHolder proxyHolder = ScopedProxyUtils.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName), beanFactory, true);%0A        BeanDefinitionReaderUtils.registerBeanDefinition(proxyHolder, beanFactory);%0A%0A        String proxyName = proxyHolder.getBeanName();%0A        @SuppressWarnings(%22unchecked%22)%0A        T result = (T)beanFactory.getBean(proxyName);%0A%0A        return result;%0A    %7D%0A%0A%7D%0A

should rename this project to aksw-spring-utils