KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > portlet > PentahoPortletSession


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Aug 2, 2005
14  * @author James Dixon
15  */

16
17 package org.pentaho.ui.portlet;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Locale JavaDoc;
22
23 import javax.portlet.PortletSession;
24
25 import org.apache.commons.collections.iterators.EnumerationIterator;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.pentaho.core.session.BaseSession;
29
30 public class PentahoPortletSession extends BaseSession {
31
32     /**
33      *
34      */

35     private static final long serialVersionUID = -4543813127374975180L;
36
37     private PortletSession portletSession;
38
39     private ArrayList JavaDoc addedAttributes;
40
41     private static final Log logger = LogFactory.getLog(PentahoPortletSession.class);
42
43     public Log getLogger() {
44         return logger;
45     }
46
47     public PentahoPortletSession(String JavaDoc userName, PortletSession portletSession, Locale JavaDoc locale) {
48         super(userName, portletSession.getId(), locale);
49         this.portletSession = portletSession;
50         addedAttributes = new ArrayList JavaDoc();
51     }
52
53     public Object JavaDoc getAttribute(String JavaDoc attributeName) {
54         return portletSession.getAttribute(attributeName, PortletSession.APPLICATION_SCOPE);
55     }
56
57     public Object JavaDoc getAttribute(String JavaDoc attributeName, int scope) {
58         return portletSession.getAttribute(attributeName, scope);
59     }
60
61     public Iterator JavaDoc getAttributeNames() {
62         return new EnumerationIterator(portletSession.getAttributeNames());
63     }
64
65     public void setAttribute(String JavaDoc attributeName, Object JavaDoc value) {
66         portletSession.setAttribute(attributeName, value, PortletSession.APPLICATION_SCOPE);
67         addedAttributes.add(attributeName);
68     }
69
70     public void setAttribute(String JavaDoc attributeName, Object JavaDoc value, int scope) {
71         portletSession.setAttribute(attributeName, value, scope);
72         addedAttributes.add(attributeName);
73     }
74
75     public Object JavaDoc removeAttribute(String JavaDoc attributeName) {
76         Object JavaDoc result = getAttribute(attributeName);
77         portletSession.removeAttribute(attributeName);
78         addedAttributes.remove(attributeName);
79         return result;
80     }
81
82     public Object JavaDoc removeAttribute(String JavaDoc attributeName, int scope) {
83         Object JavaDoc result = getAttribute(attributeName, scope);
84         portletSession.removeAttribute(attributeName, scope);
85         addedAttributes.remove(attributeName);
86         return result;
87     }
88
89     public void destroy() {
90         if (portletSession != null) {
91             Iterator JavaDoc attributeIterator = addedAttributes.iterator();
92             while (attributeIterator.hasNext()) {
93                 portletSession.removeAttribute((String JavaDoc) attributeIterator.next(), PortletSession.APPLICATION_SCOPE);
94             }
95         }
96         super.destroy();
97     }
98
99 }
100
Popular Tags