View Javadoc
1   /*
2    * The contents of this file are subject to the terms of the Common Development and
3    * Distribution License (the License). You may not use this file except in compliance with the
4    * License.
5    *
6    * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7    * specific language governing permission and limitations under the License.
8    *
9    * When distributing Covered Software, include this CDDL Header Notice in each file and include
10   * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11   * Header, with the fields enclosed by brackets [] replaced by your own identifying
12   * information: "Portions Copyright [year] [name of copyright owner]".
13   *
14   * Copyright 2016 ForgeRock AS.
15   */
16  package org.forgerock.http.grizzly;
17  
18  import java.io.IOException;
19  import java.util.Collection;
20  import java.util.Map;
21  import java.util.Set;
22  
23  import org.glassfish.grizzly.http.server.Session;
24  
25  /**
26   * Exposes the session managed by Grizzly as an exchange session.
27   */
28  final class SessionAdapter implements org.forgerock.http.session.Session {
29  
30      private final Session session;
31  
32      SessionAdapter(Session session) {
33          this.session = session;
34      }
35  
36      @Override
37      public int size() {
38          return session.attributes().size();
39      }
40  
41      @Override
42      public boolean isEmpty() {
43          return session.attributes().isEmpty();
44      }
45  
46      @Override
47      public boolean containsKey(Object key) {
48          return session.attributes().containsKey(key);
49      }
50  
51      @Override
52      public boolean containsValue(Object value) {
53          return session.attributes().containsValue(value);
54      }
55  
56      @Override
57      public Object get(Object key) {
58          return session.attributes().get(key);
59      }
60  
61      @Override
62      public Object put(String key, Object value) {
63          return session.attributes().put(key, value);
64      }
65  
66      @Override
67      public Object remove(Object key) {
68          return session.attributes().remove(key);
69      }
70  
71      @Override
72      public void putAll(Map<? extends String, ? extends Object> m) {
73          session.attributes().putAll(m);
74      }
75  
76      @Override
77      public void clear() {
78          session.attributes().clear();
79      }
80  
81      @Override
82      public Set<String> keySet() {
83          return session.attributes().keySet();
84      }
85  
86      @Override
87      public Collection<Object> values() {
88          return session.attributes().values();
89      }
90  
91      @Override
92      public Set<Map.Entry<String, Object>> entrySet() {
93          return session.attributes().entrySet();
94      }
95  
96      @Override
97      public void save(org.forgerock.http.protocol.Response response) throws IOException {
98          // Nothing to do when using Session
99      }
100 }