01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.dwrp;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: /**
22: * A set of constants that represent how browsers need data flushed to them
23: * @author Joe Walker [joe at getahead dot ltd dot uk]
24: */
25: public enum PartialResponse {
26: /**
27: * The client can not handle partial responses
28: */
29: NO("0"),
30:
31: /**
32: * The client can handle partial responses
33: */
34: YES("1"),
35:
36: /**
37: * The client can only handle partial responses with a 4k data post
38: * (can be whitespace) - we're talking IE here.
39: */
40: FLUSH("2");
41:
42: /**
43: * @param id The string that the browser passes for this value
44: */
45: private PartialResponse(String id) {
46: this .id = id;
47: }
48:
49: /**
50: * The browser version of this value
51: */
52: private final String id;
53:
54: /**
55: * A lookup table of browser strings to enum constants
56: */
57: private static final Map<String, PartialResponse> ids = new HashMap<String, PartialResponse>();
58:
59: /**
60: * Setup the lookup table
61: */
62: static {
63: for (PartialResponse partialResponse : PartialResponse.values()) {
64: ids.put(partialResponse.id, partialResponse);
65: }
66: }
67:
68: /**
69: * Convert a string from the web into a PartialResponse. The values are
70: * PARTIAL_RESPONSE_NO = "0", PARTIAL_RESPONSE_YES = "1" and
71: * PARTIAL_RESPONSE_FLUSH = "2"
72: * @param lookupid The PartialResponse to look-up
73: * @return a matching PartialResponse or null if one was not found
74: */
75: public static PartialResponse fromOrdinal(String lookupid) {
76: return ids.get(lookupid);
77: }
78: }
|