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;
023:
024: import java.util.Arrays;
025:
026: /**
027: * Describes a constructor exposed by an MBean
028: *
029: * This implementation protects its immutability by taking shallow clones of all arrays
030: * supplied in constructors and by returning shallow array clones in getXXX() methods.
031: *
032: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
033: * @author <a href="mailto:trevor@protocool.com">Trevor Squires</a>.
034: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
035: *
036: * @version $Revision: 57200 $
037: *
038: * <p><b>Revisions:</b>
039: * <p><b>20020711 Adrian Brock:</b>
040: * <ul>
041: * <li> Serialization </li>
042: * </ul>
043: */
044: public class MBeanConstructorInfo extends MBeanFeatureInfo implements
045: java.io.Serializable, Cloneable {
046: // Constants -----------------------------------------------------
047:
048: private static final long serialVersionUID = 4433990064191844427L;
049:
050: // Attributes ----------------------------------------------------
051: private MBeanParameterInfo[] signature = null;
052:
053: /**
054: * The cached string
055: */
056: private transient String cacheString;
057:
058: /**
059: * The cached hashCode
060: */
061: private transient int cacheHashCode;
062:
063: // Constructors --------------------------------------------------
064: public MBeanConstructorInfo(java.lang.String description,
065: java.lang.reflect.Constructor constructor) {
066: super (constructor.getName(), description);
067:
068: Class[] sign = constructor.getParameterTypes();
069: signature = new MBeanParameterInfo[sign.length];
070:
071: for (int i = 0; i < sign.length; ++i) {
072: String name = sign[i].getName();
073: signature[i] = new MBeanParameterInfo(name, name,
074: "MBean Constructor Parameter.");
075: }
076: }
077:
078: public MBeanConstructorInfo(java.lang.String name,
079: java.lang.String description, MBeanParameterInfo[] signature)
080: throws IllegalArgumentException {
081: super (name, description);
082:
083: this .signature = (null == signature) ? new MBeanParameterInfo[0]
084: : (MBeanParameterInfo[]) signature.clone();
085: }
086:
087: public synchronized Object clone() {
088: MBeanConstructorInfo clone = null;
089: try {
090: clone = (MBeanConstructorInfo) super .clone();
091: clone.signature = (MBeanParameterInfo[]) this .signature
092: .clone();
093: } catch (CloneNotSupportedException e) {
094: }
095:
096: return clone;
097: }
098:
099: public MBeanParameterInfo[] getSignature() {
100: return (MBeanParameterInfo[]) signature.clone();
101: }
102:
103: public boolean equals(Object object) {
104: if (this == object)
105: return true;
106: if (object == null
107: || (object instanceof MBeanConstructorInfo) == false)
108: return false;
109:
110: MBeanConstructorInfo other = (MBeanConstructorInfo) object;
111:
112: if (super .equals(other) == false)
113: return false;
114:
115: MBeanParameterInfo[] this Params = this .getSignature();
116: MBeanParameterInfo[] otherParams = other.getSignature();
117: if (this Params.length != otherParams.length)
118: return false;
119: for (int i = 0; i < this Params.length; ++i)
120: if (this Params[i].equals(otherParams[i]) == false)
121: return false;
122:
123: return true;
124: }
125:
126: public int hashCode() {
127: if (cacheHashCode == 0) {
128: cacheHashCode = super .hashCode();
129: }
130: return cacheHashCode;
131: }
132:
133: /**
134: * @return a human readable string
135: */
136: public String toString() {
137: if (cacheString == null) {
138: StringBuffer buffer = new StringBuffer(100);
139: buffer.append(getClass().getName()).append(":");
140: buffer.append(" name=").append(getName());
141: buffer.append(" description=").append(getDescription());
142: buffer.append(" signature=").append(
143: Arrays.asList(signature));
144: cacheString = buffer.toString();
145: }
146: return cacheString;
147: }
148: }
|