KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > comanche > RequestAnalyzer


1 package comanche;
2 import java.io.*;
3 import org.objectweb.fractal.api.control.BindingController;
4
5 public class RequestAnalyzer implements RequestHandler, BindingController {
6   private RequestHandler rh;
7   private Logger l;
8   // configuration aspect
9
public String JavaDoc[] listFc () { return new String JavaDoc[] { "l", "rh" }; }
10   public Object JavaDoc lookupFc (String JavaDoc itfName) {
11     if (itfName.equals("l")) { return l; }
12     else if (itfName.equals("rh")) { return rh; }
13     else return null;
14   }
15   public void bindFc (String JavaDoc itfName, Object JavaDoc itfValue) {
16     if (itfName.equals("l")) { l = (Logger)itfValue; }
17     else if (itfName.equals("rh")) { rh = (RequestHandler)itfValue; }
18   }
19   public void unbindFc (String JavaDoc itfName) {
20     if (itfName.equals("l")) { l = null; }
21     else if (itfName.equals("rh")) { rh = null; }
22   }
23   // functional aspect
24
public void handleRequest (Request r) throws IOException {
25     r.in = new InputStreamReader(r.s.getInputStream());
26     r.out = new PrintStream(r.s.getOutputStream());
27     String JavaDoc rq = new LineNumberReader(r.in).readLine();
28     l.log(rq);
29     if (rq.startsWith("GET ")) {
30       r.url = rq.substring(5, rq.indexOf(' ', 4));
31       rh.handleRequest(r);
32     }
33     r.out.close();
34     r.s.close();
35   }
36 }
37
Popular Tags