001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Aug 2, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.ui.portlet;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.Locale;
022:
023: import javax.portlet.PortletSession;
024:
025: import org.apache.commons.collections.iterators.EnumerationIterator;
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.pentaho.core.session.BaseSession;
029:
030: public class PentahoPortletSession extends BaseSession {
031:
032: /**
033: *
034: */
035: private static final long serialVersionUID = -4543813127374975180L;
036:
037: private PortletSession portletSession;
038:
039: private ArrayList addedAttributes;
040:
041: private static final Log logger = LogFactory
042: .getLog(PentahoPortletSession.class);
043:
044: public Log getLogger() {
045: return logger;
046: }
047:
048: public PentahoPortletSession(String userName,
049: PortletSession portletSession, Locale locale) {
050: super (userName, portletSession.getId(), locale);
051: this .portletSession = portletSession;
052: addedAttributes = new ArrayList();
053: }
054:
055: public Object getAttribute(String attributeName) {
056: return portletSession.getAttribute(attributeName,
057: PortletSession.APPLICATION_SCOPE);
058: }
059:
060: public Object getAttribute(String attributeName, int scope) {
061: return portletSession.getAttribute(attributeName, scope);
062: }
063:
064: public Iterator getAttributeNames() {
065: return new EnumerationIterator(portletSession
066: .getAttributeNames());
067: }
068:
069: public void setAttribute(String attributeName, Object value) {
070: portletSession.setAttribute(attributeName, value,
071: PortletSession.APPLICATION_SCOPE);
072: addedAttributes.add(attributeName);
073: }
074:
075: public void setAttribute(String attributeName, Object value,
076: int scope) {
077: portletSession.setAttribute(attributeName, value, scope);
078: addedAttributes.add(attributeName);
079: }
080:
081: public Object removeAttribute(String attributeName) {
082: Object result = getAttribute(attributeName);
083: portletSession.removeAttribute(attributeName);
084: addedAttributes.remove(attributeName);
085: return result;
086: }
087:
088: public Object removeAttribute(String attributeName, int scope) {
089: Object result = getAttribute(attributeName, scope);
090: portletSession.removeAttribute(attributeName, scope);
091: addedAttributes.remove(attributeName);
092: return result;
093: }
094:
095: public void destroy() {
096: if (portletSession != null) {
097: Iterator attributeIterator = addedAttributes.iterator();
098: while (attributeIterator.hasNext()) {
099: portletSession.removeAttribute(
100: (String) attributeIterator.next(),
101: PortletSession.APPLICATION_SCOPE);
102: }
103: }
104: super.destroy();
105: }
106:
107: }
|