Java Code Examples for org.springframework.util.xml.DomUtils

The following examples show how to use org.springframework.util.xml.DomUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
//        获取到这个binding-table-rules节点对象
        Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
        if (null == bindingTableRulesElement) {
            return Collections.emptyList();
        }
//        获取子节点binding-table-rule的节点对象
        List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
//        初始化BindingTableRuleConfig对象
        BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder.rootBeanDefinition(BindingTableRuleConfig.class);
        List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
        for (Element bindingTableRuleElement : bindingTableRuleElements) {
//            解析logic-tables节点并对BindingTableRuleConfig对象的tableNames属性赋值
            bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
            result.add(bindingTableRuleFactory.getBeanDefinition());
        }
        return result;
    }
 
Example 2
Source Project: spring-analysis-note   Source File: ConfigBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 3
Source Project: spring-analysis-note   Source File: ScriptBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
/**
 * Resolves the script source from either the '{@code script-source}' attribute or
 * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and
 * returns {@code null} if neither or both of these values are specified.
 */
@Nullable
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
	boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
	if (hasScriptSource && !elements.isEmpty()) {
		readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
		return null;
	}
	else if (hasScriptSource) {
		return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	}
	else if (!elements.isEmpty()) {
		Element inlineElement = elements.get(0);
		return "inline:" + DomUtils.getTextValue(inlineElement);
	}
	else {
		readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
		return null;
	}
}
 
Example 4
Source Project: spring-analysis-note   Source File: CacheAdviceParser.java    License: MIT License 6 votes vote down vote up
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	builder.addPropertyReference("cacheManager", CacheNamespaceHandler.extractCacheManager(element));
	CacheNamespaceHandler.parseKeyGenerator(element, builder.getBeanDefinition());

	List<Element> cacheDefs = DomUtils.getChildElementsByTagName(element, DEFS_ELEMENT);
	if (!cacheDefs.isEmpty()) {
		// Using attributes source.
		List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext);
		builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions);
	}
	else {
		// Assume annotations source.
		builder.addPropertyValue("cacheOperationSources",
				new RootBeanDefinition("org.springframework.cache.annotation.AnnotationCacheOperationSource"));
	}
}
 
Example 5
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
	String contextPath = element.getAttribute("context-path");
	if (StringUtils.hasText(contextPath)) {
		beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
	}

	List<Element> classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
	if (!classes.isEmpty()) {
		ManagedList<String> classesToBeBound = new ManagedList<>(classes.size());
		for (Element classToBeBound : classes) {
			String className = classToBeBound.getAttribute("name");
			classesToBeBound.add(className);
		}
		beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
	}
}
 
Example 6
@Override
protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) {
	Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
	if (envValue != null) {
		// Specific environment settings defined, overriding any shared properties.
		definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
	}
	else {
		// Check whether there is a reference to shared environment properties...
		String envRef = element.getAttribute(ENVIRONMENT_REF);
		if (StringUtils.hasLength(envRef)) {
			definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
		}
	}

	String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
	if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
		definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
	}
}
 
Example 7
/**
 * Parse replaced-method sub-elements of the given bean element.
 */
public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) {
	NodeList nl = beanEle.getChildNodes();
	for (int i = 0; i < nl.getLength(); i++) {
		Node node = nl.item(i);
		if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) {
			Element replacedMethodEle = (Element) node;
			String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE);
			String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
			ReplaceOverride replaceOverride = new ReplaceOverride(name, callback);
			// Look for arg-type match elements.
			List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
			for (Element argTypeEle : argTypeEles) {
				String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE);
				match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle));
				if (StringUtils.hasText(match)) {
					replaceOverride.addTypeIdentifier(match);
				}
			}
			replaceOverride.setSource(extractSource(replacedMethodEle));
			overrides.addOverride(replaceOverride);
		}
	}
}
 
Example 8
private ManagedList<?> getDeferredResultInterceptors(
		Element element, @Nullable Object source, ParserContext context) {

	ManagedList<Object> interceptors = new ManagedList<>();
	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 = context.getDelegate().parseBeanDefinitionElement(converter);
				if (beanDef != null) {
					beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
					interceptors.add(beanDef);
				}
			}
		}
	}
	return interceptors;
}
 
Example 9
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	builder.addPropertyReference("transactionManager", TxNamespaceHandler.getTransactionManagerName(element));

	List<Element> txAttributes = DomUtils.getChildElementsByTagName(element, ATTRIBUTES_ELEMENT);
	if (txAttributes.size() > 1) {
		parserContext.getReaderContext().error(
				"Element <attributes> is allowed at most once inside element <advice>", element);
	}
	else if (txAttributes.size() == 1) {
		// Using attributes source.
		Element attributeSourceElement = txAttributes.get(0);
		RootBeanDefinition attributeSourceDefinition = parseAttributeSource(attributeSourceElement, parserContext);
		builder.addPropertyValue("transactionAttributeSource", attributeSourceDefinition);
	}
	else {
		// Assume annotations source.
		builder.addPropertyValue("transactionAttributeSource",
				new RootBeanDefinition("org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"));
	}
}
 
Example 10
/**
 * Parses the given XML element which sub-elements containing the properties
 * of the caching models to create.
 * 
 * @param element
 *          the XML element to parse
 * @return a map containing the parsed caching models.The key of each element
 *         is the value of the XML attribute <code>target</code> (a String)
 *         and the value is the caching model (an instance of
 *         <code>CachingModel</code>)
 */
private Map parseCachingModels(Element element) {
  List modelElements = DomUtils.getChildElementsByTagName(element, "caching");
  if (CollectionUtils.isEmpty(modelElements)) {
    return null;
  }

  String cacheModelKey = getCacheModelKey();
  Map models = new HashMap();
  int modelElementCount = modelElements.size();

  for (int i = 0; i < modelElementCount; i++) {
    Element modelElement = (Element) modelElements.get(i);
    String key = modelElement.getAttribute(cacheModelKey);

    CachingModel model = cacheModelParser.parseCachingModel(modelElement);
    models.put(key, model);
  }

  return models;
}
 
Example 11
Source Project: blog_demos   Source File: BeanDefinitionParserDelegate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parse a props element.
 */
public Properties parsePropsElement(Element propsEle) {
	ManagedProperties props = new ManagedProperties();
	props.setSource(extractSource(propsEle));
	props.setMergeEnabled(parseMergeAttribute(propsEle));

	List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT);
	for (Element propEle : propEles) {
		String key = propEle.getAttribute(KEY_ATTRIBUTE);
		// Trim the text value to avoid unwanted whitespace
		// caused by typical XML formatting.
		String value = DomUtils.getTextValue(propEle).trim();
		TypedStringValue keyHolder = new TypedStringValue(key);
		keyHolder.setSource(extractSource(propEle));
		TypedStringValue valueHolder = new TypedStringValue(value);
		valueHolder.setSource(extractSource(propEle));
		props.put(keyHolder, valueHolder);
	}

	return props;
}
 
Example 12
private RuntimeBeanReference registerUserDestHandler(Element brokerElem,
		RuntimeBeanReference userRegistry, RuntimeBeanReference inChannel,
		RuntimeBeanReference brokerChannel, ParserContext context, @Nullable Object source) {

	Object userDestResolver = registerUserDestResolver(brokerElem, userRegistry, context, source);

	RootBeanDefinition beanDef = new RootBeanDefinition(UserDestinationMessageHandler.class);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, inChannel);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(1, brokerChannel);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(2, userDestResolver);

	Element relayElement = DomUtils.getChildElementByTagName(brokerElem, "stomp-broker-relay");
	if (relayElement != null && relayElement.hasAttribute("user-destination-broadcast")) {
		String destination = relayElement.getAttribute("user-destination-broadcast");
		beanDef.getPropertyValues().add("broadcastDestination", destination);
	}

	String beanName = registerBeanDef(beanDef, context, source);
	return new RuntimeBeanReference(beanName);
}
 
Example 13
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 14
Source Project: redisson   Source File: RedissonDefinitionParser.java    License: Apache License 2.0 6 votes vote down vote up
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    if (element.hasChildNodes()) {
        CompositeComponentDefinition compositeDef
                = new CompositeComponentDefinition(parentId,
                        parserContext.extractSource(element));
        parserContext.pushContainingComponent(compositeDef);
        List<Element> childElts = DomUtils.getChildElements(element);
        for (Element elt : childElts) {
            if (BeanDefinitionParserDelegate.QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
                continue; //parsed elsewhere
            }
            String localName = parserContext.getDelegate().getLocalName(elt);
            localName = Conventions.attributeNameToPropertyName(localName);
            if (ConfigType.contains(localName)) {
                parseConfigTypes(elt, localName, redissonDef, parserContext);
            } else if (AddressType.contains(localName)) {
                parseAddressTypes(elt, localName, redissonDef, parserContext);
            } else if (helper.isRedissonNS(elt)) {
                elt.setAttribute(REDISSON_REF, redissonRef);
                parserContext.getDelegate().parseCustomElement(elt);
            }
        }
        parserContext.popContainingComponent();
    }
}
 
Example 15
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder beanDefinitionBuilder) {
	String contextPath = element.getAttribute("context-path");
	if (StringUtils.hasText(contextPath)) {
		beanDefinitionBuilder.addPropertyValue("contextPath", contextPath);
	}

	List<Element> classes = DomUtils.getChildElementsByTagName(element, "class-to-be-bound");
	if (!classes.isEmpty()) {
		ManagedList<String> classesToBeBound = new ManagedList<>(classes.size());
		for (Element classToBeBound : classes) {
			String className = classToBeBound.getAttribute("name");
			classesToBeBound.add(className);
		}
		beanDefinitionBuilder.addPropertyValue("classesToBeBound", classesToBeBound);
	}
}
 
Example 16
/**
 * Parse replaced-method sub-elements of the given bean element.
 */
public void parseReplacedMethodSubElements(Element beanEle, MethodOverrides overrides) {
	NodeList nl = beanEle.getChildNodes();
	for (int i = 0; i < nl.getLength(); i++) {
		Node node = nl.item(i);
		if (isCandidateElement(node) && nodeNameEquals(node, REPLACED_METHOD_ELEMENT)) {
			Element replacedMethodEle = (Element) node;
			String name = replacedMethodEle.getAttribute(NAME_ATTRIBUTE);
			String callback = replacedMethodEle.getAttribute(REPLACER_ATTRIBUTE);
			ReplaceOverride replaceOverride = new ReplaceOverride(name, callback);
			// Look for arg-type match elements.
			List<Element> argTypeEles = DomUtils.getChildElementsByTagName(replacedMethodEle, ARG_TYPE_ELEMENT);
			for (Element argTypeEle : argTypeEles) {
				String match = argTypeEle.getAttribute(ARG_TYPE_MATCH_ATTRIBUTE);
				match = (StringUtils.hasText(match) ? match : DomUtils.getTextValue(argTypeEle));
				if (StringUtils.hasText(match)) {
					replaceOverride.addTypeIdentifier(match);
				}
			}
			replaceOverride.setSource(extractSource(replacedMethodEle));
			overrides.addOverride(replaceOverride);
		}
	}
}
 
Example 17
/**
 * Return a typed String value Object for the given value element.
 */
public Object parseValueElement(Element ele, String defaultTypeName) {
	// It's a literal value.
	String value = DomUtils.getTextValue(ele);
	String specifiedTypeName = ele.getAttribute(TYPE_ATTRIBUTE);
	String typeName = specifiedTypeName;
	if (!StringUtils.hasText(typeName)) {
		typeName = defaultTypeName;
	}
	try {
		TypedStringValue typedValue = buildTypedStringValue(value, typeName);
		typedValue.setSource(extractSource(ele));
		typedValue.setSpecifiedTypeName(specifiedTypeName);
		return typedValue;
	}
	catch (ClassNotFoundException ex) {
		error("Type class [" + typeName + "] not found for <value> element", ele, ex);
		return value;
	}
}
 
Example 18
Source Project: java-technology-stack   Source File: ConfigBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext parserContext) {
	CompositeComponentDefinition compositeDef =
			new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
	parserContext.pushContainingComponent(compositeDef);

	configureAutoProxyCreator(parserContext, element);

	List<Element> childElts = DomUtils.getChildElements(element);
	for (Element elt: childElts) {
		String localName = parserContext.getDelegate().getLocalName(elt);
		if (POINTCUT.equals(localName)) {
			parsePointcut(elt, parserContext);
		}
		else if (ADVISOR.equals(localName)) {
			parseAdvisor(elt, parserContext);
		}
		else if (ASPECT.equals(localName)) {
			parseAspect(elt, parserContext);
		}
	}

	parserContext.popAndRegisterContainingComponent();
	return null;
}
 
Example 19
Source Project: java-technology-stack   Source File: ScriptBeanDefinitionParser.java    License: MIT License 6 votes vote down vote up
/**
 * Resolves the script source from either the '{@code script-source}' attribute or
 * the '{@code inline-script}' element. Logs and {@link XmlReaderContext#error} and
 * returns {@code null} if neither or both of these values are specified.
 */
@Nullable
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
	boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	List<Element> elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
	if (hasScriptSource && !elements.isEmpty()) {
		readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
		return null;
	}
	else if (hasScriptSource) {
		return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
	}
	else if (!elements.isEmpty()) {
		Element inlineElement = elements.get(0);
		return "inline:" + DomUtils.getTextValue(inlineElement);
	}
	else {
		readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
		return null;
	}
}
 
Example 20
Source Project: compass   Source File: DatasourceBeanDefinitionParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 对设置的bean进行properties属性注入
 * @param beanElement
 * @param beanDefinition
 * @param parserContext
 * @return
 */
private BeanDefinition parsePropertyElement(Element beanElement,BeanDefinition beanDefinition,ParserContext parserContext)
{
		if(beanElement==null)
		{
			return beanDefinition;
		}
	List<Element> propertyElements = DomUtils.getChildElementsByTagName(beanElement, PROPERTY);
	if(CollectionUtils.isEmpty(propertyElements))
	{
		return beanDefinition;
	}

	for (Element propertyElement:propertyElements) 
	{
		parserContext.getDelegate().parsePropertyElement(propertyElement, beanDefinition);
	}
	
	return beanDefinition;
}
 
Example 21
@Override
protected void postProcess(BeanDefinitionBuilder definitionBuilder, Element element) {
	Object envValue = DomUtils.getChildElementValueByTagName(element, ENVIRONMENT);
	if (envValue != null) {
		// Specific environment settings defined, overriding any shared properties.
		definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, envValue);
	}
	else {
		// Check whether there is a reference to shared environment properties...
		String envRef = element.getAttribute(ENVIRONMENT_REF);
		if (StringUtils.hasLength(envRef)) {
			definitionBuilder.addPropertyValue(JNDI_ENVIRONMENT, new RuntimeBeanReference(envRef));
		}
	}

	String lazyInit = element.getAttribute(LAZY_INIT_ATTRIBUTE);
	if (StringUtils.hasText(lazyInit) && !DEFAULT_VALUE.equals(lazyInit)) {
		definitionBuilder.setLazyInit(TRUE_VALUE.equals(lazyInit));
	}
}
 
Example 22
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	List<Element> childElements = DomUtils.getChildElementsByTagName(element, "definitions");
	if (!childElements.isEmpty()) {
		List<String> locations = new ArrayList<>(childElements.size());
		for (Element childElement : childElements) {
			locations.add(childElement.getAttribute("location"));
		}
		builder.addPropertyValue("definitions", StringUtils.toStringArray(locations));
	}
	if (element.hasAttribute("check-refresh")) {
		builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));
	}
	if (element.hasAttribute("validate-definitions")) {
		builder.addPropertyValue("validateDefinitions", element.getAttribute("validate-definitions"));
	}
	if (element.hasAttribute("definitions-factory")) {
		builder.addPropertyValue("definitionsFactoryClass", element.getAttribute("definitions-factory"));
	}
	if (element.hasAttribute("preparer-factory")) {
		builder.addPropertyValue("preparerFactoryClass", element.getAttribute("preparer-factory"));
	}
}
 
Example 23
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;
}
 
Example 24
/**
 * Parse a props element.
 */
public Properties parsePropsElement(Element propsEle) {
	ManagedProperties props = new ManagedProperties();
	props.setSource(extractSource(propsEle));
	props.setMergeEnabled(parseMergeAttribute(propsEle));

	List<Element> propEles = DomUtils.getChildElementsByTagName(propsEle, PROP_ELEMENT);
	for (Element propEle : propEles) {
		String key = propEle.getAttribute(KEY_ATTRIBUTE);
		// Trim the text value to avoid unwanted whitespace
		// caused by typical XML formatting.
		String value = DomUtils.getTextValue(propEle).trim();
		TypedStringValue keyHolder = new TypedStringValue(key);
		keyHolder.setSource(extractSource(propEle));
		TypedStringValue valueHolder = new TypedStringValue(value);
		valueHolder.setSource(extractSource(propEle));
		props.put(keyHolder, valueHolder);
	}

	return props;
}
 
Example 25
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
	List<Element> childElements = DomUtils.getChildElementsByTagName(element, "definitions");
	if (!childElements.isEmpty()) {
		List<String> locations = new ArrayList<String>(childElements.size());
		for (Element childElement : childElements) {
			locations.add(childElement.getAttribute("location"));
		}
		builder.addPropertyValue("definitions", locations.toArray(new String[locations.size()]));
	}
	if (element.hasAttribute("check-refresh")) {
		builder.addPropertyValue("checkRefresh", element.getAttribute("check-refresh"));
	}
	if (element.hasAttribute("validate-definitions")) {
		builder.addPropertyValue("validateDefinitions", element.getAttribute("validate-definitions"));
	}
	if (element.hasAttribute("definitions-factory")) {
		builder.addPropertyValue("definitionsFactoryClass", element.getAttribute("definitions-factory"));
	}
	if (element.hasAttribute("preparer-factory")) {
		builder.addPropertyValue("preparerFactoryClass", element.getAttribute("preparer-factory"));
	}
}
 
Example 26
private ManagedList<?> getCallableInterceptors(
		Element element, @Nullable Object source, ParserContext context) {

	ManagedList<Object> interceptors = new ManagedList<>();
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	if (asyncElement != null) {
		Element interceptorsElement = DomUtils.getChildElementByTagName(asyncElement, "callable-interceptors");
		if (interceptorsElement != null) {
			interceptors.setSource(source);
			for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
				BeanDefinitionHolder beanDef = context.getDelegate().parseBeanDefinitionElement(converter);
				if (beanDef != null) {
					beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
					interceptors.add(beanDef);
				}
			}
		}
	}
	return interceptors;
}
 
Example 27
private ManagedList<?> getDeferredResultInterceptors(
		Element element, @Nullable Object source, ParserContext context) {

	ManagedList<Object> interceptors = new ManagedList<>();
	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 = context.getDelegate().parseBeanDefinitionElement(converter);
				if (beanDef != null) {
					beanDef = context.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
					interceptors.add(beanDef);
				}
			}
		}
	}
	return interceptors;
}
 
Example 28
private RuntimeBeanReference registerUserDestHandler(Element brokerElem,
		RuntimeBeanReference userRegistry, RuntimeBeanReference inChannel,
		RuntimeBeanReference brokerChannel, ParserContext context, Object source) {

	Object userDestResolver = registerUserDestResolver(brokerElem, userRegistry, context, source);

	RootBeanDefinition beanDef = new RootBeanDefinition(UserDestinationMessageHandler.class);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(0, inChannel);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(1, brokerChannel);
	beanDef.getConstructorArgumentValues().addIndexedArgumentValue(2, userDestResolver);

	Element relayElement = DomUtils.getChildElementByTagName(brokerElem, "stomp-broker-relay");
	if (relayElement != null && relayElement.hasAttribute("user-destination-broadcast")) {
		String destination = relayElement.getAttribute("user-destination-broadcast");
		beanDef.getPropertyValues().add("broadcastDestination", destination);
	}

	String beanName = registerBeanDef(beanDef, context, source);
	return new RuntimeBeanReference(beanName);
}
 
Example 29
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;
}
 
Example 30
private Map<String, BeanDefinition> parseTableRulesConfig(final Element element) {
    //获取到这个节点对象table-rules
    Element tableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_RULES_TAG);
    //获取到这个table-rule节点的值
    List<Element> tableRuleElements = DomUtils.getChildElementsByTagName(tableRulesElement, ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_RULE_TAG);
    Map<String, BeanDefinition> result = new ManagedMap<>(tableRuleElements.size());
    for (Element each : tableRuleElements) {
        //解析下级节点logic-table属性值作为map的key,解析其他子节点返回一个BeanDefinition对象作为map的value
        result.put(each.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLE_ATTRIBUTE), parseTableRuleConfig(each));
    }
    return result;
}