protected boolean isAspectJWeavingEnabled(String value, ParserContext parserContext) { if ("on".equals(value)) { return true; } else if ("off".equals(value)) { return false; } else { // Determine default... ClassLoader cl = parserContext.getReaderContext().getBeanClassLoader(); return (cl != null && cl.getResource(AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE) != null); } }
/** * Create a bean definition for the given class name and parent name. * @param className the name of the bean class * @param parentName the name of the bean's parent bean * @return the newly created bean definition * @throws ClassNotFoundException if bean class resolution was attempted but failed */ protected AbstractBeanDefinition createBeanDefinition(@Nullable String className, @Nullable String parentName) throws ClassNotFoundException { return BeanDefinitionReaderUtils.createBeanDefinition( parentName, className, this.readerContext.getBeanClassLoader()); }
protected boolean isAspectJWeavingEnabled(String value, ParserContext parserContext) { if ("on".equals(value)) { return true; } else if ("off".equals(value)) { return false; } else { // Determine default... ClassLoader cl = parserContext.getReaderContext().getBeanClassLoader(); return (cl != null && cl.getResource(AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE) != null); } }
/** * Create a bean definition for the given class name and parent name. * @param className the name of the bean class * @param parentName the name of the bean's parent bean * @return the newly created bean definition * @throws ClassNotFoundException if bean class resolution was attempted but failed */ protected AbstractBeanDefinition createBeanDefinition(@Nullable String className, @Nullable String parentName) throws ClassNotFoundException { return BeanDefinitionReaderUtils.createBeanDefinition( parentName, className, this.readerContext.getBeanClassLoader()); }
/** * Build a typed String value Object for the given raw value. * @see org.springframework.beans.factory.config.TypedStringValue */ protected TypedStringValue buildTypedStringValue(String value, @Nullable String targetTypeName) throws ClassNotFoundException { ClassLoader classLoader = this.readerContext.getBeanClassLoader(); TypedStringValue typedValue; if (!StringUtils.hasText(targetTypeName)) { typedValue = new TypedStringValue(value); } else if (classLoader != null) { Class<?> targetType = ClassUtils.forName(targetTypeName, classLoader); typedValue = new TypedStringValue(value, targetType); } else { typedValue = new TypedStringValue(value, targetTypeName); } return typedValue; }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) { if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) { RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME); parserContext.registerBeanComponent( new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME)); } if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) { new SpringConfiguredBeanDefinitionParser().parse(element, parserContext); } } }
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) { ManagedList<Object> result = new ManagedList<>(); for (Object object : list) { if (object instanceof BeanDefinitionHolder) { BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object; String className = beanDef.getBeanDefinition().getBeanClassName(); Assert.notNull(className, "No resolver class"); Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader()); if (WebArgumentResolver.class.isAssignableFrom(clazz)) { RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class); adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef); result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter")); continue; } } result.add(object); } return result; }
/** * Build a typed String value Object for the given raw value. * @see org.springframework.beans.factory.config.TypedStringValue */ protected TypedStringValue buildTypedStringValue(String value, @Nullable String targetTypeName) throws ClassNotFoundException { ClassLoader classLoader = this.readerContext.getBeanClassLoader(); TypedStringValue typedValue; if (!StringUtils.hasText(targetTypeName)) { typedValue = new TypedStringValue(value); } else if (classLoader != null) { Class<?> targetType = ClassUtils.forName(targetTypeName, classLoader); typedValue = new TypedStringValue(value, targetType); } else { typedValue = new TypedStringValue(value, targetTypeName); } return typedValue; }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) { if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) { RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME); parserContext.registerBeanComponent( new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME)); } if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) { new SpringConfiguredBeanDefinitionParser().parse(element, parserContext); } } }
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) { ManagedList<Object> result = new ManagedList<>(); for (Object object : list) { if (object instanceof BeanDefinitionHolder) { BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object; String className = beanDef.getBeanDefinition().getBeanClassName(); Assert.notNull(className, "No resolver class"); Class<?> clazz = ClassUtils.resolveClassName(className, context.getReaderContext().getBeanClassLoader()); if (WebArgumentResolver.class.isAssignableFrom(clazz)) { RootBeanDefinition adapter = new RootBeanDefinition(ServletWebArgumentResolverAdapter.class); adapter.getConstructorArgumentValues().addIndexedArgumentValue(0, beanDef); result.add(new BeanDefinitionHolder(adapter, beanDef.getBeanName() + "Adapter")); continue; } } result.add(object); } return result; }
/** * Create a bean definition for the given class name and parent name. * @param className the name of the bean class * @param parentName the name of the bean's parent bean * @return the newly created bean definition * @throws ClassNotFoundException if bean class resolution was attempted but failed */ protected AbstractBeanDefinition createBeanDefinition(String className, String parentName) throws ClassNotFoundException { return BeanDefinitionReaderUtils.createBeanDefinition( parentName, className, this.readerContext.getBeanClassLoader()); }
/** * @param storedProcComponent The element. * @param parserContext The parser context. * @return The list of bean metadata objects. */ public static ManagedMap<String, BeanMetadataElement> getReturningResultsetBeanDefinitions( Element storedProcComponent, ParserContext parserContext) { List<Element> returningResultsetChildElements = DomUtils.getChildElementsByTagName(storedProcComponent, "returning-resultset"); ManagedMap<String, BeanMetadataElement> returningResultsetMap = new ManagedMap<String, BeanMetadataElement>(); for (Element childElement : returningResultsetChildElements) { String name = childElement.getAttribute("name"); String rowMapperAsString = childElement.getAttribute("row-mapper"); BeanMetadataElement rowMapperBeanDefinition = null; try { // Backward compatibility ClassUtils.forName(rowMapperAsString, parserContext.getReaderContext().getBeanClassLoader()); rowMapperBeanDefinition = BeanDefinitionBuilder.genericBeanDefinition(rowMapperAsString).getBeanDefinition(); } catch (ClassNotFoundException e) { //Ignore it and fallback to bean reference rowMapperBeanDefinition = new RuntimeBeanReference(rowMapperAsString); } returningResultsetMap.put(name, rowMapperBeanDefinition); } return returningResultsetMap; }
/** * Build a typed String value Object for the given raw value. * @see org.springframework.beans.factory.config.TypedStringValue */ protected TypedStringValue buildTypedStringValue(String value, String targetTypeName) throws ClassNotFoundException { ClassLoader classLoader = this.readerContext.getBeanClassLoader(); TypedStringValue typedValue; if (!StringUtils.hasText(targetTypeName)) { typedValue = new TypedStringValue(value); } else if (classLoader != null) { Class<?> targetType = ClassUtils.forName(targetTypeName, classLoader); typedValue = new TypedStringValue(value, targetType); } else { typedValue = new TypedStringValue(value, targetTypeName); } return typedValue; }
protected boolean isAspectJWeavingEnabled(String value, ParserContext parserContext) { if ("on".equals(value)) { return true; } else if ("off".equals(value)) { return false; } else { // Determine default... ClassLoader cl = parserContext.getReaderContext().getBeanClassLoader(); return (cl != null && cl.getResource(AspectJWeavingEnabler.ASPECTJ_AOP_XML_RESOURCE) != null); } }
private String detectJBossActivationSpecClass(ParserContext parserContext) { ClassLoader classLoader = parserContext.getReaderContext().getBeanClassLoader(); if (classLoader == null) { classLoader = ClassUtils.getDefaultClassLoader(); } for (String activationSpecClassNameCandidate : ACTIVATION_SPEC_CLASSNAME_CANDIDATES) { try { classLoader.loadClass(activationSpecClassNameCandidate); return activationSpecClassNameCandidate; } catch (ClassNotFoundException e) { // ignore } } throw new BeanCreationException("Cannot find a suitable ActivationSpec class on the classpath"); } }
public BeanDefinition process(Element element, ParserContext parserContext, SpringBuildContext springBuildContext) throws ClassNotFoundException { String service = element.getAttribute("service"); Class serviceClass = parserContext.getReaderContext().getBeanClassLoader().loadClass(service); String beanName = element.getAttribute("ref"); String name = element.getAttribute("name"); if (name.equals("")) { name = beanName; } springBuildContext.exportJavaService(name, serviceClass, beanName); return null; } };
private static ManagedList<BeanDefinition> createDefaultCacheFactories(Element element, ParserContext parserContext) { ManagedList<BeanDefinition> result = new ManagedList<>(); result.setSource(parserContext.extractSource(element)); if (ClassUtils.isPresent("net.spy.memcached.MemcachedClient", parserContext.getReaderContext().getBeanClassLoader())) { result.add(getCacheFactory(MEMCACHED_FACTORY_CLASS_NAME, element)); } if (ClassUtils.isPresent("org.springframework.data.redis.connection.RedisConnectionFactory", parserContext.getReaderContext().getBeanClassLoader())) { result.add(getCacheFactory(REDIS_CONNECTION_FACTORY_CLASS_NAME, element)); } return result; }
private static ManagedList<BeanDefinition> createDefaultCacheFactories(Element element, ParserContext parserContext) { ManagedList<BeanDefinition> result = new ManagedList<>(); result.setSource(parserContext.extractSource(element)); if (ClassUtils.isPresent("net.spy.memcached.MemcachedClient", parserContext.getReaderContext().getBeanClassLoader())) { result.add(getCacheFactory(MEMCACHED_FACTORY_CLASS_NAME, element)); } if (ClassUtils.isPresent("org.springframework.data.redis.connection.RedisConnectionFactory", parserContext.getReaderContext().getBeanClassLoader())) { result.add(getCacheFactory(REDIS_CONNECTION_FACTORY_CLASS_NAME, element)); } return result; }
@Override protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); if (isAspectJWeavingEnabled(element.getAttribute(ASPECTJ_WEAVING_ATTRIBUTE), parserContext)) { if (!parserContext.getRegistry().containsBeanDefinition(ASPECTJ_WEAVING_ENABLER_BEAN_NAME)) { RootBeanDefinition def = new RootBeanDefinition(ASPECTJ_WEAVING_ENABLER_CLASS_NAME); parserContext.registerBeanComponent( new BeanComponentDefinition(def, ASPECTJ_WEAVING_ENABLER_BEAN_NAME)); } if (isBeanConfigurerAspectEnabled(parserContext.getReaderContext().getBeanClassLoader())) { new SpringConfiguredBeanDefinitionParser().parse(element, parserContext); } } }
private Class<?> lookupConfigClass(Element element, ParserContext parserContext) { Class<?> configClass = GrailsAnnotationConfiguration.class; final ClassLoader classLoader = parserContext.getReaderContext().getBeanClassLoader(); final String configClassName = element.getAttribute(CONFIG_CLASS_ATTRIBUTE); if (StringUtils.hasText(configClassName)) { try { configClass = classLoader.loadClass(configClassName); } catch (ClassNotFoundException e) { throw new BeanDefinitionParsingException(new Problem( "Unable to load specified SessionFactory configClass implementation: " + e.getMessage(), new Location(parserContext.getReaderContext().getResource()),null, e)); } } return configClass; }