Java Code Examples for org.springframework.util.xml.DomUtils#getChildElementByTagName()

The following examples show how to use org.springframework.util.xml.DomUtils#getChildElementByTagName() . 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 spring-analysis-note 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 2
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 3
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 4
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 5
Source File: CustomSchemaParser.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Finds the key of a map entry in the custom schema.
 *
 * @param grandchild - The map entry.
 * @return The object (bean or value) entry key
 */
protected Object findKey(Element grandchild, BeanDefinitionBuilder parent, ParserContext parserContext) {
    String key = grandchild.getAttribute("key");
    if (!key.isEmpty()) {
        return key;
    }

    Element keyTag = DomUtils.getChildElementByTagName(grandchild, "key");
    if (keyTag != null) {
        if (DomUtils.getChildElements(keyTag).isEmpty()) {
            return keyTag.getTextContent();
        } else {
            return parseBean(DomUtils.getChildElements(keyTag).get(0), parent, parserContext);
        }
    }

    return null;
}
 
Example 6
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 7
Source File: ResourcesBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private String registerResourceHandler(ParserContext parserContext, Element element, Object source) {
	String locationAttr = element.getAttribute("location");
	if (!StringUtils.hasText(locationAttr)) {
		parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
		return null;
	}

	ManagedList<String> locations = new ManagedList<String>();
	locations.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(locationAttr)));

	RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
	resourceHandlerDef.setSource(source);
	resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	resourceHandlerDef.getPropertyValues().add("locations", locations);

	String cacheSeconds = element.getAttribute("cache-period");
	if (StringUtils.hasText(cacheSeconds)) {
		resourceHandlerDef.getPropertyValues().add("cacheSeconds", cacheSeconds);
	}

	Element cacheControlElement = DomUtils.getChildElementByTagName(element, "cache-control");
	if (cacheControlElement != null) {
		CacheControl cacheControl = parseCacheControl(cacheControlElement);
		resourceHandlerDef.getPropertyValues().add("cacheControl", cacheControl);
	}

	Element resourceChainElement = DomUtils.getChildElementByTagName(element, "resource-chain");
	if (resourceChainElement != null) {
		parseResourceChain(resourceHandlerDef, parserContext, resourceChainElement, source);
	}

	String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
	parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
	parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
	return beanName;
}
 
Example 8
Source File: ShardingRuleBeanDefinitionParser.java    From shardingsphere with Apache License 2.0 5 votes vote down vote up
private List<BeanDefinition> parseAutoTableRulesConfiguration(final Element element) {
    Element tableRulesElement = DomUtils.getChildElementByTagName(element, ShardingRuleBeanDefinitionTag.AUTO_TABLE_RULES_TAG);
    if (null == tableRulesElement) {
        return Collections.emptyList();
    }
    List<Element> tableRuleElements = DomUtils.getChildElementsByTagName(tableRulesElement, ShardingRuleBeanDefinitionTag.AUTO_TABLE_RULE_TAG);
    List<BeanDefinition> result = new ManagedList<>(tableRuleElements.size());
    for (Element each : tableRuleElements) {
        result.add(parseAutoTableRuleConfiguration(each));
    }
    return result;
}
 
Example 9
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private void registerAnnotationMethodMessageHandler(Element messageBrokerElement,
		RuntimeBeanReference inChannel, RuntimeBeanReference outChannel,
		RuntimeBeanReference converter, RuntimeBeanReference messagingTemplate,
		ParserContext context, Object source) {

	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, inChannel);
	cavs.addIndexedArgumentValue(1, outChannel);
	cavs.addIndexedArgumentValue(2, messagingTemplate);

	MutablePropertyValues values = new MutablePropertyValues();
	String prefixAttribute = messageBrokerElement.getAttribute("application-destination-prefix");
	values.add("destinationPrefixes", Arrays.asList(StringUtils.tokenizeToStringArray(prefixAttribute, ",")));
	values.add("messageConverter", converter);

	RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketAnnotationMethodMessageHandler.class, cavs, values);
	if (messageBrokerElement.hasAttribute("path-matcher")) {
		String pathMatcherRef = messageBrokerElement.getAttribute("path-matcher");
		beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef));
	}

	Element resolversElement = DomUtils.getChildElementByTagName(messageBrokerElement, "argument-resolvers");
	if (resolversElement != null) {
		values.add("customArgumentResolvers", extractBeanSubElements(resolversElement, context));
	}

	Element handlersElement = DomUtils.getChildElementByTagName(messageBrokerElement, "return-value-handlers");
	if (handlersElement != null) {
		values.add("customReturnValueHandlers", extractBeanSubElements(handlersElement, context));
	}

	registerBeanDef(beanDef, context, source);
}
 
Example 10
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void registerAnnotationMethodMessageHandler(Element messageBrokerElement,
		RuntimeBeanReference inChannel, RuntimeBeanReference outChannel,
		RuntimeBeanReference converter, RuntimeBeanReference messagingTemplate,
		ParserContext context, @Nullable Object source) {

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, inChannel);
	cargs.addIndexedArgumentValue(1, outChannel);
	cargs.addIndexedArgumentValue(2, messagingTemplate);

	MutablePropertyValues values = new MutablePropertyValues();
	String prefixAttribute = messageBrokerElement.getAttribute("application-destination-prefix");
	values.add("destinationPrefixes", Arrays.asList(StringUtils.tokenizeToStringArray(prefixAttribute, ",")));
	values.add("messageConverter", converter);

	RootBeanDefinition beanDef = new RootBeanDefinition(WebSocketAnnotationMethodMessageHandler.class, cargs, values);
	if (messageBrokerElement.hasAttribute("path-matcher")) {
		String pathMatcherRef = messageBrokerElement.getAttribute("path-matcher");
		beanDef.getPropertyValues().add("pathMatcher", new RuntimeBeanReference(pathMatcherRef));
	}

	RuntimeBeanReference validatorRef = getValidator(messageBrokerElement, source, context);
	if (validatorRef != null) {
		beanDef.getPropertyValues().add("validator", validatorRef);
	}

	Element resolversElement = DomUtils.getChildElementByTagName(messageBrokerElement, "argument-resolvers");
	if (resolversElement != null) {
		values.add("customArgumentResolvers", extractBeanSubElements(resolversElement, context));
	}

	Element handlersElement = DomUtils.getChildElementByTagName(messageBrokerElement, "return-value-handlers");
	if (handlersElement != null) {
		values.add("customReturnValueHandlers", extractBeanSubElements(handlersElement, context));
	}

	registerBeanDef(beanDef, context, source);
}
 
Example 11
Source File: ShardingSphereAlgorithmBeanDefinitionParser.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
private Properties parsePropsElement(final Element element, final ParserContext parserContext) {
    Element propsElement = DomUtils.getChildElementByTagName(element, ShardingSphereAlgorithmBeanDefinitionTag.PROPS_TAG);
    return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
}
 
Example 12
Source File: InstanceBeanDefinitionParser.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
private Properties parseProperties(final Element element, final ParserContext parserContext) {
    Element propsElement = DomUtils.getChildElementByTagName(element, InstanceBeanDefinitionTag.PROP_TAG);
    return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
}
 
Example 13
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@Nullable
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	String orderAttribute = element.getAttribute("order");
	int order = orderAttribute.isEmpty() ? DEFAULT_MAPPING_ORDER : Integer.valueOf(orderAttribute);

	RootBeanDefinition handlerMappingDef = new RootBeanDefinition(WebSocketHandlerMapping.class);
	handlerMappingDef.setSource(source);
	handlerMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	handlerMappingDef.getPropertyValues().add("order", order);
	String handlerMappingName = context.getReaderContext().registerWithGeneratedName(handlerMappingDef);

	RuntimeBeanReference sockJsService = WebSocketNamespaceUtils.registerSockJsService(
			element, SOCK_JS_SCHEDULER_NAME, context, source);

	HandlerMappingStrategy strategy;
	if (sockJsService != null) {
		strategy = new SockJsHandlerMappingStrategy(sockJsService);
	}
	else {
		RuntimeBeanReference handler = WebSocketNamespaceUtils.registerHandshakeHandler(element, context, source);
		Element interceptElem = DomUtils.getChildElementByTagName(element, "handshake-interceptors");
		ManagedList<Object> interceptors = WebSocketNamespaceUtils.parseBeanSubElements(interceptElem, context);
		String allowedOrigins = element.getAttribute("allowed-origins");
		List<String> origins = Arrays.asList(StringUtils.tokenizeToStringArray(allowedOrigins, ","));
		interceptors.add(new OriginHandshakeInterceptor(origins));
		strategy = new WebSocketHandlerMappingStrategy(handler, interceptors);
	}

	ManagedMap<String, Object> urlMap = new ManagedMap<>();
	urlMap.setSource(source);
	for (Element mappingElement : DomUtils.getChildElementsByTagName(element, "mapping")) {
		strategy.addMapping(mappingElement, urlMap, context);
	}
	handlerMappingDef.getPropertyValues().add("urlMap", urlMap);

	context.registerComponent(new BeanComponentDefinition(handlerMappingDef, handlerMappingName));
	context.popAndRegisterContainingComponent();
	return null;
}
 
Example 14
Source File: AnnotationDrivenBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String getAsyncTimeout(Element element) {
	Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
	return (asyncElement != null) ? asyncElement.getAttribute("default-timeout") : null;
}
 
Example 15
Source File: TransactionManagerParser.java    From spring-ldap with Apache License 2.0 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {

    String contextSourceRef = getString(element, ATT_CONTEXT_SOURCE_REF, ContextSourceParser.DEFAULT_ID);
    String dataSourceRef = element.getAttribute(ATT_DATA_SOURCE_REF);
    String sessionFactoryRef = element.getAttribute(ATT_SESSION_FACTORY_REF);

    if(StringUtils.hasText(dataSourceRef) && StringUtils.hasText(sessionFactoryRef)) {
        throw new IllegalArgumentException(
                String.format("Only one of %s and %s can be specified",
                        ATT_DATA_SOURCE_REF, ATT_SESSION_FACTORY_REF));
    }

    BeanDefinitionBuilder builder;
    if(StringUtils.hasText(dataSourceRef)) {
        builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceAndDataSourceTransactionManager.class);
        builder.addPropertyReference("dataSource", dataSourceRef);
    } else if(StringUtils.hasText(sessionFactoryRef)) {
        builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceAndHibernateTransactionManager.class);
        builder.addPropertyReference("sessionFactory", sessionFactoryRef);
    } else {
        // Standard transaction manager
        builder = BeanDefinitionBuilder.rootBeanDefinition(ContextSourceTransactionManager.class);
    }

    builder.addPropertyReference("contextSource", contextSourceRef);

    Element defaultStrategyChild = DomUtils.getChildElementByTagName(element, Elements.DEFAULT_RENAMING_STRATEGY);
    Element differentSubtreeChild = DomUtils.getChildElementByTagName(element, Elements.DIFFERENT_SUBTREE_RENAMING_STRATEGY);

    if(defaultStrategyChild != null) {
        builder.addPropertyValue("renamingStrategy", parseDefaultRenamingStrategy(defaultStrategyChild));
    }

    if(differentSubtreeChild != null) {
        builder.addPropertyValue("renamingStrategy", parseDifferentSubtreeRenamingStrategy(differentSubtreeChild));
    }

    String id = getString(element, AbstractBeanDefinitionParser.ID_ATTRIBUTE, DEFAULT_ID);

    BeanDefinition beanDefinition = builder.getBeanDefinition();
    parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, id));

    return beanDefinition;
}
 
Example 16
Source File: PersistenceUnitReader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parse the unit info DOM element.
 */
protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version, URL rootUrl)
		throws IOException {

	SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();

	// set JPA version (1.0 or 2.0)
	unitInfo.setPersistenceXMLSchemaVersion(version);

	// set persistence unit root URL
	unitInfo.setPersistenceUnitRootUrl(rootUrl);

	// set unit name
	unitInfo.setPersistenceUnitName(persistenceUnit.getAttribute(UNIT_NAME).trim());

	// set transaction type
	String txType = persistenceUnit.getAttribute(TRANSACTION_TYPE).trim();
	if (StringUtils.hasText(txType)) {
		unitInfo.setTransactionType(PersistenceUnitTransactionType.valueOf(txType));
	}

	// evaluate data sources
	String jtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, JTA_DATA_SOURCE);
	if (StringUtils.hasText(jtaDataSource)) {
		unitInfo.setJtaDataSource(this.dataSourceLookup.getDataSource(jtaDataSource.trim()));
	}

	String nonJtaDataSource = DomUtils.getChildElementValueByTagName(persistenceUnit, NON_JTA_DATA_SOURCE);
	if (StringUtils.hasText(nonJtaDataSource)) {
		unitInfo.setNonJtaDataSource(this.dataSourceLookup.getDataSource(nonJtaDataSource.trim()));
	}

	// provider
	String provider = DomUtils.getChildElementValueByTagName(persistenceUnit, PROVIDER);
	if (StringUtils.hasText(provider)) {
		unitInfo.setPersistenceProviderClassName(provider.trim());
	}

	// exclude unlisted classes
	Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
	if (excludeUnlistedClasses != null) {
		String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
		unitInfo.setExcludeUnlistedClasses(!StringUtils.hasText(excludeText) || Boolean.valueOf(excludeText));
	}

	// set JPA 2.0 shared cache mode
	String cacheMode = DomUtils.getChildElementValueByTagName(persistenceUnit, SHARED_CACHE_MODE);
	if (StringUtils.hasText(cacheMode)) {
		unitInfo.setSharedCacheMode(SharedCacheMode.valueOf(cacheMode));
	}

	// set JPA 2.0 validation mode
	String validationMode = DomUtils.getChildElementValueByTagName(persistenceUnit, VALIDATION_MODE);
	if (StringUtils.hasText(validationMode)) {
		unitInfo.setValidationMode(ValidationMode.valueOf(validationMode));
	}

	parseProperties(persistenceUnit, unitInfo);
	parseManagedClasses(persistenceUnit, unitInfo);
	parseMappingFiles(persistenceUnit, unitInfo);
	parseJarFiles(persistenceUnit, unitInfo);

	return unitInfo;
}
 
Example 17
Source File: MessageBrokerBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public BeanDefinition parse(Element element, ParserContext context) {
	Object source = context.extractSource(element);
	CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
	context.pushContainingComponent(compDefinition);

	Element channelElem = DomUtils.getChildElementByTagName(element, "client-inbound-channel");
	RuntimeBeanReference inChannel = getMessageChannel("clientInboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "client-outbound-channel");
	RuntimeBeanReference outChannel = getMessageChannel("clientOutboundChannel", channelElem, context, source);

	channelElem = DomUtils.getChildElementByTagName(element, "broker-channel");
	RuntimeBeanReference brokerChannel = getMessageChannel("brokerChannel", channelElem, context, source);

	RuntimeBeanReference userRegistry = registerUserRegistry(element, context, source);
	Object userDestHandler = registerUserDestHandler(element, userRegistry, inChannel, brokerChannel, context, source);

	RuntimeBeanReference converter = registerMessageConverter(element, context, source);
	RuntimeBeanReference template = registerMessagingTemplate(element, brokerChannel, converter, context, source);
	registerAnnotationMethodMessageHandler(element, inChannel, outChannel,converter, template, context, source);

	RootBeanDefinition broker = registerMessageBroker(element, inChannel, outChannel, brokerChannel,
			userDestHandler, template, userRegistry, context, source);

	// WebSocket and sub-protocol handling

	ManagedMap<String, Object> urlMap = registerHandlerMapping(element, context, source);
	RuntimeBeanReference stompHandler = registerStompHandler(element, inChannel, outChannel, context, source);
	for (Element endpointElem : DomUtils.getChildElementsByTagName(element, "stomp-endpoint")) {
		RuntimeBeanReference requestHandler = registerRequestHandler(endpointElem, stompHandler, context, source);
		String pathAttribute = endpointElem.getAttribute("path");
		Assert.hasText(pathAttribute, "Invalid <stomp-endpoint> (no path mapping)");
		for (String path : StringUtils.tokenizeToStringArray(pathAttribute, ",")) {
			path = path.trim();
			Assert.hasText(path, () -> "Invalid <stomp-endpoint> path attribute: " + pathAttribute);
			if (DomUtils.getChildElementByTagName(endpointElem, "sockjs") != null) {
				path = (path.endsWith("/") ? path + "**" : path + "/**");
			}
			urlMap.put(path, requestHandler);
		}
	}

	Map<String, Object> scopeMap = Collections.singletonMap("websocket", new SimpSessionScope());
	RootBeanDefinition scopeConfigurer = new RootBeanDefinition(CustomScopeConfigurer.class);
	scopeConfigurer.getPropertyValues().add("scopes", scopeMap);
	registerBeanDefByName("webSocketScopeConfigurer", scopeConfigurer, context, source);

	registerWebSocketMessageBrokerStats(broker, inChannel, outChannel, context, source);

	context.popAndRegisterContainingComponent();
	return null;
}
 
Example 18
Source File: ResourcesBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private String registerResourceHandler(ParserContext parserContext, Element element, Object source) {
	String locationAttr = element.getAttribute("location");
	if (!StringUtils.hasText(locationAttr)) {
		parserContext.getReaderContext().error("The 'location' attribute is required.", parserContext.extractSource(element));
		return null;
	}

	ManagedList<String> locations = new ManagedList<String>();
	locations.addAll(Arrays.asList(StringUtils.commaDelimitedListToStringArray(locationAttr)));

	RootBeanDefinition resourceHandlerDef = new RootBeanDefinition(ResourceHttpRequestHandler.class);
	resourceHandlerDef.setSource(source);
	resourceHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

	MutablePropertyValues values = resourceHandlerDef.getPropertyValues();
	values.add("locations", locations);

	String cacheSeconds = element.getAttribute("cache-period");
	if (StringUtils.hasText(cacheSeconds)) {
		values.add("cacheSeconds", cacheSeconds);
	}

	Element cacheControlElement = DomUtils.getChildElementByTagName(element, "cache-control");
	if (cacheControlElement != null) {
		CacheControl cacheControl = parseCacheControl(cacheControlElement);
		values.add("cacheControl", cacheControl);
	}

	Element resourceChainElement = DomUtils.getChildElementByTagName(element, "resource-chain");
	if (resourceChainElement != null) {
		parseResourceChain(resourceHandlerDef, parserContext, resourceChainElement, source);
	}

	Object manager = MvcNamespaceUtils.getContentNegotiationManager(parserContext);
	if (manager != null) {
		values.add("contentNegotiationManager", manager);
	}

	String beanName = parserContext.getReaderContext().generateBeanName(resourceHandlerDef);
	parserContext.getRegistry().registerBeanDefinition(beanName, resourceHandlerDef);
	parserContext.registerComponent(new BeanComponentDefinition(resourceHandlerDef, beanName));
	return beanName;
}
 
Example 19
Source File: DataSourceBeanDefinitionParser.java    From shardingsphere with Apache License 2.0 4 votes vote down vote up
private Properties parseProperties(final Element element, final ParserContext parserContext) {
    Element propsElement = DomUtils.getChildElementByTagName(element, DataSourceBeanDefinitionTag.PROPS_TAG);
    return null == propsElement ? new Properties() : parserContext.getDelegate().parsePropsElement(propsElement);
}
 
Example 20
Source File: AwsParserUtils.java    From spring-integration-aws with MIT License 4 votes vote down vote up
public static void registerPermissions(Element element,
		BeanDefinitionBuilder executorBuilder,
		ParserContext parserContext) {

	Element permissionsElement = DomUtils.getChildElementByTagName(element,
			"permissions");
	if (permissionsElement != null) {
		Set<Permission> permissions = new HashSet<Permission>();
		NodeList permNodes = permissionsElement.getChildNodes();
		for (int i = 0; i < permNodes.getLength(); i++) {
			Node permNode = permNodes.item(i);
			if (Node.ELEMENT_NODE == permNode.getNodeType()) {
				Element permissionElement = (Element) permNode;
				Permission permission = new Permission(
						permissionElement.getAttribute("label"),
						new HashSet<String>(), new HashSet<String>());

				Element actionsElement = DomUtils.getChildElementByTagName(
						permissionElement, "actions");
				NodeList actionNodes = actionsElement.getChildNodes();
				for (int j = 0; j < actionNodes.getLength(); j++) {
					Node actionNode = actionNodes.item(j);
					if (Node.ELEMENT_NODE == actionNode.getNodeType()) {
						Element actionElement = (Element) actionNode;
						permission.getActions().add(
								actionElement.getTextContent());
					}
				}

				Element accountsElement = DomUtils
						.getChildElementByTagName(permissionElement,
								"aws-accounts");
				NodeList accountNodes = accountsElement.getChildNodes();
				for (int j = 0; j < accountNodes.getLength(); j++) {
					Node accountNode = accountNodes.item(j);
					if (Node.ELEMENT_NODE == accountNode.getNodeType()) {
						Element accountElement = (Element) accountNode;
						permission.getAwsAccountIds().add(
								accountElement.getTextContent());
					}
				}

				permissions.add(permission);
			}
		}

		executorBuilder.addPropertyValue("permissions", permissions);
	}
}