01: // BooleanAttribute.java
02: // $Id: BooleanAttribute.java,v 1.4 2000/08/16 21:37:55 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.upgrade;
07:
08: import java.io.DataInputStream;
09: import java.io.DataOutputStream;
10: import java.io.IOException;
11:
12: /**
13: * The generic description of an BooleanAttribute.
14: */
15:
16: public class BooleanAttribute extends Attribute {
17:
18: /**
19: * Is the given object a valid BooleanAttribute value ?
20: * @param obj The object to test.
21: * @return A boolean <strong>true</strong> if okay.
22: */
23:
24: public boolean checkValue(Object obj) {
25: return (obj instanceof Boolean);
26: }
27:
28: /**
29: * Get the number of bytes required to save that attribute value.
30: * @param The value about to be pickled.
31: * @return The number of bytes needed to pickle that value.
32: */
33:
34: public final int getPickleLength(Object value) {
35: return 1;
36: }
37:
38: /**
39: * Pickle an boolean to the given output stream.
40: * @param out The output stream to pickle to.
41: * @param obj The object to pickle.
42: * @exception IOException If some IO error occured.
43: */
44:
45: public void pickle(DataOutputStream out, Object b)
46: throws IOException {
47: out.writeBoolean(((Boolean) b).booleanValue());
48: }
49:
50: /**
51: * Unpickle an boolean from the given input stream.
52: * @param in The input stream to unpickle from.
53: * @return An instance of Boolean.
54: * @exception IOException If some IO error occured.
55: */
56:
57: public Object unpickle(DataInputStream in) throws IOException {
58: return (in.readBoolean()) ? Boolean.TRUE : Boolean.FALSE;
59: }
60:
61: public BooleanAttribute(String name, Boolean def, Integer flags) {
62: super (name, def, flags);
63: this .type = "java.lang.Boolean";
64: }
65:
66: }
|