1 /***
2 * FunctionOperator.java
3 *
4 * $Author: mballesteros $
5 * $Date: 2003/11/28 19:18:03 $
6 * $Revision: 1.1 $
7 */
8 package net.sf.jec;
9
10 /***
11 *
12 * @author mballesteros
13 */
14 class FunctionOperator extends InvertibleOperator {
15
16 private Function function;
17
18 /*** Creates a new instance of FunctionOperator */
19 public FunctionOperator(Function function) {
20 this.function = function;
21 }
22
23 /*** Returns the associated value to the given context and root context
24 * @param rootCtx The root context, needed for operators that require
25 * expression evaluation from root point. Example: Indexer operators
26 * @param ctx The current context where the operator will work over
27 */
28 protected Object directMap(Object rootCtx, Object ctx) throws EvaluationException {
29 Object[] arguments = new Object[argOps.length];
30 for (int i=0; i<argOps.length; i++) {
31 arguments[i] = argOps[i].apply(rootCtx, rootCtx);
32 }
33 return function.directMap(arguments);
34 }
35
36 /*** Returns an expression String representation for this operator
37 */
38 public String toExpressionString() {
39 return null;
40 }
41
42 /*** Returns a function representation String for this operator
43 */
44 public String toFunctionString() {
45 return null;
46 }
47
48 /*** Sets the given value if this operator is at the end of the operator chain
49 * or just resolves the context object and passes it to the next operator in
50 * the chain.
51 * @param rootCtx The root context, needed for operators that require
52 * expression evaluation from root point. Example: Indexer operators
53 * @param ctx The current context where the operator will work over
54 * @param value The value to set.
55 */
56 protected void inverseMap(Object rootCtx, Object ctx, Object value) throws EvaluationException {
57 if (argOps.length == 1) {
58 ((InvertibleOperator)argOps[0]).applyInverse(rootCtx, ctx, function.inverseMap(new Object[]{value}));
59 } else {
60 Object[] arguments = new Object[argOps.length];
61 arguments[0] = value;
62 for (int i=1; i<argOps.length; i++) {
63 arguments[i] = argOps[i].apply(rootCtx, rootCtx);
64 }
65 ((InvertibleOperator)argOps[0]).applyInverse(rootCtx, ctx, function.inverseMap(arguments));
66 }
67 }
68 }
This page was automatically generated by Maven