View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.management.config;
8   
9   import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
10  import org.mule.config.spring.parsers.assembly.BeanAssembler;
11  import org.mule.config.spring.parsers.processors.ProvideDefaultNameFromElement;
12  import org.mule.module.management.agent.JmxAgentConfigurer;
13  import org.mule.util.StringUtils;
14  
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  import org.springframework.beans.factory.xml.ParserContext;
19  import org.w3c.dom.Element;
20  import org.w3c.dom.Node;
21  import org.w3c.dom.NodeList;
22  
23  public class JmxAgentDefinitionParser extends AbstractMuleBeanDefinitionParser
24  {
25      public static final String CONNECTOR_SERVER = "connector-server";
26  
27      public JmxAgentDefinitionParser()
28      {
29          singleton = true;
30          addAlias("server", "mBeanServer");
31          registerPreProcessor(new ProvideDefaultNameFromElement());
32      }
33  
34      protected Class<?> getBeanClass(Element element)
35      {
36          return JmxAgentConfigurer.class;
37      }
38  
39      @Override
40      protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
41      {
42          NodeList childNodes = element.getChildNodes();
43          for (int i = 0; i < childNodes.getLength(); i++)
44          {
45              Node node = childNodes.item(i);
46              if (CONNECTOR_SERVER.equals(node.getLocalName()))
47              {
48                  assembler.extendBean("connectorServerUrl", ((Element) node).getAttribute("url"), false);
49                  String rebind = ((Element) node).getAttribute("rebind");
50  
51                  if (!StringUtils.isEmpty(rebind))
52                  {
53                      Map<String, String> csProps = new HashMap<String, String>();
54                      csProps.put("jmx.remote.jndi.rebind", rebind);
55                      assembler.extendBean("connectorServerProperties", csProps, false);
56                  }
57              }
58          }
59  
60          super.postProcess(context, assembler, element);
61      }
62  
63  }