1 16 package org.directwebremoting.spring; 17 18 import org.directwebremoting.create.AbstractCreator; 19 import org.springframework.aop.support.AopUtils; 20 import org.springframework.context.ApplicationContextAware; 21 import org.springframework.context.ApplicationContext; 22 import org.springframework.beans.FatalBeanException; 23 import org.springframework.beans.factory.InitializingBean; 24 import org.springframework.util.Assert; 25 26 34 public class BeanCreator extends AbstractCreator implements ApplicationContextAware, InitializingBean { 35 36 42 public void afterPropertiesSet() 43 { 44 if (bean != null) { 46 this.beanClass = bean.getClass(); 47 } else if (beanId != null) { 48 this.beanClass = applicationContext.getType(beanId); 49 } else { 50 throw new FatalBeanException( 51 "You should either set the bean property directly or set the beanId property"); 52 } 53 54 if(AopUtils.isCglibProxyClass(this.beanClass)) { 56 this.beanClass = this.beanClass.getSuperclass(); 57 } 58 } 59 60 67 public Class getType() 68 { 69 return beanClass; 70 } 71 72 77 public Object getInstance() 78 { 79 synchronized(monitor) { 80 if (bean == null) { 81 Assert.notNull(beanId, "The bean id needs to be specified"); 82 bean = applicationContext.getBean(beanId); 83 } 84 } 85 86 return bean; 87 } 88 89 93 public void setBean(Object bean) 94 { 95 this.bean = bean; 96 } 97 98 105 public void setBeanClass(Class beanClass) 106 { 107 this.beanClass = beanClass; 108 } 109 110 116 public void setApplicationContext(ApplicationContext applicationContext) 117 { 118 this.applicationContext = applicationContext; 119 } 120 121 127 public void setBeanId(String beanId) 128 { 129 this.beanId = beanId; 130 } 131 132 139 public void setConfig(CreatorConfig config) 140 { 141 this.config = config; 142 } 143 144 148 public CreatorConfig getConfig() 149 { 150 return config; 151 } 152 153 156 private Object bean; 157 158 161 private Class beanClass; 162 163 166 private String beanId; 167 168 171 private ApplicationContext applicationContext; 172 173 176 private CreatorConfig config; 177 178 179 private final Object monitor = new Object (); 180 } 181 | Popular Tags |