@SuppressWarnings("unchecked") public BeanDefinitionHolder decorate( Node node, BeanDefinitionHolder holder, ParserContext parserContext) { BeanDefinition filterChainProxy = holder.getBeanDefinition(); ManagedList<BeanMetadataElement> securityFilterChains = new ManagedList<BeanMetadataElement>(); Element elt = (Element) node; MatcherType matcherType = MatcherType.fromElement(elt); List<Element> filterChainElts = DomUtils.getChildElementsByTagName(elt, Elements.FILTER_CHAIN); for (Element chain : filterChainElts) { String path = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN); String filters = chain.getAttribute(HttpSecurityBeanDefinitionParser.ATT_FILTERS); if (!StringUtils.hasText(path)) { parserContext .getReaderContext() .error( "The attribute '" + HttpSecurityBeanDefinitionParser.ATT_PATH_PATTERN + "' must not be empty", elt); } if (!StringUtils.hasText(filters)) { parserContext .getReaderContext() .error( "The attribute '" + HttpSecurityBeanDefinitionParser.ATT_FILTERS + "'must not be empty", elt); } BeanDefinition matcher = matcherType.createMatcher(parserContext, path, null); if (filters.equals(HttpSecurityBeanDefinitionParser.OPT_FILTERS_NONE)) { securityFilterChains.add(createSecurityFilterChain(matcher, new ManagedList(0))); } else { String[] filterBeanNames = StringUtils.tokenizeToStringArray(filters, ","); ManagedList filterChain = new ManagedList(filterBeanNames.length); for (String name : filterBeanNames) { filterChain.add(new RuntimeBeanReference(name)); } securityFilterChains.add(createSecurityFilterChain(matcher, filterChain)); } } filterChainProxy.getConstructorArgumentValues().addGenericArgumentValue(securityFilterChains); return holder; }
@SuppressWarnings("unchecked") public void handleListenersElement( Element stepElement, BeanDefinition beanDefinition, ParserContext parserContext) { MutablePropertyValues propertyValues = beanDefinition.getPropertyValues(); List<Element> listenersElements = DomUtils.getChildElementsByTagName(stepElement, LISTENERS_ELE); if (listenersElements.size() == 1) { Element listenersElement = listenersElements.get(0); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition( listenersElement.getTagName(), parserContext.extractSource(stepElement)); parserContext.pushContainingComponent(compositeDef); ManagedList listenerBeans = new ManagedList(); if (propertyValues.contains("listeners")) { listenerBeans = (ManagedList) propertyValues.getPropertyValue("listeners").getValue(); } listenerBeans.setMergeEnabled( listenersElement.hasAttribute(MERGE_ATTR) && Boolean.valueOf(listenersElement.getAttribute(MERGE_ATTR))); List<Element> listenerElements = DomUtils.getChildElementsByTagName(listenersElement, "listener"); if (listenerElements != null) { for (Element listenerElement : listenerElements) { listenerBeans.add(parse(listenerElement, parserContext)); } } propertyValues.addPropertyValue("listeners", listenerBeans); parserContext.popAndRegisterContainingComponent(); } }
private ManagedList<AbstractBeanDefinition> parseListeners( Element element, ParserContext parserContext) { List<Element> listenersElements = DomUtils.getChildElementsByTagName(element, LISTENERS_ELEMENT); ManagedList<AbstractBeanDefinition> listeners = new ManagedList<AbstractBeanDefinition>(); if (listenersElements.size() == 1) { Element listenersElement = listenersElements.get(0); CompositeComponentDefinition compositeDef = new CompositeComponentDefinition( listenersElement.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); listeners.setMergeEnabled(false); List<Element> listenerElements = DomUtils.getChildElementsByTagName(listenersElement, LISTENER_ELEMENT); for (Element listenerElement : listenerElements) { BeanDefinitionBuilder bd = BeanDefinitionBuilder.genericBeanDefinition(listenerType); bd.addPropertyValue( "delegate", new RuntimeBeanReference(listenerElement.getAttribute(REF_ATTRIBUTE))); listeners.add(bd.getBeanDefinition()); } parserContext.popAndRegisterContainingComponent(); } else if (listenersElements.size() > 1) { parserContext .getReaderContext() .error( "The '<listeners/>' element may not appear more than once in a single <job/>.", element); } return listeners; }
@SuppressWarnings({"rawtypes", "unchecked"}) public static ManagedList configureAdviceChain( Element adviceChainElement, Element txElement, BeanDefinition parentBeanDefinition, ParserContext parserContext) { ManagedList adviceChain = null; // Schema validation ensures txElement and adviceChainElement are mutually exclusive if (txElement != null) { adviceChain = new ManagedList(); adviceChain.add(IntegrationNamespaceUtils.configureTransactionAttributes(txElement)); } if (adviceChainElement != null) { adviceChain = new ManagedList(); NodeList childNodes = adviceChainElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element) child; String localName = child.getLocalName(); if ("bean".equals(localName)) { BeanDefinitionHolder holder = parserContext .getDelegate() .parseBeanDefinitionElement(childElement, parentBeanDefinition); parserContext.registerBeanComponent(new BeanComponentDefinition(holder)); adviceChain.add(new RuntimeBeanReference(holder.getBeanName())); } else if ("ref".equals(localName)) { String ref = childElement.getAttribute("bean"); adviceChain.add(new RuntimeBeanReference(ref)); } else { BeanDefinition customBeanDefinition = parserContext.getDelegate().parseCustomElement(childElement, parentBeanDefinition); if (customBeanDefinition == null) { parserContext .getReaderContext() .error("failed to parse custom element '" + localName + "'", childElement); } adviceChain.add(customBeanDefinition); } } } } return adviceChain; }
private ManagedList<Object> extractBeanSubElements( Element parentElement, ParserContext parserContext) { ManagedList<Object> list = new ManagedList<Object>(); list.setSource(parserContext.extractSource(parentElement)); for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, "bean", "ref")) { Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null); list.add(object); } return list; }
/** * @param storedProcComponent * @param parserContext */ public static ManagedList<BeanDefinition> getSqlParameterDefinitionBeanDefinitions( Element storedProcComponent, ParserContext parserContext) { List<Element> sqlParameterDefinitionChildElements = DomUtils.getChildElementsByTagName(storedProcComponent, "sql-parameter-definition"); ManagedList<BeanDefinition> sqlParameterList = new ManagedList<BeanDefinition>(); for (Element childElement : sqlParameterDefinitionChildElements) { String name = childElement.getAttribute("name"); String sqlType = childElement.getAttribute("type"); String direction = childElement.getAttribute("direction"); String scale = childElement.getAttribute("scale"); final BeanDefinitionBuilder parameterBuilder; if ("OUT".equalsIgnoreCase(direction)) { parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SqlOutParameter.class); } else if ("INOUT".equalsIgnoreCase(direction)) { parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SqlInOutParameter.class); } else { parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(SqlParameter.class); } if (StringUtils.hasText(name)) { parameterBuilder.addConstructorArgValue(name); } else { parserContext .getReaderContext() .error( "The 'name' attribute must be set for the Sql parameter element.", storedProcComponent); } if (StringUtils.hasText(sqlType)) { JdbcTypesEnum jdbcTypeEnum = JdbcTypesEnum.convertToJdbcTypesEnum(sqlType); if (jdbcTypeEnum != null) { parameterBuilder.addConstructorArgValue(jdbcTypeEnum.getCode()); } else { parameterBuilder.addConstructorArgValue(sqlType); } } else { parameterBuilder.addConstructorArgValue(Types.VARCHAR); } if (StringUtils.hasText(scale)) { parameterBuilder.addConstructorArgValue(new TypedStringValue(scale, Integer.class)); } sqlParameterList.add(parameterBuilder.getBeanDefinition()); } return sqlParameterList; }
private ManagedList<Object> wrapLegacyResolvers(List<Object> list, ParserContext context) { ManagedList<Object> result = new ManagedList<Object>(); for (Object object : list) { if (object instanceof BeanDefinitionHolder) { BeanDefinitionHolder beanDef = (BeanDefinitionHolder) object; String className = beanDef.getBeanDefinition().getBeanClassName(); 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; }
private ManagedList<BeanReference> extractBeanRefSubElements( Element parentElement, ParserContext parserContext) { ManagedList<BeanReference> list = new ManagedList<BeanReference>(); list.setSource(parserContext.extractSource(parentElement)); for (Element refElement : DomUtils.getChildElementsByTagName(parentElement, "ref")) { BeanReference reference; if (StringUtils.hasText("bean")) { reference = new RuntimeBeanReference(refElement.getAttribute("bean"), false); list.add(reference); } else if (StringUtils.hasText("parent")) { reference = new RuntimeBeanReference(refElement.getAttribute("parent"), true); list.add(reference); } else { parserContext .getReaderContext() .error( "'bean' or 'parent' attribute is required for <ref> element", parserContext.extractSource(parentElement)); } } return list; }
/** * @param storedProcComponent * @param parserContext */ public static ManagedList<BeanDefinition> getProcedureParameterBeanDefinitions( Element storedProcComponent, ParserContext parserContext) { ManagedList<BeanDefinition> procedureParameterList = new ManagedList<BeanDefinition>(); List<Element> parameterChildElements = DomUtils.getChildElementsByTagName(storedProcComponent, "parameter"); for (Element childElement : parameterChildElements) { BeanDefinitionBuilder parameterBuilder = BeanDefinitionBuilder.genericBeanDefinition(ProcedureParameter.class); String name = childElement.getAttribute("name"); String expression = childElement.getAttribute("expression"); String value = childElement.getAttribute("value"); String type = childElement.getAttribute("type"); if (StringUtils.hasText(name)) { parameterBuilder.addPropertyValue("name", name); } if (StringUtils.hasText(expression)) { parameterBuilder.addPropertyValue("expression", expression); } if (StringUtils.hasText(value)) { if (!StringUtils.hasText(type)) { if (LOGGER.isInfoEnabled()) { LOGGER.info( String.format( "Type attribute not set for Store " + "Procedure parameter '%s'. Defaulting to " + "'java.lang.String'.", value)); } parameterBuilder.addPropertyValue("value", new TypedStringValue(value, String.class)); } else { parameterBuilder.addPropertyValue("value", new TypedStringValue(value, type)); } } procedureParameterList.add(parameterBuilder.getBeanDefinition()); } return procedureParameterList; }
/** * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, * org.springframework.beans.factory.xml.ParserContext) */ @SuppressWarnings("unchecked") public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionBuilder beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(PurgeJmsQueuesAction.class); beanDefinition.addPropertyValue("name", element.getLocalName()); DescriptionElementParser.doParse(element, beanDefinition); String connectionFactory = "connectionFactory"; // default value if (element.hasAttribute("connection-factory")) { connectionFactory = element.getAttribute("connection-factory"); } if (!StringUtils.hasText(connectionFactory)) { parserContext .getReaderContext() .error("'connection-factory' attribute must not be empty for this element", element); } beanDefinition.addPropertyReference("connectionFactory", connectionFactory); if (element.hasAttribute("receive-timeout")) { beanDefinition.addPropertyValue("receiveTimeout", element.getAttribute("receive-timeout")); } List<String> queueNames = new ArrayList<String>(); ManagedList queueRefs = new ManagedList(); List<?> queueElements = DomUtils.getChildElementsByTagName(element, "queue"); for (Iterator<?> iter = queueElements.iterator(); iter.hasNext(); ) { Element queue = (Element) iter.next(); String queueName = queue.getAttribute("name"); String queueRef = queue.getAttribute("ref"); if (StringUtils.hasText(queueName)) { queueNames.add(queueName); } else if (StringUtils.hasText(queueRef)) { queueRefs.add(BeanDefinitionBuilder.childBeanDefinition(queueRef).getBeanDefinition()); } else { throw new BeanCreationException( "Element 'queue' must set one of the attributes 'name' or 'ref'"); } } beanDefinition.addPropertyValue("queueNames", queueNames); beanDefinition.addPropertyValue("queues", queueRefs); return beanDefinition.getBeanDefinition(); }
private ManagedList<?> getDeferredResultInterceptors( Element element, Object source, ParserContext parserContext) { ManagedList<? super Object> interceptors = new ManagedList<Object>(); Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support"); if (asyncElement != null) { Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "deferred-result-interceptors"); if (interceptorsElement != null) { interceptors.setSource(source); for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) { BeanDefinitionHolder beanDef = parserContext.getDelegate().parseBeanDefinitionElement(converter); beanDef = parserContext.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef); interceptors.add(beanDef); } } } return interceptors; }
private ManagedList<?> getMessageConverters( Element element, Object source, ParserContext parserContext) { Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters"); ManagedList<? super Object> messageConverters = new ManagedList<Object>(); if (convertersElement != null) { messageConverters.setSource(source); for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) { Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null); messageConverters.add(object); } } if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) { messageConverters.setSource(source); messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source)); RootBeanDefinition stringConverterDef = createConverterDefinition(StringHttpMessageConverter.class, source); stringConverterDef.getPropertyValues().add("writeAcceptCharset", false); messageConverters.add(stringConverterDef); messageConverters.add(createConverterDefinition(ResourceHttpMessageConverter.class, source)); messageConverters.add(createConverterDefinition(SourceHttpMessageConverter.class, source)); messageConverters.add( createConverterDefinition(AllEncompassingFormHttpMessageConverter.class, source)); if (romePresent) { messageConverters.add( createConverterDefinition(AtomFeedHttpMessageConverter.class, source)); messageConverters.add( createConverterDefinition(RssChannelHttpMessageConverter.class, source)); } if (jackson2XmlPresent) { RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2XmlHttpMessageConverter.class, source); GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source); jacksonFactoryDef.getPropertyValues().add("createXmlMapper", true); jacksonConverterDef .getConstructorArgumentValues() .addIndexedArgumentValue(0, jacksonFactoryDef); messageConverters.add(jacksonConverterDef); } else if (jaxb2Present) { messageConverters.add( createConverterDefinition(Jaxb2RootElementHttpMessageConverter.class, source)); } if (jackson2Present) { RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2HttpMessageConverter.class, source); GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source); jacksonConverterDef .getConstructorArgumentValues() .addIndexedArgumentValue(0, jacksonFactoryDef); messageConverters.add(jacksonConverterDef); } else if (gsonPresent) { messageConverters.add(createConverterDefinition(GsonHttpMessageConverter.class, source)); } } return messageConverters; }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { String tokenServicesRef = element.getAttribute("token-services-ref"); String resourceDetailsServiceRef = element.getAttribute("resource-details-service-ref"); String rememberMeServicesRef = element.getAttribute("remember-me-services-ref"); String accessTokenProvider = element.getAttribute("profile-manager-ref"); String requireAuthenticated = element.getAttribute("require-authenticated"); String redirectStrategyRef = element.getAttribute("redirect-strategy-ref"); if (!StringUtils.hasText(tokenServicesRef)) { tokenServicesRef = "oauth2ClientTokenServices"; BeanDefinitionBuilder tokenServices = BeanDefinitionBuilder.rootBeanDefinition(InMemoryOAuth2ClientTokenServices.class); parserContext .getRegistry() .registerBeanDefinition(tokenServicesRef, tokenServices.getBeanDefinition()); } if (!StringUtils.hasText(rememberMeServicesRef)) { rememberMeServicesRef = "oauth2ClientRememberMeServices"; BeanDefinitionBuilder rememberMeServices = BeanDefinitionBuilder.rootBeanDefinition(HttpSessionClientTokenFlashServices.class); parserContext .getRegistry() .registerBeanDefinition(rememberMeServicesRef, rememberMeServices.getBeanDefinition()); } if (!StringUtils.hasText(resourceDetailsServiceRef)) { resourceDetailsServiceRef = "oauth2ResourceDetailsService"; BeanDefinitionBuilder resourceDetailsService = BeanDefinitionBuilder.rootBeanDefinition(ResourceDetailsServiceFactoryBean.class); parserContext .getRegistry() .registerBeanDefinition( resourceDetailsServiceRef, resourceDetailsService.getBeanDefinition()); } if (!StringUtils.hasText(accessTokenProvider)) { accessTokenProvider = "oauth2AccessTokenProvider"; ManagedList<BeanMetadataElement> profiles = new ManagedList<BeanMetadataElement>(); profiles.add( BeanDefinitionBuilder.genericBeanDefinition(AuthorizationCodeAccessTokenProvider.class) .getBeanDefinition()); profiles.add( BeanDefinitionBuilder.genericBeanDefinition(ClientCredentialsAccessTokenProvider.class) .getBeanDefinition()); BeanDefinitionBuilder profileManager = BeanDefinitionBuilder.rootBeanDefinition(OAuth2AccessTokenProviderChain.class); profileManager.addConstructorArgValue(profiles); if ("false".equalsIgnoreCase(requireAuthenticated)) { profileManager.addPropertyValue("requireAuthenticated", "false"); } profileManager.addPropertyReference("tokenServices", tokenServicesRef); parserContext .getRegistry() .registerBeanDefinition(accessTokenProvider, profileManager.getBeanDefinition()); } BeanDefinitionBuilder clientContextFilterBean = BeanDefinitionBuilder.rootBeanDefinition(OAuth2ClientContextFilter.class); clientContextFilterBean.addPropertyReference("accessTokenProvider", accessTokenProvider); clientContextFilterBean.addPropertyReference("clientTokenFlashServices", rememberMeServicesRef); if (StringUtils.hasText(redirectStrategyRef)) { clientContextFilterBean.addPropertyReference("redirectStrategy", redirectStrategyRef); } ManagedList<BeanMetadataElement> filters = new ManagedList<BeanMetadataElement>(); parserContext .getRegistry() .registerBeanDefinition( "oauth2ClientContextFilter", clientContextFilterBean.getBeanDefinition()); filters.add(new RuntimeBeanReference("oauth2ClientContextFilter")); BeanDefinition fids = ConfigUtils.createSecurityMetadataSource(element, parserContext); if (fids != null) { BeanDefinitionBuilder consumerFilterBean = BeanDefinitionBuilder.rootBeanDefinition(OAuth2ClientProcessingFilter.class); consumerFilterBean.addPropertyValue("objectDefinitionSource", fids); consumerFilterBean.addPropertyReference("resourceDetailsService", resourceDetailsServiceRef); parserContext .getRegistry() .registerBeanDefinition( "oauth2ClientSecurityFilter", consumerFilterBean.getBeanDefinition()); filters.add(new RuntimeBeanReference("oauth2ClientSecurityFilter")); } BeanDefinitionBuilder filterChain = BeanDefinitionBuilder.rootBeanDefinition(CompositeFilter.class); filterChain.addPropertyValue("filters", filters); return filterChain.getBeanDefinition(); }