01: /*
02: * $Id: ChildEndpointDefinitionParser.java 10790 2008-02-12 20:53:32Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
10:
11: package org.mule.config.spring.parsers.specific.endpoint.support;
12:
13: import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
14: import org.mule.config.spring.parsers.generic.AutoIdUtils;
15: import org.mule.config.spring.parsers.generic.ChildDefinitionParser;
16: import org.mule.util.StringUtils;
17: import org.mule.endpoint.AbstractEndpointBuilder;
18:
19: import org.springframework.beans.factory.support.BeanDefinitionBuilder;
20: import org.springframework.beans.factory.xml.ParserContext;
21: import org.w3c.dom.Element;
22:
23: /**
24: * A parser for "embedded" endpoints - ie inbound, outbound and response endpoints.
25: * Because we have automatic String -> MuleEnpointURI conversin via property editors
26: * this can be used in a variety of ways. It should work directly with a simple String
27: * address attribute or, in combination with a child element (handled by
28: * {@link ChildAddressDefinitionParser},
29: * or embedded in
30: * {@link AddressedEndpointDefinitionParser}
31: * for a more compact single-eleent approach.
32: *
33: * <p>This class does support references to other endpoints.</p>
34: * TODO - check that references are global!
35: */
36: public class ChildEndpointDefinitionParser extends
37: ChildDefinitionParser {
38:
39: public ChildEndpointDefinitionParser(Class endpoint) {
40: super ("endpoint", endpoint);
41: addIgnored(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF);
42: EndpointUtils.addProperties(this );
43: EndpointUtils.addPostProcess(this );
44: }
45:
46: // @Override
47: public BeanDefinitionBuilder createBeanDefinitionBuilder(
48: Element element, Class beanClass) {
49: BeanDefinitionBuilder builder = super
50: .createBeanDefinitionBuilder(element, beanClass);
51: String global = element
52: .getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF);
53: if (StringUtils.isNotBlank(global)) {
54: builder.addConstructorArgReference(global);
55: builder.addDependsOn(global);
56: }
57: return builder;
58: }
59:
60: // @Override
61: public String getBeanName(Element element) {
62: if (null != element
63: .getAttributeNode(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF)) {
64: return AutoIdUtils
65: .uniqueValue("ref:"
66: + element
67: .getAttribute(AbstractMuleBeanDefinitionParser.ATTRIBUTE_REF));
68: } else {
69: return super .getBeanName(element);
70: }
71: }
72:
73: //@Override
74: protected void parseChild(Element element,
75: ParserContext parserContext, BeanDefinitionBuilder builder) {
76: // Not sure if this is required. Adding for now for backwards compatability
77: if (element.getParentNode().getNodeName().equals(
78: "chaining-router")
79: || element.getParentNode().getNodeName().equals(
80: "exception-based-router")) {
81: builder.addPropertyValue(
82: AbstractEndpointBuilder.PROPERTY_REMOTE_SYNC,
83: Boolean.TRUE);
84: }
85:
86: super.parseChild(element, parserContext, builder);
87: }
88:
89: }
|