1 7 8 9 package javax.management.openmbean; 10 11 12 import java.io.IOException ; 15 import java.io.ObjectInputStream ; 16 import java.io.Serializable ; 17 import java.util.Arrays ; 18 import java.util.Collections ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 25 26 45 public abstract class OpenType implements Serializable { 46 47 48 static final long serialVersionUID = -9195195325186646468L; 49 50 51 57 static final List <String > ALLOWED_CLASSNAMES_LIST = 58 Collections.unmodifiableList( 59 Arrays.asList( 60 "java.lang.Void", 61 "java.lang.Boolean", 62 "java.lang.Character", 63 "java.lang.Byte", 64 "java.lang.Short", 65 "java.lang.Integer", 66 "java.lang.Long", 67 "java.lang.Float", 68 "java.lang.Double", 69 "java.lang.String", 70 "java.math.BigDecimal", 71 "java.math.BigInteger", 72 "java.util.Date", 73 "javax.management.ObjectName", 74 CompositeData .class.getName(), TabularData .class.getName()) ); 77 101 public static final String [] ALLOWED_CLASSNAMES = 102 ALLOWED_CLASSNAMES_LIST.toArray(new String [0]); 103 104 107 private String className; 108 109 112 private String description; 113 114 117 private String typeName; 118 119 122 private transient boolean isArray = false; 123 124 125 126 127 151 protected OpenType(String className, 152 String typeName, 153 String description) throws OpenDataException { 154 155 if ( (className == null) || (className.trim().equals("")) ) { 158 throw new IllegalArgumentException ("Argument className cannot be null or empty."); 159 } 160 if ( (typeName == null) || (typeName.trim().equals("")) ) { 161 throw new IllegalArgumentException ("Argument typeName cannot be null or empty."); 162 } 163 if ( (description == null) || (description.trim().equals("")) ) { 164 throw new IllegalArgumentException ("Argument description cannot be null or empty."); 165 } 166 167 className = className.trim(); 170 typeName = typeName.trim(); 171 description = description.trim(); 172 173 int n = 0; 177 while (className.startsWith("[", n)) { 178 n++; 179 } 180 String eltClassName; boolean isArray = false; 182 if (n > 0) { 183 eltClassName = className.substring(n+1, className.length()-1); isArray = true; 186 } else { 187 eltClassName = className; 189 } 190 191 if ( ! ALLOWED_CLASSNAMES_LIST.contains(eltClassName) ) { 194 throw new OpenDataException ("Argument className=\""+ className + 195 "\" is not one of the allowed Java class names for open data."); 196 } 197 198 this.className = className; 201 this.typeName = typeName; 202 this.description = description; 203 this.isArray = isArray; 204 } 205 206 207 208 209 221 public String getClassName() { 222 223 return className; 224 } 225 226 231 public String getTypeName() { 232 233 return typeName; 234 } 235 236 241 public String getDescription() { 242 243 return description; 244 } 245 246 252 public boolean isArray() { 253 254 return isArray; 255 } 256 257 265 public abstract boolean isValue(Object obj) ; 266 267 268 269 270 278 public abstract boolean equals(Object obj) ; 279 280 public abstract int hashCode() ; 281 282 287 public abstract String toString() ; 288 289 292 private void readObject(ObjectInputStream in) 293 throws IOException , ClassNotFoundException { 294 in.defaultReadObject(); 295 isArray = (className.startsWith("[")); 296 } 297 298 } 299 300 | Popular Tags |