}
Context c = getShell().getContext();
EventCentral ec = (EventCentral) c.get("EventCentral");
if (ec == null) {
error("EventCentral not bound in context.");
return;
}
switch (action) {
case ADD:
{
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class liscls = null;
try {
liscls = cl.loadClass(aclazz);
} catch (ClassNotFoundException e) {
error("No such class: " + aclazz);
return;
}
EventListener lis = null;
// if extra params
// load class and find constructor that takes one String as parameter
try {
// create Listener
lis = (EventListener) liscls.newInstance();
//} catch (NoSuchMethodException e) {
// error("No constructor for extra parameters found: " + liscls);
// return;
} catch (InstantiationException e) {
error("Could not instantiate class: " + liscls);
return;
} catch (IllegalAccessException e) {
error("Not allowed to instantiate class: " + liscls);
return;
}
String origin = ec.produceOrigin(compName);
// register it with the pattern
ec.registerEventListener(origin, lis, patterns);
BufferObjectWriter boo = new BufferObjectWriter(getStdOut());
boo.writeObject(origin);
boo.flush();
}
break;
case LIST:
{
Iterator it = ec.listenersIterator();
while (it.hasNext()) {
Map.Entry ent = (Map.Entry) it.next();
Object key = ent.getKey();
Object val = ent.getValue();
err.println(key + " = " + val);
}
}
break;
case DELETE:
{
// find listener whose string representation equals
// then call unregister
Iterator it = ec.listenersIterator();
EventListener lis = null;
while (it.hasNext()) {
Map.Entry ent = (Map.Entry) it.next();
lis = (EventListener) ent.getKey();
if (String.valueOf(lis).equals(dlisStr)) break;
}
if (lis == null) {
if (canThrowEx()) {
throw new Exception("Event listener not registered: " + dlisStr);
} else {
err.println("Event listener not registered: " + dlisStr);
log.debug("done");
return;
}
}
ec.unregisterEventListener(lis);
}
break;
default:
}