01: package org.osbl.agent.model.condition;
02:
03: /**
04: * This kind of Operator is used when the operation is a method call.
05: *
06: * The resulting expression will be of the form:
07: *
08: * left.operatorCode(right)
09: *
10: * Thus, the method to be called should accept only one parameter.
11: *
12: * @author Sebastian Nozzi.
13: */
14: public class MethodOperator extends Operator {
15:
16: /**
17: * Instantiates a new method operator.
18: */
19: public MethodOperator() {
20: }
21:
22: /**
23: * Instantiates a new method operator specifying an operatorString.
24: * The operatorString should be a method name.
25: *
26: * @param operatorString a method name, used for both implementation and label.
27: */
28: public MethodOperator(String operatorString) {
29: this (operatorString, operatorString);
30: }
31:
32: /**
33: * Instantiates a new method operator, specifying label and operatorCode.
34: *
35: * @param label the descriptive label.
36: * @param operatorCode the operator code, which should be a method name.
37: */
38: public MethodOperator(String label, String operatorCode) {
39: super (label, operatorCode);
40: }
41:
42: /**
43: * Constructs the expression as in a method call, for example:
44: *
45: * message.matches("W.*")
46: *
47: * where "message" is the left part, "W.*" is the right part and "matches" the operatorCode.
48: *
49: * @param left the left
50: * @param right the right
51: *
52: * @return the expression
53: *
54: * @see org.osbl.agent.model.condition.Operator#getExpression(java.lang.String, java.lang.String)
55: */
56: protected String getExpression(String left, String right) {
57:
58: // Construct the expression as in a method call.
59: return left + "." + this .getOperatorCode() + "(" + right + ")";
60:
61: }
62:
63: }
|