001    // Copyright 2005 The Apache Software Foundation
002    //
003    // Licensed under the Apache License, Version 2.0 (the "License");
004    // you may not use this file except in compliance with the License.
005    // You may obtain a copy of the License at
006    //
007    //     http://www.apache.org/licenses/LICENSE-2.0
008    //
009    // Unless required by applicable law or agreed to in writing, software
010    // distributed under the License is distributed on an "AS IS" BASIS,
011    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012    // See the License for the specific language governing permissions and
013    // limitations under the License.
014    
015    package org.apache.tapestry.portlet;
016    
017    import java.util.List;
018    
019    import javax.portlet.PortletSession;
020    
021    import org.apache.hivemind.util.Defense;
022    import org.apache.tapestry.describe.DescriptionReceiver;
023    import org.apache.tapestry.web.WebSession;
024    import org.apache.tapestry.web.WebUtils;
025    
026    /**
027     * Adapts a {@link javax.portlet.PortletSession}as a
028     * {@link org.apache.tapestry.web.WebSession}.
029     * 
030     * @author Howard M. Lewis Ship
031     * @since 4.0
032     */
033    public class PortletWebSession implements WebSession
034    {
035    
036        private final PortletSession _portletSession;
037    
038        public PortletWebSession(final PortletSession portletSession)
039        {
040            Defense.notNull(portletSession, "portletSession");
041    
042            _portletSession = portletSession;
043        }
044    
045        public void describeTo(DescriptionReceiver receiver)
046        {
047            receiver.describeAlternate(_portletSession);
048        }
049    
050        public String getId()
051        {
052            return _portletSession.getId();
053        }
054    
055        public boolean isNew()
056        {
057            return _portletSession.isNew();
058        }
059    
060        public List getAttributeNames()
061        {
062            return WebUtils.toSortedList(_portletSession.getAttributeNames());
063        }
064    
065        public Object getAttribute(String name)
066        {
067            return _portletSession.getAttribute(name);
068        }
069    
070        public void setAttribute(String name, Object attribute)
071        {
072            _portletSession.setAttribute(name, attribute);
073        }
074    
075        public void invalidate()
076        {
077            _portletSession.invalidate();
078        }
079    
080        /** 
081         * {@inheritDoc}
082         */
083        public long getCreationTime()
084        {
085            return _portletSession.getCreationTime();
086        }
087    
088        /** 
089         * {@inheritDoc}
090         */
091        public long getLastAccessedTime()
092        {
093            return _portletSession.getLastAccessedTime();
094        }
095    
096        /** 
097         * {@inheritDoc}
098         */
099        public int getMaxInactiveInterval()
100        {
101            return _portletSession.getMaxInactiveInterval();
102        }
103    
104        /** 
105         * {@inheritDoc}
106         */
107        public void setMaxInactiveInterval(int interval)
108        {
109            _portletSession.setMaxInactiveInterval(interval);
110        }
111        
112    }