Browse files

Refactored DOMBuilder framework

  • Loading branch information...
1 parent a97f468 commit 16f1a8b25afd539f7537e1d84cc682336eff659f David Turanski committed Oct 30, 2012
View
20 ...pringframework/integration/dsl/groovy/amqp/builder/IntegrationBuilderModuleSupport.groovy
@@ -12,11 +12,14 @@
*/
package org.springframework.integration.dsl.groovy.amqp.builder
+import org.springframework.integration.dsl.groovy.amqp.AmqpOutbound
+import org.springframework.integration.dsl.groovy.amqp.AmqpInbound
import org.springframework.integration.dsl.groovy.amqp.builder.dom.AmqpInboundDomBuilder
import org.springframework.integration.dsl.groovy.amqp.builder.dom.AmqpOutboundDomBuilder
import org.springframework.integration.dsl.groovy.builder.AbstractIntegrationBuilderModuleSupport
import org.springframework.integration.dsl.groovy.builder.IntegrationBuilder
import org.springframework.integration.dsl.groovy.builder.dom.IntegrationDomSupport
+import org.springframework.integration.dsl.groovy.builder.dom.XMLNamespaceSupport;
/**
* @author David Turanski
@@ -45,13 +48,18 @@ class IntegrationBuilderModuleSupport extends AbstractIntegrationBuilderModuleSu
@Override
void registerDomBuilders(IntegrationDomSupport integrationDomSupport) {
- integrationDomSupport.namespaceSupport.addIntegrationNamespace('int-amqp')
- integrationDomSupport.namespaceSupport.addSpringNamespace('rabbit')
- integrationDomSupport.domBuilders['org.springframework.integration.dsl.groovy.amqp.AmqpOutbound'] \
- = new AmqpOutboundDomBuilder(integrationDomSupport:integrationDomSupport)
- integrationDomSupport.domBuilders['org.springframework.integration.dsl.groovy.amqp.AmqpInbound'] \
- = new AmqpInboundDomBuilder(integrationDomSupport:integrationDomSupport)
+ integrationDomSupport.registerDomBuilder (AmqpOutbound.class,
+ new AmqpOutboundDomBuilder())
+ integrationDomSupport.registerDomBuilder(AmqpInbound.class,
+ new AmqpInboundDomBuilder())
}
+
+ @Override
+ public void registerNamespaces(XMLNamespaceSupport namespaceSupport) {
+ namespaceSupport.addIntegrationNamespace('int-amqp')
+ namespaceSupport.addSpringNamespace('rabbit')
+
+ }
}
View
2 ...ngframework/integration/dsl/groovy/builder/AbstractIntegrationBuilderModuleSupport.groovy
@@ -13,6 +13,7 @@
package org.springframework.integration.dsl.groovy.builder
import org.springframework.integration.dsl.groovy.builder.dom.IntegrationDomSupport
+import org.springframework.integration.dsl.groovy.builder.dom.XMLNamespaceSupport
/**
* @author David Turanski
@@ -21,4 +22,5 @@ import org.springframework.integration.dsl.groovy.builder.dom.IntegrationDomSupp
abstract class AbstractIntegrationBuilderModuleSupport {
abstract void registerBuilderFactories(IntegrationBuilder builder)
abstract void registerDomBuilders(IntegrationDomSupport integrationDomSupport)
+ abstract void registerNamespaces(XMLNamespaceSupport namespaceSupport)
}
View
14 .../springframework/integration/dsl/groovy/builder/dom/IntegrationComponentDomBuilder.groovy
@@ -45,10 +45,20 @@ abstract class IntegrationComponentDomBuilder {
doBuild(builder,applicationContext,component,closure)
}
- void build(builder, ApplicationContext applicationContext, component) {
+ /**
+ *
+ * @param builder StreamingMarkupBuilder
+ * @param applicationContext the Spring ApplicationContext
+ * @param component the IntegrationComponent
+ */
+ final void build(builder, ApplicationContext applicationContext, component) {
build(builder, applicationContext, component, null)
}
-
+
+ /**
+ * Convenience method to get the assigned SI core namespace prefix
+ * @return
+ */
protected String getSiPrefix() {
integrationDomSupport.namespaceSupport.integrationNamespacePrefix
}
View
51 ...roovy/org/springframework/integration/dsl/groovy/builder/dom/IntegrationDomSupport.groovy
@@ -27,26 +27,32 @@ import groovy.xml.XmlUtil
class IntegrationDomSupport {
private Log logger = LogFactory.getLog(IntegrationDomSupport)
private XMLNamespaceSupport namespaceSupport = new XMLNamespaceSupport()
+
+ private final domBuilders = [:]
/**
- * Translate DSL context to XML
- * @param integrationContext
- * @return Spring XML bean definitions
+ * Default constructor
*/
-
- private final domBuilders = [:]
-
IntegrationDomSupport() {
registerBuilders()
}
+
+ /**
+ * Constructor to register additional DOM builders for external modules
+ *
+ * @param moduleSupportInstances
+ */
IntegrationDomSupport(List<AbstractIntegrationBuilderModuleSupport> moduleSupportInstances) {
this()
moduleSupportInstances?.each {AbstractIntegrationBuilderModuleSupport moduleSupport ->
moduleSupport.registerDomBuilders(this)
+ moduleSupport.registerNamespaces(this.namespaceSupport)
}
}
-
+ /*
+ * Register core DSL DOM Builders
+ */
private void registerBuilders() {
domBuilders["org.springframework.integration.dsl.groovy.AbstractChannel"]=new ChannelDomBuilder(this)
domBuilders["org.springframework.integration.dsl.groovy.SimpleEndpoint"]=new SimpleEndpointDomBuilder(this)
@@ -59,8 +65,12 @@ class IntegrationDomSupport {
domBuilders["org.springframework.integration.dsl.groovy.XMLBean"]=new SpringXMLBuilder()
}
- IntegrationComponentDomBuilder domBuilder(Class clazz) {
-
+ /**
+ * Get the DOM Builder registered for an IntegrationComponent by its class
+ * @param clazz
+ * @return the builder or null if one does not exist
+ */
+ IntegrationComponentDomBuilder domBuilder(Class clazz) {
def builder = null
if (AbstractChannel.isAssignableFrom(clazz)) {
builder = domBuilders[AbstractChannel.class.name]
@@ -76,16 +86,35 @@ class IntegrationDomSupport {
builder
}
+ /**
+ * Get the DOM Builder assigned to an Integration Component by
+ * its class name
+ * @param className
+ * @return the builder or null if one does not exist
+ */
IntegrationComponentDomBuilder domBuilder(String className) {
domBuilders[className]
}
+ /**
+ * Return the DOM builder for an IntegrationComponent instance
+ * @param component the instance
+ * @return the builder or null if one does not exist
+ */
IntegrationComponentDomBuilder domBuilder(Object component) {
domBuilder(component.class)
}
-
-
+ protected void registerDomBuilder(Class clazz, IntegrationComponentDomBuilder domBuilder) {
+ domBuilder.integrationDomSupport = this;
+ domBuilders[clazz.name] = domBuilder
+ }
+
+ /**
+ * Translate DSL context to XML
+ * @param integrationContext the DSL IntegrationContext
+ * @return Spring XML bean definitions
+ */
def translateToXML(integrationContext) {
resolveXMLBeanNamespaces(integrationContext.components.findAll {it instanceof XMLNamespace} )
View
14 ...pringframework/integration/dsl/groovy/http/builder/IntegrationBuilderModuleSupport.groovy
@@ -14,22 +14,28 @@ package org.springframework.integration.dsl.groovy.http.builder
import org.springframework.integration.dsl.groovy.builder.AbstractIntegrationBuilderModuleSupport
import org.springframework.integration.dsl.groovy.builder.IntegrationBuilder
import org.springframework.integration.dsl.groovy.builder.dom.IntegrationDomSupport
+import org.springframework.integration.dsl.groovy.builder.dom.XMLNamespaceSupport
import org.springframework.integration.dsl.groovy.http.builder.dom.HttpOutboundDomBuilder
-
+import org.springframework.integration.dsl.groovy.http.HttpOutbound
/**
* @author David Turanski
*
*/
class IntegrationBuilderModuleSupport extends AbstractIntegrationBuilderModuleSupport {
+
@Override
void registerBuilderFactories(IntegrationBuilder builder) {
builder.registerFactory 'httpGet', new HttpOutboundFactory()
}
@Override
void registerDomBuilders(IntegrationDomSupport integrationDomSupport) {
- integrationDomSupport.namespaceSupport.addIntegrationNamespace('int-http')
- integrationDomSupport.domBuilders['org.springframework.integration.dsl.groovy.http.HttpOutbound'] \
- = new HttpOutboundDomBuilder(integrationDomSupport:integrationDomSupport)
+ integrationDomSupport.registerDomBuilder(HttpOutbound.class,
+ new HttpOutboundDomBuilder())
+ }
+
+ @Override
+ public void registerNamespaces(XMLNamespaceSupport namespaceSupport) {
+ namespaceSupport.addIntegrationNamespace('int-http')
}
}
View
17 ...springframework/integration/dsl/groovy/jms/builder/IntegrationBuilderModuleSupport.groovy
@@ -11,9 +11,12 @@
* specific language governing permissions and limitations under the License.
*/
package org.springframework.integration.dsl.groovy.jms.builder
+import org.springframework.integration.dsl.groovy.jms.JmsListener
+import org.springframework.integration.dsl.groovy.jms.JmsOutbound
import org.springframework.integration.dsl.groovy.builder.AbstractIntegrationBuilderModuleSupport
import org.springframework.integration.dsl.groovy.builder.IntegrationBuilder
import org.springframework.integration.dsl.groovy.builder.dom.IntegrationDomSupport
+import org.springframework.integration.dsl.groovy.builder.dom.XMLNamespaceSupport;
import org.springframework.integration.dsl.groovy.jms.builder.dom.JmsListenerDomBuilder
import org.springframework.integration.dsl.groovy.jms.builder.dom.JmsOutboundDomBuilder
@@ -32,10 +35,14 @@ class IntegrationBuilderModuleSupport extends AbstractIntegrationBuilderModuleSu
@Override
void registerDomBuilders(IntegrationDomSupport integrationDomSupport) {
- integrationDomSupport.namespaceSupport.addIntegrationNamespace('int-jms')
- integrationDomSupport.domBuilders['org.springframework.integration.dsl.groovy.jms.JmsListener'] \
- = new JmsListenerDomBuilder(integrationDomSupport:integrationDomSupport)
- integrationDomSupport.domBuilders['org.springframework.integration.dsl.groovy.jms.JmsOutbound'] \
- = new JmsOutboundDomBuilder(integrationDomSupport:integrationDomSupport)
+ integrationDomSupport.registerDomBuilder(JmsListener.class,
+ new JmsListenerDomBuilder())
+ integrationDomSupport.registerDomBuilder(JmsOutbound.class,
+ new JmsOutboundDomBuilder())
+ }
+
+ @Override
+ public void registerNamespaces(XMLNamespaceSupport namespaceSupport) {
+ namespaceSupport.addIntegrationNamespace('int-jms')
}
}

0 comments on commit 16f1a8b

Please sign in to comment.