jdk/src/share/classes/java/beans/EventHandler.java
author malenkov
Thu, 29 Jan 2009 15:34:50 +0300
changeset 1851 8203c7eb8caf
parent 1299 027d966d5658
child 5185 e29dad1b6945
permissions -rw-r--r--
6788531: java.beans.Statement imposes excessive access control Reviewed-by: peterz, rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1851
8203c7eb8caf 6788531: java.beans.Statement imposes excessive access control
malenkov
parents: 1299
diff changeset
     2
 * Copyright 2000-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.lang.reflect.InvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.reflect.misc.MethodUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The <code>EventHandler</code> class provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * support for dynamically generating event listeners whose methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * execute a simple statement involving an incoming event object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * and a target object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The <code>EventHandler</code> class is intended to be used by interactive tools, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * application builders, that allow developers to make connections between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * beans. Typically connections are made from a user interface bean
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * (the event <em>source</em>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * to an application logic bean (the <em>target</em>). The most effective
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * connections of this kind isolate the application logic from the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * interface.  For example, the <code>EventHandler</code> for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * connection from a <code>JCheckBox</code> to a method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * that accepts a boolean value can deal with extracting the state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * of the check box and passing it directly to the method so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * the method is isolated from the user interface layer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Inner classes are another, more general way to handle events from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * user interfaces.  The <code>EventHandler</code> class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * handles only a subset of what is possible using inner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * classes. However, <code>EventHandler</code> works better
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * with the long-term persistence scheme than inner classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Also, using <code>EventHandler</code> in large applications in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * which the same interface is implemented many times can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * reduce the disk and memory footprint of the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * The reason that listeners created with <code>EventHandler</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * have such a small
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * footprint is that the <code>Proxy</code> class, on which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the <code>EventHandler</code> relies, shares implementations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * of identical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * interfaces. For example, if you use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * the <code>EventHandler</code> <code>create</code> methods to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * all the <code>ActionListener</code>s in an application,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * all the action listeners will be instances of a single class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * (one created by the <code>Proxy</code> class).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * In general, listeners based on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * the <code>Proxy</code> class require one listener class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * to be created per <em>listener type</em> (interface),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * whereas the inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * approach requires one class to be created per <em>listener</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * (object that implements the interface).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * You don't generally deal directly with <code>EventHandler</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Instead, you use one of the <code>EventHandler</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <code>create</code> methods to create
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * an object that implements a given listener interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * This listener object uses an <code>EventHandler</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * behind the scenes to encapsulate information about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * event, the object to be sent a message when the event occurs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * the message (method) to be sent, and any argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * to the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * The following section gives examples of how to create listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * objects using the <code>create</code> methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <h2>Examples of Using EventHandler</h2>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * The simplest use of <code>EventHandler</code> is to install
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * a listener that calls a method on the target object with no arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * In the following example we create an <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * that invokes the <code>toFront</code> method on an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * of <code>javax.swing.JFrame</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *myButton.addActionListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *    (ActionListener)EventHandler.create(ActionListener.class, frame, "toFront"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * When <code>myButton</code> is pressed, the statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <code>frame.toFront()</code> will be executed.  One could get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * the same effect, with some additional compile-time type safety,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * by defining a new implementation of the <code>ActionListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * interface and adding an instance of it to the button:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *myButton.addActionListener(new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *        frame.toFront();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * The next simplest use of <code>EventHandler</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * to extract a property value from the first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * of the method in the listener interface (typically an event object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * and use it to set the value of a property in the target object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * In the following example we create an <code>ActionListener</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * sets the <code>nextFocusableComponent</code> property of the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * (myButton) object to the value of the "source" property of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *EventHandler.create(ActionListener.class, myButton, "nextFocusableComponent", "source")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * This would correspond to the following inner class implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 *    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *        myButton.setNextFocusableComponent((Component)e.getSource());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * It's also possible to create an <code>EventHandler</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * just passes the incoming event object to the target's action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * If the fourth <code>EventHandler.create</code> argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * an empty string, then the event is just passed along:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *EventHandler.create(ActionListener.class, target, "doActionEvent", "")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * This would correspond to the following inner class implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *        target.doActionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * Probably the most common use of <code>EventHandler</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * is to extract a property value from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <em>source</em> of the event object and set this value as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * the value of a property of the target object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * In the following example we create an <code>ActionListener</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * sets the "label" property of the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * object to the value of the "text" property of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * source (the value of the "source" property) of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 *EventHandler.create(ActionListener.class, myButton, "label", "source.text")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * This would correspond to the following inner class implementation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *new ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 *    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 *        myButton.setLabel(((JTextField)e.getSource()).getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 *}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * The event property may be "qualified" with an arbitrary number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * of property prefixes delimited with the "." character. The "qualifying"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * names that appear before the "." characters are taken as the names of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * properties that should be applied, left-most first, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * the event object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * For example, the following action listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *EventHandler.create(ActionListener.class, target, "a", "b.c.d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 * might be written as the following inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
 * (assuming all the properties had canonical getter methods and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
 * returned the appropriate types):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
 *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
 *new ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
 *    public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
 *        target.setA(e.getB().getC().isD());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
 *}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
 * The target property may also be "qualified" with an arbitrary number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
 * of property prefixs delimited with the "." character.  For example, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * following action listener:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
 *   EventHandler.create(ActionListener.class, target, "a.b", "c.d")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
 * might be written as the following inner class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
 * (assuming all the properties had canonical getter methods and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
 * returned the appropriate types):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
 *   //Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
 *   new ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
 *     public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
 *         target.getA().setB(e.getC().isD());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
 *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
 *}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
 *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
 * As <code>EventHandler</code> ultimately relies on reflection to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
 * a method we recommend against targeting an overloaded method.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
 * if the target is an instance of the class <code>MyTarget</code> which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
 * defined as:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
 *   public class MyTarget {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
 *     public void doIt(String);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
 *     public void doIt(Object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
 * Then the method <code>doIt</code> is overloaded.  EventHandler will invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
 * the method that is appropriate based on the source.  If the source is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
 * null, then either method is appropriate and the one that is invoked is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
 * undefined.  For that reason we recommend against targeting overloaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
 * methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
 * @see java.lang.reflect.Proxy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
 * @see java.util.EventObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
 * @author Mark Davidson
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
 * @author Philip Milne
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
public class EventHandler implements InvocationHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private Object target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    private String action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    private String eventPropertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    private String listenerMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private AccessControlContext acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * Creates a new <code>EventHandler</code> object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * you generally use one of the <code>create</code> methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * instead of invoking this constructor directly.  Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * {@link java.beans.EventHandler#create(Class, Object, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * the general version of create} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * the <code>eventPropertyName</code> and <code>listenerMethodName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param target the object that will perform the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param action the name of a (possibly qualified) property or method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *        the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param eventPropertyName the (possibly qualified) name of a readable property of the incoming event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param listenerMethodName the name of the method in the listener interface that should trigger the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @throws NullPointerException if <code>target</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @throws NullPointerException if <code>action</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see EventHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see #create(Class, Object, String, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see #getTarget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @see #getAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #getEventPropertyName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #getListenerMethodName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    @ConstructorProperties({"target", "action", "eventPropertyName", "listenerMethodName"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public EventHandler(Object target, String action, String eventPropertyName, String listenerMethodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        this.acc = AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        this.action = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if (target == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            throw new NullPointerException("target must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (action == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            throw new NullPointerException("action must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        this.eventPropertyName = eventPropertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        this.listenerMethodName = listenerMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Returns the object to which this event handler will send a message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @return the target of this event handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see #EventHandler(Object, String, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public Object getTarget()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Returns the name of the target's writable property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * that this event handler will set,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * or the name of the method that this event handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * will invoke on the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return the action of this event handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see #EventHandler(Object, String, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public String getAction()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Returns the property of the event that should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * used in the action applied to the target.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return the property of the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see #EventHandler(Object, String, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public String getEventPropertyName()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return eventPropertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns the name of the method that will trigger the action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * A return value of <code>null</code> signifies that all methods in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * listener interface trigger the action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @return the name of the method that will trigger the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @see #EventHandler(Object, String, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public String getListenerMethodName()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        return listenerMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    private Object applyGetters(Object target, String getters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (getters == null || getters.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int firstDot = getters.indexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (firstDot == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            firstDot = getters.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        String first = getters.substring(0, firstDot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        String rest = getters.substring(Math.min(firstDot + 1, getters.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            Method getter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (target != null) {
1851
8203c7eb8caf 6788531: java.beans.Statement imposes excessive access control
malenkov
parents: 1299
diff changeset
   388
                getter = Statement.getMethod(target.getClass(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                      "get" + NameGenerator.capitalize(first),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                      new Class[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                if (getter == null) {
1851
8203c7eb8caf 6788531: java.beans.Statement imposes excessive access control
malenkov
parents: 1299
diff changeset
   392
                    getter = Statement.getMethod(target.getClass(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                                   "is" + NameGenerator.capitalize(first),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                                   new Class[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                if (getter == null) {
1851
8203c7eb8caf 6788531: java.beans.Statement imposes excessive access control
malenkov
parents: 1299
diff changeset
   397
                    getter = Statement.getMethod(target.getClass(), first, new Class[]{});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            if (getter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                throw new RuntimeException("No method called: " + first +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                           " defined on " + target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            Object newTarget = MethodUtil.invoke(getter, target, new Object[]{});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return applyGetters(newTarget, rest);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
1280
f58fc9f575e3 6351692: catch(Throwable) in java.beans.MetaData preventing thread shutdown
malenkov
parents: 674
diff changeset
   407
        catch (Exception e) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            throw new RuntimeException("Failed to call method: " + first +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                       " on " + target, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Extract the appropriate property value from the event and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * pass it to the action associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * this <code>EventHandler</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param proxy the proxy object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param method the method in the listener interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @return the result of applying the action to the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see EventHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public Object invoke(final Object proxy, final Method method, final Object[] arguments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return AccessController.doPrivileged(new PrivilegedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                return invokeInternal(proxy, method, arguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }, acc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    private Object invokeInternal(Object proxy, Method method, Object[] arguments) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        String methodName = method.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (method.getDeclaringClass() == Object.class)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            // Handle the Object public methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            if (methodName.equals("hashCode"))  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                return new Integer(System.identityHashCode(proxy));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            } else if (methodName.equals("equals")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                return (proxy == arguments[0] ? Boolean.TRUE : Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            } else if (methodName.equals("toString")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                return proxy.getClass().getName() + '@' + Integer.toHexString(proxy.hashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        if (listenerMethodName == null || listenerMethodName.equals(methodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            Class[] argTypes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            Object[] newArgs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (eventPropertyName == null) {     // Nullary method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                newArgs = new Object[]{};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                argTypes = new Class[]{};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                Object input = applyGetters(arguments[0], getEventPropertyName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                newArgs = new Object[]{input};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                argTypes = new Class[]{input == null ? null :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                       input.getClass()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                int lastDot = action.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                if (lastDot != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    target = applyGetters(target, action.substring(0, lastDot));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    action = action.substring(lastDot + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                }
1851
8203c7eb8caf 6788531: java.beans.Statement imposes excessive access control
malenkov
parents: 1299
diff changeset
   465
                Method targetMethod = Statement.getMethod(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                             target.getClass(), action, argTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                if (targetMethod == null) {
1851
8203c7eb8caf 6788531: java.beans.Statement imposes excessive access control
malenkov
parents: 1299
diff changeset
   468
                    targetMethod = Statement.getMethod(target.getClass(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                             "set" + NameGenerator.capitalize(action), argTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (targetMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    String argTypeString = (argTypes.length == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                        ? " with no arguments"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                        : " with argument " + argTypes[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                        "No method called " + action + " on " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                        target.getClass() + argTypeString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                return MethodUtil.invoke(targetMethod, target, newArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            catch (IllegalAccessException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                throw new RuntimeException(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            catch (InvocationTargetException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                throw new RuntimeException(ex.getTargetException());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Creates an implementation of <code>listenerInterface</code> in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <em>all</em> of the methods in the listener interface apply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * the handler's <code>action</code> to the <code>target</code>. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * method is implemented by calling the other, more general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * implementation of the <code>create</code> method with both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * the <code>eventPropertyName</code> and the <code>listenerMethodName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * taking the value <code>null</code>. Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * {@link java.beans.EventHandler#create(Class, Object, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * the general version of create} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * the <code>action</code> parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * To create an <code>ActionListener</code> that shows a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * <code>JDialog</code> with <code>dialog.show()</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * one can write:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *EventHandler.create(ActionListener.class, dialog, "show")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @param listenerInterface the listener interface to create a proxy for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @param target the object that will perform the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param action the name of a (possibly qualified) property or method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *        the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @return an object that implements <code>listenerInterface</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @throws NullPointerException if <code>listenerInterface</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @throws NullPointerException if <code>target</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @throws NullPointerException if <code>action</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see #create(Class, Object, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public static <T> T create(Class<T> listenerInterface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                               Object target, String action)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return create(listenerInterface, target, action, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * Creates an implementation of <code>listenerInterface</code> in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * <em>all</em> of the methods pass the value of the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * expression, <code>eventPropertyName</code>, to the final method in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * statement, <code>action</code>, which is applied to the <code>target</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * This method is implemented by calling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * more general, implementation of the <code>create</code> method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * the <code>listenerMethodName</code> taking the value <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * {@link java.beans.EventHandler#create(Class, Object, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * the general version of create} for a complete description of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * the <code>action</code> and <code>eventPropertyName</code> parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * To create an <code>ActionListener</code> that sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * the text of a <code>JLabel</code> to the text value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * the <code>JTextField</code> source of the incoming event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * you can use the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *EventHandler.create(ActionListener.class, label, "text", "source.text");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * This is equivalent to the following code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *new ActionListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *    public void actionPerformed(ActionEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *        label.setText(((JTextField)(event.getSource())).getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @param listenerInterface the listener interface to create a proxy for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @param target the object that will perform the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param action the name of a (possibly qualified) property or method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *        the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * @param eventPropertyName the (possibly qualified) name of a readable property of the incoming event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @return an object that implements <code>listenerInterface</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @throws NullPointerException if <code>listenerInterface</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @throws NullPointerException if <code>target</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @throws NullPointerException if <code>action</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @see #create(Class, Object, String, String, String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    public static <T> T create(Class<T> listenerInterface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                               Object target, String action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                               String eventPropertyName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return create(listenerInterface, target, action, eventPropertyName, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Creates an implementation of <code>listenerInterface</code> in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * the method named <code>listenerMethodName</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * passes the value of the event expression, <code>eventPropertyName</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * to the final method in the statement, <code>action</code>, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * is applied to the <code>target</code>. All of the other listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * methods do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * The <code>eventPropertyName</code> string is used to extract a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * from the incoming event object that is passed to the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * method.  The common case is the target method takes no arguments, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * which case a value of null should be used for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <code>eventPropertyName</code>.  Alternatively if you want
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * the incoming event object passed directly to the target method use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * the empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * The format of the <code>eventPropertyName</code> string is a sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * methods or properties where each method or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * property is applied to the value returned by the preceeding method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * starting from the incoming event object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * The syntax is: <code>propertyName{.propertyName}*</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * where <code>propertyName</code> matches a method or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * property.  For example, to extract the <code>point</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * property from a <code>MouseEvent</code>, you could use either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * <code>"point"</code> or <code>"getPoint"</code> as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * <code>eventPropertyName</code>.  To extract the "text" property from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * a <code>MouseEvent</code> with a <code>JLabel</code> source use any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * of the following as <code>eventPropertyName</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <code>"source.text"</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * <code>"getSource.text"</code> <code>"getSource.getText"</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <code>"source.getText"</code>.  If a method can not be found, or an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * exception is generated as part of invoking a method a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * <code>RuntimeException</code> will be thrown at dispatch time.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * example, if the incoming event object is null, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * <code>eventPropertyName</code> is non-null and not empty, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * <code>RuntimeException</code> will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * The <code>action</code> argument is of the same format as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <code>eventPropertyName</code> argument where the last property name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * identifies either a method name or writable property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * If the <code>listenerMethodName</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <em>all</em> methods in the interface trigger the <code>action</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * executed on the <code>target</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * For example, to create a <code>MouseListener</code> that sets the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * object's <code>origin</code> property to the incoming <code>MouseEvent</code>'s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * location (that's the value of <code>mouseEvent.getPoint()</code>) each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * time a mouse button is pressed, one would write:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *<pre>
674
4867bdd4fa38 6668273: Example given in java.beans.EventHandler shows incorrect order of parameters
malenkov
parents: 2
diff changeset
   639
     *EventHandler.create(MouseListener.class, target, "origin", "point", "mousePressed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * This is comparable to writing a <code>MouseListener</code> in which all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * of the methods except <code>mousePressed</code> are no-ops:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *<blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *<pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
//Equivalent code using an inner class instead of EventHandler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *    public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *        target.setOrigin(e.getPoint());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *</blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @param listenerInterface the listener interface to create a proxy for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @param target the object that will perform the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @param action the name of a (possibly qualified) property or method on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *        the target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @param eventPropertyName the (possibly qualified) name of a readable property of the incoming event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @param listenerMethodName the name of the method in the listener interface that should trigger the action
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @return an object that implements <code>listenerInterface</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @throws NullPointerException if <code>listenerInterface</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @throws NullPointerException if <code>target</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @throws NullPointerException if <code>action</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @see EventHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public static <T> T create(Class<T> listenerInterface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                               Object target, String action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                               String eventPropertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                               String listenerMethodName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // Create this first to verify target/action are non-null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        EventHandler eventHandler = new EventHandler(target, action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                                                     eventPropertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                                                     listenerMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        if (listenerInterface == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                          "listenerInterface must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        return (T)Proxy.newProxyInstance(target.getClass().getClassLoader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                         new Class[] {listenerInterface},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                                         eventHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
}