private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext, MutablePropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition listenerDef = new RootBeanDefinition(); listenerDef.setSource(parserContext.extractSource(listenerEle)); listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter"); listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref)); listenerDef.getPropertyValues().add("defaultListenerMethod", method); PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter"); if (messageConverterPv != null) { listenerDef.getPropertyValues().addPropertyValue(messageConverterPv); containerDef.getPropertyValues().add("messageListener", listenerDef); if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) { String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE); Boolean pubSubDomain = (Boolean) commonContainerProperties.get("replyPubSubDomain"); if (pubSubDomain == null) { pubSubDomain = false; listenerDef.getPropertyValues().add( pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination); PropertyValue destinationResolver = containerDef.getPropertyValues().getPropertyValue("destinationResolver"); if (destinationResolver != null) { listenerDef.getPropertyValues().addPropertyValue(destinationResolver);
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { RootBeanDefinition definition = new RootBeanDefinition(); definition.setBeanClass(TestBean.class); MutablePropertyValues mpvs = new MutablePropertyValues(); mpvs.add("name", element.getAttribute("name")); mpvs.add("age", element.getAttribute("age")); definition.setPropertyValues(mpvs); parserContext.getRegistry().registerBeanDefinition(element.getAttribute("id"), definition); return null; } }
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { if (node instanceof Attr) { Attr attr = (Attr) node; String propertyName = parserContext.getDelegate().getLocalName(attr); String propertyValue = attr.getValue(); MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues(); if (pvs.contains(propertyName)) { parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " + "both <property> and inline syntax. Only one approach may be used per property.", attr); } if (propertyName.endsWith(REF_SUFFIX)) { propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length()); pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue)); } else { pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue); } } return definition; }
protected void visitPropertyValues(MutablePropertyValues pvs) { PropertyValue[] pvArray = pvs.getPropertyValues(); for (PropertyValue pv : pvArray) { Object newVal = resolveValue(pv.getValue()); if (!ObjectUtils.nullSafeEquals(newVal, pv.getValue())) { pvs.add(pv.getName(), newVal); } } }
@Override protected RootBeanDefinition createContainer(Element containerEle, Element listenerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition containerDef = new RootBeanDefinition(); containerDef.setSource(parserContext.extractSource(containerEle)); containerDef.setBeanClassName("org.springframework.jms.listener.endpoint.JmsMessageEndpointManager"); containerDef.getPropertyValues().addPropertyValues(specificContainerProperties); RootBeanDefinition configDef = new RootBeanDefinition(); configDef.setSource(parserContext.extractSource(containerEle)); configDef.setBeanClassName("org.springframework.jms.listener.endpoint.JmsActivationSpecConfig"); configDef.getPropertyValues().addPropertyValues(commonContainerProperties); parseListenerConfiguration(listenerEle, parserContext, configDef.getPropertyValues()); containerDef.getPropertyValues().add("activationSpecConfig", configDef); return containerDef; }
/** * Merge URI variables into the property values to use for data binding. */ @Override @SuppressWarnings("unchecked") protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) { String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; Map<String, String> uriVars = (Map<String, String>) request.getAttribute(attr); if (uriVars != null) { uriVars.forEach((name, value) -> { if (mpvs.contains(name)) { if (logger.isWarnEnabled()) { logger.warn("Skipping URI variable '" + name + "' because request contains bind value with same name."); } } else { mpvs.addPropertyValue(name, value); } }); } }
private RuntimeBeanReference registerUserDestResolver(Element brokerElem, RuntimeBeanReference userRegistry, ParserContext context, @Nullable Object source) { RootBeanDefinition beanDef = new RootBeanDefinition(DefaultUserDestinationResolver.class); beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, userRegistry); if (brokerElem.hasAttribute("user-destination-prefix")) { beanDef.getPropertyValues().add("userDestinationPrefix", brokerElem.getAttribute("user-destination-prefix")); } if (brokerElem.hasAttribute("path-matcher")) { String pathMatcherRef = brokerElem.getAttribute("path-matcher"); beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef)); } return new RuntimeBeanReference(registerBeanDef(beanDef, context, source)); }
private static void registerCacheAdvisor(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME)) { Object source = parserContext.extractSource(element); String sourceName = parserContext.getReaderContext().registerWithGeneratedName(sourceDef); new RootBeanDefinition("org.springframework.cache.jcache.interceptor.JCacheInterceptor"); interceptorDef.setSource(source); interceptorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); interceptorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); parseErrorHandler(element, interceptorDef); String interceptorName = parserContext.getReaderContext().registerWithGeneratedName(interceptorDef); advisorDef.setSource(source); advisorDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); advisorDef.getPropertyValues().add("cacheOperationSource", new RuntimeBeanReference(sourceName)); advisorDef.getPropertyValues().add("adviceBeanName", interceptorName); if (element.hasAttribute("order")) { advisorDef.getPropertyValues().add("order", element.getAttribute("order")); parserContext.getRegistry().registerBeanDefinition(CacheManagementConfigUtils.JCACHE_ADVISOR_BEAN_NAME, advisorDef); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), source); compositeDef.addNestedComponent(new BeanComponentDefinition(sourceDef, sourceName)); compositeDef.addNestedComponent(new BeanComponentDefinition(interceptorDef, interceptorName));
private RuntimeBeanReference getContentNegotiationManager( Element element, @Nullable Object source, ParserContext context) { RuntimeBeanReference beanRef; if (element.hasAttribute("content-negotiation-manager")) { String name = element.getAttribute("content-negotiation-manager"); beanRef = new RuntimeBeanReference(name); } else { RootBeanDefinition factoryBeanDef = new RootBeanDefinition(ContentNegotiationManagerFactoryBean.class); factoryBeanDef.setSource(source); factoryBeanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); factoryBeanDef.getPropertyValues().add("mediaTypes", getDefaultMediaTypes()); String name = CONTENT_NEGOTIATION_MANAGER_BEAN_NAME; context.getReaderContext().getRegistry().registerBeanDefinition(name , factoryBeanDef); context.registerComponent(new BeanComponentDefinition(factoryBeanDef, name)); beanRef = new RuntimeBeanReference(name); } return beanRef; }
private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { ManagedList<TypedStringValue> includePatterns = new ManagedList<>(); NodeList childNodes = element.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node instanceof Element) { Element includeElement = (Element) node; TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); valueHolder.setSource(parserContext.extractSource(includeElement)); includePatterns.add(valueHolder); } } if (!includePatterns.isEmpty()) { includePatterns.setSource(parserContext.extractSource(element)); beanDef.getPropertyValues().add("includePatterns", includePatterns); } }
/** * Create a {@link RootBeanDefinition} for the advisor described in the supplied. Does <strong>not</strong> * parse any associated '{@code pointcut}' or '{@code pointcut-ref}' attributes. */ private AbstractBeanDefinition createAdvisorBeanDefinition(Element advisorElement, ParserContext parserContext) { RootBeanDefinition advisorDefinition = new RootBeanDefinition(DefaultBeanFactoryPointcutAdvisor.class); advisorDefinition.setSource(parserContext.extractSource(advisorElement)); String adviceRef = advisorElement.getAttribute(ADVICE_REF); if (!StringUtils.hasText(adviceRef)) { parserContext.getReaderContext().error( "'advice-ref' attribute contains empty value.", advisorElement, this.parseState.snapshot()); } else { advisorDefinition.getPropertyValues().add( ADVICE_BEAN_NAME, new RuntimeBeanNameReference(adviceRef)); } if (advisorElement.hasAttribute(ORDER_PROPERTY)) { advisorDefinition.getPropertyValues().add( ORDER_PROPERTY, advisorElement.getAttribute(ORDER_PROPERTY)); } return advisorDefinition; }
private BeanDefinition createContentNegotiatingViewResolver(Element resolverElement, ParserContext context) { RootBeanDefinition beanDef = new RootBeanDefinition(ContentNegotiatingViewResolver.class); beanDef.setSource(context.extractSource(resolverElement)); beanDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); MutablePropertyValues values = beanDef.getPropertyValues(); List<Element> elements = DomUtils.getChildElementsByTagName(resolverElement, "default-views"); if (!elements.isEmpty()) { ManagedList<Object> list = new ManagedList<>(); for (Element element : DomUtils.getChildElementsByTagName(elements.get(0), "bean", "ref")) { list.add(context.getDelegate().parsePropertySubElement(element, null)); } values.add("defaultViews", list); } if (resolverElement.hasAttribute("use-not-acceptable")) { values.add("useNotAcceptableStatusCode", resolverElement.getAttribute("use-not-acceptable")); } Object manager = MvcNamespaceUtils.getContentNegotiationManager(context); if (manager != null) { values.add("contentNegotiationManager", manager); } return beanDef; }
private RootBeanDefinition getRedirectView(Element element, @Nullable HttpStatus status, @Nullable Object source) { RootBeanDefinition redirectView = new RootBeanDefinition(RedirectView.class); redirectView.setSource(source); redirectView.getConstructorArgumentValues().addIndexedArgumentValue(0, element.getAttribute("redirect-url")); if (status != null) { redirectView.getPropertyValues().add("statusCode", status); } if (element.hasAttribute("context-relative")) { redirectView.getPropertyValues().add("contextRelative", element.getAttribute("context-relative")); } else { redirectView.getPropertyValues().add("contextRelative", true); } if (element.hasAttribute("keep-query-params")) { redirectView.getPropertyValues().add("propagateQueryParams", element.getAttribute("keep-query-params")); } return redirectView; }
static BeanDefinition parseKeyGenerator(Element element, BeanDefinition def) { String name = element.getAttribute("key-generator"); if (StringUtils.hasText(name)) { def.getPropertyValues().add("keyGenerator", new RuntimeBeanReference(name.trim())); } return def; }
Object source = context.extractSource(element); if (pathMatchingElement.hasAttribute("suffix-pattern")) { Boolean useSuffixPatternMatch = Boolean.valueOf(pathMatchingElement.getAttribute("suffix-pattern")); handlerMappingDef.getPropertyValues().add("useSuffixPatternMatch", useSuffixPatternMatch); if (pathMatchingElement.hasAttribute("trailing-slash")) { Boolean useTrailingSlashMatch = Boolean.valueOf(pathMatchingElement.getAttribute("trailing-slash")); handlerMappingDef.getPropertyValues().add("useTrailingSlashMatch", useTrailingSlashMatch); if (pathMatchingElement.hasAttribute("registered-suffixes-only")) { Boolean useRegisteredSuffixPatternMatch = Boolean.valueOf(pathMatchingElement.getAttribute("registered-suffixes-only")); handlerMappingDef.getPropertyValues().add("useRegisteredSuffixPatternMatch", useRegisteredSuffixPatternMatch); if (pathMatchingElement.hasAttribute("path-helper")) { pathHelperRef = new RuntimeBeanReference(pathMatchingElement.getAttribute("path-helper")); handlerMappingDef.getPropertyValues().add("urlPathHelper", pathHelperRef); if (pathMatchingElement.hasAttribute("path-matcher")) { pathMatcherRef = new RuntimeBeanReference(pathMatchingElement.getAttribute("path-matcher")); handlerMappingDef.getPropertyValues().add("pathMatcher", pathMatcherRef);
private void addUrlBasedViewResolverProperties(Element element, RootBeanDefinition beanDefinition) { if (element.hasAttribute("prefix")) { beanDefinition.getPropertyValues().add("prefix", element.getAttribute("prefix")); } if (element.hasAttribute("suffix")) { beanDefinition.getPropertyValues().add("suffix", element.getAttribute("suffix")); } if (element.hasAttribute("cache-views")) { beanDefinition.getPropertyValues().add("cache", element.getAttribute("cache-views")); } if (element.hasAttribute("view-class")) { beanDefinition.getPropertyValues().add("viewClass", element.getAttribute("view-class")); } if (element.hasAttribute("view-names")) { beanDefinition.getPropertyValues().add("viewNames", element.getAttribute("view-names")); } }
@Override public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) { String pathAttribute = element.getAttribute("path"); String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ","); RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler")); ConstructorArgumentValues cargs = new ConstructorArgumentValues(); cargs.addIndexedArgumentValue(0, handlerReference); cargs.addIndexedArgumentValue(1, this.handshakeHandlerReference); RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cargs, null); requestHandlerDef.setSource(context.extractSource(element)); requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList); String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef); RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName); for (String mapping : mappings) { urlMap.put(mapping, requestHandlerRef); } } }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { String agentId = element.getAttribute(AGENT_ID_ATTRIBUTE); if (StringUtils.hasText(agentId)) { RootBeanDefinition bd = new RootBeanDefinition(MBeanServerFactoryBean.class); bd.getPropertyValues().add("agentId", agentId); return bd; } AbstractBeanDefinition specialServer = findServerForSpecialEnvironment(); if (specialServer != null) { return specialServer; } RootBeanDefinition bd = new RootBeanDefinition(MBeanServerFactoryBean.class); bd.getPropertyValues().add("locateExistingServerIfPossible", Boolean.TRUE); // Mark as infrastructure bean and attach source location. bd.setRole(BeanDefinition.ROLE_INFRASTRUCTURE); bd.setSource(parserContext.extractSource(element)); return bd; }
@Override public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinition bd = LangNamespaceUtils.registerScriptFactoryPostProcessorIfNecessary(parserContext.getRegistry()); String refreshCheckDelay = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE); if (StringUtils.hasText(refreshCheckDelay)) { bd.getPropertyValues().add("defaultRefreshCheckDelay", Long.valueOf(refreshCheckDelay)); } String proxyTargetClass = element.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE); if (StringUtils.hasText(proxyTargetClass)) { bd.getPropertyValues().add("defaultProxyTargetClass", new TypedStringValue(proxyTargetClass, Boolean.class)); } return null; }
@Override public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) { Element element = (Element) node; BeanDefinition def = definition.getBeanDefinition(); MutablePropertyValues mpvs = (def.getPropertyValues() == null) ? new MutablePropertyValues() : def.getPropertyValues(); mpvs.add("name", element.getAttribute("name")); mpvs.add("age", element.getAttribute("age")); ((AbstractBeanDefinition) def).setPropertyValues(mpvs); return definition; } }