KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > naming > lib > BasicPNamingContext


1 /**
2  * JORM: an implementation of a generic mapping system for persistent Java
3  * objects. Two mapping are supported: to RDBMS and to binary files.
4  * Copyright (C) 2001-2003 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: jorm-team@objectweb.org
21  *
22  */

23
24 package org.objectweb.jorm.naming.lib;
25
26 import org.objectweb.jorm.naming.api.PNamingContext;
27 import org.objectweb.jorm.naming.api.PName;
28 import org.objectweb.jorm.naming.api.PExceptionNaming;
29 import org.objectweb.jorm.naming.api.PNameGetter;
30 import org.objectweb.jorm.type.api.PType;
31 import org.objectweb.jorm.api.PException;
32
33 import java.util.Date JavaDoc;
34 import java.math.BigInteger JavaDoc;
35 import java.math.BigDecimal JavaDoc;
36
37 /**
38  * Default implementation for a PNamingContext with no coding support.
39  * @author P. D?chamboux
40  */

41 public abstract class BasicPNamingContext implements PNamingContext {
42     protected PType ptype = null;
43
44     public PType getPType() {
45         return ptype;
46     }
47
48     public void setPType(PType pt) {
49         ptype = pt;
50     }
51
52     public boolean codingSupported(int codingtype) {
53         return false;
54     }
55
56     public PName decode(byte[] en) throws PExceptionNaming {
57         return null;
58     }
59
60     public PName decodeCharArray(char[] en) throws PExceptionNaming {
61         throw new UnsupportedOperationException JavaDoc("char[] coding not supported");
62     }
63
64     public PName decodeAbstract(Object JavaDoc en, Object JavaDoc context) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
65         throw new UnsupportedOperationException JavaDoc("abstract coding not supported");
66     }
67
68     public PName decodeByte(byte en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
69         throw new UnsupportedOperationException JavaDoc("byte coding not supported");
70     }
71
72     public PName decodeObyte(Byte JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
73         throw new UnsupportedOperationException JavaDoc("Byte coding not supported");
74     }
75
76     public PName decodeChar(char en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
77         throw new UnsupportedOperationException JavaDoc("char coding not supported");
78     }
79
80     public PName decodeOchar(Character JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
81         throw new UnsupportedOperationException JavaDoc("Character coding not supported");
82     }
83
84     public PName decodeInt(int en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
85         throw new UnsupportedOperationException JavaDoc("int coding not supported");
86     }
87
88     public PName decodeOint(Integer JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
89         throw new UnsupportedOperationException JavaDoc("Integer coding not supported");
90     }
91
92     public PName decodeLong(long en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
93         throw new UnsupportedOperationException JavaDoc("long coding not supported");
94     }
95
96     public PName decodeOlong(Long JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
97         throw new UnsupportedOperationException JavaDoc("Long coding not supported");
98     }
99
100     public PName decodeShort(short en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
101         throw new UnsupportedOperationException JavaDoc("short coding not supported");
102     }
103
104     public PName decodeOshort(Short JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
105         throw new UnsupportedOperationException JavaDoc("Short coding not supported");
106     }
107
108     public PName decodeDate(Date JavaDoc en) throws PExceptionNaming {
109         throw new UnsupportedOperationException JavaDoc("date coding not supported");
110     }
111
112     public PName decodeBigInteger(BigInteger JavaDoc en) throws PExceptionNaming {
113         throw new UnsupportedOperationException JavaDoc("BigInteger coding not supported");
114     }
115
116     public PName decodeBigDecimal(BigDecimal JavaDoc en) throws PExceptionNaming {
117         throw new UnsupportedOperationException JavaDoc("BigDecimal coding not supported");
118     }
119
120     public byte[] encode(PName pn) throws PExceptionNaming {
121         if (codingSupported(CTBYTEARRAY)) {
122             try {
123                 return ((PNameGetter) pn.encodeAbstract()).pngetByteArrayField(null, null);
124             } catch (PExceptionNaming e) {
125                 throw e;
126             } catch (PException e) {
127                 throw new PExceptionNaming(e);
128             }
129         }
130         return null;
131     }
132
133     public char[] encodeCharArray(PName pn) throws PExceptionNaming {
134         if (codingSupported(CTCHARARRAY)) {
135             try {
136                 return ((PNameGetter) pn.encodeAbstract()).pngetCharArrayField(null, null);
137             } catch (PExceptionNaming e) {
138                 throw e;
139             } catch (PException e) {
140                 throw new PExceptionNaming(e);
141             }
142         }
143         throw new UnsupportedOperationException JavaDoc("char[] coding not supported");
144     }
145
146     public Object JavaDoc encodeAbstract(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
147         if (codingSupported(CTCOMPOSITE)) {
148             return pn;
149         }
150         throw new UnsupportedOperationException JavaDoc("abstract coding not supported");
151     }
152
153     public byte encodeByte(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
154         if (codingSupported(CTBYTE)) {
155             try {
156                 return ((PNameGetter) pn.encodeAbstract()).pngetByteField(null, null);
157             } catch (PExceptionNaming e) {
158                 throw e;
159             } catch (PException e) {
160                 throw new PExceptionNaming(e);
161             }
162         }
163         throw new UnsupportedOperationException JavaDoc("byte coding not supported");
164     }
165
166     public Byte JavaDoc encodeObyte(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
167         if (codingSupported(CTOBYTE)) {
168             try {
169                 return ((PNameGetter) pn.encodeAbstract()).pngetObyteField(null, null);
170             } catch (PExceptionNaming e) {
171                 throw e;
172             } catch (PException e) {
173                 throw new PExceptionNaming(e);
174             }
175         }
176         throw new UnsupportedOperationException JavaDoc("Byte coding not supported");
177     }
178
179     public char encodeChar(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
180         if (codingSupported(CTCHAR)) {
181             try {
182                 return ((PNameGetter) pn.encodeAbstract()).pngetCharField(null, null);
183             } catch (PExceptionNaming e) {
184                 throw e;
185             } catch (PException e) {
186                 throw new PExceptionNaming(e);
187             }
188         }
189         throw new UnsupportedOperationException JavaDoc("char coding not supported");
190     }
191
192     public Character JavaDoc encodeOchar(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
193         if (codingSupported(CTOCHAR)) {
194             try {
195                 return ((PNameGetter) pn.encodeAbstract()).pngetOcharField(null, null);
196             } catch (PExceptionNaming e) {
197                 throw e;
198             } catch (PException e) {
199                 throw new PExceptionNaming(e);
200             }
201         }
202         throw new UnsupportedOperationException JavaDoc("Character coding not supported");
203     }
204
205     public int encodeInt(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
206         if (codingSupported(CTINT)) {
207             try {
208                 return ((PNameGetter) pn.encodeAbstract()).pngetIntField(null, null);
209             } catch (PExceptionNaming e) {
210                 throw e;
211             } catch (PException e) {
212                 throw new PExceptionNaming(e);
213             }
214         }
215         throw new UnsupportedOperationException JavaDoc("int coding not supported");
216     }
217
218     public Integer JavaDoc encodeOint(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
219         if (codingSupported(CTOINT)) {
220             try {
221                 return ((PNameGetter) pn.encodeAbstract()).pngetOintField(null, null);
222             } catch (PExceptionNaming e) {
223                 throw e;
224             } catch (PException e) {
225                 throw new PExceptionNaming(e);
226             }
227         }
228         throw new UnsupportedOperationException JavaDoc("Integer coding not supported");
229     }
230
231     public long encodeLong(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
232         if (codingSupported(CTLONG)) {
233             try {
234                 return ((PNameGetter) pn.encodeAbstract()).pngetLongField(null, null);
235             } catch (PExceptionNaming e) {
236                 throw e;
237             } catch (PException e) {
238                 throw new PExceptionNaming(e);
239             }
240         }
241         throw new UnsupportedOperationException JavaDoc("long coding not supported");
242     }
243
244     public Long JavaDoc encodeOlong(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
245         if (codingSupported(CTOLONG)) {
246             try {
247                 return ((PNameGetter) pn.encodeAbstract()).pngetOlongField(null, null);
248             } catch (PExceptionNaming e) {
249                 throw e;
250             } catch (PException e) {
251                 throw new PExceptionNaming(e);
252             }
253         }
254         throw new UnsupportedOperationException JavaDoc("Long coding not supported");
255     }
256
257     public short encodeShort(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
258         if (codingSupported(CTSHORT)) {
259             try {
260                 return ((PNameGetter) pn.encodeAbstract()).pngetShortField(null, null);
261             } catch (PExceptionNaming e) {
262                 throw e;
263             } catch (PException e) {
264                 throw new PExceptionNaming(e);
265             }
266         }
267         throw new UnsupportedOperationException JavaDoc("short coding not supported");
268     }
269
270     public Short JavaDoc encodeOshort(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
271         if (codingSupported(CTOSHORT)) {
272             try {
273                 return ((PNameGetter) pn.encodeAbstract()).pngetOshortField(null, null);
274             } catch (PExceptionNaming e) {
275                 throw e;
276             } catch (PException e) {
277                 throw new PExceptionNaming(e);
278             }
279         }
280         throw new UnsupportedOperationException JavaDoc("Short coding not supported");
281     }
282
283     public Date JavaDoc encodeDate(PName pn) throws PExceptionNaming {
284         if (codingSupported(CTDATE)) {
285             try {
286                 return ((PNameGetter) pn.encodeAbstract()).pngetDateField(null, null);
287             } catch (PExceptionNaming e) {
288                 throw e;
289             } catch (PException e) {
290                 throw new PExceptionNaming(e);
291             }
292         }
293         throw new UnsupportedOperationException JavaDoc("date coding not supported");
294     }
295
296     public BigInteger JavaDoc encodeBigInteger(PName pn) throws PExceptionNaming {
297         if (codingSupported(CTBIGINTEGER)) {
298             try {
299                 return ((PNameGetter) pn.encodeAbstract()).pngetBigIntegerField(null, null);
300             } catch (PExceptionNaming e) {
301                 throw e;
302             } catch (PException e) {
303                 throw new PExceptionNaming(e);
304             }
305         }
306         throw new UnsupportedOperationException JavaDoc("BigInteger coding not supported");
307     }
308
309     public BigDecimal JavaDoc encodeBigDecimal(PName pn) throws PExceptionNaming {
310         if (codingSupported(CTBIGDECIMAL)) {
311             try {
312                 return ((PNameGetter) pn.encodeAbstract()).pngetBigDecimalField(null, null);
313             } catch (PExceptionNaming e) {
314                 throw e;
315             } catch (PException e) {
316                 throw new PExceptionNaming(e);
317             }
318         }
319         throw new UnsupportedOperationException JavaDoc("BigDecimal coding not supported");
320     }
321
322     public boolean supportDynamicComposite() {
323         return false;
324     }
325
326     public boolean supportCompositeField(String JavaDoc fn, PType ft) {
327         return false;
328     }
329
330     public boolean supportStaticComposite() {
331         return false;
332     }
333 }
334
Popular Tags