You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2002/11/12 23:36:59 UTC
cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang Notifier.java
bayard 2002/11/12 14:36:59
Modified: lang/src/java/org/apache/commons/lang Notifier.java
Log:
Some of the modifications Stephen wants.
Revision Changes Path
1.2 +26 -18 jakarta-commons/lang/src/java/org/apache/commons/lang/Notifier.java
Index: Notifier.java
===================================================================
RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/Notifier.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Notifier.java 12 Nov 2002 03:01:04 -0000 1.1
+++ Notifier.java 12 Nov 2002 22:36:59 -0000 1.2
@@ -54,8 +54,10 @@
package org.apache.commons.lang;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.EventObject;
import java.util.Iterator;
+import java.util.List;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
@@ -76,10 +78,11 @@
private String methodName;
private Class clss;
- public Notifier() {
- }
-
public Notifier(Class listener) {
+ if(listener == null) {
+ throw new IllegalArgumentException("Illegal to have a null listener Class. ");
+ }
+
this.clss = clss;
// now we check methods, if only one of them, then
// let's set it
@@ -90,18 +93,24 @@
}
/**
- * Set the name of the method to call upon the listeners.
+ * Construct with the class and the name of the method to
+ * call upon the listeners.
*/
- public void setListenerMethod(String name) {
+ public Notifier(Class clss, String name) {
+ if(clss == null) {
+ throw new IllegalArgumentException("Illegal to have a null Listener Class. ");
+ }
+ if(name == null) {
+ throw new IllegalArgumentException("Illegal to have a null method name. ");
+ }
+ this.clss = clss;
this.methodName = name;
- if(this.clss != null) {
- try {
- // then we get the Method object
- this.listenerMethod = this.clss.getDeclaredMethod(name, new Class[] { EventObject.class} );
- } catch(NoSuchMethodException nsme) {
-// nsme.printStackTrace();
- throw new IllegalArgumentException("Method not on Class. ");
- }
+ try {
+ // then we get the Method object
+ this.listenerMethod = this.clss.getDeclaredMethod(name, new Class[] { EventObject.class} );
+ } catch(NoSuchMethodException nsme) {
+// nsme.printStackTrace();
+ throw new IllegalArgumentException("Method not on Class. ");
}
}
@@ -113,10 +122,9 @@
this.listeners.remove(not);
}
- public ArrayList getListeners() {
- ArrayList cloned = new ArrayList();
- cloned.addAll(listeners);
- return cloned;
+ public List getListeners() {
+ ArrayList cloned = new ArrayList(listeners);
+ return Collections.unmodifiableList(cloned);
}
/**
@@ -138,7 +146,7 @@
* This is usable when a Listener has more than one method and
* a single Notifier wants to be shared.
*/
- public void notify(Method listenerMethod, EventObject event) throws NotifierException {
+ private void notify(Method listenerMethod, EventObject event) throws NotifierException {
Iterator itr = getListeners().iterator();
while(itr.hasNext()) {
try {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>