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.MBeanConstructorInfo;
029: import javax.management.MBeanParameterInfo;
030:
031: /**
032: * OpenMBeanConstructorInfo implementation
033: *
034: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
035: *
036: * @version $Revision: 57200 $
037: *
038: */
039: public class OpenMBeanConstructorInfoSupport extends
040: MBeanConstructorInfo implements OpenMBeanConstructorInfo,
041: Serializable {
042: // Constants -----------------------------------------------------
043:
044: private static final long serialVersionUID = -4400441579007477003L;
045:
046: // Attributes ----------------------------------------------------
047:
048: private transient int cachedHashCode;
049:
050: private transient String cachedToString;
051:
052: // Static --------------------------------------------------------
053:
054: private static MBeanParameterInfo[] convertArray(
055: OpenMBeanParameterInfo[] array) {
056: if (array == null)
057: return null;
058: MBeanParameterInfo[] result = new MBeanParameterInfo[array.length];
059: System.arraycopy(array, 0, result, 0, array.length);
060: return result;
061: }
062:
063: // Constructors --------------------------------------------------
064:
065: /**
066: * Contruct an OpenMBeanConstructorInfoSupport<p>
067: *
068: * @param name cannot be null or empty
069: * @param description cannot be null or empty
070: * @param signature the parameters of the constructor
071: * @exception IllegalArgumentException when one of the above
072: * constraints is not satisfied
073: */
074: public OpenMBeanConstructorInfoSupport(String name,
075: String description, OpenMBeanParameterInfo[] signature) {
076: super (name, description, convertArray(signature));
077: if (name == null)
078: throw new IllegalArgumentException("null name");
079: if (name.trim().length() == 0)
080: throw new IllegalArgumentException("empty name");
081: if (description == null)
082: throw new IllegalArgumentException("null description");
083: if (description.trim().length() == 0)
084: throw new IllegalArgumentException("empty description");
085: }
086:
087: // Public --------------------------------------------------------
088:
089: // OpenMBeanConstructorInfo Implementation -----------------------
090:
091: // Object Overrides ----------------------------------------------
092:
093: public boolean equals(Object obj) {
094: if (this == obj)
095: return true;
096: if (obj == null
097: || !(obj instanceof OpenMBeanConstructorInfoSupport))
098: return false;
099: OpenMBeanConstructorInfo other = (OpenMBeanConstructorInfo) obj;
100:
101: if (getName().equals(other.getName()) == false)
102: return false;
103:
104: if (Arrays.asList(getSignature()).equals(
105: Arrays.asList(other.getSignature())) == false)
106: return false;
107:
108: return true;
109: }
110:
111: public int hashCode() {
112: if (cachedHashCode != 0)
113: return cachedHashCode;
114: cachedHashCode = getName().hashCode();
115: cachedHashCode += Arrays.asList(getSignature()).hashCode();
116: return cachedHashCode;
117: }
118:
119: public String toString() {
120: if (cachedToString != null)
121: return cachedToString;
122: StringBuffer buffer = new StringBuffer(getClass().getName());
123: buffer.append(": name=");
124: buffer.append(getName());
125: buffer.append(", signature=");
126: buffer.append(Arrays.asList(getSignature()));
127: cachedToString = buffer.toString();
128: return cachedToString;
129: }
130:
131: // Protected -----------------------------------------------------
132:
133: // Private -------------------------------------------------------
134:
135: // Inner Classes -------------------------------------------------
136: }
|