List of usage examples for org.springframework.beans.factory.support AbstractBeanDefinition getBeanClass
public Class<?> getBeanClass() throws IllegalStateException
From source file:org.springmodules.cache.config.ConfigAssert.java
/** * Asserts that the given bean definition wraps a bean of the given class. * /*from w w w . j a v a 2 s . c o m*/ * @param beanDefinition * the given bean definition * @param expectedClass * the expected class of the wrapped bean */ public static void assertBeanDefinitionWrapsClass(AbstractBeanDefinition beanDefinition, Class expectedClass) { Assert.assertEquals("<Bean definition class>", expectedClass, beanDefinition.getBeanClass()); }
From source file:com.graby.store.base.remote.RemotingAnnotationHandlerMapping.java
/** * Checks for presence of the {@link org.springframework.web.bind.annotation.RequestMapping} * annotation on the handler class and on any of its methods. *///w w w . j a v a2 s . co m protected String[] determineUrlsForHandler(String beanName) { ApplicationContext context = getApplicationContext(); Class<?> handlerType = context.getType(beanName); RemotingService mapping = AnnotationUtils.findAnnotation(handlerType, RemotingService.class); if (mapping == null && context instanceof ConfigurableApplicationContext && context.containsBeanDefinition(beanName)) { ConfigurableApplicationContext cac = (ConfigurableApplicationContext) context; BeanDefinition bd = cac.getBeanFactory().getMergedBeanDefinition(beanName); if (bd instanceof AbstractBeanDefinition) { AbstractBeanDefinition abd = (AbstractBeanDefinition) bd; if (abd.hasBeanClass()) { Class<?> beanClass = abd.getBeanClass(); mapping = AnnotationUtils.findAnnotation(beanClass, RemotingService.class); } } } if (mapping != null) { this.cachedMappings.put(handlerType, mapping); Set<String> urls = new LinkedHashSet<String>(); String path = mapping.serviceUrl(); if (path != null) { addUrlsForPath(urls, path); return StringUtils.toStringArray(urls); } else { return null; } } else { return null; } }
From source file:com.googlecode.ehcache.annotations.key.SpELCacheKeyGenerator.java
/** * Create a new key generator with the specified name. */// ww w . j ava2s. co m @SuppressWarnings("unchecked") protected CacheKeyGenerator<Serializable> createKeyGenerator(String name, Class<CacheKeyGenerator<Serializable>> keyGeneratorClass, MutablePropertyValues properties) { final AbstractBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(keyGeneratorClass); if (this.reflectionHelper != null && ReflectionHelperAware.class.isAssignableFrom(beanDefinition.getBeanClass())) { properties.addPropertyValue("reflectionHelper", this.reflectionHelper); } beanDefinition.setPropertyValues(properties); this.cacheKeyBeanFactory.registerBeanDefinition(name, beanDefinition); return this.cacheKeyBeanFactory.getBean(name, CacheKeyGenerator.class); }
From source file:com.longio.spring.LioBootstrap.java
private void resolveLservice(ApplicationContext app, DefaultListableBeanFactory bf) { for (String name : bf.getBeanDefinitionNames()) { AbstractBeanDefinition bd = (AbstractBeanDefinition) bf.getBeanDefinition(name); if (!bd.hasBeanClass()) { continue; }//from w w w . j av a2 s .com if (!name.endsWith("Service")) { continue; } Class<?> cls = bd.getBeanClass(); if (cls != LioFactoryBean.class) { continue; } Object obj = app.getBean(name); app.getAutowireCapableBeanFactory().autowireBean(obj); Lservice ls = obj.getClass().getAnnotation(Lservice.class); if (ls != null) { String pkg = ls.path(); Connector connector = getConnector(bf); for (Dispatcher d : connector.getDispatcheres(pkg)) { MethodRefFactory mrf = new DefaultMethodRefFactory(cmdLookup); d.registerMethodRefs(mrf.createMethodRefs(obj)); } logger.info("load longio [" + pkg + "] service"); } LsAutowired lsa = obj.getClass().getAnnotation(LsAutowired.class); if (lsa != null) { String pkg = lsa.path(); logger.info("load longio client [" + pkg + "] service"); } } }
From source file:com.longio.spring.LioBootstrap.java
private void resolveLfilters(ApplicationContext app, DefaultListableBeanFactory bf) { List<MessageFilter> filters = new ArrayList<MessageFilter>(); for (String name : bf.getBeanDefinitionNames()) { AbstractBeanDefinition bd = (AbstractBeanDefinition) bf.getBeanDefinition(name); //System.out.println("+++++++++++++++" + name); if (!bd.hasBeanClass()) { continue; }/*from w ww .j av a 2 s.c om*/ if (!name.endsWith("Filter")) { continue; } Class<?> cls = bd.getBeanClass(); if (cls != LioFactoryBean.class) { continue; } Object obj = app.getBean(name); app.getAutowireCapableBeanFactory().autowireBean(obj); LsFilter lf = obj.getClass().getAnnotation(LsFilter.class); if (lf != null) { filters.add((MessageFilter) obj); } } Connector connector = getConnector(bf); for (Dispatcher d : connector.getDispatcheres("*")) { d.registerMessageFilters(filters); for (MessageFilter filter : filters) { logger.info("load longio [" + filter.getClass().getCanonicalName() + "] message filter"); } } }
From source file:com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.java
protected final <T> T getOrCreateChildBean(Class<T> beanType, String beanClass, Property[] properties) { final StringBuilder beanNameBuilder = new StringBuilder(); beanNameBuilder.append(beanClass);/*from w w w .ja va 2 s. co m*/ final MutablePropertyValues mutablePropertyValues = new MutablePropertyValues(); //Sort the properties array first so bean name generation is always consistent Arrays.sort(properties, PropertyComparator.INSTANCE); for (Property property : properties) { final String name = property.name(); final String value = property.value(); final String ref = property.ref(); beanNameBuilder.append("[").append(name).append(",").append(value).append(",").append(ref).append("]"); if (value.length() > 0) { if (ref.length() > 0) { throw new IllegalArgumentException( "Only one of value or ref must be specified no both on Property with name: " + name); } mutablePropertyValues.addPropertyValue(name, value); } else if (ref.length() > 0) { mutablePropertyValues.addPropertyValue(name, new RuntimeBeanReference(ref)); } else { throw new IllegalArgumentException( "Either value or ref must be specified on Property with name: " + name); } } final String beanName = beanNameBuilder.toString(); //See if the bean is already registered using the compiled bean name, if so just use that instance if (this.childBeanFactory.containsBean(beanName)) { return this.childBeanFactory.getBean(beanName, beanType); } //Create and register the bean if it didn't already exist final AbstractBeanDefinition beanDefinition; try { beanDefinition = BeanDefinitionReaderUtils.createBeanDefinition(null, beanClass, ClassUtils.getDefaultClassLoader()); } catch (ClassNotFoundException e) { throw new BeanCreationException( "Could not find class '" + beanClass + "' to create " + beanType + " from", e); } if (ReflectionHelperAware.class.isAssignableFrom(beanDefinition.getBeanClass())) { mutablePropertyValues.addPropertyValue("reflectionHelper", this.reflectionHelper); } beanDefinition.setPropertyValues(mutablePropertyValues); this.childBeanFactory.registerBeanDefinition(beanName, beanDefinition); return this.childBeanFactory.getBean(beanName, beanType); }
From source file:net.paoding.rose.web.impl.module.ModulesBuilderImpl.java
private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module) throws IllegalAccessException { AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory() .getBeanDefinition(beanName); String beanClassName = beanDefinition.getBeanClassName(); String controllerSuffix = null; for (String suffix : RoseConstants.CONTROLLER_SUFFIXES) { if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) { if (suffix.length() == 1 && Character .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) { continue; }/*from ww w. j a v a2 s .c o m*/ controllerSuffix = suffix; break; } } if (controllerSuffix == null) { if (beanDefinition.hasBeanClass()) { Class<?> beanClass = beanDefinition.getBeanClass(); if (beanClass.isAnnotationPresent(Path.class)) { throw new IllegalArgumentException( "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, " + "is it a Resource/Controller? wrong spelling? : " + beanClassName); } } // ?l?r?uer?or??? if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor") || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) { // ?throw??? logger.error("", new IllegalArgumentException( "invalid class name end wrong spelling? : " + beanClassName)); } return false; } String[] controllerPaths = null; if (!beanDefinition.hasBeanClass()) { try { beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e); } } final Class<?> clazz = beanDefinition.getBeanClass(); final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz), controllerSuffix); Path reqMappingAnnotation = clazz.getAnnotation(Path.class); if (reqMappingAnnotation != null) { controllerPaths = reqMappingAnnotation.value(); } if (controllerPaths != null) { // controllerPaths.length==0path?controller for (int i = 0; i < controllerPaths.length; i++) { if ("#".equals(controllerPaths[i])) { controllerPaths[i] = "/" + controllerName; } else if (controllerPaths[i].equals("/")) { controllerPaths[i] = ""; } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') { controllerPaths[i] = "/" + controllerPaths[i]; } if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) { if (controllerPaths[i].endsWith("//")) { throw new IllegalArgumentException("invalid path '" + controllerPaths[i] + "' for controller " + beanClassName + ": don't end with more than one '/'"); } controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1); } } } else { // TODO: ?0.91.0?201007?? if (controllerName.equals("index") || controllerName.equals("home") || controllerName.equals("welcome")) { // ??IndexController/HomeController/WelcomeController@Path("") throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName()); } else { controllerPaths = new String[] { "/" + controllerName }; } } // Controller??Context?? // Context??? Object controller = context.getBean(beanName); module.addController(// controllerPaths, clazz, controllerName, controller); if (Proxy.isProxyClass(controller.getClass())) { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': add controller " + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName()); } } else { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() // + "': add controller " + Arrays.toString(controllerPaths) + "= " + controller.getClass().getName()); } } return true; }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module) throws IllegalAccessException { AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory() .getBeanDefinition(beanName); String beanClassName = beanDefinition.getBeanClassName(); String controllerSuffix = null; for (String suffix : BlitzConstants.CONTROLLER_SUFFIXES) { if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) { if (suffix.length() == 1 && Character .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) { continue; }//from w w w. j a v a 2 s .co m controllerSuffix = suffix; break; } } if (controllerSuffix == null) { if (beanDefinition.hasBeanClass()) { Class<?> beanClass = beanDefinition.getBeanClass(); if (beanClass.isAnnotationPresent(Path.class)) { throw new IllegalArgumentException( "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, " + "is it a Resource/Controller? wrong spelling? : " + beanClassName); } } // ?l?r?uer?or??? if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor") || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) { // ?throw??? logger.error("", new IllegalArgumentException( "invalid class name end wrong spelling? : " + beanClassName)); } return false; } String[] controllerPaths = null; if (!beanDefinition.hasBeanClass()) { try { beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e); } } final Class<?> clazz = beanDefinition.getBeanClass(); final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz), controllerSuffix); Path reqMappingAnnotation = clazz.getAnnotation(Path.class); if (reqMappingAnnotation != null) { controllerPaths = reqMappingAnnotation.value(); } if (controllerPaths != null) { // controllerPaths.length==0path?controller for (int i = 0; i < controllerPaths.length; i++) { if ("#".equals(controllerPaths[i])) { controllerPaths[i] = "/" + controllerName; } else if (controllerPaths[i].equals("/")) { controllerPaths[i] = ""; } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') { controllerPaths[i] = "/" + controllerPaths[i]; } if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) { if (controllerPaths[i].endsWith("//")) { throw new IllegalArgumentException("invalid path '" + controllerPaths[i] + "' for controller " + beanClassName + ": don't end with more than one '/'"); } controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1); } } } else { // TODO: ?0.91.0?201007?? if (controllerName.equals("index") || controllerName.equals("home") || controllerName.equals("welcome")) { // ??IndexController/HomeController/WelcomeController@Path("") throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName()); } else { controllerPaths = new String[] { "/" + controllerName }; } } // Controller??Context?? // Context??? Object controller = context.getBean(beanName); module.addController(// controllerPaths, clazz, controllerName, controller); if (Proxy.isProxyClass(controller.getClass())) { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': add controller " + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName()); } } else { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() // + "': add controller " + Arrays.toString(controllerPaths) + "= " + controller.getClass().getName()); } } return true; }
From source file:com.sinosoft.one.mvc.web.impl.module.ModulesBuilderImpl.java
private boolean checkController(final XmlWebApplicationContext context, String beanName, ModuleImpl module) throws IllegalAccessException { AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) context.getBeanFactory() .getBeanDefinition(beanName); String beanClassName = beanDefinition.getBeanClassName(); String controllerSuffix = null; for (String suffix : MvcConstants.CONTROLLER_SUFFIXES) { if (beanClassName.length() > suffix.length() && beanClassName.endsWith(suffix)) { if (suffix.length() == 1 && Character .isUpperCase(beanClassName.charAt(beanClassName.length() - suffix.length() - 1))) { continue; }/*from w w w.j a va 2 s.co m*/ controllerSuffix = suffix; break; } } if (controllerSuffix == null) { if (beanDefinition.hasBeanClass()) { Class<?> beanClass = beanDefinition.getBeanClass(); if (beanClass.isAnnotationPresent(Path.class)) { throw new IllegalArgumentException( "@" + Path.class.getSimpleName() + " is only allowed in Resource/Controller, " + "is it a Resource/Controller? wrong spelling? : " + beanClassName); } } // ?l?r?uer?or??? if (beanClassName.endsWith("Controler") || beanClassName.endsWith("Controllor") || beanClassName.endsWith("Resouce") || beanClassName.endsWith("Resorce")) { // ?throw??? logger.error("", new IllegalArgumentException( "invalid class name end wrong spelling? : " + beanClassName)); } return false; } String[] controllerPaths = null; if (!beanDefinition.hasBeanClass()) { try { beanDefinition.resolveBeanClass(Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new CannotLoadBeanClassException("", beanName, beanDefinition.getBeanClassName(), e); } } final Class<?> clazz = beanDefinition.getBeanClass(); final String controllerName = StringUtils.removeEnd(ClassUtils.getShortNameAsProperty(clazz), controllerSuffix); Path reqMappingAnnotation = clazz.getAnnotation(Path.class); if (reqMappingAnnotation != null) { controllerPaths = reqMappingAnnotation.value(); } if (controllerPaths != null) { // controllerPaths.length==0path?controller for (int i = 0; i < controllerPaths.length; i++) { if ("#".equals(controllerPaths[i])) { controllerPaths[i] = "/" + controllerName; } else if (controllerPaths[i].equals("/")) { controllerPaths[i] = ""; } else if (controllerPaths[i].length() > 0 && controllerPaths[i].charAt(0) != '/') { controllerPaths[i] = "/" + controllerPaths[i]; } if (controllerPaths[i].length() > 1 && controllerPaths[i].endsWith("/")) { if (controllerPaths[i].endsWith("//")) { throw new IllegalArgumentException("invalid path '" + controllerPaths[i] + "' for controller " + beanClassName + ": don't end with more than one '/'"); } controllerPaths[i] = controllerPaths[i].substring(0, controllerPaths[i].length() - 1); } } } else { // TODO: ?0.91.0?201007?? if (controllerName.equals("index") || controllerName.equals("home") || controllerName.equals("welcome")) { // ??IndexController/HomeController/WelcomeController@Path("") throw new IllegalArgumentException("please add @Path(\"\") to " + clazz.getName()); } else { controllerPaths = new String[] { "/" + controllerName }; } } // Controller??Context?? // Context??? Object controller = context.getBean(beanName); module.addController(// controllerPaths, clazz, controllerName, controller); if (Proxy.isProxyClass(controller.getClass())) { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() + "': add controller " + Arrays.toString(controllerPaths) + "= proxy of " + clazz.getName()); } } else { if (logger.isDebugEnabled()) { logger.debug("module '" + module.getMappingPath() // + "': add controller " + Arrays.toString(controllerPaths) + "= " + controller.getClass().getName()); } } return true; }
From source file:uk.org.ponder.rsac.support.BeanDefUtil.java
static RSACBeanInfo convertBeanDef(BeanDefinition origdef, String beanname, ConfigurableListableBeanFactory factory, MethodAnalyser abdAnalyser, BeanDefConverter converter) { RSACBeanInfo rbi = new RSACBeanInfo(); AbstractBeanDefinition def = getMergedBeanDefinition(factory, beanname, origdef); MutablePropertyValues pvs = def.getPropertyValues(); PropertyValue[] values = pvs.getPropertyValues(); for (int j = 0; j < values.length; ++j) { PropertyValue thispv = values[j]; Object beannames = BeanDefUtil.propertyValueToBeanName(thispv.getValue(), converter); boolean skip = false; // skip recording the dependency if it was unresolvable (some // unrecognised // type) or was a single-valued type referring to a static dependency. // NB - we now record ALL dependencies - bean-copying strategy // discontinued. if (beannames == null // || beannames instanceof String // && !blankcontext.containsBean((String) beannames) ) {/*from www . j ava 2s. c om*/ skip = true; } if (!skip) { rbi.recordDependency(thispv.getName(), beannames); } } // NB - illegal cast here is unavoidable. // Bit of a problem here with Spring flow - apparently the bean class // will NOT be set for a "factory-method" bean UNTIL it has been // instantiated // via the logic in AbstractAutowireCapableBeanFactory l.376: // protected BeanWrapper instantiateUsingFactoryMethod( AbstractBeanDefinition abd = def; rbi.factorybean = abd.getFactoryBeanName(); rbi.factorymethod = abd.getFactoryMethodName(); rbi.initmethod = abd.getInitMethodName(); rbi.destroymethod = abd.getDestroyMethodName(); rbi.islazyinit = abd.isLazyInit(); rbi.dependson = abd.getDependsOn(); rbi.issingleton = abd.isSingleton(); rbi.isabstract = abd.isAbstract(); rbi.aliases = factory.containsBeanDefinition(beanname) ? factory.getAliases(beanname) : StringArrayParser.EMPTY_STRINGL; if (abd.hasConstructorArgumentValues()) { ConstructorArgumentValues cav = abd.getConstructorArgumentValues(); boolean hasgeneric = !cav.getGenericArgumentValues().isEmpty(); boolean hasindexed = !cav.getIndexedArgumentValues().isEmpty(); if (hasgeneric && hasindexed) { throw new UnsupportedOperationException("RSAC Bean " + beanname + " has both indexed and generic constructor arguments, which is not supported"); } if (hasgeneric) { List cvalues = cav.getGenericArgumentValues(); rbi.constructorargvals = new ConstructorArgumentValues.ValueHolder[cvalues.size()]; for (int i = 0; i < cvalues.size(); ++i) { rbi.constructorargvals[i] = (ConstructorArgumentValues.ValueHolder) cvalues.get(i); } } else if (hasindexed) { Map cvalues = cav.getIndexedArgumentValues(); rbi.constructorargvals = new ConstructorArgumentValues.ValueHolder[cvalues.size()]; for (int i = 0; i < cvalues.size(); ++i) { rbi.constructorargvals[i] = (ConstructorArgumentValues.ValueHolder) cvalues.get(new Integer(i)); } } } if (rbi.factorymethod == null) { // Core Spring change at 2.0M5 - ALL bean classes are now irrevocably // lazy!! // Package org.springframework.beans // introduced lazy loading (and lazy validation) of bean classes in // standard bean factories and bean definition readers AccessMethod bcnaccess = abdAnalyser.getAccessMethod("beanClassName"); if (bcnaccess != null) { String bcn = (String) bcnaccess.getChildObject(abd); if (bcn != null) { rbi.beanclass = ClassGetter.forName(bcn); if (rbi.beanclass == null) { throw new IllegalArgumentException("Class name " + bcn + " for bean definition with name " + beanname + " cannot be resolved"); } } } else { // all right then BE like that! We'll work out the class later. // NB - beandef.getBeanClass() was eliminated around 1.2, we must // use the downcast even earlier now. rbi.beanclass = abd.getBeanClass(); } } return rbi; }