KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > expression > lib > BasicVariableOperand


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 package org.objectweb.medor.expression.lib;
24
25 import org.objectweb.jorm.type.api.PType;
26 import org.objectweb.jorm.type.api.PTypeSpace;
27 import org.objectweb.medor.expression.api.TypingException;
28 import org.objectweb.medor.expression.api.VariableOperand;
29
30 import java.util.Date JavaDoc;
31
32 public class BasicVariableOperand
33     extends BasicOperand
34     implements VariableOperand {
35
36     public BasicVariableOperand() {
37         super();
38     }
39     public BasicVariableOperand(BasicOperand p) {
40         super(p);
41     }
42     public BasicVariableOperand(PType p) {
43         super(p);
44     }
45
46     public BasicVariableOperand(boolean b) {
47         super(b);
48     }
49
50     public BasicVariableOperand(char p) {
51         super(p);
52     }
53
54     public BasicVariableOperand(byte p) {
55         super(p);
56     }
57
58     public BasicVariableOperand(short p) {
59         super(p);
60     }
61
62     public BasicVariableOperand(int p) {
63         super(p);
64     }
65
66     public BasicVariableOperand(long p) {
67         super(p);
68     }
69
70     public BasicVariableOperand(float p) {
71         super(p);
72     }
73
74     public BasicVariableOperand(double p) {
75         super(p);
76     }
77
78     public BasicVariableOperand(String JavaDoc p) {
79         super(p);
80     }
81
82     public BasicVariableOperand(Date JavaDoc p) {
83         super(p);
84     }
85
86     public void setType(PType type) {
87         longValue = 0;
88         doubleValue = 0;
89         objectValue = null;
90         this.type = type;
91     }
92
93     public void setValue(boolean p) throws TypingException {
94         if (PTypeSpace.BOOLEAN.isa(type)) {
95             longValue = (p ? 1 : 0);
96             doubleValue = (p ? 1 : 0);
97         } else
98             throw new TypingException("This Operand can not store a boolean value");
99     }
100
101     public void setValue(int p) throws TypingException {
102         if (PTypeSpace.INT.isa(type)) {
103             longValue = p;
104             doubleValue = p;
105         } else
106             throw new TypingException("This Operand can not store an integer value " + type.getTypeCode());
107     }
108
109     public void setValue(byte p) throws TypingException {
110         if (PTypeSpace.BYTE.isa(type)) {
111             longValue = p;
112             doubleValue = p;
113         } else
114             throw new TypingException("This Operand can not store a byte value");
115     }
116
117
118     public void setValue(short p) throws TypingException {
119         if (PTypeSpace.SHORT.isa(type)) {
120             longValue = p;
121             doubleValue = p;
122         } else
123             throw new TypingException("This Operand can not store a short value");
124     }
125
126
127     public void setValue(long p) throws TypingException {
128         if (PTypeSpace.LONG.isa(type)) {
129             longValue = p;
130             doubleValue = p;
131         } else
132             throw new TypingException("This Operand can not store a long value");
133     }
134
135     public void setValue(float p) throws TypingException {
136         if (PTypeSpace.FLOAT.isa(type)) {
137             doubleValue = p;
138         } else
139             throw new TypingException("This Operand can not store a float value");
140     }
141
142     public void setValue(double p) throws TypingException {
143         if (PTypeSpace.DOUBLE.isa(type)) {
144             doubleValue = p;
145         } else
146             throw new TypingException("This Operand can not store a double value");
147     }
148
149     public void setValue(char p) throws TypingException {
150         if (PTypeSpace.CHAR.isa(type)) {
151             doubleValue = p;
152             longValue = p;
153         } else
154             throw new TypingException("This Operand can not store a CHAR value");
155     }
156
157     public void setValue(String JavaDoc p) throws TypingException {
158         if (PTypeSpace.STRING.isa(type)) {
159             objectValue = p;
160         } else
161             throw new TypingException("This Operand can not store a string value " + type.getJavaName());
162     }
163
164     public void setValue(Date JavaDoc p) throws TypingException {
165         objectValue = p;
166     }
167
168
169     public void setValue(Object JavaDoc p) throws TypingException {
170         objectValue = p;
171         switch(type.getTypeCode()) {
172         case PType.TYPECODE_BOOLEAN:
173             longValue = ((Boolean JavaDoc) p).booleanValue() ? 1 : 0;
174             doubleValue = longValue;
175             break;
176         case PType.TYPECODE_BYTE:
177             longValue = ((Byte JavaDoc) p).byteValue();
178             doubleValue = longValue;
179             break;
180         case PType.TYPECODE_CHAR:
181             longValue = ((Character JavaDoc) p).charValue();
182             doubleValue = longValue;
183             break;
184         case PType.TYPECODE_SHORT:
185             longValue = ((Short JavaDoc) p).shortValue();
186             doubleValue = longValue;
187             break;
188         case PType.TYPECODE_INT:
189             longValue = ((Integer JavaDoc) p).intValue();
190             doubleValue = longValue;
191             break;
192         case PType.TYPECODE_LONG:
193             longValue = ((Long JavaDoc) p).longValue();
194             doubleValue = longValue;
195             break;
196         case PType.TYPECODE_FLOAT:
197             doubleValue = ((Float JavaDoc) p).floatValue();
198             break;
199         case PType.TYPECODE_DOUBLE:
200             doubleValue = ((Double JavaDoc) p).doubleValue();
201             break;
202         }
203     }
204 }
205
Popular Tags