1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.impl.cookie;
29
30 import java.util.Collection;
31 import java.util.HashMap;
32 import java.util.Map;
33 import java.util.concurrent.ConcurrentHashMap;
34
35 import org.apache.http.annotation.Contract;
36 import org.apache.http.annotation.ThreadingBehavior;
37 import org.apache.http.cookie.CommonCookieAttributeHandler;
38 import org.apache.http.cookie.CookieAttributeHandler;
39 import org.apache.http.cookie.CookieSpec;
40 import org.apache.http.util.Args;
41 import org.apache.http.util.Asserts;
42
43
44
45
46
47
48
49
50
51 @Contract(threading = ThreadingBehavior.SAFE)
52 public abstract class AbstractCookieSpec implements CookieSpec {
53
54
55
56
57 private final Map<String, CookieAttributeHandler> attribHandlerMap;
58
59
60
61
62 public AbstractCookieSpec() {
63 super();
64 this.attribHandlerMap = new ConcurrentHashMap<String, CookieAttributeHandler>(10);
65 }
66
67
68
69
70 protected AbstractCookieSpec(final HashMap<String, CookieAttributeHandler> map) {
71 super();
72 Asserts.notNull(map, "Attribute handler map");
73 this.attribHandlerMap = new ConcurrentHashMap<String, CookieAttributeHandler>(map);
74 }
75
76
77
78
79 protected AbstractCookieSpec(final CommonCookieAttributeHandler... handlers) {
80 super();
81 this.attribHandlerMap = new ConcurrentHashMap<String, CookieAttributeHandler>(handlers.length);
82 for (final CommonCookieAttributeHandler handler: handlers) {
83 this.attribHandlerMap.put(handler.getAttributeName(), handler);
84 }
85 }
86
87
88
89
90
91
92 @Deprecated
93 public void registerAttribHandler(
94 final String name, final CookieAttributeHandler handler) {
95 Args.notNull(name, "Attribute name");
96 Args.notNull(handler, "Attribute handler");
97 this.attribHandlerMap.put(name, handler);
98 }
99
100
101
102
103
104
105
106
107
108 protected CookieAttributeHandler findAttribHandler(final String name) {
109 return this.attribHandlerMap.get(name);
110 }
111
112
113
114
115
116
117
118
119
120 protected CookieAttributeHandler getAttribHandler(final String name) {
121 final CookieAttributeHandler handler = findAttribHandler(name);
122 Asserts.check(handler != null, "Handler not registered for " +
123 name + " attribute");
124 return handler;
125 }
126
127 protected Collection<CookieAttributeHandler> getAttribHandlers() {
128 return this.attribHandlerMap.values();
129 }
130
131 }