1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
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 * This class associates "Enabling interfaces" to the service that provides the
30 * dependency.
31 */
32 public class WiringServiceTable extends Hashtable implements WiringService {
33
34 private static final long serialVersionUID = -9151935136150279119L;
35
36 /**
37 * @see org.apache.james.jspf.wiring.WiringService#wire(java.lang.Object)
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 }