01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10: package org.mmbase.util.functions;
11:
12: import java.lang.reflect.*;
13:
14: import org.mmbase.util.logging.Logger;
15: import org.mmbase.util.logging.Logging;
16:
17: /**
18: * Maintains all methods of a certain class as function object (as long as they have unique names).
19: *
20: * @since MMBase-1.9
21: * @author Michiel Meeuwissen
22: * @version $Id: ClassFunctionProvider.java,v 1.3 2007/11/25 18:25:49 nklasens Exp $
23: */
24: public class ClassFunctionProvider extends FunctionProvider {
25: private static final Logger log = Logging
26: .getLoggerInstance(ClassFunctionProvider.class);
27:
28: public ClassFunctionProvider(Class<?> clazz, Object instance) {
29: for (Method m : clazz.getMethods()) {
30: if (!functions.containsKey(m.getName())) {
31: try {
32: addFunction(MethodFunction.getFunction(
33: MethodFunction
34: .getMethod(clazz, m.getName()), m
35: .getName(), instance));
36: } catch (Exception e) {
37: log.error("For " + m.getName() + " of " + clazz
38: + " : " + e.getMessage());
39: }
40: }
41: }
42: }
43:
44: }
|