Annotation of java/classes/org/w3c/tools/resources/ObjectAttribute.java, revision 1.2.2.2
1.1 bmahe 1: // ObjectAttribute.java
1.2.2.2 ! bmahe 2: // $Id: ObjectAttribute.java,v 1.2.2.1 1999/06/11 15:04:09 bmahe Exp $
1.1 bmahe 3: // (c) COPYRIGHT MIT and INRIA, 1996.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5:
6: package org.w3c.tools.resources;
7:
8: import java.io.* ;
9:
10: /**
11: * A generic Object attribute.
12: * This attribute is usefull for attributes that are:
13: * <ul>
14: * <li>Have Object values.
15: * <li>Need not be saved (have the DONTSAVE bit set).
16: * </ul>
17: */
18:
19: public class ObjectAttribute extends Attribute {
20: /**
21: * The class for values of this attribute.
22: */
23: protected Class cls = null ;
24:
25: /**
26: * Check that a value is allowed for this attribute.
27: * @param value The value to check.
28: * @return A boolean <strong>true</strong> if value is allowed.
29: */
30:
31: public boolean checkValue(Object value) {
32: return true;
33: }
34:
35: /**
1.2.2.1 bmahe 36: * Pickle an integer to the given output stream.
37: * @param obj The object to pickle.
38: * @exception IOException If some IO error occured.
1.1 bmahe 39: */
40:
1.2.2.1 bmahe 41: public String pickle(Object obj) {
1.1 bmahe 42: throw new RuntimeException("Can't pickle ObjectAttribute");
43: }
44:
45: /**
1.2.2.1 bmahe 46: * Unpickle an integer from the given input stream.
47: * @param value the string representation of this integer
48: * @return An instance of Integer.
49: * @exception IOException If some IO error occured.
1.1 bmahe 50: */
51:
1.2.2.1 bmahe 52: public Object unpickle (String value) {
53: throw new RuntimeException("Can't pickle ObjectAttribute");
1.1 bmahe 54: }
55:
1.2.2.2 ! bmahe 56: public String stringify(Object value) {
! 57: throw new RuntimeException("Can't pickle ObjectAttribute");
! 58: }
! 59:
1.1 bmahe 60: /**
61: * Create a new ObjectAttribute instance.
62: * @param name The name of the attribute.
63: * @param cls The class for this attribute values.
64: * @param def The default value for this attribute.
65: * @param flags The attribute flags.
66: */
67:
68: public ObjectAttribute(String name, Class cls, Object def, int flags) {
69: super(name, def, flags) ;
70: // Check consistency
71: if ( ! checkFlag(DONTSAVE) ) {
72: String error = "ObjectAttribute can't pickle themselves." ;
73: throw new RuntimeException (error) ;
74: }
75: this.cls = cls ;
76: }
77:
78: /**
79: * Create a new ObjectAttribute instance.
80: * @param name The name of the attribute.
81: * @param cname The name class for this attribute values.
82: * @param def The default value for this attribute.
83: * @param flags The attribute flags.
84: * @exception RuntimeException If we couldn't resolve the class name.
85: */
86:
87: public ObjectAttribute(String name, String cname, Object def, int flags) {
88: super(name, def, flags) ;
89: // Check consistency:
90: if ( ! checkFlag(DONTSAVE) ) {
91: String error = "ObjectAttribute can't pickle themselves." ;
92: throw new RuntimeException (error) ;
93: }
94: // Resolve the class:
95: try {
96: this.cls = Class.forName(cname) ;
97: } catch (Exception ex) {
98: throw new RuntimeException("unable to resolve class "+cname) ;
99: }
100: this.type = "java.lang.Object";
101: }
102:
103:
104: }
Webmaster