KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibm > webdav > ConditionFactor


1 package com.ibm.webdav;
2
3 /*
4  * (C) Copyright IBM Corp. 2000 All rights reserved.
5  *
6  * The program is provided "AS IS" without any warranty express or
7  * implied, including the warranty of non-infringement and the implied
8  * warranties of merchantibility and fitness for a particular purpose.
9  * IBM will not be liable for any damages suffered by you as a result
10  * of using the Program. In no event will IBM be liable for any
11  * special, indirect or consequential damages or lost profits even if
12  * IBM has been advised of the possibility of their occurrence. IBM
13  * will not be liable for any third party claims against you.
14  */

15 import java.io.StreamTokenizer JavaDoc;
16 import java.io.IOException JavaDoc;
17
18
19 /** A ConditionFactor represents some state of a resource that must be
20  * satisfied in order for the associated request to be valid. The ConditionFactors in
21  * a ConditionTerm must all match with states of the resource, i.e., they are AND'ed
22  * together. Conditions are contained in a Precondition which is used in a
23  * WebDAV If header. ConditionFactors are either constructed by the client, or may
24  * have been given to the client in a previous method request. A ConditionFactor can
25  * be either a StateToken or an EntityTag as defined by section 9.4 of the WebDAV
26  * spec.
27  * @author Jim Amsden <jamsden@us.ibm.com>
28  * @see com.ibm.webdav.Precondition
29  * @see com.ibm.webdav.ConditionFactor
30  * @see com.ibm.webdav.ConditionTerm
31  * @see com.ibm.webdav.EntityTag
32  * @see com.ibm.webdav.StateToken
33  */

34 public abstract class ConditionFactor
35 {
36    // ------------------------------------------------------------------------
37

38    private boolean not_ = false;
39 /** Create a ConditionFactor (either a StateToken or EntityTag) by parsing
40  * the tokenizer contining an If header value.
41  * @param tokenizer a StreamTokenizer containing the contents of a state token or entity tag
42  * from a WebDAV If header
43  * @return the parsed ConditionFactor
44  * @exception com.ibm.webdav.WebDAVException thrown if there is a syntax error in the If header
45  */

46 public static ConditionFactor create(StreamTokenizer JavaDoc tokenizer) throws WebDAVException {
47     boolean not = false;
48     ConditionFactor factor = null;
49     try {
50         int token = tokenizer.ttype;
51         if (token == StreamTokenizer.TT_WORD) {
52             if (tokenizer.sval.equalsIgnoreCase("Not")) {
53                 not = true;
54             } else {
55                 throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Error parsing If header: expected Not");
56             }
57             token = tokenizer.nextToken();
58         }
59         switch (token) {
60             case '<' :
61                 {
62                     factor = StateToken.create(tokenizer);
63                     break;
64                 }
65             case '[' :
66                 {
67                     factor = EntityTag.create(tokenizer);
68                     break;
69                 }
70             default :
71                 {
72                     throw new WebDAVException(WebDAVStatus.SC_BAD_REQUEST, "Error parsing If header: saw: " + (char) token + " expected: < or [");
73                 }
74         }
75     } catch (IOException JavaDoc exc) {
76     }
77     factor.setNot(not);
78     return factor;
79 }
80 /** Negate the comparison on this ConditionFactor?
81  @return true if the condition factor was negated in the If header
82  */

83 public boolean not() {
84     return not_;
85 }
86 /** Set how to compare to this ConditionFactor. Value is true implies match for
87  * a valid request, false implies the request is valid only if the ConditionFactor
88  * doesn't match.
89  * @param value true means negate the condition
90  */

91 public void setNot(boolean value) {
92     not_ = value;
93 }
94 /** Return a String representation of this ConditionFactor as defined by the If
95  * header in section 9.4 of the WebDAV spec.
96  * @return a string representation of a state token or entity tag
97  */

98 public abstract String JavaDoc toString();
99 }
100
Popular Tags