comanche.RequestDispatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of comanche Show documentation
Show all versions of comanche Show documentation
The Fractal Comanche example.
package comanche;
import java.io.*;
import java.util.*;
import org.objectweb.fractal.api.control.BindingController;
public class RequestDispatcher implements RequestHandler, BindingController {
private Map handlers = new TreeMap();
// configuration aspect
public String[] listFc () {
return (String[])handlers.keySet().toArray(new String[handlers.size()]);
}
public Object lookupFc (String itfName) {
if (itfName.startsWith("h")) { return handlers.get(itfName); }
else return null;
}
public void bindFc (String itfName, Object itfValue) {
if (itfName.startsWith("h")) { handlers.put(itfName, itfValue); }
}
public void unbindFc (String itfName) {
if (itfName.startsWith("h")) { handlers.remove(itfName); }
}
// functional aspect
public void handleRequest (Request r) throws IOException {
Iterator i = handlers.values().iterator();
while (i.hasNext()) {
try {
((RequestHandler)i.next()).handleRequest(r); return;
} catch (IOException _) { }
}
}
}