001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package mx4j.server;
010:
011: import java.security.AccessController;
012: import java.security.PrivilegedAction;
013: import javax.management.MBeanInfo;
014: import javax.management.ObjectInstance;
015: import javax.management.ObjectName;
016:
017: import mx4j.MX4JSystemKeys;
018:
019: /**
020: * Objects of this class hold metadata information about MBeans.
021: *
022: * @version $Revision: 1.8 $
023: * @see Factory
024: */
025: public interface MBeanMetaData {
026: /**
027: * Sets the MBean instance
028: *
029: * @see #getMBean
030: */
031: public void setMBean(Object mbean);
032:
033: /**
034: * Returns the MBean instance
035: *
036: * @see #setMBean
037: */
038: public Object getMBean();
039:
040: /**
041: * Sets the classloader for the MBean
042: *
043: * @see #getClassLoader
044: */
045: public void setClassLoader(ClassLoader loader);
046:
047: /**
048: * Returns the classloader for the MBean
049: *
050: * @see #setClassLoader
051: */
052: public ClassLoader getClassLoader();
053:
054: /**
055: * Sets the ObjectName of the MBean
056: *
057: * @see #getObjectName
058: */
059: public void setObjectName(ObjectName name);
060:
061: /**
062: * Returns the ObjectName of the MBean
063: *
064: * @see #setObjectName
065: */
066: public ObjectName getObjectName();
067:
068: /**
069: * Sets the MBeanInfo of the MBean
070: *
071: * @see #getMBeanInfo
072: */
073: public void setMBeanInfo(MBeanInfo info);
074:
075: /**
076: * Returns the MBeanInfo of the MBean
077: *
078: * @see #setMBeanInfo
079: */
080: public MBeanInfo getMBeanInfo();
081:
082: /**
083: * Sets the management interface of the standard MBean
084: *
085: * @see #getMBeanInterface
086: */
087: public void setMBeanInterface(Class management);
088:
089: /**
090: * Returns the management interface of the standard MBean
091: *
092: * @see #setMBeanInterface
093: */
094: public Class getMBeanInterface();
095:
096: /**
097: * Sets whether the MBean is standard
098: *
099: * @see #isMBeanStandard
100: */
101: public void setMBeanStandard(boolean value);
102:
103: /**
104: * Returns whether the MBean is standard
105: *
106: * @see #setMBeanStandard
107: */
108: public boolean isMBeanStandard();
109:
110: /**
111: * Sets whether the MBean is dynamic
112: *
113: * @see #isMBeanDynamic
114: */
115: public void setMBeanDynamic(boolean value);
116:
117: /**
118: * Returns whether the MBean is dynamic
119: *
120: * @see #setMBeanDynamic
121: */
122: public boolean isMBeanDynamic();
123:
124: /**
125: * Sets the MBeanInvoker of the standard MBean
126: *
127: * @see #getMBeanInvoker
128: */
129: public void setMBeanInvoker(MBeanInvoker invoker);
130:
131: /**
132: * Returns the MBeanInvoker of the standard MBean
133: *
134: * @see #getMBeanInvoker
135: */
136: public MBeanInvoker getMBeanInvoker();
137:
138: /**
139: * Returns the ObjectInstance of the MBean
140: *
141: * @see #getMBeanInfo
142: * @see #getObjectName
143: */
144: public ObjectInstance getObjectInstance();
145:
146: /**
147: * Factory class that creates instance of the {@link MBeanMetaData} interface.
148: * The default implementation is {@link MX4JMBeanMetaData}, but it can be overridden
149: * by setting the system property defined by {@link MX4JSystemKeys#MX4J_MBEAN_METADATA}.
150: */
151: public static class Factory {
152: public static MBeanMetaData create() {
153: String className = (String) AccessController
154: .doPrivileged(new PrivilegedAction() {
155: public Object run() {
156: return System
157: .getProperty(MX4JSystemKeys.MX4J_MBEAN_METADATA);
158: }
159: });
160: if (className == null)
161: className = "mx4j.server.MX4JMBeanMetaData";
162:
163: try {
164: try {
165: ClassLoader loader = MBeanMetaData.class
166: .getClassLoader();
167: if (loader == null)
168: loader = Thread.currentThread()
169: .getContextClassLoader();
170: return (MBeanMetaData) loader.loadClass(className)
171: .newInstance();
172: } catch (ClassNotFoundException x) {
173: // Not found with the current classloader, try the context classloader
174: return (MBeanMetaData) Thread.currentThread()
175: .getContextClassLoader().loadClass(
176: className).newInstance();
177: }
178: } catch (Exception x) {
179: throw new Error(x.toString());
180: }
181: }
182: }
183: }
|