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; }
/** * @param elt * @param parserContext * @param pkgs */ private void parsePathsElement(Element element, ParserContext parserContext, Set<String> pkgs) { List<Element> pkgElts = DomUtils.getChildElementsByTagName(element, PATH_ELEMENT); for (Element pkgElt : pkgElts) { String value = DomUtils.getTextValue(pkgElt).trim(); pkgs.add(value); } }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); BeanDefinitionBuilder redisConfigBeanBuilder = BeanDefinitionBuilder.genericBeanDefinition(RedisConnectionFactoryConfig.class.getName()); BeanDefinition cloudPoolConfiguration = null; Element poolElement = DomUtils.getChildElementByTagName(element, ELEMENT_POOL); if (poolElement != null) { cloudPoolConfiguration = parsePoolElement(poolElement, parserContext); } redisConfigBeanBuilder.addConstructorArgValue(cloudPoolConfiguration); Element propertiesElement = DomUtils.getChildElementByTagName(element, CONNECTION_PROPERTIES); if (propertiesElement != null) { Map<?, ?> properties = parserContext .getDelegate() .parseMapElement(propertiesElement, builder.getRawBeanDefinition()); redisConfigBeanBuilder.addConstructorArgValue(properties); } builder.addConstructorArgValue(redisConfigBeanBuilder.getBeanDefinition()); }
@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(); } }
@SuppressWarnings("unchecked") public static BeanMetadataElement parseListenerElement( Element element, ParserContext parserContext, BeanDefinition enclosing) { String listenerRef = element.getAttribute(REF_ATTR); List<Element> beanElements = DomUtils.getChildElementsByTagName(element, BEAN_ELE); List<Element> refElements = DomUtils.getChildElementsByTagName(element, REF_ELE); verifyListenerAttributesAndSubelements( listenerRef, beanElements, refElements, element, parserContext); if (StringUtils.hasText(listenerRef)) { return new RuntimeBeanReference(listenerRef); } else if (beanElements.size() == 1) { Element beanElement = beanElements.get(0); BeanDefinitionHolder beanDefinitionHolder = parserContext.getDelegate().parseBeanDefinitionElement(beanElement, enclosing); parserContext .getDelegate() .decorateBeanDefinitionIfRequired(beanElement, beanDefinitionHolder); return beanDefinitionHolder; } else { return (BeanMetadataElement) parserContext.getDelegate().parsePropertySubElement(refElements.get(0), null); } }
@SuppressWarnings({"unchecked"}) private void parseProcessors( Element element, ParserContext parserContext, GenericBeanDefinition beanDefinition) { Element processorsElement = DomUtils.getChildElementByTagName(element, EVENT_PROCESSORS_ELEMENT); Element snapshotTriggerElement = DomUtils.getChildElementByTagName(element, SNAPSHOT_TRIGGER_ELEMENT); if (snapshotTriggerElement != null) { BeanDefinition triggerDefinition = snapshotterTriggerParser.parse(snapshotTriggerElement, parserContext); PropertyValue aggregateCache = beanDefinition.getPropertyValues().getPropertyValue("cache"); if (aggregateCache != null) { triggerDefinition.getPropertyValues().add("aggregateCache", aggregateCache.getValue()); } beanDefinition.getPropertyValues().add(SNAPSHOTTER_TRIGGER_PROPERTY, triggerDefinition); } if (processorsElement != null) { List<Object> processorsList = parserContext.getDelegate().parseListElement(processorsElement, beanDefinition); if (!processorsList.isEmpty()) { beanDefinition.getPropertyValues().add(EVENT_STREAM_DECORATORS_PROPERTY, processorsList); } } }
@Override protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) { final BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(ContentEnricher.class); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply"); List<Element> subElements = DomUtils.getChildElementsByTagName(element, "property"); if (!CollectionUtils.isEmpty(subElements)) { ManagedMap<String, Object> expressions = new ManagedMap<String, Object>(); for (Element subElement : subElements) { String name = subElement.getAttribute("name"); BeanDefinition beanDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "value", "expression", parserContext, subElement, true); expressions.put(name, beanDefinition); } builder.addPropertyValue("propertyExpressions", expressions); } subElements = DomUtils.getChildElementsByTagName(element, "header"); if (!CollectionUtils.isEmpty(subElements)) { ManagedMap<String, Object> expressions = new ManagedMap<String, Object>(); for (Element subElement : subElements) { String name = subElement.getAttribute("name"); BeanDefinition expressionDefinition = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression( "value", "expression", parserContext, subElement, true); BeanDefinitionBuilder valueProcessorBuilder = BeanDefinitionBuilder.genericBeanDefinition( IntegrationNamespaceUtils.BASE_PACKAGE + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor"); valueProcessorBuilder .addConstructorArgValue(expressionDefinition) .addConstructorArgValue(subElement.getAttribute("type")); IntegrationNamespaceUtils.setValueIfAttributeDefined( valueProcessorBuilder, subElement, "overwrite"); expressions.put(name, valueProcessorBuilder.getBeanDefinition()); } builder.addPropertyValue("headerExpressions", expressions); } IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "should-clone-payload"); String requestPayloadExpression = element.getAttribute("request-payload-expression"); if (StringUtils.hasText(requestPayloadExpression)) { BeanDefinitionBuilder expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class); expressionBuilder.addConstructorArgValue(requestPayloadExpression); builder.addPropertyValue("requestPayloadExpression", expressionBuilder.getBeanDefinition()); } return builder; }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String scriptLocation = element.getAttribute(LOCATION_ATTRIBUTE); String scriptText = DomUtils.getTextValue(element); if (!(StringUtils.hasText(scriptLocation) ^ StringUtils.hasText(scriptText))) { parserContext .getReaderContext() .error( "Either the 'location' attribute or inline script text must be provided, but not both.", element); return; } List<Element> variableElements = DomUtils.getChildElementsByTagName(element, "variable"); String scriptVariableGeneratorName = element.getAttribute("script-variable-generator"); if (StringUtils.hasText(scriptVariableGeneratorName) && variableElements.size() > 0) { parserContext .getReaderContext() .error( "'script-variable-generator' and 'variable' sub-elements are mutually exclusive.", element); return; } if (StringUtils.hasText(scriptLocation)) { builder.addConstructorArgValue( this.resolveScriptLocation(element, parserContext.getReaderContext(), scriptLocation)); } else { if (getScriptSourceClassName() != null) { builder.addConstructorArgValue( new StaticScriptSource(scriptText, getScriptSourceClassName())); } else { builder.addConstructorArgValue(new StaticScriptSource(scriptText)); } } BeanMetadataElement scriptVariableGeneratorDef = null; if (!StringUtils.hasText(scriptVariableGeneratorName)) { BeanDefinitionBuilder scriptVariableGeneratorBuilder = BeanDefinitionBuilder.genericBeanDefinition(DefaultScriptVariableGenerator.class); ManagedMap<String, Object> variableMap = buildVariablesMap(element, parserContext, variableElements); if (!CollectionUtils.isEmpty(variableMap)) { scriptVariableGeneratorBuilder.addConstructorArgValue(variableMap); } scriptVariableGeneratorDef = scriptVariableGeneratorBuilder.getBeanDefinition(); } else { scriptVariableGeneratorDef = new RuntimeBeanReference(scriptVariableGeneratorName); } builder.addConstructorArgValue(scriptVariableGeneratorDef); postProcess(builder, element, parserContext); }
/** * @param element * @param parserContext * @param xmlDataList */ private void parseClassElement( Element element, ParserContext parserContext, List<Map<String, Object>> xmlDataList) { String className = element.getAttribute(CLASS_NAME_ATTR).replaceAll("//s+", ""); if (StringUtils.hasText(className)) { List<Element> interfaceElts = DomUtils.getChildElementsByTagName(element, INTERFACE_ELEMENT); for (Element interfaceElt : interfaceElts) { String description = interfaceElt.getAttribute(DESCRIPTION_ATTR).replaceAll("//s+", ""); if (StringUtils.hasText(description)) { List<Element> dataElts = DomUtils.getChildElementsByTagName(interfaceElt, DATA_ELEMENT); int dataEltsSize = dataElts.size(); String[] datas = new String[dataEltsSize]; for (int i = 0; i < dataEltsSize; i++) { String value = DomUtils.getTextValue(dataElts.get(i)).trim(); datas[i] = value; } Object[] wrappedDatas = wrapSingleArray(datas); HashMap<String, Object> dataMap = new HashMap<String, Object>(); Class<?> clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } String internalClassName = Type.getInternalName(clazz); String methodName = Util.getMethodNameFromMethodExternalDesc(description); Class<?>[] parameterTypes = Util.getParameterTypesFromMethodExternalDesc(description); Method method; try { method = clazz.getMethod(methodName, parameterTypes); } catch (Exception e) { throw new RuntimeException(e); } Object[] wrappedParameterTypes = wrapSingleArray(parameterTypes); String methodDesc = Type.getMethodDescriptor(method); Type returnType = Type.getReturnType(methodDesc); Class<?> returnClass = Util.getClass(returnType); dataMap.put("key", className + "." + description); dataMap.put("internalClassName", internalClassName); dataMap.put("className", className); dataMap.put("clazz", clazz); dataMap.put("methodName", methodName); dataMap.put("methodDesc", methodDesc); dataMap.put("returnClass", returnClass); dataMap.put("argumentClasses", wrappedParameterTypes); dataMap.put("datas", wrappedDatas); xmlDataList.add(dataMap); } } } }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(RequestHandlerRetryAdvice.class); BeanDefinitionBuilder retryTemplateBuilder = BeanDefinitionBuilder.genericBeanDefinition(RetryTemplate.class); boolean customTemplate = false; Element backOffPolicyEle = DomUtils.getChildElementByTagName(element, "fixed-back-off"); BeanDefinitionBuilder backOffBuilder = null; if (backOffPolicyEle != null) { backOffBuilder = BeanDefinitionBuilder.genericBeanDefinition(FixedBackOffPolicy.class); IntegrationNamespaceUtils.setValueIfAttributeDefined( backOffBuilder, backOffPolicyEle, "interval", "backOffPeriod"); } else { backOffPolicyEle = DomUtils.getChildElementByTagName(element, "exponential-back-off"); if (backOffPolicyEle != null) { backOffBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExponentialBackOffPolicy.class); IntegrationNamespaceUtils.setValueIfAttributeDefined( backOffBuilder, backOffPolicyEle, "initial", "initialInterval"); IntegrationNamespaceUtils.setValueIfAttributeDefined( backOffBuilder, backOffPolicyEle, "multiplier"); IntegrationNamespaceUtils.setValueIfAttributeDefined( backOffBuilder, backOffPolicyEle, "maximum", "maxInterval"); } } if (backOffBuilder != null) { retryTemplateBuilder.addPropertyValue("backOffPolicy", backOffBuilder.getBeanDefinition()); customTemplate = true; } String maxAttemptsAttr = element.getAttribute("max-attempts"); if (StringUtils.hasText(maxAttemptsAttr)) { BeanDefinitionBuilder retryPolicyBuilder = BeanDefinitionBuilder.genericBeanDefinition(SimpleRetryPolicy.class); IntegrationNamespaceUtils.setValueIfAttributeDefined( retryPolicyBuilder, element, "max-attempts"); retryTemplateBuilder.addPropertyValue("retryPolicy", retryPolicyBuilder.getBeanDefinition()); customTemplate = true; } if (customTemplate) { builder.addPropertyValue("retryTemplate", retryTemplateBuilder.getBeanDefinition()); } String recoveryChannelAttr = element.getAttribute("recovery-channel"); if (StringUtils.hasText(recoveryChannelAttr)) { BeanDefinitionBuilder emsrBuilder = BeanDefinitionBuilder.genericBeanDefinition(ErrorMessageSendingRecoverer.class); emsrBuilder.addConstructorArgReference(recoveryChannelAttr); IntegrationNamespaceUtils.setValueIfAttributeDefined(emsrBuilder, element, "send-timeout"); builder.addPropertyValue("recoveryCallback", emsrBuilder.getBeanDefinition()); } return builder.getBeanDefinition(); }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { BeanDefinitionBuilder metadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(PollerMetadata.class); if (element.hasAttribute("ref")) { parserContext .getReaderContext() .error( "the 'ref' attribute must not be present on the top-level 'poller' element", element); } configureTrigger(element, metadataBuilder, parserContext); IntegrationNamespaceUtils.setValueIfAttributeDefined( metadataBuilder, element, "max-messages-per-poll"); IntegrationNamespaceUtils.setValueIfAttributeDefined( metadataBuilder, element, "receive-timeout"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined( metadataBuilder, element, "task-executor"); Element txElement = DomUtils.getChildElementByTagName(element, "transactional"); Element adviceChainElement = DomUtils.getChildElementByTagName(element, "advice-chain"); IntegrationNamespaceUtils.configureAndSetAdviceChainIfPresent( adviceChainElement, txElement, metadataBuilder.getRawBeanDefinition(), parserContext); if (txElement != null) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined( metadataBuilder, txElement, "synchronization-factory", "transactionSynchronizationFactory"); } else if (adviceChainElement != null) { IntegrationNamespaceUtils.setReferenceIfAttributeDefined( metadataBuilder, adviceChainElement, "synchronization-factory", "transactionSynchronizationFactory"); } String errorChannel = element.getAttribute("error-channel"); if (StringUtils.hasText(errorChannel)) { BeanDefinitionBuilder errorHandler = BeanDefinitionBuilder.genericBeanDefinition(MessagePublishingErrorHandler.class); errorHandler.addPropertyReference("defaultErrorChannel", errorChannel); metadataBuilder.addPropertyValue("errorHandler", errorHandler.getBeanDefinition()); } return metadataBuilder.getBeanDefinition(); }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { List<Element> childElements = DomUtils.getChildElementsByTagName(element, "script"); if (!childElements.isEmpty()) { List<String> locations = new ArrayList<String>(childElements.size()); for (Element childElement : childElements) { locations.add(childElement.getAttribute("location")); } builder.addPropertyValue("scripts", locations.toArray(new String[locations.size()])); } builder.addPropertyValue("engineName", element.getAttribute("engine-name")); if (element.hasAttribute("render-object")) { builder.addPropertyValue("renderObject", element.getAttribute("render-object")); } if (element.hasAttribute("render-function")) { builder.addPropertyValue("renderFunction", element.getAttribute("render-function")); } if (element.hasAttribute("charset")) { builder.addPropertyValue("charset", Charset.forName(element.getAttribute("charset"))); } if (element.hasAttribute("resource-loader-path")) { builder.addPropertyValue("resourceLoaderPath", element.getAttribute("resource-loader-path")); } if (element.hasAttribute("shared-engine")) { builder.addPropertyValue("sharedEngine", element.getAttribute("shared-engine")); } }
@Override protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { if (DomUtils.getChildElementByTagName(element, "async") != null) { return async.parseInternal(element, parserContext); } return sync.parseInternal(element, parserContext); }
public static BeanComponentDefinition parseInnerHandlerDefinition( Element element, ParserContext parserContext) { // parses out the inner bean definition for concrete implementation if defined List<Element> childElements = DomUtils.getChildElementsByTagName(element, "bean"); BeanComponentDefinition innerComponentDefinition = null; if (childElements != null && childElements.size() == 1) { Element beanElement = childElements.get(0); BeanDefinitionParserDelegate delegate = parserContext.getDelegate(); BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(beanElement); bdHolder = delegate.decorateBeanDefinitionIfRequired(beanElement, bdHolder); BeanDefinition inDef = bdHolder.getBeanDefinition(); innerComponentDefinition = new BeanComponentDefinition(inDef, bdHolder.getBeanName()); } String ref = element.getAttribute(REF_ATTRIBUTE); Assert.isTrue( !(StringUtils.hasText(ref) && innerComponentDefinition != null), "Ambiguous definition. Inner bean " + (innerComponentDefinition == null ? innerComponentDefinition : innerComponentDefinition.getBeanDefinition().getBeanClassName()) + " declaration and \"ref\" " + ref + " are not allowed together."); return innerComponentDefinition; }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { String exchangeName = element.getAttribute(NAME_ATTRIBUTE); builder.addConstructorArgValue(new TypedStringValue(exchangeName)); parseBindings(element, parserContext, builder, exchangeName); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined( builder, element, DURABLE_ATTRIBUTE, true); NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined( builder, element, AUTO_DELETE_ATTRIBUTE, false); Element argumentsElement = DomUtils.getChildElementByTagName(element, ARGUMENTS_ELEMENT); if (argumentsElement != null) { String ref = argumentsElement.getAttribute(REF_ATTRIBUTE); Map<?, ?> map = parserContext .getDelegate() .parseMapElement(argumentsElement, builder.getRawBeanDefinition()); if (StringUtils.hasText(ref)) { if (map != null && map.size() > 0) { parserContext .getReaderContext() .error("You cannot have both a 'ref' and a nested map", element); } builder.addConstructorArgReference(ref); } else { builder.addConstructorArgValue(map); } } NamespaceUtils.parseDeclarationControls(element, builder); }
private ManagedList<?> getArgumentResolvers(Element element, ParserContext parserContext) { Element resolversElement = DomUtils.getChildElementByTagName(element, "argument-resolvers"); if (resolversElement != null) { ManagedList<Object> resolvers = extractBeanSubElements(resolversElement, parserContext); return wrapLegacyResolvers(resolvers, parserContext); } return null; }
protected void parseBindings( Element element, ParserContext parserContext, BeanDefinitionBuilder builder, String exchangeName) { Element bindingsElement = DomUtils.getChildElementByTagName(element, BINDINGS_ELE); doParseBindings(element, parserContext, exchangeName, bindingsElement, this); }
private RuntimeBeanReference getAsyncExecutor(Element element) { Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support"); if (asyncElement != null) { if (asyncElement.hasAttribute("task-executor")) { return new RuntimeBeanReference(asyncElement.getAttribute("task-executor")); } } return null; }
private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) { List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT); ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap = new ManagedMap<TypedStringValue, RuleBasedTransactionAttribute>(methods.size()); transactionAttributeMap.setSource(parserContext.extractSource(attrEle)); for (Element methodEle : methods) { String name = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE); TypedStringValue nameHolder = new TypedStringValue(name); nameHolder.setSource(parserContext.extractSource(methodEle)); RuleBasedTransactionAttribute attribute = new RuleBasedTransactionAttribute(); String propagation = methodEle.getAttribute(PROPAGATION_ATTRIBUTE); String isolation = methodEle.getAttribute(ISOLATION_ATTRIBUTE); String timeout = methodEle.getAttribute(TIMEOUT_ATTRIBUTE); String readOnly = methodEle.getAttribute(READ_ONLY_ATTRIBUTE); if (StringUtils.hasText(propagation)) { attribute.setPropagationBehaviorName( RuleBasedTransactionAttribute.PREFIX_PROPAGATION + propagation); } if (StringUtils.hasText(isolation)) { attribute.setIsolationLevelName(RuleBasedTransactionAttribute.PREFIX_ISOLATION + isolation); } if (StringUtils.hasText(timeout)) { try { attribute.setTimeout(Integer.parseInt(timeout)); } catch (NumberFormatException ex) { parserContext .getReaderContext() .error("Timeout must be an integer value: [" + timeout + "]", methodEle); } } if (StringUtils.hasText(readOnly)) { attribute.setReadOnly(Boolean.valueOf(methodEle.getAttribute(READ_ONLY_ATTRIBUTE))); } List<RollbackRuleAttribute> rollbackRules = new LinkedList<RollbackRuleAttribute>(); if (methodEle.hasAttribute(ROLLBACK_FOR_ATTRIBUTE)) { String rollbackForValue = methodEle.getAttribute(ROLLBACK_FOR_ATTRIBUTE); addRollbackRuleAttributesTo(rollbackRules, rollbackForValue); } if (methodEle.hasAttribute(NO_ROLLBACK_FOR_ATTRIBUTE)) { String noRollbackForValue = methodEle.getAttribute(NO_ROLLBACK_FOR_ATTRIBUTE); addNoRollbackRuleAttributesTo(rollbackRules, noRollbackForValue); } attribute.setRollbackRules(rollbackRules); transactionAttributeMap.put(nameHolder, attribute); } RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(NameMatchTransactionAttributeSource.class); attributeSourceDefinition.setSource(parserContext.extractSource(attrEle)); attributeSourceDefinition.getPropertyValues().add("nameMap", transactionAttributeMap); return attributeSourceDefinition; }
@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; }
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<?> 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 void parseEntries( Element element, String name, EntryType type, List<BeanDefinition> entries) { List<Element> cp = DomUtils.getChildElementsByTagName(element, name); for (Element entry : cp) { BeanDefinitionBuilder bd = BeanDefinitionBuilder.genericBeanDefinition(CacheEntry.class); bd.addConstructorArgValue(type); bd.addConstructorArgValue(entry.getAttribute("value")); entries.add(bd.getBeanDefinition()); } }
@Override public PreRenderActions getPreRenderActions() { validateScreenXmlDoc(); Element preRenderActionElement = DomUtils.getChildElementByTagName(screenXmlDocument.getDocumentElement(), "pre-actions"); GuiElementDefinitionParser parser = getParserDelegate().getScreenElementDefinitionParser("pre-actions"); PreRenderActions preRenderActions = parser.parse(preRenderActionElement, PreRenderActions.class); return preRenderActions; }
/** * Parse the split and turn it into a list of transitions. * * @param element the <split/gt; element to parse * @param parserContext the parser context for the bean factory * @return a collection of bean definitions for {@link * org.springframework.batch.core.job.flow.support.StateTransition} instances objects */ public Collection<BeanDefinition> parse(Element element, ParserContext parserContext) { String idAttribute = element.getAttribute("id"); BeanDefinitionBuilder stateBuilder = BeanDefinitionBuilder.genericBeanDefinition( "org.springframework.batch.core.job.flow.support.state.SplitState"); String taskExecutorBeanId = element.getAttribute("task-executor"); if (StringUtils.hasText(taskExecutorBeanId)) { RuntimeBeanReference taskExecutorRef = new RuntimeBeanReference(taskExecutorBeanId); stateBuilder.addPropertyValue("taskExecutor", taskExecutorRef); } List<Element> flowElements = DomUtils.getChildElementsByTagName(element, "flow"); if (flowElements.size() < 2) { parserContext .getReaderContext() .error("A <split/> must contain at least two 'flow' elements.", element); } Collection<BeanDefinition> flows = new ManagedList<BeanDefinition>(); int i = 0; String prefix = idAttribute; for (Element nextElement : flowElements) { String ref = nextElement.getAttribute(PARENT_ATTR); if (StringUtils.hasText(ref)) { if (nextElement.getElementsByTagName("*").getLength() > 0) { parserContext .getReaderContext() .error( "A <flow/> in a <split/> must have ref= or nested <flow/>, but not both.", nextElement); } AbstractBeanDefinition flowDefinition = new GenericBeanDefinition(); flowDefinition.setParentName(ref); MutablePropertyValues propertyValues = flowDefinition.getPropertyValues(); propertyValues.addPropertyValue("name", prefix + "." + i); flows.add(flowDefinition); } else { InlineFlowParser flowParser = new InlineFlowParser(prefix + "." + i, jobFactoryRef); flows.add(flowParser.parse(nextElement, parserContext)); } i++; } stateBuilder.addConstructorArgValue(flows); stateBuilder.addConstructorArgValue(prefix); return InlineFlowParser.getNextElements( parserContext, stateBuilder.getBeanDefinition(), element); }
/** * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, * org.springframework.beans.factory.xml.ParserContext) */ public BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionBuilder beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(AntRunAction.class); DescriptionElementParser.doParse(element, beanDefinition); BeanDefinitionParserUtils.setPropertyValue( beanDefinition, element.getAttribute("build-file"), "buildFilePath"); Element executeElement = DomUtils.getChildElementByTagName(element, "execute"); BeanDefinitionParserUtils.setPropertyValue( beanDefinition, executeElement.getAttribute("target"), "target"); BeanDefinitionParserUtils.setPropertyValue( beanDefinition, executeElement.getAttribute("targets"), "targets"); Properties properties = new Properties(); Element propertiesElement = DomUtils.getChildElementByTagName(element, "properties"); if (propertiesElement != null) { BeanDefinitionParserUtils.setPropertyValue( beanDefinition, propertiesElement.getAttribute("file"), "propertyFilePath"); List<?> propertyElements = DomUtils.getChildElementsByTagName(propertiesElement, "property"); if (propertyElements.size() > 0) { for (Iterator<?> iter = propertyElements.iterator(); iter.hasNext(); ) { Element propertyElement = (Element) iter.next(); properties.put( propertyElement.getAttribute("name"), propertyElement.getAttribute("value")); } beanDefinition.addPropertyValue("properties", properties); } } BeanDefinitionParserUtils.setPropertyReference( beanDefinition, element.getAttribute("build-listener"), "buildListener"); beanDefinition.addPropertyValue("name", element.getLocalName()); return beanDefinition.getBeanDefinition(); }
@Override protected void doParse( Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { super.doParse(element, parserContext, builder); Set<String> paths = new HashSet<String>(); List<Map<String, Object>> xmlDataList = new ArrayList<Map<String, Object>>(); String privilegeBean = null; /*List<Element> childElts = DomUtils.getChildElements(element); for (Element elt: childElts) { String localName = parserContext.getDelegate().getLocalName(elt); if (PATHS_ELEMENT.equals(localName)) { annotationScan = true; parsePathsElement(elt, parserContext, paths); } else if (CLASS_ELEMENT.equals(localName)) { parseClassElement(elt, parserContext, xmlDataList); } else if (PRIVILEGE_ELEMENT.equals(localName)) { privilegeBean = elt.getAttribute("ref"); } }*/ Element pathsElement = DomUtils.getChildElementByTagName(element, PATHS_ELEMENT); if (pathsElement != null) { parsePathsElement(pathsElement, parserContext, paths); } Element classElement = DomUtils.getChildElementByTagName(element, CLASS_ELEMENT); if (classElement != null) { parseClassElement(classElement, parserContext, xmlDataList); } Element privilegeElement = DomUtils.getChildElementByTagName(element, PRIVILEGE_ELEMENT); if (privilegeElement != null) { privilegeBean = privilegeElement.getAttribute("ref"); builder.addPropertyReference("imtPrivilege", privilegeBean); } builder.addPropertyValue("annotationScan", annotationScan); builder.addPropertyValue("paths", paths); builder.addPropertyValue("xmlDataList", xmlDataList); builder.addPropertyValue("beanAdapter", new SpringBeanAdapter()); builder.addPropertyValue("scanner", new SpringClassScanner()); builder.setInitMethodName("init"); }
public Document getDocument() { if (document == null) { return null; } Element documentElement = document.getDocumentElement(); Element entityEle = DomUtils.getChildElementByTagName(documentElement, "entity"); Document retXmlDoc = UtilXml.makeEmptyXmlDocument(entityEle.getAttribute("name")); List<Element> fieldEles = DomUtils.getChildElementsByTagName(entityEle, "field"); for (Element fieldEle : fieldEles) { String name = fieldEle.getAttribute("name"); String type = fieldEle.getAttribute("type"); Element namedFieldEl = retXmlDoc.createElement(name); namedFieldEl.setAttribute("type", type); retXmlDoc.getDocumentElement().appendChild(namedFieldEl); } return retXmlDoc; }
/** * @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; }