List of usage examples for org.springframework.beans.factory.support RootBeanDefinition getPropertyValues
@Override
public MutablePropertyValues getPropertyValues()
From source file:eap.config.ConfigBeanDefinitionParser.java
/** * Creates a {@link BeanDefinition} for the {@link AspectJExpressionPointcut} class using * the supplied pointcut expression.//from w w w . j a va 2s . c o m */ protected AbstractBeanDefinition createPointcutDefinition(String expression) { RootBeanDefinition beanDefinition = new RootBeanDefinition(AspectJExpressionPointcut.class); beanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE); beanDefinition.setSynthetic(true); beanDefinition.getPropertyValues().add(EXPRESSION, expression); return beanDefinition; }
From source file:eap.config.ConfigBeanDefinitionParser.java
/** * Creates the RootBeanDefinition for a POJO advice bean. Also causes pointcut * parsing to occur so that the pointcut may be associate with the advice bean. * This same pointcut is also configured as the pointcut for the enclosing * Advisor definition using the supplied MutablePropertyValues. *///from ww w. j a v a 2s . com private AbstractBeanDefinition createAdviceDefinition(Element adviceElement, ParserContext parserContext, String aspectName, int order, RootBeanDefinition methodDef, RootBeanDefinition aspectFactoryDef, List<BeanDefinition> beanDefinitions, List<BeanReference> beanReferences) { RootBeanDefinition adviceDefinition = new RootBeanDefinition(getAdviceClass(adviceElement, parserContext)); adviceDefinition.setSource(parserContext.extractSource(adviceElement)); adviceDefinition.getPropertyValues().add(ASPECT_NAME_PROPERTY, aspectName); adviceDefinition.getPropertyValues().add(DECLARATION_ORDER_PROPERTY, order); if (adviceElement.hasAttribute(RETURNING)) { adviceDefinition.getPropertyValues().add(RETURNING_PROPERTY, adviceElement.getAttribute(RETURNING)); } if (adviceElement.hasAttribute(THROWING)) { adviceDefinition.getPropertyValues().add(THROWING_PROPERTY, adviceElement.getAttribute(THROWING)); } if (adviceElement.hasAttribute(ARG_NAMES)) { adviceDefinition.getPropertyValues().add(ARG_NAMES_PROPERTY, adviceElement.getAttribute(ARG_NAMES)); } ConstructorArgumentValues cav = adviceDefinition.getConstructorArgumentValues(); cav.addIndexedArgumentValue(METHOD_INDEX, methodDef); Object pointcut = parsePointcutProperty(adviceElement, parserContext); if (pointcut instanceof BeanDefinition) { cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcut); beanDefinitions.add((BeanDefinition) pointcut); } else if (pointcut instanceof String) { RuntimeBeanReference pointcutRef = new RuntimeBeanReference((String) pointcut); cav.addIndexedArgumentValue(POINTCUT_INDEX, pointcutRef); beanReferences.add(pointcutRef); } cav.addIndexedArgumentValue(ASPECT_INSTANCE_FACTORY_INDEX, aspectFactoryDef); return adviceDefinition; }
From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java
/** * Create a {@link CacheAttributeSource} bean that will be used by the advisor and interceptor * //from www .j a v a 2 s. c o m * @return Reference to the {@link CacheAttributeSource}. Should never be null. */ protected RuntimeBeanReference setupCacheAttributeSource(Element element, ParserContext parserContext, Object elementSource) { final RuntimeBeanReference cachingReflectionHelper = this.setupCachingReflectionHelper(parserContext, elementSource); final RuntimeBeanReference defaultCacheKeyGenerator = this.setupDefaultCacheKeyGenerators(element, parserContext, elementSource); final RuntimeBeanReference defaultCacheResolverFactory = this.setupDefaultCacheResolverFactory(element, parserContext, elementSource); final RuntimeBeanReference defaultCacheableInterceptor = this.setupDefaultCacheableInterceptor(element, parserContext, elementSource); final RuntimeBeanReference defaultTriggersRemoveInterceptor = this .setupDefaultTriggersRemoveInterceptor(element, parserContext, elementSource); final RootBeanDefinition cacheAttributeSource = new RootBeanDefinition(CacheAttributeSourceImpl.class); cacheAttributeSource.setSource(elementSource); cacheAttributeSource.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); final MutablePropertyValues propertyValues = cacheAttributeSource.getPropertyValues(); RuntimeBeanReference cacheManagerReference = new RuntimeBeanReference( element.getAttribute(XSD_ATTR__CACHE_MANAGER)); propertyValues.addPropertyValue("cacheManager", cacheManagerReference); propertyValues.addPropertyValue("createCaches", Boolean.parseBoolean(element.getAttribute(XSD_ATTR__CREATE_MISSING_CACHES))); propertyValues.addPropertyValue("defaultCacheKeyGenerator", defaultCacheKeyGenerator); propertyValues.addPropertyValue("reflectionHelper", cachingReflectionHelper); if (defaultCacheResolverFactory != null) { propertyValues.addPropertyValue("cacheResolverFactory", defaultCacheResolverFactory); } if (defaultCacheableInterceptor != null) { propertyValues.addPropertyValue("defaultCacheableInterceptor", defaultCacheableInterceptor); } if (defaultTriggersRemoveInterceptor != null) { propertyValues.addPropertyValue("defaultTriggersRemoveInterceptor", defaultTriggersRemoveInterceptor); } final String blockingCacheScope = element.getAttribute(XSD_ATTR__SELF_POPULATING_CACHE_SCOPE); if (blockingCacheScope != null) { propertyValues.addPropertyValue("selfPopulatingCacheScope", SelfPopulatingCacheScope.valueOf(blockingCacheScope.toUpperCase())); } if (element.hasAttribute(XSD_ATTR__EXECUTOR)) { RuntimeBeanReference executorReference = new RuntimeBeanReference( element.getAttribute(XSD_ATTR__EXECUTOR)); propertyValues.addPropertyValue("executor", executorReference); } if (element.hasAttribute(XSD_ATTR__SCHEDULER)) { RuntimeBeanReference schedulerReference = new RuntimeBeanReference( element.getAttribute(XSD_ATTR__SCHEDULER)); propertyValues.addPropertyValue("scheduler", schedulerReference); } final XmlReaderContext readerContext = parserContext.getReaderContext(); final String cacheAttributeSourceBeanName = readerContext.registerWithGeneratedName(cacheAttributeSource); return new RuntimeBeanReference(cacheAttributeSourceBeanName); }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private void processStartParameters(Node node, RootBeanDefinition bean) { String value = node.getTextContent(); bean.getPropertyValues().addPropertyValue("userStartParameters", this.convertToList(value)); }
From source file:com.mtgi.analytics.aop.config.v11.BtManagerBeanDefinitionParser.java
@Override protected void transform(ConfigurableListableBeanFactory factory, BeanDefinition template, Element element, ParserContext parserContext) {//from ww w .jav a 2 s . c o m ManagerComponentDefinition def = (ManagerComponentDefinition) parserContext.getContainingComponent(); String managerId = overrideAttribute(ATT_ID, template, element); if (managerId == null) template.setAttribute(ATT_ID, managerId = "defaultTrackingManager"); if ("false".equals(element.getAttribute(ATT_ENABLED))) { //manager is disabled. replace definition with dummy instance. template.setBeanClassName(DisabledBehaviorTrackingManager.class.getName()); //clear properties and attributes. for (String att : template.attributeNames()) if (!ATT_ID.equals(att)) template.removeAttribute(att); template.getPropertyValues().clear(); //terminate immediately, do not parse any nested definitions (persisters, AOP config, context beans, etc) return; } overrideProperty(ATT_APPLICATION, template, element, false); overrideProperty(ATT_FLUSH_THRESHOLD, template, element, false); //wake up MBeanExporter if we're going to be doing MBean registration. if ("true".equalsIgnoreCase(element.getAttribute(ATT_REGISTER_MBEANS))) { AbstractBeanDefinition exporter = (AbstractBeanDefinition) factory .getBeanDefinition(CONFIG_MBEAN_EXPORTER); exporter.setLazyInit(false); //append manager ID to mbean name, in case of multiple managers in a single application. BeanDefinition naming = factory.getBeanDefinition(CONFIG_NAMING_STRATEGY); naming.getPropertyValues().addPropertyValue("value", managerId); } //prefer references to beans in the parent factory if they've been specified if (element.hasAttribute(ATT_MBEAN_SERVER)) factory.registerAlias(element.getAttribute(ATT_MBEAN_SERVER), CONFIG_MBEAN_SERVER); if (element.hasAttribute(ATT_SCHEDULER)) factory.registerAlias(element.getAttribute(ATT_SCHEDULER), CONFIG_SCHEDULER); if (element.hasAttribute(ATT_TASK_EXECUTOR)) factory.registerAlias(element.getAttribute(ATT_TASK_EXECUTOR), CONFIG_EXECUTOR); //make note of external persister element so that we don't activate log rotation. if (element.hasAttribute(ATT_PERSISTER)) { def.addNestedProperty(ATT_PERSISTER); MutablePropertyValues props = template.getPropertyValues(); props.removePropertyValue(ATT_PERSISTER); props.addPropertyValue(ATT_PERSISTER, new RuntimeBeanReference(element.getAttribute(ATT_PERSISTER))); } if (element.hasAttribute(ATT_SESSION_CONTEXT)) { //override default session context with reference def.addNestedProperty("sessionContext"); factory.registerAlias(element.getAttribute(ATT_SESSION_CONTEXT), CONFIG_SESSION_CONTEXT); } //handle AOP configuration if needed if (element.hasAttribute(ATT_METHOD_EXPRESSION)) { //activate global AOP proxying if it hasn't already been done (borrowed logic from AopNamespaceHandler / config element parser) activateAopProxies(parserContext, element); //register pointcut definition for the provided expression. RootBeanDefinition pointcut = new RootBeanDefinition(AspectJExpressionPointcut.class); //rely on deprecated method to maintain spring 2.0 support pointcut.setSingleton(false); pointcut.setSynthetic(true); pointcut.getPropertyValues().addPropertyValue("expression", element.getAttribute(ATT_METHOD_EXPRESSION)); //create implicit pointcut advice bean. RootBeanDefinition advice = new RootBeanDefinition(BehaviorTrackingAdvice.class); advice.getPropertyValues().addPropertyValue("trackingManager", new RuntimeBeanReference(managerId)); //register advice, pointcut, and advisor entry to bind the two together. XmlReaderContext ctx = parserContext.getReaderContext(); String pointcutId = ctx.registerWithGeneratedName(pointcut); String adviceId = ctx.registerWithGeneratedName(advice); RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); advisorDefinition.getPropertyValues().addPropertyValue("adviceBeanName", new RuntimeBeanNameReference(adviceId)); advisorDefinition.getPropertyValues().addPropertyValue("pointcut", new RuntimeBeanReference(pointcutId)); ctx.registerWithGeneratedName(advisorDefinition); } //configure flush trigger and job to be globally unique based on manager name. BeanDefinition flushTrigger = factory.getBeanDefinition("com.mtgi.analytics.btFlushTrigger"); SchedulerActivationPostProcessor.configureTriggerDefinition(flushTrigger, element.getAttribute(ATT_FLUSH_SCHEDULE), managerId + "_flush"); //set up a post-processor to register the flush job with the selected scheduler instance. the job and scheduler //come from the template factory, but the post-processor runs when the currently-parsing factory is finished. SchedulerActivationPostProcessor.registerPostProcessor(parserContext, factory, CONFIG_SCHEDULER, CONFIG_NAMESPACE + ".btFlushTrigger"); //ManagerComponentDefinition is a flag to nested parsers that they should push their parsed bean definitions into //the manager bean definition. for example, see BtPersisterBeanDefinitionParser. //descend on nested child nodes to pick up persister and session context configuration NodeList children = element.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node node = children.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String namespaceUri = node.getNamespaceURI(); NamespaceHandler handler = parserContext.getReaderContext().getNamespaceHandlerResolver() .resolve(namespaceUri); ParserContext nestedCtx = new ParserContext(parserContext.getReaderContext(), parserContext.getDelegate(), template); nestedCtx.pushContainingComponent(def); handler.parse((Element) node, nestedCtx); } } if (!def.nestedProperties.contains(ATT_PERSISTER)) { //no persister registered. schedule default log rotation trigger. BtXmlPersisterBeanDefinitionParser.configureLogRotation(parserContext, factory, null); } if (!def.nestedProperties.contains("sessionContext")) { //custom session context not registered. select appropriate default class //depending on whether we are in a web context or not. if (parserContext.getReaderContext().getReader().getResourceLoader() instanceof WebApplicationContext) { BeanDefinition scDef = factory.getBeanDefinition(CONFIG_SESSION_CONTEXT); scDef.setBeanClassName(SpringSessionContext.class.getName()); } } }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private void processParamsWithoutValidation(Node node, RootBeanDefinition bean) { NodeList nodeList = node.getChildNodes(); Map map = new Hashtable(); bean.getPropertyValues().addPropertyValue("paramsWithoutValidation", map); for (int i = 0; i < nodeList.getLength(); i++) { Node mappingNode = nodeList.item(i); if (mappingNode.getNodeType() == Node.ELEMENT_NODE) { if (mappingNode.getLocalName().equalsIgnoreCase("mapping")) { this.processMapping(mappingNode, map); }//from www . ja v a 2 s .com } } }
From source file:com.weibo.api.motan.config.springsupport.MotanBeanDefinitionParser.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void parseMethods(String id, NodeList nodeList, RootBeanDefinition beanDefinition, ParserContext parserContext) throws ClassNotFoundException { if (nodeList != null && nodeList.getLength() > 0) { ManagedList methods = null;/*from w ww .j av a2 s .com*/ for (int i = 0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node instanceof Element) { Element element = (Element) node; if ("method".equals(node.getNodeName()) || "method".equals(node.getLocalName())) { String methodName = element.getAttribute("name"); if (methodName == null || methodName.length() == 0) { throw new IllegalStateException("<motan:method> name attribute == null"); } if (methods == null) { methods = new ManagedList(); } BeanDefinition methodBeanDefinition = parse((Element) node, parserContext, MethodConfig.class, false); String name = id + "." + methodName; BeanDefinitionHolder methodBeanDefinitionHolder = new BeanDefinitionHolder( methodBeanDefinition, name); methods.add(methodBeanDefinitionHolder); } } } if (methods != null) { beanDefinition.getPropertyValues().addPropertyValue("methods", methods); } } }
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 }//w ww .j a v a 2 s .c om 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.hdiv.config.xml.ConfigBeanDefinitionParser.java
private RootBeanDefinition createKeyFactory(Element element, Object source) { RootBeanDefinition bean = new RootBeanDefinition(KeyFactory.class); bean.setSource(source);//w w w .ja v a 2 s. c o m bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); bean.getPropertyValues().addPropertyValue("algorithm", "AES"); bean.getPropertyValues().addPropertyValue("keySize", "128"); bean.getPropertyValues().addPropertyValue("prngAlgorithm", "SHA1PRNG"); bean.getPropertyValues().addPropertyValue("provider", "SUN"); return bean; }
From source file:org.hdiv.config.xml.ConfigBeanDefinitionParser.java
private RootBeanDefinition createRedirectHelper(Element element, Object source) { RootBeanDefinition bean = new RootBeanDefinition(RedirectHelper.class); bean.setSource(source);/*www .j a va 2 s.co m*/ bean.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); bean.getPropertyValues().addPropertyValue("linkUrlProcessor", new RuntimeBeanReference("linkUrlProcessor")); return bean; }