001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package javax.management;
009:
010: import java.lang.reflect.Method;
011: import java.io.Serializable;
012:
013: /**
014: * Describes a management operation exposed by an MBean.
015: *
016: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
017: */
018:
019: public class MBeanOperationInfo extends MBeanFeatureInfo implements
020: Serializable, Cloneable {
021: /**
022: * Indicates that the operation is read-like,
023: * it basically returns information.
024: */
025: public static final int INFO = 0;
026:
027: /**
028: * Indicates that the operation is a write-like,
029: * and would modify the MBean in some way, typically by writing some value
030: * or changing a configuration.
031: */
032: public static final int ACTION = 1;
033:
034: /**
035: * Indicates that the operation is a read/write-like.
036: */
037: public static final int ACTION_INFO = 2;
038:
039: /**
040: * Indicates that the operation has an "unknown" nature.
041: */
042: public static final int UNKNOWN = 3;
043:
044: /**
045: * The method's return value.
046: */
047: private String type = null;
048:
049: /**
050: * The signature of the method, that is, the class names of the arguments.
051: */
052: private MBeanParameterInfo[] signature = null;
053:
054: /**
055: * Returns the impact of the method, one of
056: * <CODE>INFO</CODE>, <CODE>ACTION</CODE>, <CODE>ACTION_INFO</CODE>, <CODE>UNKNOWN</CODE>.
057: */
058: private int impact = MBeanOperationInfo.UNKNOWN;
059:
060: /**
061: * Constructs an <CODE>MBeanOperationInfo</CODE> object.
062: *
063: * @param method The <CODE>java.lang.reflect.Method</CODE> object describing the MBean operation.
064: * @param description A human readable description of the operation.
065: */
066: public MBeanOperationInfo(String description, Method method) {
067: super (method.getName(), description);
068: findMethodReturnType(method);
069: findMethodParameterTypes(method);
070: }
071:
072: /**
073: * Constructs an <CODE>MBeanOperationInfo</CODE> object.
074: *
075: * @param name The name of the method.
076: * @param description A human readable description of the operation.
077: * @param signature <CODE>MBeanParameterInfo</CODE> objects describing the parameters(arguments) of the method.
078: * @param type The type of the method'name return value.
079: * @param impact The impact of the method, one of <CODE>INFO, ACTION, ACTION_INFO, UNKNOWN</CODE>.
080: */
081: public MBeanOperationInfo(String name, String description,
082: MBeanParameterInfo[] signature, String type, int impact) {
083: super (name, description);
084: this .signature = signature;
085: this .type = type;
086: this .impact = impact;
087: }
088:
089: public Object clone() {
090: try {
091: return super .clone();
092: } catch (CloneNotSupportedException clonenotsupportedexception) {
093: return null;
094: }
095: }
096:
097: /**
098: * Returns the description of the method's return value.
099: */
100: public String getReturnType() {
101: return type;
102: }
103:
104: /**
105: * Returns the signature of the method, that is, information on the operation's arguments.
106: */
107: public MBeanParameterInfo[] getSignature() {
108: if (signature != null) {
109: int len = signature.length;
110: MBeanParameterInfo[] paramsInfo = new MBeanParameterInfo[len];
111: for (int i = 0; i < len; i++) {
112: paramsInfo[i] = (MBeanParameterInfo) (signature[i])
113: .clone();
114: }
115: return paramsInfo;
116: } else {
117: return new MBeanParameterInfo[0];
118: }
119: }
120:
121: /**
122: * Returns the impact of the method, one of
123: * <CODE>INFO</CODE>, <CODE>ACTION</CODE>, <CODE>ACTION_INFO</CODE>, <CODE>UNKNOWN</CODE>.
124: */
125: public int getImpact() {
126: return impact;
127: }
128:
129: /**
130: * Sets the action signature and parameters.
131: * <P>
132: */
133: private void findMethodParameterTypes(Method method) {
134: String[] sigs = findSignatures(method.getParameterTypes());
135: if (sigs != null) {
136: int len = sigs.length;
137: signature = new MBeanParameterInfo[len];
138: for (int i = 0; i < len; i++) {
139: signature[i] = new MBeanParameterInfo("", sigs[i], "");
140: }
141: }
142: }
143:
144: /**
145: * Converts the array of classes to an array of class signatures.
146: */
147: private String[] findSignatures(Class[] clz) {
148: String signers[] = new String[clz.length];
149: for (int i = 0; i < clz.length; i++) {
150: signers[i] = clz[i].getName();
151: }
152: return signers;
153: }
154:
155: private void findMethodReturnType(Method method) {
156: type = method.getReturnType().getName();
157: }
158: }
|