001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.mockobjects.portlet;
018:
019: import java.util.Enumeration;
020: import java.util.Hashtable;
021: import javax.portlet.PortletContext;
022: import javax.portlet.PortletSession;
023:
024: /**
025: * A mock portlet session, useful for unit testing and offline utilities
026: * Note: currently doesn't support scoping
027: *
028: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
029: * @version $Id: MockPortletSession.java 516448 2007-03-09 16:25:47Z ate $
030: */
031: public class MockPortletSession implements PortletSession {
032: // Hashtable (not HashMap) makes enumerations easier to work with
033: Hashtable attributes = new Hashtable();
034:
035: public MockPortletSession() {
036: }
037:
038: /* (non-Javadoc)
039: * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
040: */
041: public Object getAttribute(String name) {
042: return attributes.get(name);
043: }
044:
045: /* (non-Javadoc)
046: * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
047: */
048: public Object getAttribute(String name, int scope) {
049: return attributes.get(name);
050: }
051:
052: /* (non-Javadoc)
053: * @see javax.portlet.PortletSession#getAttributeNames(int)
054: */
055: public Enumeration getAttributeNames(int scope) {
056: return attributes.keys();
057: }
058:
059: /* (non-Javadoc)
060: * @see javax.portlet.PortletSession#getCreationTime()
061: */
062: public long getCreationTime() {
063: // TODO Auto-generated method stub
064: return 0;
065: }
066:
067: /* (non-Javadoc)
068: * @see javax.portlet.PortletSession#getId()
069: */
070: public String getId() {
071: // TODO Auto-generated method stub
072: return null;
073: }
074:
075: /* (non-Javadoc)
076: * @see javax.portlet.PortletSession#getLastAccessedTime()
077: */
078: public long getLastAccessedTime() {
079: // TODO Auto-generated method stub
080: return 0;
081: }
082:
083: /* (non-Javadoc)
084: * @see javax.portlet.PortletSession#getMaxInactiveInterval()
085: */
086: public int getMaxInactiveInterval() {
087: // TODO Auto-generated method stub
088: return 0;
089: }
090:
091: /* (non-Javadoc)
092: * @see javax.portlet.PortletSession#invalidate()
093: */
094: public void invalidate() {
095: // TODO Auto-generated method stub
096: }
097:
098: /* (non-Javadoc)
099: * @see javax.portlet.PortletSession#isNew()
100: */
101: public boolean isNew() {
102: // TODO Auto-generated method stub
103: return false;
104: }
105:
106: /* (non-Javadoc)
107: * @see javax.portlet.PortletSession#removeAttribute(java.lang.String)
108: */
109: public void removeAttribute(String name) {
110: attributes.remove(name);
111: }
112:
113: /* (non-Javadoc)
114: * @see javax.portlet.PortletSession#removeAttribute(java.lang.String, int)
115: */
116: public void removeAttribute(String name, int scope) {
117: attributes.remove(name);
118: }
119:
120: /* (non-Javadoc)
121: * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object)
122: */
123: public void setAttribute(String name, Object value) {
124: attributes.put(name, value);
125: }
126:
127: public Enumeration getAttributeNames() {
128: return this .getAttributeNames(PortletSession.PORTLET_SCOPE);
129: }
130:
131: /* (non-Javadoc)
132: * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object, int)
133: */
134: public void setAttribute(String name, Object value, int scope) {
135: attributes.put(name, value);
136: }
137:
138: /* (non-Javadoc)
139: * @see javax.portlet.PortletSession#setMaxInactiveInterval(int)
140: */
141: public void setMaxInactiveInterval(int interval) {
142: // TODO Auto-generated method stub
143: }
144:
145: /* (non-Javadoc)
146: * @see javax.portlet.PortletSession#getPortletContext()
147: */
148: public PortletContext getPortletContext() {
149: // TODO Auto-generated method stub
150: return null;
151: }
152: }
|