View Javadoc

1   /*
2    * $Id: JmxAgentDefinitionParser.java 19191 2010-08-25 21:05:23Z 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.management.config;
11  
12  import org.mule.config.spring.parsers.AbstractMuleBeanDefinitionParser;
13  import org.mule.config.spring.parsers.assembly.BeanAssembler;
14  import org.mule.config.spring.parsers.processors.ProvideDefaultNameFromElement;
15  import org.mule.module.management.agent.JmxAgentConfigurer;
16  import org.mule.util.StringUtils;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.springframework.beans.factory.xml.ParserContext;
22  import org.w3c.dom.Element;
23  import org.w3c.dom.Node;
24  import org.w3c.dom.NodeList;
25  
26  public class JmxAgentDefinitionParser extends AbstractMuleBeanDefinitionParser
27  {
28      public static final String CONNECTOR_SERVER = "connector-server";
29  
30      public JmxAgentDefinitionParser()
31      {
32          singleton = true;
33          addAlias("server", "mBeanServer");
34          registerPreProcessor(new ProvideDefaultNameFromElement());
35      }
36  
37      protected Class<?> getBeanClass(Element element)
38      {
39          return JmxAgentConfigurer.class;
40      }
41  
42      @Override
43      protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
44      {
45          NodeList childNodes = element.getChildNodes();
46          for (int i = 0; i < childNodes.getLength(); i++)
47          {
48              Node node = childNodes.item(i);
49              if (CONNECTOR_SERVER.equals(node.getLocalName()))
50              {
51                  assembler.extendBean("connectorServerUrl", ((Element) node).getAttribute("url"), false);
52                  String rebind = ((Element) node).getAttribute("rebind");
53  
54                  if (!StringUtils.isEmpty(rebind))
55                  {
56                      Map<String, String> csProps = new HashMap<String, String>();
57                      csProps.put("jmx.remote.jndi.rebind", rebind);
58                      assembler.extendBean("connectorServerProperties", csProps, false);
59                  }
60              }
61          }
62  
63          super.postProcess(context, assembler, element);
64      }
65  
66  }