KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > support > AutoDiscoveryJmxSupportFactory


1 /*
2  * $Id: AutoDiscoveryJmxSupportFactory.java 4219 2006-12-09 10:15:14Z lajos $
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 MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10 package org.mule.management.support;
11
12 import org.apache.commons.logging.Log;
13 import org.apache.commons.logging.LogFactory;
14 import org.mule.util.ClassUtils;
15
16 import javax.management.ObjectName JavaDoc;
17 import java.lang.reflect.Method JavaDoc;
18
19 /**
20  * Will discover if newer JMX version is available, otherwise fallback to JMX 1.1
21  * style support.
22  */

23 public class AutoDiscoveryJmxSupportFactory implements JmxSupportFactory
24 {
25     /**
26      * logger used by this class
27      */

28     private transient Log logger = LogFactory.getLog(getClass());
29
30     /**
31      * Will try to detect if JMX 1.2 or later is available, otherwise will fallback
32      * to the JMX 1.1 version of the support class.
33      *
34      * @return matching support class instance
35      * @see JmxLegacySupport
36      */

37     public JmxSupport newJmxSupport()
38     {
39         // TODO cache the support class instance
40
Class JavaDoc clazz = ObjectName JavaDoc.class;
41         // method escape() is available since JMX 1.2
42
Method JavaDoc method = ClassUtils.getMethod("quote", new Class JavaDoc[]{String JavaDoc.class}, clazz);
43
44         final boolean jmxModernAvailable = method == null;
45         final JmxSupport jmxSupport;
46         // tertiary operand does not work anymore after hiererachy refactoring ?!
47
if (jmxModernAvailable)
48         {
49             jmxSupport = new JmxModernSupport();
50         }
51         else
52         {
53             jmxSupport = new JmxLegacySupport();
54         }
55         if (logger.isDebugEnabled())
56         {
57             logger.debug("JMX support instance is " + jmxSupport);
58         }
59         return jmxSupport;
60     }
61
62 }
63
Popular Tags