View Javadoc

1   /*
2    * $Id: BpmNamespaceHandler.java 19710 2010-09-23 16:29:07Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.bpm.config;
11  
12  import org.mule.config.spring.handlers.AbstractMuleNamespaceHandler;
13  import org.mule.config.spring.parsers.collection.ChildMapEntryDefinitionParser;
14  import org.mule.config.spring.parsers.generic.MuleOrphanDefinitionParser;
15  import org.mule.config.spring.parsers.specific.ComponentDefinitionParser;
16  import org.mule.config.spring.parsers.specific.RouterDefinitionParser;
17  import org.mule.endpoint.URIBuilder;
18  import org.mule.module.bpm.Process;
19  import org.mule.module.bpm.ProcessComponent;
20  import org.mule.routing.outbound.EndpointSelector;
21  import org.mule.transport.bpm.ProcessConnector;
22  import org.mule.transport.bpm.jbpm.JBpmConnector;
23  
24  import org.springframework.beans.factory.support.BeanDefinitionBuilder;
25  import org.springframework.beans.factory.xml.ParserContext;
26  import org.w3c.dom.Element;
27  
28  /**
29   * Registers a Bean Definition Parsers for the "bpm" namespace.
30   */
31  public class BpmNamespaceHandler extends AbstractMuleNamespaceHandler
32  {
33      public static final String PROCESS = "process";
34  
35      /** 
36       * Allows simple configuration of jBPM from the generic "bpm" namespace.  Otherwise you would need to include both the 
37       * "bpm" and "jbpm" namespaces in your config, which is not really justified.
38       */
39      public static final String JBPM_WRAPPER_CLASS = "org.mule.module.jbpm.Jbpm";
40  
41      public void init()
42      {
43          registerStandardTransportEndpoints(ProcessConnector.PROTOCOL, new String[]{PROCESS}).addAlias(PROCESS, URIBuilder.PATH);
44          registerConnectorDefinitionParser(ProcessConnector.class);
45          registerBeanDefinitionParser("outbound-router", new BpmOutboundRouterDefinitionParser());
46          
47          registerBeanDefinitionParser("process", new ProcessComponentDefinitionParser());
48  
49          registerMuleBeanDefinitionParser("process-definition", new ChildMapEntryDefinitionParser("processDefinitions", "name", "resource"));
50  
51          try
52          {
53              registerBeanDefinitionParser("jbpm", new MuleOrphanDefinitionParser(Class.forName(JBPM_WRAPPER_CLASS), true));
54          }
55          catch (ClassNotFoundException e)
56          {
57              logger.warn(e.getMessage());
58          }
59          registerBeanDefinitionParser("jbpm-connector", new MuleOrphanDefinitionParser(JBpmConnector.class, true));
60      }
61  
62      /**
63       * This is merely a shortcut for:
64       *   <endpoint-selector-router evaluator="header" expression="MULE_BPM_ENDPOINT"> 
65       * @deprecated It is recommended to configure BPM as a component rather than a transport for 3.x
66       */
67      class BpmOutboundRouterDefinitionParser extends RouterDefinitionParser
68      {
69          public BpmOutboundRouterDefinitionParser()
70          {
71              super(EndpointSelector.class);
72          }
73  
74          protected void parseChild(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
75          {
76              builder.addPropertyValue("evaluator", "header");
77              builder.addPropertyValue("expression", Process.PROPERTY_ENDPOINT);
78              super.parseChild(element, parserContext, builder);
79          }        
80      }
81      
82      class ProcessComponentDefinitionParser extends ComponentDefinitionParser
83      {
84          public ProcessComponentDefinitionParser()
85          {
86              super(ProcessComponent.class);
87              addAlias("processName", "name");
88              addAlias("processDefinition", "resource");
89          }
90      }
91  }
92