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.util.List;
13:
14: /**
15: * A wrapped function is a base class for function objects based on an other function object.
16: *
17: * @since MMBase-1.8
18: * @author Pierre van Rooden
19: * @version $Id: WrappedFunction.java,v 1.15 2007/12/06 08:21:42 michiel Exp $
20: */
21: public abstract class WrappedFunction<R> implements Function<R> {
22:
23: protected Function<R> wrappedFunction;
24:
25: /**
26: * Constructor for Basic Function
27: * @param function The function to wrap
28: */
29: public WrappedFunction(Function<R> function) {
30: wrappedFunction = function;
31: }
32:
33: public Parameters createParameters() {
34: return wrappedFunction.createParameters();
35: }
36:
37: public R getFunctionValue(Parameters parameters) {
38: return wrappedFunction.getFunctionValue(parameters);
39: }
40:
41: public R getFunctionValueWithList(List<?> parameters) {
42: if (parameters instanceof Parameters) {
43: return getFunctionValue((Parameters) parameters);
44: } else {
45: Parameters params = wrappedFunction.createParameters();
46: params.setAutoCasting(true);
47: params.setAll(parameters);
48: return getFunctionValue(params);
49: }
50: }
51:
52: public R getFunctionValue(Object... parameters) {
53: Parameters params = wrappedFunction.createParameters();
54: params.setAutoCasting(true);
55: params.setAll(parameters);
56: return getFunctionValue(params);
57: }
58:
59: public void setDescription(String description) {
60: wrappedFunction.setDescription(description);
61: }
62:
63: public String getDescription() {
64: return wrappedFunction.getDescription();
65: }
66:
67: public String getName() {
68: return wrappedFunction.getName();
69: }
70:
71: public Parameter<?>[] getParameterDefinition() {
72: return wrappedFunction.getParameterDefinition();
73: }
74:
75: public void setParameterDefinition(Parameter<?>[] params) {
76: wrappedFunction.setParameterDefinition(params);
77: }
78:
79: public ReturnType<R> getReturnType() {
80: return wrappedFunction.getReturnType();
81: }
82:
83: public void setReturnType(ReturnType<R> type) {
84: wrappedFunction.setReturnType(type);
85: }
86:
87: public int hashCode() {
88: return getName().hashCode();
89: }
90:
91: public String toString() {
92: return "WRAPPED " + wrappedFunction.toString();
93: }
94:
95: }
|