KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > j2ee > session > StateInterceptor


1 // ========================================================================
2
// $Id: StateInterceptor.java,v 1.4 2004/05/09 20:30:47 gregwilkins Exp $
3
// Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.j2ee.session;
17
18 //----------------------------------------
19

20 import java.rmi.RemoteException JavaDoc;
21 import java.util.Enumeration JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import javax.servlet.http.HttpSession JavaDoc;
25
26 //----------------------------------------
27
/**
28  * Superlass for StateInterceptors - objects which
29  * wrap-n-delegate/decorate a State instance. A stack of
30  * StateInterceptors form a StateContainer.
31  *
32  * @author <a HREF="mailto:jules@mortbay.com">Jules Gosnell</a>
33  * @version 1.0
34  */

35 public class
36   StateInterceptor
37   implements State, Cloneable JavaDoc
38 {
39   // protected final ThreadLocal _state =new ThreadLocal();
40
// protected State getState () {return (State)_state.get();}
41
// protected void setState(State state) {_state.set(state);}
42
//
43
private final static ThreadLocal JavaDoc _manager=new ThreadLocal JavaDoc();
44   protected Manager getManager () {return (Manager)_manager.get();}
45   protected void setManager(Manager manager) {_manager.set(manager);}
46
47   private final static ThreadLocal JavaDoc _session=new ThreadLocal JavaDoc();
48   protected HttpSession JavaDoc getSession () {return (HttpSession JavaDoc)_session.get();}
49   protected void setSession(HttpSession JavaDoc session) {_session.set(session);}
50
51   // management of this attribute needs to move into the container...
52
private State _state;
53   protected State getState () {return _state;}
54   protected void setState(State state) {_state=state;}
55
56   // protected HttpSession _session;
57
// protected HttpSession getSession () {return _session;}
58
// protected void setSession(HttpSession session) {_session=session;}
59

60   //----------------------------------------
61
// 'StateInterceptor' API
62
//----------------------------------------
63

64   // lifecycle
65
public void start() {}
66   public void stop() {}
67
68   // misc
69
public String JavaDoc toString() {return "<"+getClass()+"->"+getState()+">";}
70
71   //----------------------------------------
72
// wrapped-n-delegated-to 'State' API
73
//----------------------------------------
74
// invariant field accessors
75
public String JavaDoc getId() throws RemoteException JavaDoc {return getState().getId();}
76   public int getActualMaxInactiveInterval() throws RemoteException JavaDoc {return getState().getActualMaxInactiveInterval();}
77   public long getCreationTime() throws RemoteException JavaDoc {return getState().getCreationTime();}
78
79   // variant field accessors
80
public Map JavaDoc getAttributes() throws RemoteException JavaDoc {return getState().getAttributes();}
81   public void setAttributes(Map JavaDoc attributes) throws RemoteException JavaDoc {getState().setAttributes(attributes);}
82   public long getLastAccessedTime() throws RemoteException JavaDoc {return getState().getLastAccessedTime();}
83   public void setLastAccessedTime(long time) throws RemoteException JavaDoc {getState().setLastAccessedTime(time);}
84   public int getMaxInactiveInterval() throws RemoteException JavaDoc {return getState().getMaxInactiveInterval();}
85   public void setMaxInactiveInterval(int interval) throws RemoteException JavaDoc {getState().setMaxInactiveInterval(interval);}
86
87   // compound fn-ality
88
public Object JavaDoc getAttribute(String JavaDoc name) throws RemoteException JavaDoc {return getState().getAttribute(name);}
89   public Object JavaDoc setAttribute(String JavaDoc name, Object JavaDoc value, boolean returnValue) throws RemoteException JavaDoc {return getState().setAttribute(name, value, returnValue);}
90   public Object JavaDoc removeAttribute(String JavaDoc name, boolean returnValue) throws RemoteException JavaDoc {return getState().removeAttribute(name, returnValue);}
91   public Enumeration JavaDoc getAttributeNameEnumeration() throws RemoteException JavaDoc {return getState().getAttributeNameEnumeration();}
92   public String JavaDoc[] getAttributeNameStringArray() throws RemoteException JavaDoc {return getState().getAttributeNameStringArray();}
93   public boolean isValid() throws RemoteException JavaDoc {return getState().isValid();}
94
95   public Object JavaDoc
96     clone()
97     {
98       Object JavaDoc tmp=null;
99       try
100       {
101     tmp=getClass().newInstance();
102       }
103       catch (Exception JavaDoc e)
104       {
105     // _log.error("could not clone "+getClass().getName(),e); - TODO
106
}
107
108       return tmp;
109     }
110 }
111
112
Popular Tags