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.Method;
13: import java.lang.reflect.InvocationTargetException;
14:
15: import org.mmbase.bridge.*;
16:
17: /**
18: * The FunctionFactory instanciates {@link Function} objects. There are 6 static getFunctions
19: * objects in this class, which correspond to 6 different kind of Function objects.
20: *
21: * The function factory was more important in the 1.7 version of MMBase. Since MMBase 1.8 there are
22: * {@link FunctionProvider}s, so often, it is just as easy and straight forward to simply call the
23: * getFunction method on the relevant FunctionProvider (like {@link FunctionSet}, {@link Cloud},
24: * {@link Module}, or {@link Node}) or to simply instantiate the Function object (e.g. {@link BeanFunction})
25: *
26: * @author Michiel Meeuwissen
27: * @version $Id: FunctionFactory.java,v 1.10 2007/11/25 18:25:49 nklasens Exp $
28: * @since MMBase-1.7
29: */
30: public class FunctionFactory {
31:
32: /**
33: * Gets a function from a function set
34: */
35: public static Function<?> getFunction(String setName,
36: String functionName) {
37: return FunctionSets.getFunction(setName, functionName);
38: }
39:
40: /**
41: * Gets a function from a function set on a certain cloud
42: */
43: public static Function getFunction(Cloud cloud, String setName,
44: String functionName) {
45: return cloud.getFunction(setName, functionName);
46: }
47:
48: /**
49: * Gets a function object for a Node.
50: */
51: public static Function getFunction(Node node, String functionName) {
52: return node.getFunction(functionName);
53: // return NodeFunction.getFunction(node, functionName);
54: }
55:
56: /**
57: * Gets a function object for a NodeManager
58: */
59: public static Function getFunction(NodeManager nodeManager,
60: String functionName) {
61: return nodeManager.getFunction(functionName);
62: }
63:
64: /**
65: * Gets a function object for a Module
66: */
67: public static Function getFunction(Module module,
68: String functionName) {
69: return module.getFunction(functionName);
70: }
71:
72: /**
73: * Gets a function object for a certain Method
74: */
75: public static Function<Object> getFunction(Method method,
76: String functionName) {
77: return new MethodFunction(method, functionName);
78: }
79:
80: /**
81: * Gets a function object for a Bean
82: */
83: public static Function<Object> getFunction(Class<?> claz,
84: String functionName)
85: throws java.lang.IllegalAccessException,
86: InstantiationException, InvocationTargetException {
87: return BeanFunction.getFunction(claz, functionName);
88: }
89:
90: }
|