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.io.Serializable;
025:
026: /**
027: * General information for MBean descriptor objects.
028: *
029: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
030: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>
031: *
032: * <p><b>Revisions:</b>
033: * <p><b>20020711 Adrian Brock:</b>
034: * <ul>
035: * <li> Serialization </li>
036: * </ul>
037: *
038: * @version $Revision: 57200 $
039: */
040: public class MBeanFeatureInfo implements Serializable {
041: // Constants -----------------------------------------------------
042:
043: private static final long serialVersionUID = 3952882688968447265L;
044:
045: // Attributes ----------------------------------------------------
046:
047: /**
048: * Name of the MBean feature.
049: */
050: protected String name = null;
051:
052: /**
053: * Human readable description string of the MBean feature.
054: */
055: protected String description = null;
056:
057: /**
058: * The cached string
059: */
060: private transient String cacheString;
061:
062: /**
063: * The cached hashCode
064: */
065: private transient int cacheHashCode;
066:
067: // Constructors --------------------------------------------------
068:
069: /**
070: * Constructs an MBean feature info object.
071: *
072: * @param name name of the MBean feature
073: * @param description human readable description string of the feature
074: * @exception IllegalArgumentException if the name is not a valid java type
075: */
076: public MBeanFeatureInfo(String name, String description)
077: throws IllegalArgumentException {
078: /* This was removed in the jmx-1.2 mr
079: - Illegal identifiers no longer produce exceptions (4839259)
080: if (MetaDataUtil.isValidJavaType(name) == false)
081: throw new IllegalArgumentException("name is not a valid java type (or is a reserved word): " + name);
082: */
083: this .name = name;
084: this .description = description;
085: }
086:
087: // Public --------------------------------------------------------
088:
089: /**
090: * Returns the name of the MBean feature.
091: *
092: * @return name string
093: */
094: public String getName() {
095: return name;
096: }
097:
098: /**
099: * Returns the description of the MBean feature.
100: *
101: * @return a human readable description string
102: */
103: public String getDescription() {
104: return description;
105: }
106:
107: public boolean equals(Object object) {
108: if (this == object)
109: return true;
110: if (object == null
111: || (object instanceof MBeanFeatureInfo) == false)
112: return false;
113:
114: MBeanFeatureInfo other = (MBeanFeatureInfo) object;
115: boolean equals = false;
116: if (this .getName().equals(other.getName())) {
117: String this Description = getDescription();
118: String otherDescription = other.getDescription();
119: if (this Description == null)
120: equals = this Description == otherDescription;
121: else
122: equals = this Description.equals(otherDescription);
123: }
124:
125: return equals;
126: }
127:
128: public int hashCode() {
129: if (cacheHashCode == 0) {
130: cacheHashCode = getName().hashCode();
131: if (getDescription() != null)
132: cacheHashCode += getDescription().hashCode();
133: }
134: return cacheHashCode;
135: }
136:
137: public String toString() {
138: if (cacheString == null) {
139: StringBuffer buffer = new StringBuffer(100);
140: buffer.append(getClass().getName()).append(":");
141: buffer.append(" name=").append(getName());
142: buffer.append(" description=").append(getDescription());
143: cacheString = buffer.toString();
144: }
145: return cacheString;
146: }
147: }
|