Annotation of java/classes/org/w3c/tools/resources/Attribute.java, revision 1.1.2.4
1.1 bmahe 1: // Attribute.java
1.1.2.4 ! bmahe 2: // $Id: Attribute.java,v 1.1.2.3 1999/06/15 15:46:22 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: * Instances of this class describe an attribute of a resource.
12: */
13:
14: abstract public class Attribute implements Serializable {
15: /**
16: * Flags value - This attribute is computed from the resource state.
17: */
18: public static final int COMPUTED = (1<<0) ;
19: /**
20: * Flag value - This attribute is editable.
21: */
22: public static final int EDITABLE = (1<<1) ;
23: /**
24: * Flag value - This attribute is mandatory.
25: */
26: public static final int MANDATORY = (1<<2) ;
27: /**
28: * Flag value - This attribute shouldn't be saved.
29: */
30: public static final int DONTSAVE = (1<<3) ;
31: /**
32: * The attribute name.
33: */
34: protected String name = null ;
35: /**
36: * The attribute's value type, as the name of its class.
37: */
38: protected String type = null ;
39: /**
40: * The attribute's default value.
41: */
42: private transient Object defvalue = null ;
43: /**
44: * The associated flags (see the predefined flags).
45: */
46: protected int flags = 0 ;
1.1.2.3 bmahe 47:
48: public String getFlag() {
49: return String.valueOf(flags);
50: }
51:
52: public void setFlag(String flag) {
53: try {
54: flags = Integer.parseInt(flag);
55: } catch (Exception ex) {
56: flags = 0;
57: }
58: }
1.1 bmahe 59:
60: /**
61: * Get this attribute name.
62: * @return A String giving the attribute name.
63: */
64:
65: public String getName() {
66: return name ;
67: }
68:
69: /**
1.1.2.2 bmahe 70: * set the attribute name.
71: * @param name the attribute name.
72: */
73: public void setName(String name) {
74: this.name = name;
75: }
76:
77: /**
1.1 bmahe 78: * Get this attribute type.
79: */
80:
81: public String getType() {
82: return type ;
83: }
84:
85: /**
86: * Check some flag on this attribute description.
87: */
88:
89: public boolean checkFlag(int tst) {
90: return (flags & tst) == tst ;
91: }
92:
93: /**
94: * Get this attribute default value.
95: * @return A default value for this attribute (may be
96: * <strong>null</strong>).
97: */
98:
99: public Object getDefault() {
100: return defvalue ;
101: }
102:
103: /**
104: * Is the provided object a suitable value for this attribute ?
105: * If so, store it into the given store.
106: * @param value The value to check.
107: * @param store The array to store the value to if succeed.
108: * @param idx The location in the above array.
109: * @return A boolean <strong>true</strong> if this object can be used
110: * as a value for this attribute.
111: * @exception IllegalAttributeAccess If the provided value doesn't match
112: * the expected type.
113: */
114:
1.1.2.1 bmahe 115: public abstract boolean checkValue(Object value) ;
1.1.2.4 ! bmahe 116:
! 117: public abstract String stringify(Object value) ;
1.1 bmahe 118:
119: /**
120: * Private constructore to create a new resource attribute description.
121: * @param name The name of the attribute.
122: * @param def Its default value.
123: * @param flags Its associated flags.
124: */
125:
126: public Attribute(String name, Object def, int flags) {
127: this.name = name ;
128: this.defvalue = def ;
129: this.flags = flags ;
130: }
1.1.2.2 bmahe 131:
132: /**
133: * Empty contructor, (cls.newInstance())
134: */
135: public Attribute() {
136: this.defvalue = null ;
137: this.flags = COMPUTED;
138: }
139:
1.1 bmahe 140: }
Webmaster