01: // LongAttribute.java
02: // $Id: LongAttribute.java,v 1.4 2000/08/16 21:37:56 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 LongAttribute.
14: */
15:
16: public class LongAttribute extends Attribute {
17:
18: /**
19: * Is the given object a valid LongAttribute 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 Long) || (obj == null);
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 8;
36: }
37:
38: /**
39: * Pickle an long 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 l)
46: throws IOException {
47: out.writeLong(((Long) l).longValue());
48: }
49:
50: /**
51: * Unpickle an long from the given input stream.
52: * @param in The input stream to unpickle from.
53: * @return An instance of Long.
54: * @exception IOException If some IO error occured.
55: */
56:
57: public Object unpickle(DataInputStream in) throws IOException {
58: return new Long(in.readLong());
59: }
60:
61: public LongAttribute(String name, Long def, Integer flags) {
62: super (name, def, flags);
63: this .type = "java.lang.Long";
64: }
65: }
|