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.hc.client5.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.hc.client5.http.cookie.CommonCookieAttributeHandler;
36 import org.apache.hc.client5.http.cookie.CookieAttributeHandler;
37 import org.apache.hc.client5.http.cookie.CookieSpec;
38 import org.apache.hc.core5.annotation.Contract;
39 import org.apache.hc.core5.annotation.ThreadingBehavior;
40 import org.apache.hc.core5.util.Asserts;
41
42
43
44
45
46
47
48
49 @Contract(threading = ThreadingBehavior.SAFE)
50 public abstract class AbstractCookieSpec implements CookieSpec {
51
52
53
54
55 private final Map<String, CookieAttributeHandler> attribHandlerMap;
56
57
58
59
60 public AbstractCookieSpec() {
61 super();
62 this.attribHandlerMap = new ConcurrentHashMap<>(10);
63 }
64
65
66
67
68 protected AbstractCookieSpec(final HashMap<String, CookieAttributeHandler> map) {
69 super();
70 Asserts.notNull(map, "Attribute handler map");
71 this.attribHandlerMap = new ConcurrentHashMap<>(map);
72 }
73
74
75
76
77 protected AbstractCookieSpec(final CommonCookieAttributeHandler... handlers) {
78 super();
79 this.attribHandlerMap = new ConcurrentHashMap<>(handlers.length);
80 for (final CommonCookieAttributeHandler handler: handlers) {
81 this.attribHandlerMap.put(handler.getAttributeName(), handler);
82 }
83 }
84
85
86
87
88
89
90
91
92
93 protected CookieAttributeHandler findAttribHandler(final String name) {
94 return this.attribHandlerMap.get(name);
95 }
96
97
98
99
100
101
102
103
104
105 protected CookieAttributeHandler getAttribHandler(final String name) {
106 final CookieAttributeHandler handler = findAttribHandler(name);
107 Asserts.check(handler != null, "Handler not registered for " +
108 name + " attribute");
109 return handler;
110 }
111
112 protected Collection<CookieAttributeHandler> getAttribHandlers() {
113 return this.attribHandlerMap.values();
114 }
115
116 }