Source code: org/ujac/util/exi/ExpressionTuple.java
1 /*
2 * Copyright (C) 2003 by Christian Lauer.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * If you didn't download this code from the following link, you should check if
19 * you aren't using an obsolete version:
20 * http://sourceforge.net/projects/ujac
21 */
22
23 package org.ujac.util.exi;
24
25 /**
26 * Title: ExpressionTuple<br>
27 * Description: A class holding expression tuples: object, operation and operand.<br>
28 *<br>Log: $Log: ExpressionTuple.java,v $
29 *<br>Log: Revision 1.8 2003/11/01 12:06:38 lauerc
30 *<br>Log: Added copyright notice.
31 *<br>Log:
32 *<br>Log: Revision 1.7 2003/08/29 05:06:32 lauerc
33 *<br>Log: Added flag 'explicitelyEncapsulated'.
34 *<br>Log:
35 *<br>Log: Revision 1.6 2003/07/28 23:18:04 lauerc
36 *<br>Log: Class ExpressionTuple is defived from new class Operand now.
37 *<br>Log: The object and operand members are of type Operand now,
38 *<br>Log: which means they can be VariableOperands, ConstantOperands and
39 *<br>Log: ExpressionTuples.
40 *<br>Log: The attribute operation is of type Operation now.
41 *<br>Log:
42 *<br>Log: Revision 1.5 2003/05/20 21:20:16 lauerc
43 *<br>Log: Added method getCode which returns the actual code for the expression.
44 *<br>Log:
45 *<br>Log: Revision 1.4 2003/03/09 14:03:53 lauerc
46 *<br>Log: Changed type of source to char array.
47 *<br>Log:
48 *<br>Log: Revision 1.3 2003/03/08 18:20:55 lauerc
49 *<br>Log: Added a constructor which initializes source, position and length.
50 *<br>Log: Added operator which passes the total position and length of an expression to a new nested expression.
51 *<br>Log: Deleted unused constructors.
52 *<br>Log:
53 *<br>Log: Revision 1.2 2003/03/08 17:04:01 lauerc
54 *<br>Log: Added properties source, position and length, removed unused properties.
55 *<br>Log:
56 *<br>Log: Revision 1.1 2003/03/05 06:23:25 lauerc
57 *<br>Log: Initial revision.
58 *<br>Log:
59 *@author $Author: lauerc $
60 *@version $Revision: 1.8 $
61 */
62 public class ExpressionTuple extends Operand {
63
64 /** The object which to call. */
65 private Operand object;
66 /** The operation for the expression. */
67 private Operation operation;
68 /** The object which to call. */
69 private Operand operand;
70 /** Tells whether the expression was explicitely encapsulated or not. */
71 private boolean explitelyEncapsulated;
72
73 /** The result of the expression. */
74 private Object result;
75
76 /**
77 * Default constructor for ExpressionTuple.
78 */
79 public ExpressionTuple() {
80 }
81
82 /**
83 * Constructs an ExpressionTuple instance with specific arguments.
84 * @param source The textual source for the expression.
85 * @param position The start position of the expression within the source.
86 * @param length The length of the expression.
87 */
88 public ExpressionTuple(char[] source, int position, int length) {
89 super(source, position, length);
90 }
91
92 /**
93 * Constructs an ExpressionTuple instance with specific arguments.
94 * Copies the source, totalPosition and totalLength from the outer expression.
95 * @param outer The outer expression.
96 */
97 public ExpressionTuple(ExpressionTuple outer) {
98 super(outer);
99 }
100
101 /**
102 * @see org.ujac.util.exi.Operand#isSimple()
103 */
104 public boolean isSimple() {
105 return false;
106 }
107
108 /**
109 * Returns the object.
110 * @return The object to call.
111 */
112 public Operand getObject() {
113 return object;
114 }
115 /**
116 * Sets the object.
117 * @param object The object to set
118 */
119 public void setObject(Operand object) {
120 this.object = object;
121 }
122
123 /**
124 * Returns the operand.
125 * @return The operand to use for the call.
126 */
127 public Operand getOperand() {
128 return operand;
129 }
130 /**
131 * Sets the operand.
132 * @param operand The operand to set
133 */
134 public void setOperand(Operand operand) {
135 this.operand = operand;
136 }
137
138 /**
139 * Gets the explitelyEncapsulated flag.
140 * @return The current value of the explitelyEncapsulated flag.
141 */
142 public boolean isExplitelyEncapsulated() {
143 return explitelyEncapsulated;
144 }
145 /**
146 * Sets the explitelyEncapsulated flag.
147 * @param explitelyEncapsulated The value for the explitelyEncapsulated flag to set.
148 */
149 public void setExplitelyEncapsulated(boolean explitelyEncapsulated) {
150 this.explitelyEncapsulated = explitelyEncapsulated;
151 }
152
153 /**
154 * Returns the operation.
155 * @return The operation to execute.
156 */
157 public Operation getOperation() {
158 return operation;
159 }
160 /**
161 * Sets the operation.
162 * @param operation The operation to set
163 */
164 public void setOperation(Operation operation) {
165 this.operation = operation;
166 }
167
168 /**
169 * Returns the result.
170 * @return Object
171 */
172 public Object getResult() {
173 return result;
174 }
175 /**
176 * Sets the result.
177 * @param result The result to set
178 */
179 public void setResult(Object result) {
180 this.result = result;
181 }
182
183 /**
184 * Gets the operand value.
185 * @return the value of the operand.
186 */
187 public Object getValue() {
188 return result;
189 }
190
191 /**
192 * Converts expression tuple to String.
193 *@return The objects content as a String.
194 */
195 public String toString() {
196 StringBuffer content = new StringBuffer("${");
197 //content.append("objectVariable='").append(objectVariable.toString()).append("'");
198 content.append(object);
199
200
201 if (operation != null) {
202 content.append(" ").append(operation.toString());
203 }
204
205 if (operand != null) {
206 content.append(" ").append(operand.toString());
207 }
208
209 if (result != null) {
210 if (content.length() <= 2) {
211 content.append("'").append(result).append("'");
212 }
213 }
214
215 return content.append('}').toString();
216 }
217
218 }