--- /dev/null
+// SegmentArrayAttribute.java\r
+// $Id: SegmentArrayAttribute.java,v 1.1 2010/06/15 12:22:50 smhuang Exp $\r
+// (c) COPYRIGHT MIT and INRIA, 1996.\r
+// Please first read the full copyright statement in file COPYRIGHT.html\r
+\r
+package org.w3c.tools.resources.upgrade ;\r
+\r
+import java.io.DataInputStream;\r
+import java.io.DataOutputStream;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+import org.w3c.util.CountOutputStream;\r
+import org.w3c.jigsaw.ssi.Segment;\r
+\r
+/**\r
+ * Attribute used to make the document segment information persistent.\r
+ * @author Antonio Ramirez <anto@mit.edu>\r
+ */ \r
+class SegmentArrayAttribute extends Attribute {\r
+\r
+ public boolean checkValue(Object value)\r
+ {\r
+ return (value instanceof Segment[] || value == null);\r
+ }\r
+\r
+ /**\r
+ * Get the number of bytes required to save that attribute value.\r
+ * @param The value about to be pickled.\r
+ * @return The number of bytes needed to pickle that value.\r
+ */\r
+\r
+ public final int getPickleLength(Object value) {\r
+ CountOutputStream out = new CountOutputStream();\r
+ DataOutputStream dout = new DataOutputStream(out);\r
+ Segment ss[] = (Segment[]) value;\r
+ try {\r
+ pickle(dout, ss);\r
+ dout.close();\r
+ return out.getCount();\r
+ } catch (IOException ex) {\r
+ throw new RuntimeException("IO erred in CountOutputStream.");\r
+ }\r
+ }\r
+\r
+ public void pickle(DataOutputStream out,Object obj)\r
+ throws IOException\r
+ {\r
+ Segment[] segs = (Segment[]) obj ;\r
+ out.writeInt(segs.length);\r
+ for(int i=0;i<segs.length;i++) \r
+ segs[i].pickle(out) ;\r
+ }\r
+\r
+ public Object unpickle(DataInputStream in)\r
+ throws IOException\r
+ {\r
+ int n = in.readInt() ;\r
+ \r
+ Segment segs[] = new Segment [n] ;\r
+\r
+ for(int i=0;i<n;i++)\r
+ segs[i] = Segment.unpickle(in) ;\r
+ \r
+ return segs ;\r
+ }\r
+\r
+ public SegmentArrayAttribute(String name, Segment[] def, Integer flags)\r
+ {\r
+ super(name,def,flags) ;\r
+ this.type = "[Lorg.w3c.jigsaw.ssi.Segment;";\r
+ }\r
+\r
+ public String stringify(Object value)\r
+ {\r
+ Segment[] segs = (Segment[]) value ;\r
+ StringBuffer buf = new StringBuffer(160) ;\r
+ buf.append('[') ;\r
+ for(int i=0;i<segs.length;i++) {\r
+ buf.append(segs[i].toString()) ;\r
+ buf.append(' ') ;\r
+ }\r
+ buf.append(']') ;\r
+ return buf.toString() ;\r
+ }\r
+}\r