View Javadoc

1   /*
2    * $Id: JmxAgentDefinitionParser.java 11234 2008-03-06 23:44:34Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.JmxAgent;
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 JmxAgent.class;
40      }
41  
42      protected void postProcess(ParserContext context, BeanAssembler assembler, Element element)
43      {
44          NodeList childNodes = element.getChildNodes();
45          for (int i = 0; i < childNodes.getLength(); i++) {
46              Node node = childNodes.item(i);
47              if (CONNECTOR_SERVER.equals(node.getLocalName())) {
48                  assembler.extendBean("connectorServerUrl", ((Element) node).getAttribute("url"), false);
49                  String rebind = ((Element) node).getAttribute("rebind");
50                  if (!StringUtils.isEmpty(rebind)) {
51                      Map csProps = new HashMap();
52                      csProps.put("jmx.remote.jndi.rebind", rebind);
53                      assembler.extendBean("connectorServerProperties", csProps, false);
54                  }
55              }
56          }
57          super.postProcess(context, assembler, element);
58      }
59  
60  }