Lines 96-103
Link Here
|
96 |
* listenerClass |
96 |
* listenerClass |
97 |
*/ |
97 |
*/ |
98 |
protected WeakListenerImpl(Class<?> listenerClass, java.util.EventListener l) { |
98 |
protected WeakListenerImpl(Class<?> listenerClass, java.util.EventListener l) { |
|
|
99 |
this(listenerClass, l, null); |
100 |
} |
101 |
|
102 |
/** |
103 |
* @param listenerClass class/interface of the listener |
104 |
* @param l listener to delegate to, <code>l</code> must be an instance of |
105 |
* listenerClass |
106 |
*/ |
107 |
protected WeakListenerImpl(Class<?> listenerClass, java.util.EventListener l, String name) { |
99 |
this.listenerClass = listenerClass; |
108 |
this.listenerClass = listenerClass; |
100 |
ref = new ListenerReference(l, this); |
109 |
ref = new ListenerReference(l, name, this); |
101 |
} |
110 |
} |
102 |
|
111 |
|
103 |
/** Setter for the source field. If a WeakReference to an underlying listener is |
112 |
/** Setter for the source field. If a WeakReference to an underlying listener is |
Lines 185-190
Link Here
|
185 |
PropertyChange(Class<?> clazz, PropertyChangeListener l) { |
194 |
PropertyChange(Class<?> clazz, PropertyChangeListener l) { |
186 |
super(clazz, l); |
195 |
super(clazz, l); |
187 |
} |
196 |
} |
|
|
197 |
|
198 |
/** Constructor. |
199 |
* @param clazz required class |
200 |
* @param l listener to delegate to |
201 |
* @param propertyName the associated property name |
202 |
*/ |
203 |
PropertyChange(PropertyChangeListener l, String propertyName) { |
204 |
super(PropertyChangeListener.class, l, propertyName); |
205 |
} |
188 |
|
206 |
|
189 |
/** Tests if the object we reference to still exists and |
207 |
/** Tests if the object we reference to still exists and |
190 |
* if so, delegate to it. Otherwise remove from the source |
208 |
* if so, delegate to it. Otherwise remove from the source |
Lines 217-222
Link Here
|
217 |
super(VetoableChangeListener.class, l); |
235 |
super(VetoableChangeListener.class, l); |
218 |
} |
236 |
} |
219 |
|
237 |
|
|
|
238 |
/** Constructor. |
239 |
* @param l listener to delegate to |
240 |
* @param propertyName the associated property name |
241 |
*/ |
242 |
VetoableChange(VetoableChangeListener l, String propertyName) { |
243 |
super(VetoableChangeListener.class, l, propertyName); |
244 |
} |
245 |
|
220 |
/** Tests if the object we reference to still exists and |
246 |
/** Tests if the object we reference to still exists and |
221 |
* if so, delegate to it. Otherwise remove from the source |
247 |
* if so, delegate to it. Otherwise remove from the source |
222 |
* if it has removePropertyChangeListener method. |
248 |
* if it has removePropertyChangeListener method. |
Lines 513-524
Link Here
|
513 |
private static Class<?> lastClass; |
539 |
private static Class<?> lastClass; |
514 |
private static String lastMethodName; |
540 |
private static String lastMethodName; |
515 |
private static Method lastRemove; |
541 |
private static Method lastRemove; |
|
|
542 |
private static Method lastNamedRemove; |
516 |
private static final Object LOCK = new Object(); |
543 |
private static final Object LOCK = new Object(); |
517 |
WeakListenerImpl weakListener; |
544 |
WeakListenerImpl weakListener; |
|
|
545 |
private String name; |
518 |
|
546 |
|
519 |
ListenerReference(Object ref, WeakListenerImpl weakListener) { |
547 |
ListenerReference(Object ref, String name, WeakListenerImpl weakListener) { |
520 |
super(ref, Utilities.activeReferenceQueue()); |
548 |
super(ref, Utilities.activeReferenceQueue()); |
521 |
this.weakListener = weakListener; |
549 |
this.weakListener = weakListener; |
|
|
550 |
this.name = name; |
522 |
} |
551 |
} |
523 |
|
552 |
|
524 |
/** Requestes cleanup of the listener with a provided source. |
553 |
/** Requestes cleanup of the listener with a provided source. |
Lines 534-540
Link Here
|
534 |
// plan new cleanup into the activeReferenceQueue with this listener and |
563 |
// plan new cleanup into the activeReferenceQueue with this listener and |
535 |
// provided source |
564 |
// provided source |
536 |
weakListener.source = new WeakReference<Object> (source) { |
565 |
weakListener.source = new WeakReference<Object> (source) { |
537 |
ListenerReference doNotGCRef = new ListenerReference(new Object(), weakListener); |
566 |
ListenerReference doNotGCRef = new ListenerReference(new Object(), name, weakListener); |
538 |
}; |
567 |
}; |
539 |
} |
568 |
} |
540 |
} |
569 |
} |
Lines 566-579
Link Here
|
566 |
String methodName = ref.removeMethodName(); |
595 |
String methodName = ref.removeMethodName(); |
567 |
|
596 |
|
568 |
synchronized (LOCK) { |
597 |
synchronized (LOCK) { |
569 |
if (lastClass == methodClass && lastRemove != null && methodName.equals(lastMethodName)) { |
598 |
if (lastClass == methodClass) { |
570 |
remove = lastRemove; |
599 |
if (name == null) { |
|
|
600 |
if (lastRemove != null && methodName.equals(lastMethodName)) { |
601 |
remove = lastRemove; |
602 |
} |
603 |
} else { |
604 |
if (lastNamedRemove != null && methodName.equals(lastMethodName)) { |
605 |
remove = lastNamedRemove; |
606 |
} |
607 |
} |
571 |
} |
608 |
} |
572 |
} |
609 |
} |
573 |
|
610 |
|
574 |
// get the remove method or use the last one |
611 |
// get the remove method or use the last one |
575 |
if (remove == null) { |
612 |
if (remove == null) { |
576 |
remove = getRemoveMethod(methodClass, methodName, ref.listenerClass); |
613 |
if (name == null) { |
|
|
614 |
remove = getRemoveMethod(methodClass, methodName, ref.listenerClass); |
615 |
} |
577 |
if (remove == null) { |
616 |
if (remove == null) { |
578 |
remove = getRemoveMethod(methodClass, methodName, String.class, ref.listenerClass); |
617 |
remove = getRemoveMethod(methodClass, methodName, String.class, ref.listenerClass); |
579 |
} |
618 |
} |
Lines 585-600
Link Here
|
585 |
synchronized (LOCK) { |
624 |
synchronized (LOCK) { |
586 |
lastClass = methodClass; |
625 |
lastClass = methodClass; |
587 |
lastMethodName = methodName; |
626 |
lastMethodName = methodName; |
588 |
lastRemove = remove; |
627 |
if (name == null) { |
|
|
628 |
lastRemove = remove; |
629 |
} else { |
630 |
lastNamedRemove = remove; |
631 |
} |
589 |
} |
632 |
} |
590 |
} |
633 |
} |
591 |
} |
634 |
} |
592 |
|
635 |
|
593 |
try { |
636 |
try { |
594 |
if (remove.getParameterTypes().length == 1) { |
637 |
if (remove.getParameterTypes().length == 1) { |
595 |
remove.invoke(src, new Object[]{ref.getImplementator()}); |
638 |
remove.invoke(src, new Object[]{ref.getImplementator()}); |
596 |
} else { |
639 |
} else { |
597 |
remove.invoke(src, new Object[]{"", ref.getImplementator()}); |
640 |
String nameParam = (name == null) ? "" : name; |
|
|
641 |
remove.invoke(src, new Object[]{nameParam, ref.getImplementator()}); |
598 |
} |
642 |
} |
599 |
} catch (Exception ex) { // from invoke(), should not happen |
643 |
} catch (Exception ex) { // from invoke(), should not happen |
600 |
// #151415 - ignore exception from AbstractPreferences if node has been removed |
644 |
// #151415 - ignore exception from AbstractPreferences if node has been removed |