KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > filter > jorm > lib > EncodePName


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, S. Chassande-Barrioz
22  */

23 package org.objectweb.medor.filter.jorm.lib;
24
25 import org.objectweb.jorm.api.PException;
26 import org.objectweb.jorm.naming.api.PName;
27 import org.objectweb.jorm.naming.api.PNameGetter;
28 import org.objectweb.jorm.type.api.PType;
29 import org.objectweb.medor.api.EvaluationException;
30 import org.objectweb.medor.api.MedorException;
31 import org.objectweb.medor.expression.api.CalculatedParameterOperand;
32 import org.objectweb.medor.expression.api.ParameterOperand;
33 import org.objectweb.medor.expression.api.TypingException;
34 import org.objectweb.medor.expression.api.ExpressionException;
35 import org.objectweb.medor.expression.api.VariableOperand;
36 import org.objectweb.medor.expression.lib.BasicParameterOperand;
37 import org.objectweb.medor.type.lib.QType;
38
39 import java.util.Map JavaDoc;
40
41 /**
42  * This implementation of the CalculatedParameterOperand interface encode a
43  * a PName. This PName must be given in parameter among the ParameterOperand
44  * of the evaluate method.
45  * There are two constructor weither the PName structure
46  *
47  * @author S.Chassande-Barrioz
48  */

49 public class EncodePName
50     extends BasicParameterOperand
51     implements CalculatedParameterOperand {
52
53     String JavaDoc fieldName = null;
54
55     public EncodePName(PType type, String JavaDoc parameterName) {
56         super(type, parameterName);
57         fieldName = null;
58     }
59
60     public EncodePName(PType type, String JavaDoc parameterName, String JavaDoc fieldName) {
61         super(type, parameterName);
62         this.fieldName = fieldName;
63     }
64
65     public Object JavaDoc clone(Object JavaDoc clone, Map JavaDoc obj2clone) throws CloneNotSupportedException JavaDoc {
66         clone = super.clone(clone, obj2clone);
67         ((EncodePName) clone).fieldName = fieldName;
68         return clone;
69     }
70     // IMPLEMENTATION OF THE CalculatedParameterOperand INTERFACE //
71
//------------------------------------------------------------//
72

73     public void evaluate(ParameterOperand[] pos) throws ExpressionException {
74         PName pn = null;
75         for (int i = 0; i < pos.length; i++) {
76             if (pos[i] != null
77                     && name.equals(pos[i].getName())
78                     && pos[i].getType().getTypeCode() == QType.TYPECODE_PNAME) {
79                 pn = (PName) pos[i].getObject();
80             }
81         }
82         if (pn == null)
83             throw new ExpressionException("Impossible to evaluate this parameter wihtout the parameter " + name);
84         try {
85             assignEncodedValue(pn, this, fieldName);
86         } catch (Exception JavaDoc e) {
87             throw new ExpressionException("Impossible to encode the PName", e);
88         }
89     }
90
91     public final static void assignEncodedValue(PName pn,
92                                                 VariableOperand op,
93                                                 String JavaDoc fieldname)
94             throws PException, MedorException, TypingException {
95         if (fieldname == null) {
96             switch (op.getType().getTypeCode()) {
97             case QType.TYPECODE_BYTE:
98                 op.setValue(pn.encodeByte());
99                 break;
100             case QType.TYPECODE_CHAR:
101                 op.setValue(pn.encodeChar());
102                 break;
103             case QType.TYPECODE_INT:
104                 op.setValue(pn.encodeInt());
105                 break;
106             case QType.TYPECODE_LONG:
107                 op.setValue(pn.encodeLong());
108                 break;
109             case QType.TYPECODE_SHORT:
110                 op.setValue(pn.encodeShort());
111                 break;
112             case QType.TYPECODE_OBJBYTE:
113                 op.setValue(pn.encodeObyte());
114                 break;
115             case QType.TYPECODE_OBJCHAR:
116                 op.setValue(pn.encodeOchar());
117                 break;
118             case QType.TYPECODE_OBJINT:
119                 op.setValue(pn.encodeOint());
120                 break;
121             case QType.TYPECODE_OBJLONG:
122                 op.setValue(pn.encodeOlong());
123                 break;
124             case QType.TYPECODE_OBJSHORT:
125                 op.setValue(pn.encodeOshort());
126                 break;
127             case QType.TYPECODE_DATE:
128                 op.setValue(pn.encodeDate());
129                 break;
130             case QType.TYPECODE_STRING:
131                 op.setValue(pn.encodeString());
132                 break;
133             case QType.TYPECODE_BIGINTEGER:
134                 op.setValue(pn.encodeBigInteger());
135                 break;
136             case QType.TYPECODE_BIGDECIMAL:
137                 op.setValue(pn.encodeBigDecimal());
138                 break;
139             default:
140                 throw new EvaluationException("Unsupported naming type: (jormName:"
141                         + op.getType().getJormName()
142                         +", code" + op.getType().getTypeCode() + ")");
143             }
144         } else {
145             // Composite PName
146
Object JavaDoc conn = null;
147             PNameGetter png = (PNameGetter) pn.encodeAbstract();
148             switch (op.getType().getTypeCode()) {
149             case QType.TYPECODE_BYTE:
150                 op.setValue(png.pngetByteField(fieldname, conn));
151                 break;
152             case QType.TYPECODE_CHAR:
153                 op.setValue(png.pngetCharField(fieldname, conn));
154                 break;
155             case QType.TYPECODE_INT:
156                 op.setValue(png.pngetIntField(fieldname, conn));
157                 break;
158             case QType.TYPECODE_LONG:
159                 op.setValue(png.pngetLongField(fieldname, conn));
160                 break;
161             case QType.TYPECODE_SHORT:
162                 op.setValue(png.pngetShortField(fieldname, conn));
163                 break;
164             case QType.TYPECODE_OBJBYTE:
165                 op.setValue(png.pngetObyteField(fieldname, conn));
166                 break;
167             case QType.TYPECODE_OBJCHAR:
168                 op.setValue(png.pngetOcharField(fieldname, conn));
169                 break;
170             case QType.TYPECODE_OBJINT:
171                 op.setValue(png.pngetOintField(fieldname, conn));
172                 break;
173             case QType.TYPECODE_OBJLONG:
174                 op.setValue(png.pngetOlongField(fieldname, conn));
175                 break;
176             case QType.TYPECODE_OBJSHORT:
177                 op.setValue(png.pngetOshortField(fieldname, conn));
178                 break;
179             case QType.TYPECODE_DATE:
180                 op.setValue(png.pngetDateField(fieldname, conn));
181                 break;
182             case QType.TYPECODE_STRING:
183                 op.setValue(png.pngetStringField(fieldname, conn));
184                 break;
185             case QType.TYPECODE_BIGINTEGER:
186                 op.setValue(png.pngetBigIntegerField(fieldname, conn));
187                 break;
188             case QType.TYPECODE_BIGDECIMAL:
189                 op.setValue(png.pngetBigDecimalField(fieldname, conn));
190                 break;
191             default:
192                 throw new EvaluationException("Unsupported naming type" + op.getType());
193             }
194         }
195
196     }
197 }
198
Popular Tags