001    /**
002     * Copyright 2010 The Kuali Foundation Licensed under the
003     * Educational Community License, Version 2.0 (the "License"); you may
004     * not use this file except in compliance with the License. You may
005     * obtain a copy of the License at
006     *
007     * http://www.osedu.org/licenses/ECL-2.0
008     *
009     * Unless required by applicable law or agreed to in writing,
010     * software distributed under the License is distributed on an "AS IS"
011     * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012     * or implied. See the License for the specific language governing
013     * permissions and limitations under the License.
014     */
015    
016    package org.kuali.student.common.test.spring;
017    
018    import org.springframework.beans.BeansException;
019    import org.springframework.beans.factory.config.BeanDefinition;
020    import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
021    import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
022    import org.springframework.beans.factory.support.BeanDefinitionRegistry;
023    import org.springframework.beans.factory.support.RootBeanDefinition;
024    import org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor;
025    
026    @Deprecated
027    public class DaoPostProcessor implements BeanFactoryPostProcessor {
028            private String daoImplClasses;
029    
030            /**
031             * @return the daoImplClasses
032             */
033            public String getDaoImplClasses() {
034                    return daoImplClasses;
035            }
036    
037            /**
038             * @param daoImplClasses
039             *            the daoImplClasses to set
040             */
041            public void setDaoImplClasses(String daoImplClasses) {
042                    this.daoImplClasses = daoImplClasses;
043            }
044    
045            @Override
046            public void postProcessBeanFactory(
047                            ConfigurableListableBeanFactory beanFactory) throws BeansException {
048                    String[] classes = daoImplClasses.split(",");
049                    BeanDefinitionRegistry registry = ((BeanDefinitionRegistry) beanFactory);
050                    PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor();
051                    if (classes != null && classes.length > 0) {
052                            for (String line : classes) {
053                                    if (!"".equals(line)) {
054                                            try {
055                                                    String[] split = line.split("\\|");
056                                                    String className = split[0];
057                                                    Class<?> clazz = Class.forName(className);
058                                                    BeanDefinition definition = new RootBeanDefinition(
059                                                                    clazz);
060                                                    registry.registerBeanDefinition(clazz.getSimpleName(),
061                                                                    definition);
062                                                    pabpp.postProcessMergedBeanDefinition(
063                                                                    (RootBeanDefinition) definition, clazz, clazz
064                                                                                    .getSimpleName());
065    
066                                            } catch (Exception e) {
067                                                    throw new RuntimeException(e);
068                                            }
069                                    }
070                            }
071                    }
072            }
073    }