001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package javax.management.openmbean;
023:
024: import java.io.Serializable;
025:
026: import java.util.Arrays;
027:
028: import javax.management.MBeanOperationInfo;
029: import javax.management.MBeanParameterInfo;
030:
031: /**
032: * OpenMBeanOperationInfo implementation
033: *
034: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
035: *
036: * @version $Revision: 57200 $
037: *
038: */
039: public class OpenMBeanOperationInfoSupport extends MBeanOperationInfo
040: implements OpenMBeanOperationInfo, Serializable {
041: // Constants -----------------------------------------------------
042:
043: private static final long serialVersionUID = 4996859732565369366L;
044:
045: // Attributes ----------------------------------------------------
046:
047: /**
048: * The open type of the return value
049: */
050: private OpenType returnOpenType;
051:
052: private transient int cachedHashCode;
053:
054: private transient String cachedToString;
055:
056: // Static --------------------------------------------------------
057:
058: private static MBeanParameterInfo[] convertArray(
059: OpenMBeanParameterInfo[] array) {
060: if (array == null)
061: return null;
062: MBeanParameterInfo[] result = new MBeanParameterInfo[array.length];
063: System.arraycopy(array, 0, result, 0, array.length);
064: return result;
065: }
066:
067: // Constructors --------------------------------------------------
068:
069: /**
070: * Contruct an OpenMBeanOperationInfoSupport<p>
071: *
072: * @param name cannot be null or empty
073: * @param description cannot be null or empty
074: * @param signature the parameters of the operation
075: * @param returnOpenType the open type of the return value
076: * @param impact the impact of the operation
077: * @exception IllegalArgumentException when one of the above
078: * constraints is not satisfied
079: */
080: public OpenMBeanOperationInfoSupport(String name,
081: String description, OpenMBeanParameterInfo[] signature,
082: OpenType returnOpenType, int impact) {
083: super (name, description, convertArray(signature),
084: returnOpenType == null ? null : returnOpenType
085: .getClassName(), impact);
086: if (name == null)
087: throw new IllegalArgumentException("null name");
088: if (name.trim().length() == 0)
089: throw new IllegalArgumentException("empty name");
090: if (description == null)
091: throw new IllegalArgumentException("null description");
092: if (description.trim().length() == 0)
093: throw new IllegalArgumentException("empty description");
094: if (returnOpenType == null)
095: throw new IllegalArgumentException("null return open type");
096: if (impact != ACTION && impact != ACTION_INFO && impact != INFO)
097: throw new IllegalArgumentException("Invalid action");
098:
099: this .returnOpenType = returnOpenType;
100: }
101:
102: // Public --------------------------------------------------------
103:
104: public OpenType getReturnOpenType() {
105: return returnOpenType;
106: }
107:
108: // OpenMBeanOperationInfo Implementation -------------------------
109:
110: // Object Overrides ----------------------------------------------
111:
112: public boolean equals(Object obj) {
113: if (this == obj)
114: return true;
115: if (obj == null
116: || !(obj instanceof OpenMBeanOperationInfoSupport))
117: return false;
118: OpenMBeanOperationInfo other = (OpenMBeanOperationInfo) obj;
119:
120: if (getName().equals(other.getName()) == false)
121: return false;
122:
123: if (getReturnOpenType().equals(other.getReturnOpenType()) == false)
124: return false;
125:
126: if (Arrays.asList(getSignature()).equals(
127: Arrays.asList(other.getSignature())) == false)
128: return false;
129:
130: if (getImpact() != other.getImpact())
131: return false;
132:
133: return true;
134: }
135:
136: public int hashCode() {
137: if (cachedHashCode != 0)
138: return cachedHashCode;
139: cachedHashCode = getName().hashCode();
140: cachedHashCode += getReturnOpenType().hashCode();
141: cachedHashCode += Arrays.asList(getSignature()).hashCode();
142: cachedHashCode += getImpact();
143: return cachedHashCode;
144: }
145:
146: public String toString() {
147: if (cachedToString != null)
148: return cachedToString;
149: StringBuffer buffer = new StringBuffer(getClass().getName());
150: buffer.append(": name=");
151: buffer.append(getName());
152: buffer.append(", returnOpenType=");
153: buffer.append(getReturnOpenType());
154: buffer.append(", signature=");
155: buffer.append(Arrays.asList(getSignature()));
156: buffer.append(", impact=");
157: switch (getImpact()) {
158: case ACTION:
159: buffer.append("ACTION");
160: break;
161: case ACTION_INFO:
162: buffer.append("ACTION_INFO");
163: break;
164: case INFO:
165: buffer.append("INFO");
166: break;
167: default:
168: buffer.append("UNKNOWN");
169: }
170: cachedToString = buffer.toString();
171: return cachedToString;
172: }
173:
174: // Protected -----------------------------------------------------
175:
176: // Private -------------------------------------------------------
177:
178: // Inner Classes -------------------------------------------------
179: }
|