Java Code Examples for org.springframework.beans.factory.support.ManagedMap#put()

The following examples show how to use org.springframework.beans.factory.support.ManagedMap#put() . 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: HandlersBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, handlerReference);
	cargs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		urlMap.put(mapping, requestHandlerRef);
	}
}
 
Example 2
Source File: HandlersBeanDefinitionParser.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cargs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**");
		urlMap.put(pathPattern, requestHandlerRef);
	}
}
 
Example 3
Source File: CustomSchemaParser.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Parses a list of elements into a map of beans/standard content.
 *
 * @param grandChildren - The list of beans/content in a bean property
 * @param child - The property tag for the parent.
 * @param parent - The parent bean that the tag is nested in.
 * @param parserContext - Provided information and functionality regarding current bean set.
 * @return A managedSet of the nested content.
 */
protected ManagedMap parseMap(ArrayList<Element> grandChildren, Element child, BeanDefinitionBuilder parent,
        ParserContext parserContext) {
    ManagedMap map = new ManagedMap();

    String merge = child.getAttribute("merge");
    if (merge != null) {
        map.setMergeEnabled(Boolean.valueOf(merge));
    }

    for (int j = 0; j < grandChildren.size(); j++) {
        Object key = findKey(grandChildren.get(j), parent, parserContext);
        Object value = findValue(grandChildren.get(j), parent, parserContext);

        map.put(key, value);
    }

    return map;
}
 
Example 4
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, handlerReference);
	cargs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		urlMap.put(mapping, requestHandlerRef);
	}
}
 
Example 5
Source File: HandlersBeanDefinitionParser.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	String[] mappings = StringUtils.tokenizeToStringArray(pathAttribute, ",");
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cargs = new ConstructorArgumentValues();
	cargs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cargs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cargs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**");
		urlMap.put(pathPattern, requestHandlerRef);
	}
}
 
Example 6
Source File: HandlersBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, this.sockJsService, "SockJsService");
	cavs.addIndexedArgumentValue(1, handlerReference, "WebSocketHandler");

	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(SockJsHttpRequestHandler.class, cavs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		String pathPattern = (mapping.endsWith("/") ? mapping + "**" : mapping + "/**");
		urlMap.put(pathPattern, requestHandlerRef);
	}
}
 
Example 7
Source File: HandlersBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void addMapping(Element element, ManagedMap<String, Object> urlMap, ParserContext context) {
	String pathAttribute = element.getAttribute("path");
	List<String> mappings = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
	RuntimeBeanReference handlerReference = new RuntimeBeanReference(element.getAttribute("handler"));

	ConstructorArgumentValues cavs = new ConstructorArgumentValues();
	cavs.addIndexedArgumentValue(0, handlerReference);
	if (this.handshakeHandlerReference != null) {
		cavs.addIndexedArgumentValue(1, this.handshakeHandlerReference);
	}
	RootBeanDefinition requestHandlerDef = new RootBeanDefinition(WebSocketHttpRequestHandler.class, cavs, null);
	requestHandlerDef.setSource(context.extractSource(element));
	requestHandlerDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	requestHandlerDef.getPropertyValues().add("handshakeInterceptors", this.interceptorsList);
	String requestHandlerName = context.getReaderContext().registerWithGeneratedName(requestHandlerDef);
	RuntimeBeanReference requestHandlerRef = new RuntimeBeanReference(requestHandlerName);

	for (String mapping : mappings) {
		urlMap.put(mapping, requestHandlerRef);
	}
}
 
Example 8
Source File: CommunicationXmlParser.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/** 获取指令策略集合 */
private static ManagedMap<String, Object> getStrategies(Element configurationElement, ParserContext context) {
    // 设置每个执行策略配置
    ManagedMap<String, Object> strategies = new ManagedMap<>();
    String strategyName = configurationElement.getAttribute(AttributeDefinition.REFERENCE.getName());
    strategies.put(StringUtility.EMPTY, new RuntimeBeanReference(strategyName));
    List<Element> elements = XmlUtility.getChildElementsByTagName(configurationElement, ElementDefinition.STRATEGY.getName());
    for (Element element : elements) {
        String name = element.getAttribute(AttributeDefinition.NAME.getName());
        String reference = element.getAttribute(AttributeDefinition.REFERENCE.getName());
        strategies.put(name, new RuntimeBeanReference(reference));
    }
    return strategies;
}
 
Example 9
Source File: DictionaryBeanFactoryPostProcessor.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * Iterates through the map values and calls helpers to process the value
 *
 * @param mapVal the set to process
 * @param propertyName name of the property which has the map value
 * @param nestedBeanStack stack of bean containers which contains the map property
 */
protected void visitMap(Map<?, ?> mapVal, String propertyName, Stack<BeanDefinitionHolder> nestedBeanStack) {
    boolean isMergeEnabled = false;
    if (mapVal instanceof ManagedMap) {
        isMergeEnabled = ((ManagedMap) mapVal).isMergeEnabled();
    }

    ManagedMap newMap = new ManagedMap();
    newMap.setMergeEnabled(isMergeEnabled);

    for (Map.Entry entry : mapVal.entrySet()) {
        Object key = entry.getKey();
        Object val = entry.getValue();

        if (isStringValue(val)) {
            val = processMapStringPropertyValue(propertyName, mapVal, getString(val), key, nestedBeanStack,
                    beanProcessors);
        } else {
            val = visitPropertyValue(propertyName, val, nestedBeanStack);
        }

        newMap.put(key, val);
    }

    mapVal.clear();
    mapVal.putAll(newMap);
}
 
Example 10
Source File: ReferenceBeanDefinitionParser.java    From Thunder with Apache License 2.0 5 votes vote down vote up
private Map parseMethodElements(Element referenceElement, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String methodElementName = ThunderConstant.METHOD_ELEMENT_NAME;
    String methodAttributeName = ThunderConstant.METHOD_ATTRIBUTE_NAME;
    String parameterTypesAttributeName = ThunderConstant.PARAMETER_TYPES_ATTRIBUTE_NAME;

    List<Element> methodElements = DomUtils.getChildElementsByTagName(referenceElement, methodElementName);

    ManagedMap methodMap = new ManagedMap(methodElements.size());
    methodMap.setMergeEnabled(true);
    methodMap.setSource(parserContext.getReaderContext().extractSource(referenceElement));

    for (Element methodElement : methodElements) {
        String method = methodElement.getAttribute(methodAttributeName);
        String parameterTypes = methodElement.getAttribute(parameterTypesAttributeName);

        MethodKey methodKey = new MethodKey();
        methodKey.setMethod(method);
        methodKey.setParameterTypes(parameterTypes);
        if (methodMap.containsKey(methodKey)) {
            throw FrameworkExceptionFactory.createMethodDuplicatedException(methodElementName, methodKey);
        }

        methodMap.put(methodKey, parserContext.getDelegate().parseCustomElement(methodElement, builder.getRawBeanDefinition()));
    }

    return methodMap;
}
 
Example 11
Source File: AbstractBeanDefinitionParser.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void parse(final BeanDefinition definition, final String id, final Element element, final String name,
                  final ParserContext context) {
    NodeList nodes = element.getChildNodes();
    if (nodes != null && nodes.getLength() > 0) {
        ManagedMap parameters = new ManagedMap();
        Node node;
        String key;
        String value;
        boolean hidden;
        for (int i = 0; i < nodes.getLength(); i++) {
            node = nodes.item(i);
            if (node instanceof Element && (PARAMETER.equals(node.getNodeName())
                    || PARAMETER.equals(node.getLocalName()))) {
                key = ((Element) node).getAttribute("key");
                if (!RequestContext.VALID_KEY.test(key)) {
                    throw new IllegalConfigureException("param.key", key, "key can not start with "
                            + Constants.HIDE_KEY_PREFIX + " and " + Constants.INTERNAL_KEY_PREFIX, ExceptionCode.COMMON_ABUSE_HIDE_KEY);
                }
                value = ((Element) node).getAttribute("value");
                hidden = Converts.getBoolean(((Element) node).getAttribute("hide"), Boolean.FALSE);
                if (hidden) {
                    key = Constants.HIDE_KEY_PREFIX + key;
                }
                parameters.put(key, new TypedStringValue(value, String.class));
            }
        }
        if (!parameters.isEmpty()) {
            definition.getPropertyValues().addPropertyValue(name, parameters);
        }
    }
}
 
Example 12
Source File: TxAdviceBeanDefinitionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
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;
}
 
Example 13
Source File: TxAdviceBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 14
Source File: TxAdviceBeanDefinitionParser.java    From spring-analysis-note with MIT License 4 votes vote down vote up
private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) {
	List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT);
	ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap =
			new ManagedMap<>(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<>();
		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;
}
 
Example 15
Source File: MessageBrokerBeanDefinitionParser.java    From spring4-understanding with Apache License 2.0 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.state(StringUtils.hasText(pathAttribute), "Invalid <stomp-endpoint> (no path mapping)");
		List<String> paths = Arrays.asList(StringUtils.tokenizeToStringArray(pathAttribute, ","));
		for (String path : paths) {
			path = path.trim();
			Assert.state(StringUtils.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.<String, Object>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 16
Source File: MessageBrokerBeanDefinitionParser.java    From java-technology-stack 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 17
Source File: TxAdviceBeanDefinitionParser.java    From java-technology-stack with MIT License 4 votes vote down vote up
private RootBeanDefinition parseAttributeSource(Element attrEle, ParserContext parserContext) {
	List<Element> methods = DomUtils.getChildElementsByTagName(attrEle, METHOD_ELEMENT);
	ManagedMap<TypedStringValue, RuleBasedTransactionAttribute> transactionAttributeMap =
			new ManagedMap<>(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<>();
		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;
}
 
Example 18
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 19
Source File: ServiceBeanDefinitionParser.java    From jdal with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public AbstractBeanDefinition parse(Element element, ParserContext parserContext) {
	
	// default dao and service classes
	String daoClassName = JPA_DAO_CLASS_NAME;
	String serviceClassName = PERSISTENT_SERVICE_CLASS_NAME;
	String name = null;
	boolean declareService = false;
	
	if (element.hasAttribute(DAO_CLASS)) 
		daoClassName = element.getAttribute(DAO_CLASS);
	
	if (element.hasAttribute(SERVICE_CLASS)) {
		serviceClassName = element.getAttribute(SERVICE_CLASS);
		declareService = true;
	}
	
	if (element.hasAttribute(NAME))
		name = element.getAttribute(NAME);
		
	if (element.hasAttribute(ENTITY)) {
		String className = element.getAttribute(ENTITY);
		if (name == null) {
			name = StringUtils.uncapitalize(
				StringUtils.substringAfterLast(className, PropertyUtils.PROPERTY_SEPARATOR));
		}
		parserContext.pushContainingComponent(
				new CompositeComponentDefinition(name, parserContext.extractSource(element)));
	
		// Dao
		BeanDefinitionBuilder daoBuilder  = BeanDefinitionBuilder.genericBeanDefinition(daoClassName);
		NodeList nl = element.getElementsByTagNameNS(element.getNamespaceURI(), CRITERIA);
		if (nl.getLength() > 0) {
			ManagedMap<String, BeanReference> builders = new ManagedMap<String, BeanReference>(nl.getLength());
			for (int i = 0; i < nl.getLength(); i++) {
				Element e = (Element) nl.item(i);
				builders.put(e.getAttribute(NAME), new RuntimeBeanReference(e.getAttribute(BUILDER)));
			}
			daoBuilder.addPropertyValue(CRITERIA_BUILDER_MAP, builders);
		}
		
		daoBuilder.addConstructorArgValue(ClassUtils.resolveClassName(className, null));
		daoBuilder.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
		String daoBeanName; 
	
		if (declareService) {
			// use dao suffix
			daoBeanName = name + DAO_SUFFIX;
			registerBeanDefinition(parserContext, daoBuilder, daoBeanName); 
			
			// register service wrapper
			String serviceBeanName = name + SERVICE_SUFFIX;
			BeanDefinitionBuilder serviceBuilder = BeanDefinitionBuilder.genericBeanDefinition(serviceClassName);
			serviceBuilder.addPropertyReference("dao", daoBeanName);
			registerBeanDefinition(parserContext, serviceBuilder, serviceBeanName); 
		}
		else {
			// use service suffix for dao and declare an alias with dao suffix for compatibility with older api.
			daoBeanName = name  + SERVICE_SUFFIX;
			String[] aliases = new String[] { name + DAO_SUFFIX };
			BeanComponentDefinition bcd = new BeanComponentDefinition(daoBuilder.getBeanDefinition(), 
					daoBeanName, aliases);
			parserContext.registerBeanComponent(bcd);
		}
	
		parserContext.popAndRegisterContainingComponent();
	}
	
	return null;
}