use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.
the class AbstractListenerContainerParser method parseListener.
private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {
RootBeanDefinition listenerDef = new RootBeanDefinition();
listenerDef.setSource(parserContext.extractSource(listenerEle));
listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter");
String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
if (!StringUtils.hasText(ref)) {
parserContext.getReaderContext().error("Listener 'ref' attribute contains empty value.", listenerEle);
} else {
listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
}
String method = null;
if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
if (!StringUtils.hasText(method)) {
parserContext.getReaderContext().error("Listener 'method' attribute contains empty value.", listenerEle);
}
}
listenerDef.getPropertyValues().add("defaultListenerMethod", method);
PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
if (messageConverterPv != null) {
listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
}
BeanDefinition containerDef = createContainer(containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
containerDef.getPropertyValues().add("messageListener", listenerDef);
if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
Boolean pubSubDomain = (Boolean) commonContainerProperties.getPropertyValue("replyPubSubDomain").getValue();
listenerDef.getPropertyValues().add(pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
if (containerDef.getPropertyValues().contains("destinationResolver")) {
listenerDef.getPropertyValues().add("destinationResolver", containerDef.getPropertyValues().getPropertyValue("destinationResolver").getValue());
}
}
String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
// If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
if (!StringUtils.hasText(containerBeanName)) {
containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
}
// Register the listener and fire event
parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.
the class ClearCredentialsMethodInvokingFactoryBean method createPortMapper.
private BeanReference createPortMapper(Element elt, ParserContext pc) {
// Register the portMapper. A default will always be created, even if no element
// exists.
BeanDefinition portMapper = new PortMappingsBeanDefinitionParser().parse(DomUtils.getChildElementByTagName(elt, Elements.PORT_MAPPINGS), pc);
String portMapperName = pc.getReaderContext().generateBeanName(portMapper);
pc.registerBeanComponent(new BeanComponentDefinition(portMapper, portMapperName));
return new RuntimeBeanReference(portMapperName);
}
use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-security by spring-projects.
the class ClearCredentialsMethodInvokingFactoryBean method createPortResolver.
private RuntimeBeanReference createPortResolver(BeanReference portMapper, ParserContext pc) {
RootBeanDefinition portResolver = new RootBeanDefinition(PortResolverImpl.class);
portResolver.getPropertyValues().addPropertyValue("portMapper", portMapper);
String portResolverName = pc.getReaderContext().generateBeanName(portResolver);
pc.registerBeanComponent(new BeanComponentDefinition(portResolver, portResolverName));
return new RuntimeBeanReference(portResolverName);
}
use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project camel by apache.
the class CamelNamespaceHandler method registerEndpoint.
private void registerEndpoint(Element childElement, ParserContext parserContext, String contextId) {
String id = childElement.getAttribute("id");
// must have an id to be registered
if (ObjectHelper.isNotEmpty(id)) {
BeanDefinition definition = endpointParser.parse(childElement, parserContext);
definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
// Need to add this dependency of CamelContext for Spring 3.0
try {
Method method = definition.getClass().getMethod("setDependsOn", String[].class);
method.invoke(definition, (Object) new String[] { contextId });
} catch (Exception e) {
// Do nothing here
}
parserContext.registerBeanComponent(new BeanComponentDefinition(definition, id));
}
}
use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project camel by apache.
the class CamelNamespaceHandler method autoRegisterBeanDefinition.
private void autoRegisterBeanDefinition(String id, BeanDefinition definition, ParserContext parserContext, String contextId) {
// it is a bit cumbersome to work with the spring bean definition parser
// as we kinda need to eagerly register the bean definition on the parser context
// and then later we might find out that we should not have done that in case we have multiple camel contexts
// that would have a id clash by auto registering the same bean definition with the same id such as a producer template
// see if we have already auto registered this id
BeanDefinition existing = autoRegisterMap.get(id);
if (existing == null) {
// no then add it to the map and register it
autoRegisterMap.put(id, definition);
parserContext.registerComponent(new BeanComponentDefinition(definition, id));
if (LOG.isDebugEnabled()) {
LOG.debug("Registered default: {} with id: {} on camel context: {}", new Object[] { definition.getBeanClassName(), id, contextId });
}
} else {
// ups we have already registered it before with same id, but on another camel context
// this is not good so we need to remove all traces of this auto registering.
// end user must manually add the needed XML elements and provide unique ids access all camel context himself.
LOG.debug("Unregistered default: {} with id: {} as we have multiple camel contexts and they must use unique ids." + " You must define the definition in the XML file manually to avoid id clashes when using multiple camel contexts", definition.getBeanClassName(), id);
parserContext.getRegistry().removeBeanDefinition(id);
}
}
Aggregations