01: // DoubleAttribute.java
02: // $Id: DoubleAttribute.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 DoubleAttribute.
14: */
15:
16: public class DoubleAttribute extends Attribute {
17:
18: /**
19: * Is the given object a valid DoubleAttribute value ?
20: * @param obj The object to test.
21: * @return A boolean <strong>true</strong> if okay.
22: * @exception IllegalAttributeAccess If the provided value doesn't pass the
23: * test.
24: */
25:
26: public boolean checkValue(Object obj) {
27: return (obj instanceof Double);
28: }
29:
30: /**
31: * Get the number of bytes required to save that attribute value.
32: * @param The value about to be pickled.
33: * @return The number of bytes needed to pickle that value.
34: */
35:
36: public final int getPickleLength(Object value) {
37: return 8;
38: }
39:
40: /**
41: * Pickle an double to the given output stream.
42: * @param out The output stream to pickle to.
43: * @param obj The object to pickle.
44: * @exception IOException If some IO error occured.
45: */
46:
47: public final void pickle(DataOutputStream out, Object d)
48: throws IOException {
49: out.writeDouble(((Double) d).doubleValue());
50: }
51:
52: /**
53: * Unpickle an integer from the given input stream.
54: * @param in The input stream to unpickle from.
55: * @return An instance of Double.
56: * @exception IOException If some IO error occured.
57: */
58:
59: public final Object unpickle(DataInputStream in) throws IOException {
60: return new Double(in.readDouble());
61: }
62:
63: /**
64: * Create a description for a generic Double attribute.
65: * @param name The attribute name.
66: * @param def The default value for these attributes.
67: * @param flags The associated flags.
68: */
69:
70: public DoubleAttribute(String name, Double def, Integer flags) {
71: super (name, def, flags);
72: this .type = "java.lang.Double";
73: }
74:
75: }
|