KickJava   Java API By Example, From Geeks To Geeks.

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


1 // ========================================================================
2
// $Id: ActivationInterceptor.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
22 import javax.servlet.http.HttpSessionActivationListener JavaDoc;
23 import javax.servlet.http.HttpSessionEvent JavaDoc;
24
25 import org.jfox.ioc.logger.Logger;
26
27 //----------------------------------------
28

29 public class ActivationInterceptor
30   extends StateInterceptor
31 {
32   protected static final Logger _log=Logger.getLogger(ActivationInterceptor.class);
33   protected final HttpSessionEvent JavaDoc _event;
34
35   public
36     ActivationInterceptor()
37   {
38     _event=new HttpSessionEvent JavaDoc(getSession()); // cache an event ready for use...
39
}
40
41   public Object JavaDoc
42     getAttribute(String JavaDoc name)
43     throws IllegalArgumentException JavaDoc, RemoteException JavaDoc
44   {
45     try
46     {
47       Object JavaDoc tmp=super.getAttribute(name);
48       if (tmp!=null && tmp instanceof HttpSessionActivationListener JavaDoc)
49     ((HttpSessionActivationListener JavaDoc)tmp).sessionDidActivate(_event);
50
51       return tmp;
52     }
53     catch (Exception JavaDoc e)
54     {
55       _log.error("could not get Attribute: "+name, e);
56       throw new IllegalArgumentException JavaDoc("could not get Attribute");
57     }
58   }
59
60   public Object JavaDoc
61     setAttribute(String JavaDoc name, Object JavaDoc value, boolean returnValue)
62     throws IllegalArgumentException JavaDoc
63   {
64     try
65     {
66       Object JavaDoc tmp=value;
67       if (tmp!=null && tmp instanceof HttpSessionActivationListener JavaDoc)
68     ((HttpSessionActivationListener JavaDoc)tmp).sessionWillPassivate(_event);
69
70       tmp=super.setAttribute(name, tmp, returnValue);
71
72       if (tmp!=null && tmp instanceof HttpSessionActivationListener JavaDoc)
73     ((HttpSessionActivationListener JavaDoc)tmp).sessionDidActivate(_event);
74
75       return tmp;
76     }
77     catch (Exception JavaDoc e)
78     {
79       _log.error("could not set Attribute: "+name+":"+value, e);
80       throw new IllegalArgumentException JavaDoc("could not set Attribute");
81     }
82   }
83
84   // should an attribute be activated before it is removed ? How do we deal with the bind/unbind events... - TODO
85
public Object JavaDoc
86     removeAttribute(String JavaDoc name, boolean returnValue)
87     throws IllegalArgumentException JavaDoc
88   {
89     try
90     {
91       Object JavaDoc tmp=super.removeAttribute(name, returnValue);
92
93       if (tmp!=null && tmp instanceof HttpSessionActivationListener JavaDoc)
94     ((HttpSessionActivationListener JavaDoc)tmp).sessionDidActivate(_event);
95
96       return tmp;
97     }
98     catch (Exception JavaDoc e)
99     {
100       _log.error("could not remove Attribute: "+name, e);
101       throw new IllegalArgumentException JavaDoc("could not remove Attribute");
102     }
103   }
104
105   // public Object clone() { return null; } // Stateful
106
}
107
Popular Tags