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 javax.management;
010:
011: import java.io.Serializable;
012: import java.lang.reflect.Method;
013:
014: import mx4j.util.Utils;
015:
016: /**
017: * Metadata class for an MBean operation
018: *
019: * @version $Revision: 1.13 $
020: */
021: // Change not needed, workaround to a TCK bug only to achieve TCK compliance
022: // public class MBeanOperationInfo extends MBeanFeatureInfo implements Cloneable
023: public class MBeanOperationInfo extends MBeanFeatureInfo implements
024: Cloneable, Serializable {
025: private static final long serialVersionUID = -6178860474881375330L;
026:
027: /**
028: * This impact means the operation is read-like.
029: */
030: public static final int INFO = 0;
031: /**
032: * This impact means the operation is write-like.
033: */
034: public static final int ACTION = 1;
035: /**
036: * This impact means the operation is both read-like and write-like.
037: */
038: public static final int ACTION_INFO = 2;
039: /**
040: * This impact means the operation impact is unknown.
041: */
042: public static final int UNKNOWN = 3;
043:
044: /**
045: * @serial The operation signature
046: */
047: private MBeanParameterInfo[] signature;
048: /**
049: * The operation return type
050: */
051: private String type;
052: /**
053: * The operation impact
054: */
055: private int impact;
056:
057: /**
058: * Creates a new MBeanOperationInfo.
059: *
060: * @param description The operation description
061: * @param method The method
062: */
063: public MBeanOperationInfo(String description, Method method) {
064: super (method.getName(), description);
065: Class[] params = method.getParameterTypes();
066: this .signature = new MBeanParameterInfo[params.length];
067: for (int i = 0; i < params.length; ++i) {
068: this .signature[i] = new MBeanParameterInfo("", params[i]
069: .getName(), "");
070: }
071: this .type = method.getReturnType().getName();
072: this .impact = UNKNOWN;
073: }
074:
075: /**
076: * Creates a new MBeanOperationInfo
077: *
078: * @param name The operation name
079: * @param description The operation description
080: * @param signature The operation signature
081: * @param type The operation return type
082: * @param impact The operation impact
083: */
084: public MBeanOperationInfo(String name, String description,
085: MBeanParameterInfo[] signature, String type, int impact) {
086: super (name, description);
087: this .signature = signature == null ? new MBeanParameterInfo[0]
088: : signature;
089: this .type = type;
090: this .impact = impact;
091: }
092:
093: public Object clone() {
094: try {
095: return super .clone();
096: } catch (CloneNotSupportedException ignored) {
097: return null;
098: }
099: }
100:
101: /**
102: * Returns the return type of the operation
103: */
104: public String getReturnType() {
105: return type;
106: }
107:
108: /**
109: * Returns the signature of the operation
110: */
111: public MBeanParameterInfo[] getSignature() {
112: return signature;
113: }
114:
115: /**
116: * Returns the impact of the operation
117: */
118: public int getImpact() {
119: return impact;
120: }
121:
122: public int hashCode() {
123: int hash = super .hashCode();
124:
125: String type = getReturnType();
126: if (type != null)
127: hash = 29 * hash + type.hashCode();
128: hash = 29 * hash + Utils.arrayHashCode(getSignature());
129: hash = 29 * hash + getImpact();
130:
131: return hash;
132: }
133:
134: public boolean equals(Object obj) {
135: if (!super .equals(obj))
136: return false;
137: if (!(obj instanceof MBeanOperationInfo))
138: return false;
139:
140: MBeanOperationInfo other = (MBeanOperationInfo) obj;
141:
142: String this Type = getReturnType();
143: String otherType = other.getReturnType();
144: if (this Type != null ? !this Type.equals(otherType)
145: : otherType != null)
146: return false;
147: if (!Utils.arrayEquals(getSignature(), other.getSignature()))
148: return false;
149: if (getImpact() != other.getImpact())
150: return false;
151:
152: return true;
153: }
154: }
|