KickJava   Java API By Example, From Geeks To Geeks.

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


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.expression.lib;
25
26 import org.objectweb.jorm.type.api.PType;
27 import org.objectweb.medor.expression.api.Operand;
28 import org.objectweb.medor.expression.api.ExpressionException;
29 import org.objectweb.medor.expression.api.ParameterOperand;
30
31 /**
32  *
33  * @author Sebastien Chassande-Barrioz
34  */

35 public class BasicParameterOperand
36     extends BasicVariableOperand
37     implements ParameterOperand {
38
39     protected String JavaDoc name = null;
40
41     public BasicParameterOperand() {
42         super();
43     }
44
45     public BasicParameterOperand(BasicParameterOperand po) {
46         super(po);
47         this.name = po.getName();
48     }
49
50     public BasicParameterOperand(PType type, String JavaDoc name) {
51         super(type);
52         this.name = name;
53     }
54
55     public BasicParameterOperand(PType type, String JavaDoc name, Object JavaDoc value) {
56         super(type);
57         this.name = name;
58         objectValue = value;
59     }
60
61     public BasicParameterOperand(PType type, String JavaDoc name, String JavaDoc value) {
62         super(type);
63         this.name = name;
64         objectValue = value;
65     }
66
67     public BasicParameterOperand(PType type, String JavaDoc name, boolean value) {
68         super(type);
69         this.name = name;
70         longValue = (value ? 1 : 0);
71     }
72
73     public BasicParameterOperand(PType type, String JavaDoc name, long value) {
74         super(type);
75         this.name = name;
76         longValue = value;
77     }
78
79     public BasicParameterOperand(PType type, String JavaDoc name, double value) {
80         super(type);
81         this.name = name;
82         doubleValue = value;
83     }
84
85     public Object JavaDoc clone(Object JavaDoc clone, java.util.Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
86         clone = super.clone(clone, obj2clone);
87         ((BasicParameterOperand) clone).name = name;
88         return clone;
89     }
90
91     public String JavaDoc getName() {
92         return name;
93     }
94
95     public void setName(String JavaDoc n) {
96         name = n;
97     }
98
99     public Operand evaluate(ParameterOperand[] pos, Object JavaDoc o)
100         throws ExpressionException {
101         int i = 0;
102         while (i < pos.length
103             && pos[i].getType().getTypeCode() != type.getTypeCode()
104             && !pos[i].getName().equalsIgnoreCase(name)) {
105             i++;
106         }
107         if (i < pos.length) {
108             switch (type.getTypeCode()) {
109             case PType.TYPECODE_BOOLEAN:
110                 setValue(pos[i].getBoolean());
111                 break;
112             case PType.TYPECODE_BYTE:
113                 setValue(pos[i].getByte());
114                 break;
115             case PType.TYPECODE_CHAR:
116                 setValue(pos[i].getChar());
117                 break;
118             case PType.TYPECODE_DATE:
119                 setValue(pos[i].getDate());
120                 break;
121             case PType.TYPECODE_DOUBLE:
122                 setValue(pos[i].getDouble());
123                 break;
124             case PType.TYPECODE_FLOAT:
125                 setValue(pos[i].getFloat());
126                 break;
127             case PType.TYPECODE_INT:
128                 setValue(pos[i].getInt());
129                 break;
130             case PType.TYPECODE_LONG:
131                 setValue(pos[i].getLong());
132                 break;
133             case PType.TYPECODE_SHORT:
134                 setValue(pos[i].getShort());
135                 break;
136             case PType.TYPECODE_STRING:
137                 setValue(pos[i].getString());
138                 break;
139             case PType.TYPECODE_OBJBOOLEAN:
140             case PType.TYPECODE_OBJBYTE:
141             case PType.TYPECODE_OBJCHAR:
142             case PType.TYPECODE_OBJDOUBLE:
143             case PType.TYPECODE_OBJFLOAT:
144             case PType.TYPECODE_OBJINT:
145             case PType.TYPECODE_OBJLONG:
146             case PType.TYPECODE_OBJSHORT:
147             default:
148                 objectValue = pos[i].getObject();
149                 break;
150             }
151         }
152         else
153             throw new ExpressionException("Parameter without value: " + this.getName());
154         return this;
155     }
156 }
157
Popular Tags