KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > comanche > RequestDispatcher


1 /*==============================================================================
2 Fraclet annotation- Copyright (C) 2002-2006 INRIA Futurs / LIFL
3 Fractal Component Model (contact: fractal@objectweb.org)
4
5 This library is free software; you can redistribute it and/or modify it under
6 the terms of the GNU Lesser General Public License as published by the Free
7 Software Foundation; either version 2.1 of the License, or any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12
13 You should have received a copy of the GNU Lesser General Public License along
14 with this library; if not, write to the Free Software Foundation, Inc.,
15 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17 Initial developer(s): Nicolas Pessemier (nicolas.pessemier@lifl.fr)
18 ==============================================================================*/

19 package comanche;
20 import java.io.IOException JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.TreeMap JavaDoc;
24
25 import org.objectweb.fractal.fraclet.annotation.FractalBC;
26 import org.objectweb.fractal.fraclet.annotation.FractalComponent;
27
28 @FractalComponent
29 public class RequestDispatcher implements RequestHandler {
30     
31     @FractalBC(name="h",cardinality="collection")
32     private Map JavaDoc<String JavaDoc, RequestHandler> handlers = new TreeMap JavaDoc<String JavaDoc, RequestHandler>();
33     // configuration aspect
34
// public String[] listFc () {
35
// return (String[])handlers.keySet().toArray(new String[handlers.size()]);
36
// }
37
// public Object lookupFc (String itfName) {
38
// if (itfName.startsWith("h")) { return handlers.get(itfName); }
39
// else return null;
40
// }
41
// public void bindFc (String itfName, Object itfValue) {
42
// if (itfName.startsWith("h")) { handlers.put(itfName, itfValue); }
43
// }
44
// public void unbindFc (String itfName) {
45
// if (itfName.startsWith("h")) { handlers.remove(itfName); }
46
// }
47
// functional aspect
48
public void handleRequest (Request r) throws IOException JavaDoc {
49         Iterator JavaDoc i = handlers.values().iterator();
50         while (i.hasNext()) {
51             try {
52                 ((RequestHandler)i.next()).handleRequest(r); return;
53             } catch (IOException JavaDoc _) { }
54         }
55     }
56 }
57
Popular Tags