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 notification emitted 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 MBeanNotificationInfo extends MBeanFeatureInfo implements
045: Cloneable, java.io.Serializable {
046: // Constants -----------------------------------------------------
047:
048: private static final long serialVersionUID = -3888371564530107064L;
049:
050: // Attributes ----------------------------------------------------
051: private String[] types = 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 MBeanNotificationInfo(String[] notifsType, String name,
065: String description) throws IllegalArgumentException {
066: super (name, description);
067:
068: this .types = (null == notifsType) ? new String[0]
069: : (String[]) notifsType.clone();
070: }
071:
072: // Public -------------------------------------------------------
073: public String[] getNotifTypes() {
074: return (String[]) types.clone();
075: }
076:
077: public boolean equals(Object object) {
078: if (this == object)
079: return true;
080: if (object == null
081: || (object instanceof MBeanNotificationInfo) == false)
082: return false;
083:
084: MBeanNotificationInfo other = (MBeanNotificationInfo) object;
085:
086: if (super .equals(other) == false)
087: return false;
088:
089: String[] this Types = this .getNotifTypes();
090: String[] otherTypes = other.getNotifTypes();
091: if (this Types.length != otherTypes.length)
092: return false;
093: for (int i = 0; i < this Types.length; ++i)
094: if (this Types[i].equals(otherTypes[i]) == false)
095: return false;
096:
097: return true;
098: }
099:
100: public int hashCode() {
101: if (cacheHashCode == 0) {
102: cacheHashCode = super .hashCode();
103: }
104: return cacheHashCode;
105: }
106:
107: /**
108: * @return a human readable string
109: */
110: public String toString() {
111: if (cacheString == null) {
112: StringBuffer buffer = new StringBuffer(100);
113: buffer.append(getClass().getName()).append(":");
114: buffer.append(" name=").append(getName());
115: buffer.append(" description=").append(getDescription());
116: buffer.append(" types=").append(Arrays.asList(types));
117: cacheString = buffer.toString();
118: }
119: return cacheString;
120: }
121:
122: // CLoneable implementation -------------------------------------
123: public Object clone() {
124: MBeanNotificationInfo clone = null;
125: try {
126: clone = (MBeanNotificationInfo) super .clone();
127: clone.types = getNotifTypes();
128: } catch (CloneNotSupportedException e) {
129: }
130:
131: return clone;
132: }
133: }
|