KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > event > WeakRequestListenerProxy


1 /*
2  * $Id: WeakRequestListenerProxy.java,v 1.5 2005/05/13 15:47:07 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.event;
15
16 import java.lang.ref.WeakReference JavaDoc;
17
18
19 /**
20  * A SRequestListener implementation, which uses WeakReference. This is
21  * important for volatile objects, which needs to be registered as request
22  * listener at the wings session, but which are not removed anymore from the
23  * session. To make them
24  * garbage collectable, they should use this proxy for registering as a request
25  * listener.
26  *
27  * @author <a HREF="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
28  * @version $Revision: 1.5 $
29  */

30 public final class WeakRequestListenerProxy extends WeakReference JavaDoc implements SRequestListener {
31
32
33     public WeakRequestListenerProxy(SRequestListener requestListener) {
34         super(requestListener);
35     }
36
37     /**
38      * Invokes the processRequest method of the proxied requestListener. If the
39      * listener is garbage collected, it removes itself from the session as
40      * request listener.
41      *
42      * @param e a <code>SRequestEvent</code> value
43      */

44     public void processRequest(SRequestEvent e) {
45         SRequestListener requestListener = (SRequestListener) get();
46
47         if (requestListener == null) {
48             org.wings.session.SessionManager.getSession().removeRequestListener(this);
49         } else {
50             requestListener.processRequest(e);
51         } // end of if ()
52
}
53
54     public int hashCode() {
55         Object JavaDoc requestListener = get();
56
57         if (requestListener == null) {
58             return 0;
59         } else {
60             return requestListener.hashCode();
61         } // end of if ()
62
}
63
64     public boolean equals(WeakRequestListenerProxy p) {
65         Object JavaDoc requestListener = get();
66
67         if (requestListener == null) {
68             return p.get() == null;
69         } else {
70             return requestListener.equals(p.get());
71         } // end of if ()
72
}
73
74     public boolean equals(Object JavaDoc o) {
75         if (o instanceof WeakRequestListenerProxy) {
76             return equals((WeakRequestListenerProxy) o);
77         } else {
78             return false;
79         } // end of if ()
80
}
81
82 }
83
84
Popular Tags