Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

WrappedPortletSession.java 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server;
  17. import java.util.Set;
  18. import javax.portlet.PortletSession;
  19. /**
  20. * Wrapper for {@link PortletSession}.
  21. *
  22. * @author Vaadin Ltd
  23. * @since 7.0.0
  24. * @see WrappedSession
  25. */
  26. public class WrappedPortletSession implements WrappedSession {
  27. private final PortletSession session;
  28. /**
  29. * Creates a new wrapped portlet session.
  30. *
  31. * @param session
  32. * the portlet session to wrap.
  33. */
  34. public WrappedPortletSession(PortletSession session) {
  35. this.session = session;
  36. }
  37. @Override
  38. public int getMaxInactiveInterval() {
  39. return session.getMaxInactiveInterval();
  40. }
  41. @Override
  42. public Object getAttribute(String name) {
  43. return session.getAttribute(name);
  44. }
  45. /**
  46. * Returns the object bound with the specified name in this session, or
  47. * <code>null</code> if no object is bound under the name in the given
  48. * scope.
  49. *
  50. * @param name
  51. * a string specifying the name of the object
  52. * @param scope
  53. * session scope of this attribute
  54. *
  55. * @return the object with the specified name
  56. *
  57. * @exception java.lang.IllegalStateException
  58. * if this method is called on an invalidated session, or the
  59. * scope is unknown to the container.
  60. * @exception java.lang.IllegalArgumentException
  61. * if name is <code>null</code>.
  62. *
  63. * @see PortletSession#getAttribute(String, int)
  64. * @see PortletSession#PORTLET_SCOPE
  65. * @see PortletSession#APPLICATION_SCOPE
  66. *
  67. * @since 7.6
  68. */
  69. public Object getAttribute(String name, int scope) {
  70. return session.getAttribute(name, scope);
  71. }
  72. @Override
  73. public void setAttribute(String name, Object value) {
  74. session.setAttribute(name, value);
  75. }
  76. /**
  77. * Binds an object to this session in the given scope, using the name
  78. * specified. If an object of the same name in this scope is already bound
  79. * to the session, that object is replaced.
  80. *
  81. * <p>
  82. * If the value is <code>null</code>, this has the same effect as calling
  83. * <code>removeAttribute()</code>.
  84. *
  85. *
  86. * @param name
  87. * the name to which the object is bound; this cannot be
  88. * <code>null</code>.
  89. * @param value
  90. * the object to be bound
  91. * @param scope
  92. * session scope of this attribute
  93. *
  94. * @exception java.lang.IllegalStateException
  95. * if this method is called on a session which has been
  96. * invalidated
  97. * @exception java.lang.IllegalArgumentException
  98. * if name is <code>null</code> or scope is unknown to the
  99. * container.
  100. *
  101. * @see PortletSession#setAttribute(String, Object, int)
  102. * @see PortletSession#PORTLET_SCOPE
  103. * @see PortletSession#APPLICATION_SCOPE
  104. *
  105. * @since 7.6
  106. */
  107. public void setAttribute(String name, Object value, int scope) {
  108. session.setAttribute(name, value, scope);
  109. }
  110. /**
  111. * Gets the wrapped {@link PortletSession}.
  112. *
  113. * @return the wrapped portlet session
  114. */
  115. public PortletSession getPortletSession() {
  116. return session;
  117. }
  118. @Override
  119. public Set<String> getAttributeNames() {
  120. return WrappedHttpSession.enumerationToSet(session.getAttributeNames());
  121. }
  122. /**
  123. * Gets the current set of attribute names bound to this session in the
  124. * given scope.
  125. *
  126. * @param scope
  127. * session scope of the attribute names
  128. * @return an unmodifiable set of the current attribute names in the given
  129. * scope
  130. *
  131. * @see PortletSession#getAttributeNames()
  132. *
  133. * @since 7.6
  134. */
  135. public Set<String> getAttributeNames(int scope) {
  136. return WrappedHttpSession
  137. .enumerationToSet(session.getAttributeNames(scope));
  138. }
  139. @Override
  140. public void invalidate() {
  141. session.invalidate();
  142. }
  143. @Override
  144. public String getId() {
  145. return session.getId();
  146. }
  147. @Override
  148. public long getCreationTime() {
  149. return session.getCreationTime();
  150. }
  151. @Override
  152. public long getLastAccessedTime() {
  153. return session.getLastAccessedTime();
  154. }
  155. @Override
  156. public boolean isNew() {
  157. return session.isNew();
  158. }
  159. @Override
  160. public void removeAttribute(String name) {
  161. session.removeAttribute(name);
  162. }
  163. /**
  164. * Removes the object bound with the specified name and the given scope from
  165. * this session. If the session does not have an object bound with the
  166. * specified name, this method does nothing.
  167. *
  168. * @param name
  169. * the name of the object to be removed from this session
  170. * @param scope
  171. * session scope of this attribute
  172. *
  173. * @exception java.lang.IllegalStateException
  174. * if this method is called on a session which has been
  175. * invalidated
  176. * @exception java.lang.IllegalArgumentException
  177. * if name is <code>null</code>.
  178. * @see PortletSession#removeAttribute(String, int)
  179. * @see PortletSession#PORTLET_SCOPE
  180. * @see PortletSession#APPLICATION_SCOPE
  181. *
  182. * @since 7.6
  183. */
  184. public void removeAttribute(String name, int scope) {
  185. session.removeAttribute(name, scope);
  186. }
  187. @Override
  188. public void setMaxInactiveInterval(int interval) {
  189. session.setMaxInactiveInterval(interval);
  190. }
  191. }