Some of the modifications Stephen wants.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137122 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2002-11-12 22:36:59 +00:00
parent dfac194424
commit 4c236996fa
1 changed files with 26 additions and 18 deletions

View File

@ -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 @@ public class Notifier {
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. ");
}
public Notifier(Class listener) {
this.clss = clss;
// now we check methods, if only one of them, then
// let's set it
@ -90,11 +93,18 @@ public class Notifier {
}
/**
* 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} );
@ -103,7 +113,6 @@ public class Notifier {
throw new IllegalArgumentException("Method not on Class. ");
}
}
}
public void addListener(Object not) {
this.listeners.add(not);
@ -113,10 +122,9 @@ public class Notifier {
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 @@ public class Notifier {
* 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 {