KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > filter > lib > BasicFieldOperand


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.filter.lib;
25
26 import org.objectweb.jorm.type.api.PType;
27 import org.objectweb.medor.api.Field;
28 import org.objectweb.medor.api.MedorException;
29 import org.objectweb.medor.expression.api.ExpressionException;
30 import org.objectweb.medor.expression.api.Operand;
31 import org.objectweb.medor.expression.api.ParameterOperand;
32 import org.objectweb.medor.expression.lib.BasicVariableOperand;
33 import org.objectweb.medor.filter.api.FieldOperand;
34 import org.objectweb.medor.tuple.api.Tuple;
35 import org.objectweb.medor.type.lib.QTypeTuple;
36
37 import java.util.Map JavaDoc;
38
39 /**
40  *
41  * @author Sebastien Chassande-Barrioz
42  */

43 public class BasicFieldOperand
44     extends BasicVariableOperand
45     implements FieldOperand {
46
47     Field field = null;
48     int index = -1;
49
50     public BasicFieldOperand() {
51     }
52
53     public BasicFieldOperand(Field field) {
54         super(field.getType());
55         this.field = field;
56     }
57
58     public BasicFieldOperand(PType type, Field field) {
59         super(type);
60         this.field = field;
61     }
62
63     public Object JavaDoc clone(Object JavaDoc clone, Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
64         clone = super.clone(clone, obj2clone);
65         ((BasicFieldOperand) clone).index = index;
66         ((BasicFieldOperand) clone).field = (Field) getClone(field, obj2clone);
67         return clone;
68     }
69
70     public Field getField() {
71         return field;
72     }
73
74     public void setField(Field f) {
75         field = f;
76         type = field.getType();
77     }
78
79     public int getIndex() {
80         return index;
81     }
82
83     public void setIndex(int idx) {
84         index = idx;
85     }
86
87     public String JavaDoc toString() {
88         return "FieldOperand(" + (field == null ? "null" : field.getName() + ")");
89     }
90
91     public Operand evaluate(ParameterOperand[] pos, Object JavaDoc t)
92         throws ExpressionException {
93         Tuple o = (Tuple) t;
94         try {
95             switch (type.getTypeCode()) {
96             case QTypeTuple.TYPECODE_BOOLEAN:
97                 setValue(o.getBoolean(index));
98                 break;
99             case QTypeTuple.TYPECODE_BYTE:
100                 setValue(o.getByte(index));
101                 break;
102             case QTypeTuple.TYPECODE_CHAR:
103                 setValue(o.getChar(index));
104                 break;
105             case QTypeTuple.TYPECODE_DATE:
106                 setValue(o.getDate(index));
107                 break;
108             case QTypeTuple.TYPECODE_DOUBLE:
109                 setValue(o.getDouble(index));
110                 break;
111             case QTypeTuple.TYPECODE_FLOAT:
112                 setValue(o.getFloat(index));
113                 break;
114             case QTypeTuple.TYPECODE_INT:
115                 setValue(o.getInt(index));
116                 break;
117             case QTypeTuple.TYPECODE_LONG:
118                 setValue(o.getLong(index));
119                 break;
120             case QTypeTuple.TYPECODE_SHORT:
121                 setValue(o.getShort(index));
122                 break;
123             case QTypeTuple.TYPECODE_STRING:
124                 setValue(o.getString(index));
125                 break;
126             case QTypeTuple.TYPECODE_OBJBOOLEAN:
127             case QTypeTuple.TYPECODE_OBJBYTE:
128             case QTypeTuple.TYPECODE_OBJCHAR:
129             case QTypeTuple.TYPECODE_OBJDOUBLE:
130             case QTypeTuple.TYPECODE_OBJFLOAT:
131             case QTypeTuple.TYPECODE_OBJINT:
132             case QTypeTuple.TYPECODE_OBJLONG:
133             case QTypeTuple.TYPECODE_OBJSHORT:
134             case QTypeTuple.TYPECODE_BIGDECIMAL:
135             case QTypeTuple.TYPECODE_BIGINTEGER:
136                 setValue(o.getObject(index));
137                 break;
138             }
139         }
140         catch (MedorException e) {
141             throw new ExpressionException(e);
142         }
143         super.evaluate(pos, o);
144         return this;
145     }
146 }
147
Popular Tags