org.springframework.util.xml.DomUtils Java Examples

The following examples show how to use org.springframework.util.xml.DomUtils. 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
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: ConfigBeanDefinitionParser.java    From spring-analysis-note with 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 File: AbstractJndiLocatingBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #4
Source File: ScriptBeanDefinitionParser.java    From spring-analysis-note with 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 #5
Source File: Jaxb2MarshallerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: CacheAdviceParser.java    From spring-analysis-note with 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 #7
Source File: ShardingJdbcDataSourceBeanDefinitionParser.java    From sharding-jdbc-1.5.1 with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: BeanDefinitionParserDelegate.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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 #9
Source File: AnnotationDrivenBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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 #10
Source File: TxAdviceBeanDefinitionParser.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@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 #11
Source File: AbstractCacheSetupStrategyParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 #12
Source File: BeanDefinitionParserDelegate.java    From blog_demos with 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 #13
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
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 #14
Source File: ConfigBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 #15
Source File: Jaxb2MarshallerBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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
Source File: BeanDefinitionParserDelegate.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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
Source File: BeanDefinitionParserDelegate.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 File: ConfigBeanDefinitionParser.java    From java-technology-stack with 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 File: ScriptBeanDefinitionParser.java    From java-technology-stack with 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 File: DatasourceBeanDefinitionParser.java    From compass with 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
Source File: AbstractJndiLocatingBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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
Source File: TilesConfigurerBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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
Source File: ViewResolversBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
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
Source File: BeanDefinitionParserDelegate.java    From lams with GNU General Public License v2.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 #25
Source File: TilesConfigurerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
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
Source File: AnnotationDrivenBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
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
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
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
Source File: RedissonDefinitionParser.java    From redisson with 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 #30
Source File: PersistenceUnitReader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the {@code mapping-file} XML elements.
 */
protected void parseMappingFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) {
	List<Element> files = DomUtils.getChildElementsByTagName(persistenceUnit, MAPPING_FILE_NAME);
	for (Element element : files) {
		String value = DomUtils.getTextValue(element).trim();
		if (StringUtils.hasText(value)) {
			unitInfo.addMappingFileName(value);
		}
	}
}