01: // ClassAttribute.java
02: // $Id: ClassAttribute.java,v 1.5 2002/06/09 10:14:29 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.tools.resources;
07:
08: /**
09: * The generic description of an ClassAttribute.
10: */
11:
12: public class ClassAttribute extends SimpleAttribute {
13:
14: /**
15: * Make a String out of a ClassAttribute value.
16: * The default <code>toString</code> method on classes doesn't work
17: * for that purpose, since it will preceed the class name with
18: * a <strong>class</strong> keyword.
19: * @return The String name of the class.
20: */
21:
22: public String stringify(Object value) {
23: return ((value instanceof Class) ? ((Class) value).getName()
24: : "<unknown-class>");
25: }
26:
27: /**
28: * Is the given object a valid ClassAttribute value ?
29: * @param obj The object to test.
30: * @return A boolean <strong>true</strong> if okay.
31: */
32:
33: public boolean checkValue(Object obj) {
34: return (obj instanceof Class);
35: }
36:
37: /**
38: * Pickle an integer to the given output stream.
39: * @param obj The object to pickle.
40: */
41:
42: public String pickle(Object obj) {
43: return ((Class) obj).getName();
44: }
45:
46: /**
47: * Unpickle an integer from the given input stream.
48: * @param value the string representation of this integer
49: * @return An instance of Integer.
50: */
51:
52: public Object unpickle(String value) {
53: try {
54: return Class.forName(value);
55: } catch (Exception ex) {
56: return null;
57: }
58: }
59:
60: public ClassAttribute(String name, Class def, int flags) {
61: super (name, def, flags);
62: this .type = "java.lang.Class".intern();
63: }
64:
65: public ClassAttribute() {
66: super();
67: }
68:
69: }
|