]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.lib.jetty/src/org/argeo/cms/jetty/ContextHandlerAttributes.java
Move Equinox specific code to the appropriate variant
[lgpl/argeo-commons.git] / org.argeo.cms.lib.jetty / src / org / argeo / cms / jetty / ContextHandlerAttributes.java
1 package org.argeo.cms.jetty;
2
3 import java.util.AbstractMap;
4 import java.util.Enumeration;
5 import java.util.HashSet;
6 import java.util.Map;
7 import java.util.Set;
8
9 import org.eclipse.jetty.server.handler.ContextHandler;
10
11 /**
12 * A {@link Map} implementation wrapping the attributes of a Jetty
13 * {@link ContextHandler}.
14 */
15 class ContextHandlerAttributes extends AbstractMap<String, Object> {
16 private ContextHandler contextHandler;
17
18 public ContextHandlerAttributes(ContextHandler contextHandler) {
19 super();
20 this.contextHandler = contextHandler;
21 }
22
23 @Override
24 public Set<Entry<String, Object>> entrySet() {
25 Set<Entry<String, Object>> entries = new HashSet<>();
26 for (Enumeration<String> keys = contextHandler.getAttributeNames(); keys.hasMoreElements();) {
27 entries.add(new ContextAttributeEntry(keys.nextElement()));
28 }
29 return entries;
30 }
31
32 @Override
33 public Object put(String key, Object value) {
34 Object previousValue = get(key);
35 contextHandler.setAttribute(key, value);
36 return previousValue;
37 }
38
39 private class ContextAttributeEntry implements Map.Entry<String, Object> {
40 private final String key;
41
42 public ContextAttributeEntry(String key) {
43 this.key = key;
44 }
45
46 @Override
47 public String getKey() {
48 return key;
49 }
50
51 @Override
52 public Object getValue() {
53 return contextHandler.getAttribute(key);
54 }
55
56 @Override
57 public Object setValue(Object value) {
58 Object previousValue = getValue();
59 contextHandler.setAttribute(key, value);
60 return previousValue;
61 }
62
63 }
64 }