8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.property.adapter;
27
28 import com.sun.javafx.ModuleHelper;
29 import javafx.beans.WeakListener;
30 import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty;
31
32 import java.beans.PropertyChangeEvent;
33 import java.beans.PropertyChangeListener;
34 import java.lang.ref.WeakReference;
35 import java.lang.reflect.InvocationTargetException;
36 import java.lang.reflect.Method;
37
38 import sun.reflect.misc.ReflectUtil;
39
40 import static java.util.Locale.ENGLISH;
41
42 /**
43 */
44 public class ReadOnlyPropertyDescriptor {
45
46 private static final String ADD_LISTENER_METHOD_NAME = "addPropertyChangeListener";
47 private static final String REMOVE_LISTENER_METHOD_NAME = "removePropertyChangeListener";
48 private static final String ADD_PREFIX = "add";
50 private static final String SUFFIX = "Listener";
51
52 private static final int ADD_LISTENER_TAKES_NAME = 1;
53 private static final int REMOVE_LISTENER_TAKES_NAME = 2;
54
55 protected final String name;
56 protected final Class<?> beanClass;
57 private final Method getter;
58 private final Class<?> type;
59
60 private final Method addChangeListener;
61 private final Method removeChangeListener;
62 private final int flags;
63
64 public String getName() {return name;}
65 public Method getGetter() {return getter;}
66 public Class<?> getType() {return type;}
67
68 public ReadOnlyPropertyDescriptor(String propertyName, Class<?> beanClass, Method getter) {
69 ReflectUtil.checkPackageAccess(beanClass);
70 Object thisModule = ModuleHelper.getModule(this.getClass());
71 ModuleHelper.addReads(thisModule, ModuleHelper.getModule(beanClass));
72
73 this.name = propertyName;
74 this.beanClass = beanClass;
75 this.getter = getter;
76 this.type = getter.getReturnType();
77
78 Method tmpAddChangeListener = null;
79 Method tmpRemoveChangeListener = null;
80 int tmpFlags = 0;
81
82 try {
83 final String methodName = ADD_PREFIX + capitalizedName(name) + SUFFIX;
84 tmpAddChangeListener = beanClass.getMethod(methodName, PropertyChangeListener.class);
85 } catch (NoSuchMethodException e) {
86 try {
87 tmpAddChangeListener = beanClass.getMethod(ADD_LISTENER_METHOD_NAME, String.class, PropertyChangeListener.class);
88 tmpFlags |= ADD_LISTENER_TAKES_NAME;
89 } catch (NoSuchMethodException e1) {
90 try {
91 tmpAddChangeListener = beanClass.getMethod(ADD_LISTENER_METHOD_NAME, PropertyChangeListener.class);
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.javafx.property.adapter;
27
28 import javafx.beans.WeakListener;
29 import javafx.beans.property.adapter.ReadOnlyJavaBeanProperty;
30
31 import java.beans.PropertyChangeEvent;
32 import java.beans.PropertyChangeListener;
33 import java.lang.ref.WeakReference;
34 import java.lang.reflect.InvocationTargetException;
35 import java.lang.reflect.Method;
36
37 import sun.reflect.misc.ReflectUtil;
38
39 import static java.util.Locale.ENGLISH;
40
41 /**
42 */
43 public class ReadOnlyPropertyDescriptor {
44
45 private static final String ADD_LISTENER_METHOD_NAME = "addPropertyChangeListener";
46 private static final String REMOVE_LISTENER_METHOD_NAME = "removePropertyChangeListener";
47 private static final String ADD_PREFIX = "add";
49 private static final String SUFFIX = "Listener";
50
51 private static final int ADD_LISTENER_TAKES_NAME = 1;
52 private static final int REMOVE_LISTENER_TAKES_NAME = 2;
53
54 protected final String name;
55 protected final Class<?> beanClass;
56 private final Method getter;
57 private final Class<?> type;
58
59 private final Method addChangeListener;
60 private final Method removeChangeListener;
61 private final int flags;
62
63 public String getName() {return name;}
64 public Method getGetter() {return getter;}
65 public Class<?> getType() {return type;}
66
67 public ReadOnlyPropertyDescriptor(String propertyName, Class<?> beanClass, Method getter) {
68 ReflectUtil.checkPackageAccess(beanClass);
69
70 this.name = propertyName;
71 this.beanClass = beanClass;
72 this.getter = getter;
73 this.type = getter.getReturnType();
74
75 Method tmpAddChangeListener = null;
76 Method tmpRemoveChangeListener = null;
77 int tmpFlags = 0;
78
79 try {
80 final String methodName = ADD_PREFIX + capitalizedName(name) + SUFFIX;
81 tmpAddChangeListener = beanClass.getMethod(methodName, PropertyChangeListener.class);
82 } catch (NoSuchMethodException e) {
83 try {
84 tmpAddChangeListener = beanClass.getMethod(ADD_LISTENER_METHOD_NAME, String.class, PropertyChangeListener.class);
85 tmpFlags |= ADD_LISTENER_TAKES_NAME;
86 } catch (NoSuchMethodException e1) {
87 try {
88 tmpAddChangeListener = beanClass.getMethod(ADD_LISTENER_METHOD_NAME, PropertyChangeListener.class);
|