diff --git a/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java b/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java index a2034fe..850bb6e 100644 --- a/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java +++ b/extras/src/main/java/edu/umd/cs/piccolox/event/PNotificationCenter.java @@ -93,8 +93,12 @@ * null then the listener will receive all notifications with an object * matching 'object'. If 'object' is null the listener will receive all * notifications with the name 'notificationName'. + * + * @return whether or not the listener has been added + * @throws SecurityException */ - public void addListener(Object listener, String callbackMethodName, String notificationName, Object object) { + public boolean addListener(Object listener, String callbackMethodName, String notificationName, Object object) + throws SecurityException { processKeyQueue(); Object name = notificationName; @@ -104,14 +108,16 @@ method = listener.getClass().getMethod(callbackMethodName, new Class[] { PNotification.class }); } catch (NoSuchMethodException e) { - e.printStackTrace(); - return; + return false; } - if (name == null) + if (name == null) { name = NULL_MARKER; - if (object == null) + } + + if (object == null) { object = NULL_MARKER; + } Object key = new CompoundKey(name, object); Object value = new CompoundValue(listener, method); @@ -125,6 +131,8 @@ if (!list.contains(value)) { list.add(value); } + + return true; } // **************************************************************** diff --git a/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java b/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java index f720722..ba82906 100644 --- a/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java +++ b/extras/src/test/java/edu/umd/cs/piccolox/event/PNotificationCenterTest.java @@ -41,7 +41,7 @@ super(name); } - public void testToString() { + public void testToString() throws SecurityException, NoSuchMethodException { PNotificationCenter center = PNotificationCenter.defaultCenter(); center.addListener(this, "changed1", "propertyChanged", this);