View Javadoc

1   /*
2    * $Id: BpmNamespaceHandler.java 20933 2011-01-07 16:18:53Z 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.module.bpm.ProcessComponent;
17  import org.mule.module.bpm.RulesComponent;
18  
19  /**
20   * Registers a Bean Definition Parsers for the "bpm" namespace.
21   */
22  public class BpmNamespaceHandler extends AbstractMuleNamespaceHandler
23  {
24      /** 
25       * Allows simple configuration of jBPM from the generic "bpm" namespace.  Otherwise you would need to include both the 
26       * "bpm" and "jbpm" namespaces in your config, which is not really justified.
27       */
28      public static final String JBPM_WRAPPER_CLASS = "org.mule.module.jbpm.Jbpm";
29  
30      /** 
31       * Allows simple configuration of Drools from the generic "bpm" namespace.  Otherwise you would need to include both the 
32       * "bpm" and "drools" namespaces in your config, which is not really justified.
33       */
34      public static final String DROOLS_WRAPPER_CLASS = "org.mule.module.drools.Drools";
35  
36      public void init()
37      {
38          registerBeanDefinitionParser("process", new ProcessComponentDefinitionParser());
39          registerMuleBeanDefinitionParser("process-definition", new ChildMapEntryDefinitionParser("processDefinitions", "name", "resource"));
40          try
41          {
42              registerBeanDefinitionParser("jbpm", new MuleOrphanDefinitionParser(Class.forName(JBPM_WRAPPER_CLASS), true));
43          }
44          catch (ClassNotFoundException e)
45          {
46              logger.debug("Element <bpm:jbpm> will not available because " + JBPM_WRAPPER_CLASS + " is not on the classpath");
47          }
48  
49          registerBeanDefinitionParser("rules", new RulesComponentDefinitionParser());
50          try
51          {
52              registerBeanDefinitionParser("drools", new MuleOrphanDefinitionParser(Class.forName(DROOLS_WRAPPER_CLASS), true));
53          }
54          catch (ClassNotFoundException e)
55          {
56              logger.debug("Element <drools> will not available in the bpm: namespace because it is not on the classpath");
57          }
58      }
59      
60      class ProcessComponentDefinitionParser extends ComponentDefinitionParser
61      {
62          public ProcessComponentDefinitionParser()
63          {
64              super(ProcessComponent.class);
65              addAlias("processName", "name");
66              addAlias("processDefinition", "resource");
67          }
68      }
69  
70      class RulesComponentDefinitionParser extends ComponentDefinitionParser
71      {
72          public RulesComponentDefinitionParser()
73          {
74              super(RulesComponent.class);
75              addAlias("rulesDefinition", "resource");
76          }
77      }
78  }
79