1 16 17 package org.pentaho.ui.portlet; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.Locale ; 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 35 private static final long serialVersionUID = -4543813127374975180L; 36 37 private PortletSession portletSession; 38 39 private ArrayList 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 userName, PortletSession portletSession, Locale locale) { 48 super(userName, portletSession.getId(), locale); 49 this.portletSession = portletSession; 50 addedAttributes = new ArrayList (); 51 } 52 53 public Object getAttribute(String attributeName) { 54 return portletSession.getAttribute(attributeName, PortletSession.APPLICATION_SCOPE); 55 } 56 57 public Object getAttribute(String attributeName, int scope) { 58 return portletSession.getAttribute(attributeName, scope); 59 } 60 61 public Iterator getAttributeNames() { 62 return new EnumerationIterator(portletSession.getAttributeNames()); 63 } 64 65 public void setAttribute(String attributeName, Object value) { 66 portletSession.setAttribute(attributeName, value, PortletSession.APPLICATION_SCOPE); 67 addedAttributes.add(attributeName); 68 } 69 70 public void setAttribute(String attributeName, Object value, int scope) { 71 portletSession.setAttribute(attributeName, value, scope); 72 addedAttributes.add(attributeName); 73 } 74 75 public Object removeAttribute(String attributeName) { 76 Object result = getAttribute(attributeName); 77 portletSession.removeAttribute(attributeName); 78 addedAttributes.remove(attributeName); 79 return result; 80 } 81 82 public Object removeAttribute(String attributeName, int scope) { 83 Object 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 attributeIterator = addedAttributes.iterator(); 92 while (attributeIterator.hasNext()) { 93 portletSession.removeAttribute((String ) attributeIterator.next(), PortletSession.APPLICATION_SCOPE); 94 } 95 } 96 super.destroy(); 97 } 98 99 } 100 | Popular Tags |