01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings.event;
14:
15: import java.lang.ref.WeakReference;
16:
17: /**
18: * A SRequestListener implementation, which uses WeakReference. This is
19: * important for volatile objects, which needs to be registered as request
20: * listener at the wings session, but which are not removed anymore from the
21: * session. To make them
22: * garbage collectable, they should use this proxy for registering as a request
23: * listener.
24: *
25: * @author <a href="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
26: */
27: public final class WeakRequestListenerProxy extends WeakReference
28: implements SRequestListener {
29:
30: public WeakRequestListenerProxy(SRequestListener requestListener) {
31: super (requestListener);
32: }
33:
34: /**
35: * Invokes the processRequest method of the proxied requestListener. If the
36: * listener is garbage collected, it removes itself from the session as
37: * request listener.
38: *
39: * @param e a <code>SRequestEvent</code> value
40: */
41: public void processRequest(SRequestEvent e) {
42: SRequestListener requestListener = (SRequestListener) get();
43:
44: if (requestListener == null) {
45: org.wings.session.SessionManager.getSession()
46: .removeRequestListener(this );
47: } else {
48: requestListener.processRequest(e);
49: } // end of if ()
50: }
51:
52: public int hashCode() {
53: Object requestListener = get();
54:
55: if (requestListener == null) {
56: return 0;
57: } else {
58: return requestListener.hashCode();
59: } // end of if ()
60: }
61:
62: public boolean equals(WeakRequestListenerProxy p) {
63: Object requestListener = get();
64:
65: if (requestListener == null) {
66: return p.get() == null;
67: } else {
68: return requestListener.equals(p.get());
69: } // end of if ()
70: }
71:
72: public boolean equals(Object o) {
73: if (o instanceof WeakRequestListenerProxy) {
74: return equals((WeakRequestListenerProxy) o);
75: } else {
76: return false;
77: } // end of if ()
78: }
79:
80: }
|