Frames | No Frames |
1: /* OpenType.java -- Superclass of all open types. 2: Copyright (C) 2006 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: package javax.management.openmbean; 39: 40: import java.io.Serializable; 41: 42: /** 43: * The superclass of all open types, which describe the 44: * applicable data values for open MBeans. An open type 45: * is defined by its name and description, and the name 46: * of the Java class it maps to. 47: * 48: * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 49: * @since 1.5 50: */ 51: public abstract class OpenType 52: implements Serializable 53: { 54: 55: /** 56: * Compatible with JDK 1.5 57: */ 58: private static final long serialVersionUID = -9195195325186646468L; 59: 60: /** 61: * The name of the Java class this type represents. 62: */ 63: private String className; 64: 65: /** 66: * The name of this type. 67: */ 68: private String typeName; 69: 70: /** 71: * A description of this type. 72: */ 73: private String description; 74: 75: /** 76: * An array which defines the set of Java types which can be 77: * used as open types. Note that each type is also available 78: * in array form, possibly with multiple dimensions. 79: */ 80: public static final String[] ALLOWED_CLASSNAMES = { 81: "java.lang.Void", 82: "java.lang.Boolean", 83: "java.lang.Character", 84: "java.lang.Byte", 85: "java.lang.Short", 86: "java.lang.Integer", 87: "java.lang.Long", 88: "java.lang.Float", 89: "java.lang.Double", 90: "java.lang.String", 91: "java.math.BigDecimal", 92: "java.math.BigInteger", 93: "java.util.Date", 94: "javax.management.ObjectName", 95: CompositeData.class.getName(), 96: TabularData.class.getName() 97: }; 98: 99: /** 100: * Constructs a new {@link OpenType} for the specified class 101: * with the given name and description. The name of the class 102: * must be taken from the list of {@link ALLOWED_CLASSNAMES}. 103: * Arrays are implictly included in this, and follow the usual 104: * syntax of {@link java.lang.Class#getName()} with the name 105: * preceded by n instances of '[' (where n is the number of 106: * dimensions) and an L. The name and description can not be 107: * <code>null</code> or the empty string. 108: * 109: * @param className the name of the Java class this type 110: * represents. 111: * @param name the name of the type. 112: * @param desc the description of the type. 113: * @throws IllegalArgumentException if either of <code>name</code> 114: * or <code>desc</code> are 115: * <code>null</code> or the empty 116: * string. 117: * @throws OpenDataException if the class name does not reference 118: * a listed class (from @{link ALLOWED_CLASSNAMES}) 119: */ 120: protected OpenType(String className, String name, String desc) 121: throws OpenDataException 122: { 123: if (name == null || name.equals("")) 124: throw new IllegalArgumentException("The name can not be null " + 125: "or the empty string."); 126: if (desc == null || desc.equals("")) 127: throw new IllegalArgumentException("The description can not " + 128: "be null or the empty string."); 129: String testString; 130: if (className.startsWith("[")) 131: testString = className.substring(className.indexOf("L") + 1); 132: else 133: testString = className; 134: boolean openTypeFound = false; 135: for (int a = 0; a < ALLOWED_CLASSNAMES.length; ++a) 136: if (ALLOWED_CLASSNAMES[a].equals(className)) 137: openTypeFound = true; 138: if (!openTypeFound) 139: throw new OpenDataException("The class name does not specify " + 140: "a valid open type."); 141: this.className = className; 142: typeName = name; 143: description = desc; 144: } 145: 146: /** 147: * Performs an equality test on this object and the one specified. 148: * 149: * @param obj the object to test against this one. 150: * @return true if the two objects are equivalent. 151: * @see java.lang.Object#hashCode() 152: */ 153: public abstract boolean equals(Object obj); 154: 155: /** 156: * Returns the name of the Java class this type represents. This must 157: * be one of the {@link ALLOWED_CLASSNAMES} or an array of one of them. 158: * The specification of arrays follows the standard set by 159: * {@link java.lang.Class#getName()} i.e. the name is the class name 160: * preceded by n instances of '[' and an 'L', where n is number of 161: * dimensions used by the array. 162: * 163: * @return the class name. 164: */ 165: public String getClassName() 166: { 167: return className; 168: } 169: 170: /** 171: * Returns a description of this open type. 172: * 173: * @return the description. 174: */ 175: public String getDescription() 176: { 177: return description; 178: } 179: 180: /** 181: * Returns the name of this open type. 182: * 183: * @return the type name. 184: */ 185: public String getTypeName() 186: { 187: return typeName; 188: } 189: 190: /** 191: * Returns a hash code for this open type. The hash code 192: * should be consistent with the {@link equals()} method. 193: * Thus, it should continue to return the same value while 194: * the values used by the {@link equals()} method remain 195: * the same, and should return different hash codes for 196: * objects which are judged to be different using the 197: * {@link equals()} method. 198: * 199: * @return the hash code of this instance. 200: */ 201: public abstract int hashCode(); 202: 203: /** 204: * Returns true if this open type represents an array type. 205: * 206: * @return true if this open type represents an array type. 207: */ 208: public boolean isArray() 209: { 210: return className.startsWith("["); 211: } 212: 213: /** 214: * Returns true if the specified object is a member of this 215: * type. 216: * 217: * @param obj the object to test for membership. 218: * @return true if the object is a member of this type. 219: */ 220: public abstract boolean isValue(Object obj); 221: 222: /** 223: * Returns a textual representation of this type. 224: * 225: * @return a {@link java.lang.String} representation of this 226: * type. 227: */ 228: public abstract String toString(); 229: 230: }