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: */package javax.management.openmbean;
008:
009: import java.io.Serializable;
010: import java.util.Arrays;
011: import javax.management.MBeanOperationInfo;
012: import javax.management.MBeanParameterInfo;
013:
014: /**
015: * @version $Revision: 1.11 $
016: */
017: public class OpenMBeanOperationInfoSupport extends MBeanOperationInfo
018: implements OpenMBeanOperationInfo, Serializable {
019: private static final long serialVersionUID = 4996859732565369366L;
020:
021: private OpenType returnOpenType;
022:
023: private transient int hashCode = 0;
024: private transient String toStringName = null;
025:
026: public OpenMBeanOperationInfoSupport(String name,
027: String description, OpenMBeanParameterInfo[] signature,
028: OpenType returntype, int impact) {
029: super (name, description,
030: (signature == null) ? (MBeanParameterInfo[]) Arrays
031: .asList(new OpenMBeanParameterInfo[0]).toArray(
032: new MBeanParameterInfo[0])
033: : (MBeanParameterInfo[]) Arrays.asList(
034: signature).toArray(
035: new MBeanParameterInfo[0]),
036: returntype == null ? "" : returntype.getClassName(),
037: impact);
038:
039: // Superclass constructors don't do the necessary validation
040: if (name == null || name.length() == 0)
041: throw new IllegalArgumentException(
042: "name cannot be null or empty");
043:
044: if (description == null || description.length() == 0)
045: throw new IllegalArgumentException(
046: "descripiton cannot be null or empty");
047:
048: if (returntype == null)
049: throw new IllegalArgumentException(
050: "return open type cannont be null");
051:
052: if (impact != MBeanOperationInfo.ACTION
053: && impact != MBeanOperationInfo.ACTION_INFO
054: && impact != MBeanOperationInfo.INFO
055: && impact != MBeanOperationInfo.UNKNOWN) {
056: throw new IllegalArgumentException("invalid impact");
057: }
058:
059: if (signature != null
060: && signature.getClass().isInstance(
061: MBeanParameterInfo[].class)) {
062: throw new ArrayStoreException(
063: "signature elements can't be assigned to MBeanParameterInfo");
064: }
065:
066: this .returnOpenType = returntype;
067: }
068:
069: public OpenType getReturnOpenType() {
070: return returnOpenType;
071: }
072:
073: public boolean equals(Object obj) {
074: if (obj == null)
075: return false;
076: if (obj == this )
077: return true;
078: if (!(obj instanceof OpenMBeanOperationInfo))
079: return false;
080:
081: OpenMBeanOperationInfo other = (OpenMBeanOperationInfo) obj;
082:
083: String this Name = getName();
084: String otherName = other.getName();
085: if (this Name != null ? !this Name.equals(otherName)
086: : otherName != null)
087: return false;
088:
089: if (other.getImpact() != getImpact())
090: return false;
091:
092: OpenType this Return = getReturnOpenType();
093: OpenType otherReturn = other.getReturnOpenType();
094: if (this Return != null ? !this Return.equals(otherReturn)
095: : otherReturn != null)
096: return false;
097:
098: if (!Arrays.equals(getSignature(), other.getSignature()))
099: return false;
100:
101: return true;
102: }
103:
104: public int hashCode() {
105: if (hashCode == 0) {
106: int result = getName().hashCode();
107: result += getReturnOpenType().hashCode();
108: result += getImpact();
109: result += java.util.Arrays.asList(getSignature())
110: .hashCode();
111: hashCode = result;
112: }
113: return hashCode;
114: }
115:
116: public String toString() {
117: if (toStringName == null) {
118: StringBuffer sb = new StringBuffer();
119: sb.append(getClass().getName());
120: sb.append("(name=");
121: sb.append(getName());
122: sb.append(",signature=");
123: sb.append(java.util.Arrays.asList(getSignature())
124: .toString());
125: sb.append(",returnOpenType=");
126: sb.append(returnOpenType.toString());
127: sb.append(",impact=");
128: sb.append(getImpact());
129: sb.append(")");
130:
131: toStringName = sb.toString();
132: }
133: return toStringName;
134: }
135: }
|