List of usage examples for org.springframework.beans.factory.config RuntimeBeanReference RuntimeBeanReference
public RuntimeBeanReference(Class<?> beanType)
From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java
/** * Setup the default cache key generator. * /*from w w w .j av a 2 s .c o m*/ * @return A reference to the default cache key generator. Should never be null. */ protected RuntimeBeanReference setupDefaultCacheKeyGenerators(Element element, ParserContext parserContext, Object elementSource) { //Register all of the default cache key generator types this.setupDefaultCacheKeyGenerator(ListCacheKeyGenerator.class, parserContext, elementSource); this.setupDefaultCacheKeyGenerator(HashCodeCacheKeyGenerator.class, parserContext, elementSource); this.setupDefaultCacheKeyGenerator(MessageDigestCacheKeyGenerator.class, parserContext, elementSource); this.setupDefaultCacheKeyGenerator(ReflectionHashCodeCacheKeyGenerator.class, parserContext, elementSource); this.setupDefaultCacheKeyGenerator(StringCacheKeyGenerator.class, parserContext, elementSource); //If the default cache key generator was specified simply return a bean reference for that final String defaultCacheKeyGeneratorName = element.getAttribute(XSD_ATTR__DEFAULT_CACHE_KEY_GENERATOR); if (StringUtils.hasLength(defaultCacheKeyGeneratorName)) { return new RuntimeBeanReference(defaultCacheKeyGeneratorName); } //Use the default name for the bean reference return new RuntimeBeanReference(DEFAULT_CACHE_KEY_GENERATOR); }
From source file:eap.config.ConfigBeanDefinitionParser.java
private void parseAspect(Element aspectElement, ParserContext parserContext) { String aspectId = aspectElement.getAttribute(ID); String aspectName = aspectElement.getAttribute(REF); try {// w w w. j a va 2 s .c o m this.parseState.push(new AspectEntry(aspectId, aspectName)); List<BeanDefinition> beanDefinitions = new ArrayList<BeanDefinition>(); List<BeanReference> beanReferences = new ArrayList<BeanReference>(); List<Element> declareParents = DomUtils.getChildElementsByTagName(aspectElement, DECLARE_PARENTS); for (int i = METHOD_INDEX; i < declareParents.size(); i++) { Element declareParentsElement = declareParents.get(i); beanDefinitions.add(parseDeclareParents(declareParentsElement, parserContext)); } // We have to parse "advice" and all the advice kinds in one loop, to get the // ordering semantics right. NodeList nodeList = aspectElement.getChildNodes(); boolean adviceFoundAlready = false; for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (isAdviceNode(node, parserContext)) { if (!adviceFoundAlready) { adviceFoundAlready = true; if (!StringUtils.hasText(aspectName)) { parserContext.getReaderContext().error( "<aspect> tag needs aspect bean reference via 'ref' attribute when declaring advices.", aspectElement, this.parseState.snapshot()); return; } beanReferences.add(new RuntimeBeanReference(aspectName)); } AbstractBeanDefinition advisorDefinition = parseAdvice(aspectName, i, aspectElement, (Element) node, parserContext, beanDefinitions, beanReferences); beanDefinitions.add(advisorDefinition); } } AspectComponentDefinition aspectComponentDefinition = createAspectComponentDefinition(aspectElement, aspectId, beanDefinitions, beanReferences, parserContext); parserContext.pushContainingComponent(aspectComponentDefinition); List<Element> pointcuts = DomUtils.getChildElementsByTagName(aspectElement, POINTCUT); for (Element pointcutElement : pointcuts) { parsePointcut(pointcutElement, parserContext); } parserContext.popAndRegisterContainingComponent(); } finally { this.parseState.pop(); } }
From source file:org.solmix.runtime.support.spring.AbstractBeanDefinitionParser.java
/***/ protected void parseMultiRef(String property, String value, BeanDefinitionBuilder bean, ParserContext parserContext) {//from w ww.j ava 2 s.c o m String[] values = value.split("\\s*[,]+\\s*"); ManagedList<Object> list = null; for (int i = 0; i < values.length; i++) { String v = values[i]; if (v != null && v.length() > 0) { if (list == null) { list = new ManagedList<Object>(); } list.add(new RuntimeBeanReference(v)); } } bean.getBeanDefinition().getPropertyValues().addPropertyValue(property, list); }
From source file:com.inspiresoftware.lib.dto.geda.config.AnnotationDrivenGeDABeanDefinitionParser.java
protected RuntimeBeanReference setupPointcut(final ParserContext parserContext, final Object elementSource, final RuntimeBeanReference resolver, final String[] pointcutMatchRegex, final String[] pointcutNoMatchRegex) { final RootBeanDefinition pointcut; if (pointcutMatchRegex.length == 0 && pointcutNoMatchRegex.length == 0) { pointcut = new RootBeanDefinition(GeDAMethodMatcherPointcut.class); final ConstructorArgumentValues constructorArgs = pointcut.getConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(resolver); } else {/*from w w w . j a v a2 s . c o m*/ pointcut = new RootBeanDefinition(GeDAMethodRegExMatcherPointcut.class); final ConstructorArgumentValues constructorArgs = pointcut.getConstructorArgumentValues(); constructorArgs.addGenericArgumentValue(resolver); final MutablePropertyValues propertyValues = pointcut.getPropertyValues(); if (pointcutMatchRegex.length > 0) { propertyValues.addPropertyValue("patterns", pointcutMatchRegex); } if (pointcutNoMatchRegex.length > 0) { propertyValues.addPropertyValue("excludedPatterns", pointcutNoMatchRegex); } } pointcut.setSource(elementSource); pointcut.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final XmlReaderContext readerContext = parserContext.getReaderContext(); final String pointcutBeanName = readerContext.registerWithGeneratedName(pointcut); return new RuntimeBeanReference(pointcutBeanName); }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private RootBeanDefinition createLogger(Element element, Object source) { String userData = element.getAttribute("userData"); if (userData == null || userData.length() < 1) { userData = "userData";// default userData bean id }/*from ww w.j a v a 2s . com*/ RootBeanDefinition bean = new RootBeanDefinition(Logger.class); bean.setSource(source); bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); bean.getPropertyValues().addPropertyValue("userData", new RuntimeBeanReference(userData)); return bean; }
From source file:org.springmodules.cache.config.CacheSetupStrategyParserTests.java
private RuntimeBeanReference expectCacheKeyGeneratorParsing() { CacheKeyGeneratorElementBuilder builder = new CacheKeyGeneratorElementBuilder(); elementBuilder.cacheKeyGeneratorElementBuilder = builder; RuntimeBeanReference cacheKeyGenerator = new RuntimeBeanReference("cacheKeyGenerator"); beanReferenceParser.parse(builder.toXml(), parserContext); beanReferenceParserControl.setReturnValue(cacheKeyGenerator); return cacheKeyGenerator; }
From source file:org.atomserver.utils.test.TestingAtomServer.java
private Server createServer(int port, String atomserverServletContext) { // set up the server and the atomserver web application context Server server = new Server(port); Context context = new Context(server, "/" + atomserverServletContext, true /*sessions*/, false /*no security*/); // we need to hard-code certain system properties to get the behavior we want here - we // will re-set them when we're done Properties properties = (Properties) System.getProperties().clone(); System.setProperty("atomserver.env", "asdev-hsql-mem"); System.setProperty("atomserver.servlet.context", atomserverServletContext); // TODO: this should be removed System.setProperty("atomserver.servlet.mapping", "v1"); // our Spring application context will start off by loading the basic built-in bean // definitions appContext = new GenericWebApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext); xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/propertyConfigurerBeans.xml")); xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/databaseBeans.xml")); xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/logBeans.xml")); xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/storageBeans.xml")); xmlReader.loadBeanDefinitions(new ClassPathResource("org/atomserver/spring/abderaBeans.xml")); // if we were given a Spring config location, we use that -- otherwise we configure the // workspaces that were set up through the API if (springBeansLocation != null) { xmlReader.loadBeanDefinitions(new ClassPathResource(springBeansLocation)); } else {/*from w w w. j a v a 2 s. c o m*/ RootBeanDefinition workspaces = new RootBeanDefinition(HashSet.class); ConstructorArgumentValues constructorArgumentValues = new ConstructorArgumentValues(); constructorArgumentValues.addGenericArgumentValue(workspaceSet); workspaces.setConstructorArgumentValues(constructorArgumentValues); appContext.registerBeanDefinition("org.atomserver-workspaces", workspaces); } // override the base content storage to use DB-based storage RootBeanDefinition storage = new RootBeanDefinition(DBBasedContentStorage.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("contentDAO", new RuntimeBeanReference("org.atomserver-contentDAO")); propertyValues.addPropertyValue("entriesDAO", new RuntimeBeanReference("org.atomserver-entriesDAO")); storage.setPropertyValues(propertyValues); appContext.registerBeanDefinition("org.atomserver-contentStorage", storage); // clear the existing ENV ConfigurationAwareClassLoader.invalidateENV(); // refresh the context to actually instantiate everything. appContext.refresh(); // re-set the system properties System.setProperties(properties); // clear the update ENV ConfigurationAwareClassLoader.invalidateENV(); // put our app context into the servlet context context.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appContext); // load and init the service context for v1 final ServiceContext serviceContext = (ServiceContext) appContext.getBean(ServiceContext.class.getName()); serviceContext.init(new Abdera(), Collections.EMPTY_MAP); // create a new AtomServerServlet - but override the createServiceContext method AtomServerServlet servlet = new AtomServerServlet() { protected ServiceContext createServiceContext() { return serviceContext; } }; // load and init the service context for v2 final ServiceContext serviceContextV2 = (ServiceContext) appContext .getBean("org.atomserver-serviceContext.v2"); serviceContextV2.init(new Abdera(), Collections.EMPTY_MAP); // create a new AtomServerServlet - but override the createServiceContext method AtomServerServlet servletV2 = new AtomServerServlet() { protected ServiceContext createServiceContext() { return serviceContextV2; } }; // register the servlets context.addServlet(new ServletHolder(servlet), "/v1/*"); context.addServlet(new ServletHolder(servletV2), "/v2/*"); EntriesDAOiBatisImpl entriesDAO = (EntriesDAOiBatisImpl) appContext.getBean("org.atomserver-entriesDAO"); entriesDAO.setUseWorkspaceCollectionCache(false); // ready to be started return server; }
From source file:de.acosix.alfresco.utility.common.spring.PropertyAlteringBeanFactoryPostProcessor.java
protected Object handleListValues(final PropertyValue configuredValue) { final Object value; LOGGER.debug(/*from w ww . jav a2 s .c om*/ "[{}] List of values / bean reference names has been configured - treating property {} of {} as <list>", this.beanName, this.propertyName, this.targetBeanName); final ManagedList<Object> list = new ManagedList<>(); if (this.merge && configuredValue != null) { final Object configuredValueDefinition = configuredValue.getValue(); if (configuredValueDefinition instanceof ManagedList<?>) { final ManagedList<?> oldList = (ManagedList<?>) configuredValueDefinition; list.setElementTypeName(oldList.getElementTypeName()); list.setMergeEnabled(oldList.isMergeEnabled()); list.setSource(oldList.getSource()); list.addAll(oldList); LOGGER.debug("[{}] Merged existing value list values: {}", this.beanName, oldList); } } List<Object> valuesToAdd; if (this.valueList != null) { LOGGER.debug("[{}] List of configured values for {} of {}: ", this.beanName, this.propertyName, this.targetBeanName, this.valueList); valuesToAdd = this.valueList; } else { LOGGER.debug("[{}] List of configured bean reference names for {} of {}: ", this.beanName, this.propertyName, this.targetBeanName, this.beanReferenceNameList); valuesToAdd = new ArrayList<>(); for (final String beanReferenceName : this.beanReferenceNameList) { valuesToAdd.add(new RuntimeBeanReference(beanReferenceName)); } } if (this.addAsFirst) { LOGGER.debug("[{}] Adding new entries at start of list for {} of {}", this.beanName, this.propertyName, this.targetBeanName); list.addAll(0, valuesToAdd); } else if (this.addAtIndex >= 0 && this.addAtIndex < list.size()) { LOGGER.debug("[{}] Adding new entries at position {} of list for {} of {}", this.beanName, String.valueOf(this.addAtIndex), this.propertyName, this.targetBeanName); list.addAll(this.addAtIndex, valuesToAdd); } else { LOGGER.debug("[{}] Adding new entries at end of list for {} of {}", this.beanName, this.propertyName, this.targetBeanName); list.addAll(valuesToAdd); } if (!list.isMergeEnabled() && this.mergeParent) { LOGGER.debug("[{}] Enabling \"merge\" for <list> on {} of {}", this.beanName, this.propertyName, this.targetBeanName); } list.setMergeEnabled(list.isMergeEnabled() || this.mergeParent); value = list; return value; }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private RootBeanDefinition createValidatorErrorHandler(Element element, Object source) { String userData = element.getAttribute("userData"); if (userData == null || userData.length() < 1) { userData = "userData";// default userData bean id }/*from w ww. j a v a 2s . co m*/ RootBeanDefinition bean = new RootBeanDefinition(DefaultValidatorErrorHandler.class); bean.setSource(source); bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); bean.getPropertyValues().addPropertyValue("userData", new RuntimeBeanReference(userData)); bean.getPropertyValues().addPropertyValue("config", new RuntimeBeanReference("config")); return bean; }
From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java
/** * Utility API used to setup each of the default {@link CacheKeyGenerator} implementations. Requires * that the class has a static String field named DEFAULT_BEAN_NAME declared that is used for the bean * name. // www. j av a2 s .c o m */ protected final void setupDefaultCacheKeyGenerator( Class<? extends CacheKeyGenerator<? extends Serializable>> generatorClass, ParserContext parserContext, Object elementSource) { final String generatorName; try { final Field field = generatorClass.getField("DEFAULT_BEAN_NAME"); generatorName = (String) field.get(null); } catch (Exception e) { throw new IllegalArgumentException("Could not access static field 'DEFAULT_BEAN_NAME' on " + generatorClass + ". This field is required to be setup as a default CacheKeyGenerator", e); } final RootBeanDefinition defaultKeyGenerator = new RootBeanDefinition(generatorClass); defaultKeyGenerator.setSource(elementSource); defaultKeyGenerator.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); if (ReflectionHelperAware.class.isAssignableFrom(generatorClass)) { final RuntimeBeanReference cacheManagerReference = new RuntimeBeanReference( CACHING_REFLECTION_HELPER_BEAN_NAME); final MutablePropertyValues propertyValues = defaultKeyGenerator.getPropertyValues(); propertyValues.addPropertyValue("reflectionHelper", cacheManagerReference); } final BeanDefinitionRegistry registry = parserContext.getRegistry(); registry.registerBeanDefinition(generatorName, defaultKeyGenerator); }