Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / jigsaw / src / org / w3c / www / http / HttpWarning.java
diff --git a/JMCR-Stable/real-world application/jigsaw/src/org/w3c/www/http/HttpWarning.java b/JMCR-Stable/real-world application/jigsaw/src/org/w3c/www/http/HttpWarning.java
new file mode 100644 (file)
index 0000000..09a67f7
--- /dev/null
@@ -0,0 +1,180 @@
+// HttpWarning.java\r
+// $Id: HttpWarning.java,v 1.1 2010/06/15 12:19:43 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.www.http;\r
+\r
+public class HttpWarning extends BasicValue {\r
+    /**\r
+     * Warning status - Response is stale.\r
+     */\r
+    public static final int STALE                    = 110;\r
+    /**\r
+     * Warning status - Revalidation failed.\r
+     */\r
+    public static final int REVALIDATION_FAILED      = 111;\r
+    /**\r
+     * Warning status - Disconnected opertaion.\r
+     */\r
+    public static final int DISCONNECTED_OPERATION   = 112;\r
+    /**\r
+     * Warning status - Heuristic expiration.\r
+     */\r
+    public static final int HEURISTIC_EXPIRATION     = 113;\r
+    /**\r
+     * Warning status - Miscellaneous warning\r
+     */\r
+    public static final int MISCELLANEOUS            = 199;\r
+    /**\r
+     * Warning status - Transformation applied.\r
+     */\r
+    public static final int TRANSFORMATION_APPLIED   = 214;\r
+    /**\r
+     * Warning status - Miscellaneous warning\r
+     */\r
+    public static final int PERSISTENT_MISCELLANEOUS = 199;\r
+\r
+    protected HttpWarningList list = null;\r
+\r
+    protected int    status = -1;\r
+    protected String agent  = null;\r
+    protected String text   = null;\r
+\r
+    /**\r
+     * parse.\r
+     * @exception HttpParserException if parsing failed.\r
+     */\r
+    protected void parse()\r
+       throws HttpParserException\r
+    {\r
+       ParseState ps = new ParseState(roff, rlen);\r
+       ParseState it = new ParseState();\r
+       // Get the status code:\r
+       if ( HttpParser.nextItem(raw, ps) < 0 )\r
+           error("Invalid warning, no status code.");\r
+       it.ioff   = ps.start;\r
+       it.bufend = ps.end;\r
+       this.status = HttpParser.parseInt(raw, it);\r
+       // Get the agent emiting the warning\r
+       ps.prepare();\r
+       if ( HttpParser.nextItem(raw, ps) < 0 )\r
+           error("Invalid warning, no agent field.");\r
+       this.agent = new String(raw, 0, ps.start, ps.end-ps.start);\r
+       // Get the quoted message\r
+       ps.prepare();\r
+       if ( HttpParser.nextItem(raw, ps) < 0 )\r
+           error("Invalid warning, no text message.");\r
+       it.ioff   = ps.start;\r
+       it.bufend = ps.end;\r
+       HttpParser.unquote(raw, it);\r
+       this.text = new String(raw, 0, it.start, it.end-it.start);\r
+    }\r
+\r
+    protected void updateByteValue() {\r
+       HttpBuffer buf = new HttpBuffer() ;\r
+       buf.appendInt(status);\r
+       buf.append(' ');\r
+       buf.append(agent);\r
+       buf.append(' ');\r
+       buf.appendQuoted(text);\r
+       raw  = buf.getByteCopy();\r
+       roff = 0;\r
+       rlen = raw.length;\r
+    }\r
+\r
+    protected void invalidateByteValue() {\r
+       super.invalidateByteValue();\r
+       if ( list != null )\r
+           list.invalidateByteValue();\r
+    }\r
+\r
+    public Object getValue() {\r
+       validate();\r
+       return this;\r
+    }\r
+\r
+    /**\r
+     * Get this warning status code.\r
+     * @return An integer giving the warning status code.\r
+     */\r
+\r
+    public int getStatus() {\r
+       validate();\r
+       return status;\r
+    }\r
+\r
+    /**\r
+     * Set this warning status code.\r
+     * @param status The status code for this warning.\r
+     */\r
+\r
+    public void setStatus(int status) {\r
+       if ( this.status != status )\r
+           invalidateByteValue();\r
+       this.status = status;\r
+    }\r
+\r
+    /**\r
+     * Get this warning agent.\r
+     * @return A String encoding the agent that generated the warning.\r
+     */\r
+\r
+    public String getAgent() {\r
+       validate();\r
+       return agent;\r
+    }\r
+\r
+    /**\r
+     * Set the agent that is generating the warning.\r
+     * @param agent The String describing the agent emitting the warning.\r
+     */\r
+\r
+    public void setAgent(String agent) {\r
+       if ((agent != null) && ! agent.equals(this.agent) )\r
+           invalidateByteValue();\r
+       this.agent = agent;\r
+    }\r
+\r
+    /**\r
+     * Get the warning text message.\r
+     * @return A String encoding the text message.\r
+     */\r
+\r
+    public String getText() {\r
+       validate();\r
+       return text;\r
+    }\r
+\r
+    /**\r
+     * Set the text warning message.\r
+     * @param text The new text of the warning message.\r
+     */\r
+\r
+    public void setText(String text) {\r
+       if ((text != null) && ! text.equals(this.text) )\r
+           invalidateByteValue();\r
+       this.text = text;\r
+    }\r
+\r
+    HttpWarning(HttpWarningList list, byte raw[], int roff, int rlen) {\r
+       this.list = list;\r
+       this.raw  = raw;\r
+       this.roff = roff;\r
+       this.rlen = rlen;\r
+       this.isValid = false;\r
+    }\r
+\r
+    HttpWarning(boolean isValid, int status, String agent, String text) {\r
+       this.isValid = isValid;\r
+       setStatus(status);\r
+       setAgent(agent);\r
+       setText(text);\r
+    }\r
+\r
+    public HttpWarning() {\r
+       this.isValid = false;\r
+    }\r
+}\r
+\r
+\r