01: // SegmentArrayAttribute.java
02: // $Id: SegmentArrayAttribute.java,v 1.12 2000/08/16 21:37:46 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.jigsaw.ssi;
07:
08: import org.w3c.tools.resources.ArrayAttribute;
09: import org.w3c.tools.resources.Attribute;
10:
11: import org.w3c.util.CountOutputStream;
12:
13: /**
14: * Attribute used to make the document segment information persistent.
15: * @author Antonio Ramirez <anto@mit.edu>
16: */
17: public class SegmentArrayAttribute extends ArrayAttribute {
18:
19: public boolean checkValue(Object value) {
20: return (value instanceof Segment[] || value == null);
21: }
22:
23: /**
24: * Unpickle an attribute array from a string array.
25: * @param array the String array
26: * @return a Object array
27: */
28: public Object unpickle(String array[]) {
29: Segment segs[] = new Segment[array.length];
30: for (int i = 0; i < array.length; i++)
31: segs[i] = Segment.unpickle(array[i]);
32: return segs;
33: }
34:
35: /**
36: * Pickle an attribute array into a String array.
37: * @param array the attribute array
38: * @return a String array
39: */
40: public String[] pickle(Object obj) {
41: Segment[] segs = (Segment[]) obj;
42: String strings[] = new String[segs.length];
43: for (int i = 0; i < segs.length; i++) {
44: strings[i] = segs[i].pickle();
45: }
46: return strings;
47: }
48:
49: public SegmentArrayAttribute(String name, Segment[] def, int flags) {
50: super (name, def, flags);
51: this .type = "[Lorg.w3c.jigsaw.ssi.Segment;";
52: }
53:
54: public SegmentArrayAttribute() {
55: super ();
56: this .type = "[Lorg.w3c.jigsaw.ssi.Segment;";
57: }
58:
59: public String stringify(Object value) {
60: Segment[] segs = (Segment[]) value;
61: StringBuffer buf = new StringBuffer(160);
62: buf.append('[');
63: for (int i = 0; i < segs.length; i++) {
64: buf.append(segs[i].toString());
65: buf.append(' ');
66: }
67: buf.append(']');
68: return buf.toString();
69: }
70: }
|