1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.jspf.wiring;
21
22
23 import java.lang.reflect.InvocationTargetException;
24 import java.lang.reflect.Method;
25 import java.util.Hashtable;
26 import java.util.Iterator;
27
28
29
30
31
32 public class WiringServiceTable extends Hashtable implements WiringService {
33
34 private static final long serialVersionUID = -9151935136150279119L;
35
36
37
38
39 public void wire(Object component) throws WiringServiceException {
40 Iterator i = keySet().iterator();
41 while (i.hasNext()) {
42 Class enablingClass = (Class) i.next();
43 if (enablingClass.isInstance(component)) {
44 Method[] m = enablingClass.getDeclaredMethods();
45 if (m!=null && m.length == 1 && m[0] != null) {
46 try {
47 m[0].invoke(component, new Object[] {get(enablingClass)});
48 } catch (IllegalArgumentException e) {
49 throw new WiringServiceException("Illegal argument invoking enabled service: "+enablingClass.toString(), e);
50 } catch (InvocationTargetException e) {
51 throw new WiringServiceException("Unable to invoke enabled service: "+enablingClass.toString(), e);
52 } catch (IllegalAccessException e) {
53 throw new WiringServiceException("Unable to invoke enabled service: "+enablingClass.toString(), e);
54 }
55 }
56 }
57 }
58
59 }
60
61 }