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: * A representation of an MBean attribute. It is a pair,
028: * a {@link #getName() Name} and a {@link #getValue() Value}.<p>
029: *
030: * An Attribute is returned by a getter operation or passed to a
031: * a setter operation.
032: *
033: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
034: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
035: * @version $Revision: 57200 $
036: *
037: * <p><b>Revisions:</b>
038: * <p><b>20020730 Adrian Brock:</b>
039: * <ul>
040: * <li> Serialization </li>
041: * </ul>
042: * <p><b>20020930 Juha Lindfors:</b>
043: * <ul>
044: * <li> Overrode hashCode() to return same hash for objects that are equal</li>
045: * <li> Removed 'instanceof' from equals() as it tends to break the symmetricity
046: * requirement when subclasses are involved </li>
047: * </ul>
048: *
049: */
050: public class Attribute extends Object implements Serializable {
051: // Constants -----------------------------------------------------
052:
053: private static final long serialVersionUID = 2484220110589082382L;
054:
055: // Attributes --------------------------------------------------------
056:
057: /**
058: * The name of the attribute.
059: */
060: private String name = null;
061: /**
062: * The value of the attribute.
063: */
064: private Object value = null;
065:
066: // Constructors --------------------------------------------------
067:
068: /**
069: * Contruct a new attribute given a name and value.
070: *
071: * @param name the name of the attribute.
072: * @param value the value of the attribute.
073: */
074: public Attribute(String name, Object value) {
075: this .name = name;
076: this .value = value;
077: }
078:
079: // Public --------------------------------------------------------
080:
081: /**
082: * Retrieves the name of the attribute.
083: *
084: * @return the name of the attribute.
085: */
086: public String getName() {
087: return name;
088: }
089:
090: /**
091: * Retrieves the value of the attribute.
092: *
093: * @return the value of the attribute.
094: */
095: public Object getValue() {
096: return value;
097: }
098:
099: // Object overrides ----------------------------------------------
100:
101: /**
102: * Compares two attributes for equality.
103: *
104: * @return true when the name value objects are equal, false otherwise.
105: */
106: public boolean equals(Object object) {
107: if (object == null)
108: return false;
109:
110: if (!(object.getClass().equals(this .getClass())))
111: return false;
112:
113: Attribute attr = (Attribute) object;
114:
115: return (name.equals(attr.getName()) && value.equals(attr
116: .getValue()));
117: }
118:
119: public int hashCode() {
120: return name.hashCode();
121: }
122:
123: /**
124: * @return human readable string.
125: */
126: public String toString() {
127: StringBuffer buffer = new StringBuffer(50);
128: buffer.append(getClass().getName()).append(":");
129: buffer.append(" name=").append(getName());
130: buffer.append(" value=").append(getValue());
131: return buffer.toString();
132: }
133:
134: }
|