Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / tools / resources / upgrade / ClassAttribute.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/upgrade/ClassAttribute.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/tools/resources/upgrade/ClassAttribute.java
new file mode 100644 (file)
index 0000000..1b9f94b
--- /dev/null
@@ -0,0 +1,107 @@
+// ClassAttribute.java\r
+// $Id: ClassAttribute.java,v 1.2 2010/06/15 17:53:11 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
+\r
+/**\r
+ * The generic description of an ClassAttribute.\r
+ */\r
+\r
+public class ClassAttribute extends Attribute {\r
+\r
+    /**\r
+     * Make a String out of a ClassAttribute value.\r
+     * The default <code>toString</code> method on classes doesn't work\r
+     * for that purpose, since it will preceed the class name with\r
+     * a <strong>class</strong> keyword.\r
+     * @return The String name of the class.\r
+     */\r
+\r
+    public String stringify(Object value) {\r
+       return ((value instanceof Class) \r
+               ? ((Class) value).getName()\r
+               : "<unknown-class>");\r
+    }\r
+\r
+    /**\r
+     * Is the given object a valid ClassAttribute value ?\r
+     * @param obj The object to test.\r
+     * @return A boolean <strong>true</strong> if okay.\r
+     */\r
+\r
+    public boolean checkValue(Object obj) {\r
+       return (obj instanceof Class);\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
+       String str    = ((Class) value).getName();\r
+       int    strlen = str.length() ;\r
+       int    utflen = 0 ;\r
+\r
+       for (int i = 0 ; i < strlen ; i++) {\r
+           int c = str.charAt(i);\r
+           if ((c >= 0x0001) && (c <= 0x007F)) {\r
+               utflen++;\r
+           } else if (c > 0x07FF) {\r
+               utflen += 3;\r
+           } else {\r
+               utflen += 2;\r
+           }\r
+       }\r
+       return utflen + 2 ;\r
+    }\r
+\r
+    /**\r
+     * Pickle an integer to the given output stream.\r
+     * @param out The output stream to pickle to.\r
+     * @param obj The object to pickle.\r
+     * @exception IOException If some IO error occured.\r
+     */\r
+\r
+    public void pickle(DataOutputStream out, Object c) \r
+       throws IOException\r
+    {\r
+       out.writeUTF(((Class) c).getName()) ;\r
+    }\r
+\r
+    /**\r
+     * Unpickle an integer from the given input stream.\r
+     * @param in The input stream to unpickle from.\r
+     * @return An instance of Integer.\r
+     * @exception IOException If some IO error occured.\r
+     */\r
+\r
+    public Object unpickle (DataInputStream in) \r
+       throws IOException\r
+    {\r
+       String clsname = in.readUTF() ;\r
+       try {\r
+           return Class.forName(clsname);\r
+           //Added by Jeff Huang\r
+           //TODO: FIXIT\r
+       } catch (Exception ex) {\r
+           throw new IOException ("Unable to restore class "\r
+                                  + clsname\r
+                                  + ": "\r
+                                  + ex.getMessage()) ;\r
+       }\r
+    }\r
+\r
+    public ClassAttribute(String name, Class def, Integer flags) {\r
+       super(name, def, flags) ;\r
+       this.type = "java.lang.Class";\r
+    }\r
+\r
+}\r