KickJava   Java API By Example, From Geeks To Geeks.

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


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

18 package org.objectweb.jorm.naming.lib;
19
20 import org.objectweb.jorm.naming.api.KeyFilteredNamingContext;
21 import org.objectweb.jorm.naming.api.PBinder;
22 import org.objectweb.jorm.naming.api.PNameGetter;
23 import org.objectweb.jorm.naming.api.PName;
24 import org.objectweb.jorm.naming.api.PExceptionNaming;
25 import org.objectweb.jorm.naming.api.PNameCoder;
26 import org.objectweb.jorm.naming.api.PNameGetterConverter;
27 import org.objectweb.jorm.naming.api.PNameManager;
28 import org.objectweb.jorm.api.PException;
29 import org.objectweb.jorm.type.api.PType;
30
31 import java.util.Map JavaDoc;
32 import java.util.HashMap JavaDoc;
33 import java.util.Collections JavaDoc;
34 import java.util.Date JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.math.BigDecimal JavaDoc;
37 import java.math.BigInteger JavaDoc;
38
39 /**
40  * This class is a PNamingContext for managing the inheritance. The naming
41  * is based on a single filter (Medor expression) for the overall inheritance
42  * tree. The medor expression uses naming fields from a PNameGetter. The
43  * evalution of the expression on a PNameGetter produces a value. Each non
44  * abstract persistent class must define a key value. The comparaison between
45  * key values associated to persistent classes and the result of the expression,
46  * permits to know the persistent class represented by the PNameGetter. By this
47  * way this PNamingContext can delegate the decoding to the binder of the
48  * persistent class.
49  * This class is abstract. It must be specialized for the evalution of
50  * expression.
51  *
52  * @see org.objectweb.jorm.generator.lib.KFPNCGenerator
53  * @author S.Chassande-Barrioz
54  */

55 public abstract class AbstractInheritKeyFilteredPNamingContext
56     extends BasicPNamingContext
57     implements KeyFilteredNamingContext {
58
59     /**
60      * The PType of the expression which is also the PType of the key of course.
61      */

62     protected PType expressionType;
63
64     /**
65      * The PNameGetterConvert to use to convert a primitive value to a
66      * PNameGetter. It can be null only if the coding type is composite.
67      */

68     protected PNameGetterConverter pngConverter;
69
70     /**
71      * The map mainting the association between keys and binder
72      */

73     protected Map JavaDoc key2binder;
74
75     /**
76      * The codingType of the current PNamingContext
77      */

78     protected int codingType;
79
80     /**
81      * An object representing the null pname value. If the coding type is
82      * composite, this field must be a PNameGetter. Otherwise this field is
83      * the java.lang class matching the coding type. At initialization step
84      * it is accepted that the user specify another object. See the
85      * checkNullValue() method for more information on this point.
86      */

87     protected Object JavaDoc nullValue;
88
89     protected PName nullPName;
90
91     /**
92      * Builds a PNamingContext. The use of this constructor requires to
93      * configure the expression/key type, the coding type and the pname null
94      * value with the corresponding setter methods, AND to initialize the PNC
95      * througth the init() method..
96      */

97     public AbstractInheritKeyFilteredPNamingContext() {
98         key2binder = new HashMap JavaDoc();
99     }
100
101     public AbstractInheritKeyFilteredPNamingContext(PType expressionType,
102                                                     int codingType) throws PException {
103         this();
104         setExpressionType(expressionType);
105         setCodingType(codingType);
106     }
107
108     public void init() throws PException {
109         checkNullValue();
110     }
111
112     public void setCodingType(int codingType) {
113         this.codingType = codingType;
114         if (this.codingType != PNameCoder.CTCOMPOSITE) {
115             pngConverter = new SimplePNGConverter();
116         } else {
117             pngConverter = null;
118         }
119     }
120
121     public boolean isNull(Object JavaDoc png, Object JavaDoc ctx) throws PException {
122         return false;
123     }
124
125     //IMPLEMENTATION OF THE KeyFilteredNamingContext INTERFACE //
126
//---------------------------------------------------------//
127

128     public void exportClass(PBinder binder, Object JavaDoc key) throws PException {
129         synchronized(key2binder) {
130             PBinder oldbinder = (PBinder) key2binder.put(key, binder);
131             if (oldbinder != null && oldbinder != binder) {
132                 key2binder.put(key, oldbinder);
133                 throw new PException("Another persistent class is alread exported with the same key: "
134                     + oldbinder.getBinderClassMapping().getClassName());
135             }
136         }
137     }
138
139     public void unexportClass(Object JavaDoc key) throws PException {
140         synchronized(key2binder) {
141             Object JavaDoc oldbinder = key2binder.remove(key);
142             if (oldbinder == null) {
143                 throw new PException("No persistent class to unexport with the key: " + key);
144             }
145         }
146     }
147
148     public PBinder lookup(Object JavaDoc key) {
149         return (PBinder) key2binder.get(key);
150     }
151
152     public Map JavaDoc entries() {
153         return Collections.unmodifiableMap(key2binder);
154     }
155
156     public void setExpressionType(PType type) {
157         this.expressionType = type;
158     }
159
160     public PType getExpressionType() {
161         return expressionType;
162     }
163
164     public abstract Object JavaDoc evaluate(Object JavaDoc png, Object JavaDoc ctx) throws PException;
165
166
167     //IMPLEMENTATION OF THE PNamingContext INTERFACE //
168
//-----------------------------------------------//
169

170     public PName resolve(Object JavaDoc conn, PName pn) throws PException {
171         return pn;
172     }
173
174
175     //IMPLEMENTATION OF THE PNamingManager INTERFACE //
176
//-----------------------------------------------//
177

178     public PName export(Object JavaDoc conn, Object JavaDoc infoitem) throws PException {
179         if (infoitem instanceof PName) {
180             return (PName) infoitem;
181         }
182         throw new PException("Operation not supported by this PNamingContext");
183     }
184
185     public PName export(Object JavaDoc conn, Object JavaDoc infoitem, Object JavaDoc hints)
186         throws PException {
187         throw new PException("Operation not supported by this PNamingContext");
188     }
189
190     public void unexport(Object JavaDoc conn, PName pn) throws PException {
191         throw new PException("Operation not supported by this PNamingContext");
192     }
193
194     public void unexport(Object JavaDoc conn, PName pn, Object JavaDoc hints) throws PException {
195         throw new PException("Operation not supported by this PNamingContext");
196     }
197
198
199     //IMPLEMENTATION OF THE PNamingCoder INTERFACE //
200
//---------------------------------------------//
201

202     public boolean codingSupported(int codingtype) {
203         return codingtype == codingType || codingtype == PNameCoder.CTSTRING;
204     }
205
206     public PName decodeAbstract(Object JavaDoc en, Object JavaDoc context)
207         throws PExceptionNaming, UnsupportedOperationException JavaDoc {
208         Object JavaDoc key;
209         try {
210             if (isNull(en, context)) {
211                 return nullPName;
212             }
213             key = evaluate(en, context);
214         } catch (PExceptionNaming e) {
215             throw e;
216         } catch (PException e) {
217             throw new PExceptionNaming(e);
218         }
219         PBinder binder = (PBinder) key2binder.get(key);
220         if (binder == null) {
221             throw new PExceptionNaming("No");
222         }
223         return binder.decodeAbstract(en, context);
224     }
225
226     public PName decodeByte(byte en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
227         if (codingType != CTBYTE) {
228             throw new PExceptionNaming("Bad coder type: " + codingType);
229         }
230         if (((Byte JavaDoc) nullValue).byteValue() == en) {
231             return getNull();
232         }
233         Object JavaDoc key;
234         try {
235             key = evaluate(pngConverter.convert(en), null);
236         } catch (PExceptionNaming e) {
237             throw e;
238         } catch (PException e) {
239             throw new PExceptionNaming(e);
240         }
241         PBinder binder = (PBinder) key2binder.get(key);
242         if (binder == null) {
243             throw new PExceptionNaming("No");
244         }
245         return binder.decodeByte(en);
246     }
247
248     public PName decodeObyte(Byte JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
249         if (codingType != CTOBYTE) {
250             throw new PExceptionNaming("Bad coder type: " + codingType);
251         }
252         if (nullValue == null) {
253             if (en == null) {
254                 return getNull();
255             }
256         } else if (en != null
257             && ((Byte JavaDoc) nullValue).byteValue() == en.byteValue()) {
258             return getNull();
259         }
260         Object JavaDoc key;
261         try {
262             key = evaluate(pngConverter.convert(en), null);
263         } catch (PExceptionNaming e) {
264             throw e;
265         } catch (PException e) {
266             throw new PExceptionNaming(e);
267         }
268         PBinder binder = (PBinder) key2binder.get(key);
269         if (binder == null) {
270             throw new PExceptionNaming("No binder associated to the key: " + key);
271         }
272         return binder.decodeObyte(en);
273     }
274
275     public PName decodeChar(char en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
276         if (codingType != CTCHAR) {
277             throw new PExceptionNaming("Bad coder type: " + codingType);
278         }
279         if (((Character JavaDoc) nullValue).charValue() == en) {
280             return getNull();
281         }
282         Object JavaDoc key;
283         try {
284             key = evaluate(pngConverter.convert(en), null);
285         } catch (PExceptionNaming e) {
286             throw e;
287         } catch (PException e) {
288             throw new PExceptionNaming(e);
289         }
290         PBinder binder = (PBinder) key2binder.get(key);
291         if (binder == null) {
292             throw new PExceptionNaming("No binder associated to the key: " + key);
293         }
294         return binder.decodeChar(en);
295     }
296
297     public PName decodeOchar(Character JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
298         if (codingType != CTOCHAR) {
299             throw new PExceptionNaming("Bad coder type: " + codingType);
300         }
301         if (nullValue == null) {
302             if (en == null) {
303                 return getNull();
304             }
305         } else if (en != null
306             && ((Character JavaDoc) nullValue).charValue() == en.charValue()) {
307             return getNull();
308         }
309         Object JavaDoc key;
310         try {
311             key = evaluate(pngConverter.convert(en), null);
312         } catch (PExceptionNaming e) {
313             throw e;
314         } catch (PException e) {
315             throw new PExceptionNaming(e);
316         }
317         PBinder binder = (PBinder) key2binder.get(key);
318         if (binder == null) {
319             throw new PExceptionNaming("No binder associated to the key: " + key);
320         }
321         return binder.decodeOchar(en);
322     }
323
324     public PName decodeInt(int en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
325         if (codingType != CTINT) {
326             throw new PExceptionNaming("Bad coder type: " + codingType);
327         }
328         if (((Integer JavaDoc) nullValue).intValue() == en) {
329             return getNull();
330         }
331         Object JavaDoc key;
332         try {
333             key = evaluate(pngConverter.convert(en), null);
334         } catch (PExceptionNaming e) {
335             throw e;
336         } catch (PException e) {
337             throw new PExceptionNaming(e);
338         }
339         PBinder binder = (PBinder) key2binder.get(key);
340         if (binder == null) {
341             throw new PExceptionNaming("No binder associated to the key: " + key);
342         }
343         return binder.decodeInt(en);
344     }
345
346     public PName decodeOint(Integer JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
347         if (codingType != CTOINT) {
348             throw new PExceptionNaming("Bad coder type: " + codingType);
349         }
350         if (nullValue == null) {
351             if (en == null) {
352                 return getNull();
353             }
354         } else if (en != null
355             && ((Integer JavaDoc) nullValue).intValue() == en.intValue()) {
356             return getNull();
357         }
358         Object JavaDoc key;
359         try {
360             key = evaluate(pngConverter.convert(en), null);
361         } catch (PExceptionNaming e) {
362             throw e;
363         } catch (PException e) {
364             throw new PExceptionNaming(e);
365         }
366         PBinder binder = (PBinder) key2binder.get(key);
367         if (binder == null) {
368             throw new PExceptionNaming("No binder associated to the key: " + key);
369         }
370         return binder.decodeOint(en);
371     }
372
373     public PName decodeLong(long en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
374         if (codingType != CTLONG) {
375             throw new PExceptionNaming("Bad coder type: " + codingType);
376         }
377         if (((Long JavaDoc) nullValue).longValue() == en) {
378             return getNull();
379         }
380         Object JavaDoc key;
381         try {
382             key = evaluate(pngConverter.convert(en), null);
383         } catch (PExceptionNaming e) {
384             throw e;
385         } catch (PException e) {
386             throw new PExceptionNaming(e);
387         }
388         PBinder binder = (PBinder) key2binder.get(key);
389         if (binder == null) {
390             throw new PExceptionNaming("No binder associated to the key: " + key);
391         }
392         return binder.decodeLong(en);
393     }
394
395     public PName decodeOlong(Long JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
396         if (codingType != CTOLONG) {
397             throw new PExceptionNaming("Bad coder type: " + codingType);
398         }
399         if (nullValue == null) {
400             if (en == null) {
401                 return getNull();
402             }
403         } else if (en != null
404             && ((Long JavaDoc) nullValue).longValue() == en.longValue()) {
405             return getNull();
406         }
407         Object JavaDoc key;
408         try {
409             key = evaluate(pngConverter.convert(en), null);
410         } catch (PExceptionNaming e) {
411             throw e;
412         } catch (PException e) {
413             throw new PExceptionNaming(e);
414         }
415         PBinder binder = (PBinder) key2binder.get(key);
416         if (binder == null) {
417             throw new PExceptionNaming("No binder associated to the key: " + key);
418         }
419         return binder.decodeOlong(en);
420     }
421
422     public PName decodeShort(short en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
423         if (codingType != CTSHORT) {
424             throw new PExceptionNaming("Bad coder type: " + codingType);
425         }
426         if (((Short JavaDoc) nullValue).shortValue() == en) {
427             return getNull();
428         }
429         Object JavaDoc key;
430         try {
431             key = evaluate(pngConverter.convert(en), null);
432         } catch (PExceptionNaming e) {
433             throw e;
434         } catch (PException e) {
435             throw new PExceptionNaming(e);
436         }
437         PBinder binder = (PBinder) key2binder.get(key);
438         if (binder == null) {
439             throw new PExceptionNaming("No binder associated to the key: " + key);
440         }
441         return binder.decodeLong(en);
442     }
443
444     public PName decodeOshort(Short JavaDoc en) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
445         if (codingType != CTOSHORT) {
446             throw new PExceptionNaming("Bad coder type: " + codingType);
447         }
448         if (nullValue == null) {
449             if (en == null) {
450                 return getNull();
451             }
452         } else if (en != null
453             && ((Short JavaDoc) nullValue).shortValue() == en.shortValue()) {
454             return getNull();
455         }
456         Object JavaDoc key;
457         try {
458             key = evaluate(pngConverter.convert(en), null);
459         } catch (PExceptionNaming e) {
460             throw e;
461         } catch (PException e) {
462             throw new PExceptionNaming(e);
463         }
464         PBinder binder = (PBinder) key2binder.get(key);
465         if (binder == null) {
466             throw new PExceptionNaming("No binder associated to the key: " + key);
467         }
468         return binder.decodeOshort(en);
469     }
470
471     public PName decodeCharArray(char[] en) throws PExceptionNaming {
472         if (codingType != CTCHARARRAY) {
473             throw new PExceptionNaming("Bad coder type: " + codingType);
474         }
475         if (Arrays.equals((char[]) nullValue, en)) {
476             return getNull();
477         }
478         Object JavaDoc key;
479         try {
480             key = evaluate(pngConverter.convert(en), null);
481         } catch (PExceptionNaming e) {
482             throw e;
483         } catch (PException e) {
484             throw new PExceptionNaming(e);
485         }
486         PBinder binder = (PBinder) key2binder.get(key);
487         if (binder == null) {
488             throw new PExceptionNaming("No binder associated to the key: " + key);
489         }
490         return binder.decodeCharArray(en);
491     }
492
493     public PName decode(byte[] en) throws PExceptionNaming {
494         if (codingType != CTBYTEARRAY) {
495             throw new PExceptionNaming("Bad coder type: " + codingType);
496         }
497         if (Arrays.equals((byte[]) nullValue, en)) {
498             return getNull();
499         }
500         Object JavaDoc key;
501         try {
502             key = evaluate(pngConverter.convert(en), null);
503         } catch (PExceptionNaming e) {
504             throw e;
505         } catch (PException e) {
506             throw new PExceptionNaming(e);
507         }
508         PBinder binder = (PBinder) key2binder.get(key);
509         if (binder == null) {
510             throw new PExceptionNaming("No binder associated to the key: " + key);
511         }
512         return binder.decode(en);
513     }
514
515     public PName decodeDate(Date JavaDoc en) throws PExceptionNaming {
516         if (codingType != CTDATE) {
517             throw new PExceptionNaming("Bad coder type: " + codingType);
518         }
519         if (nullValue == null) {
520             if (en == null) {
521                 return getNull();
522             }
523         } else if (en != null
524             && ((Date JavaDoc) nullValue).getTime() == en.getTime()) {
525             return getNull();
526         }
527         Object JavaDoc key;
528         try {
529             key = evaluate(pngConverter.convert(en), null);
530         } catch (PExceptionNaming e) {
531             throw e;
532         } catch (PException e) {
533             throw new PExceptionNaming(e);
534         }
535         PBinder binder = (PBinder) key2binder.get(key);
536         if (binder == null) {
537             throw new PExceptionNaming("No binder associated to the key: " + key);
538         }
539         return binder.decodeDate(en);
540     }
541
542     public PName decodeBigInteger(BigInteger JavaDoc en) throws PExceptionNaming {
543         if (codingType != CTBIGINTEGER) {
544             throw new PExceptionNaming("Bad coder type: " + codingType);
545         }
546         if (nullValue == null) {
547             if (en == null) {
548                 return getNull();
549             }
550         } else if (((BigInteger JavaDoc) nullValue).compareTo(en) == 0) {
551             return getNull();
552         }
553         Object JavaDoc key;
554         try {
555             key = evaluate(pngConverter.convert(en), null);
556         } catch (PExceptionNaming e) {
557             throw e;
558         } catch (PException e) {
559             throw new PExceptionNaming(e);
560         }
561         PBinder binder = (PBinder) key2binder.get(key);
562         if (binder == null) {
563             throw new PExceptionNaming("No binder associated to the key: " + key);
564         }
565         return binder.decodeBigInteger(en);
566     }
567
568     public PName decodeBigDecimal(BigDecimal JavaDoc en) throws PExceptionNaming {
569         if (codingType != CTBIGDECIMAL) {
570             throw new PExceptionNaming("Bad coder type: " + codingType);
571         }
572         if (nullValue == null) {
573             if (en == null) {
574                 return getNull();
575             }
576         } else if (((BigDecimal JavaDoc) nullValue).compareTo(en) == 0) {
577             return getNull();
578         }
579         Object JavaDoc key;
580         try {
581             key = evaluate(pngConverter.convert(en), null);
582         } catch (PExceptionNaming e) {
583             throw e;
584         } catch (PException e) {
585             throw new PExceptionNaming(e);
586         }
587         PBinder binder = (PBinder) key2binder.get(key);
588         if (binder == null) {
589             throw new PExceptionNaming("No binder associated to the key: " + key);
590         }
591         return binder.decodeBigDecimal(en);
592     }
593
594
595     public PName decodeString(String JavaDoc en) throws PExceptionNaming {
596
597         return null;
598     }
599
600     public byte encodeByte(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
601         if (pn == null) {
602             throw new PExceptionNaming("Impossible to encode null");
603         } else if (pn == nullPName || pn.isNull()) {
604             return ((Byte JavaDoc) nullValue).byteValue();
605         } else {
606             PNameManager pnm = pn.getPNameManager();
607             if (pnm != this && pnm != null) {
608                 return pn.getPNameManager().encodeByte(pn);
609             } else {
610                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
611             }
612         }
613     }
614
615     public char encodeChar(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
616         if (pn == null) {
617             throw new PExceptionNaming("Impossible to encode null");
618         } else if (pn == nullPName || pn.isNull()) {
619             return ((Character JavaDoc) nullValue).charValue();
620         } else {
621             PNameManager pnm = pn.getPNameManager();
622             if (pnm != this && pnm != null) {
623                 return pn.getPNameManager().encodeChar(pn);
624             } else {
625                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
626             }
627         }
628     }
629
630     public int encodeInt(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
631         if (pn == null) {
632             throw new PExceptionNaming("Impossible to encode null");
633         } else if (pn == nullPName || pn.isNull()) {
634             return ((Integer JavaDoc) nullValue).intValue();
635         } else {
636             PNameManager pnm = pn.getPNameManager();
637             if (pnm != this && pnm != null) {
638                 return pn.getPNameManager().encodeInt(pn);
639             } else {
640                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
641             }
642         }
643     }
644
645     public long encodeLong(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
646         if (pn == null) {
647             throw new PExceptionNaming("Impossible to encode null");
648         } else if (pn == nullPName || pn.isNull()) {
649             return ((Long JavaDoc) nullValue).longValue();
650         } else {
651             PNameManager pnm = pn.getPNameManager();
652             if (pnm != this && pnm != null) {
653                 return pn.getPNameManager().encodeLong(pn);
654             } else {
655                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
656             }
657         }
658     }
659
660     public short encodeShort(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
661         if (pn == null) {
662             throw new PExceptionNaming("Impossible to encode null");
663         } else if (pn == nullPName || pn.isNull()) {
664             return ((Short JavaDoc) nullValue).shortValue();
665         } else {
666             PNameManager pnm = pn.getPNameManager();
667             if (pnm != this && pnm != null) {
668                 return pn.getPNameManager().encodeShort(pn);
669             } else {
670                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
671             }
672         }
673     }
674
675     public Byte JavaDoc encodeObyte(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
676         if (pn == null) {
677             throw new PExceptionNaming("Impossible to encode null");
678         } else if (pn == nullPName || pn.isNull()) {
679             return (Byte JavaDoc) nullValue;
680         } else {
681             PNameManager pnm = pn.getPNameManager();
682             if (pnm != this && pnm != null) {
683                 return pn.getPNameManager().encodeObyte(pn);
684             } else {
685                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
686             }
687         }
688     }
689
690     public Character JavaDoc encodeOchar(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
691         if (pn == null) {
692             throw new PExceptionNaming("Impossible to encode null");
693         } else if (pn == nullPName || pn.isNull()) {
694             return (Character JavaDoc) nullValue;
695         } else {
696             PNameManager pnm = pn.getPNameManager();
697             if (pnm != this && pnm != null) {
698                 return pn.getPNameManager().encodeOchar(pn);
699             } else {
700                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
701             }
702         }
703     }
704
705     public Integer JavaDoc encodeOint(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
706         if (pn == null) {
707             throw new PExceptionNaming("Impossible to encode null");
708         } else if (pn == nullPName || pn.isNull()) {
709             return (Integer JavaDoc) nullValue;
710         } else {
711             PNameManager pnm = pn.getPNameManager();
712             if (pnm != this && pnm != null) {
713                 return pn.getPNameManager().encodeOint(pn);
714             } else {
715                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
716             }
717         }
718     }
719
720     public Long JavaDoc encodeOlong(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
721         if (pn == null) {
722             throw new PExceptionNaming("Impossible to encode null");
723         } else if (pn == nullPName || pn.isNull()) {
724             return (Long JavaDoc) nullValue;
725         } else {
726             PNameManager pnm = pn.getPNameManager();
727             if (pnm != this && pnm != null) {
728                 return pn.getPNameManager().encodeOlong(pn);
729             } else {
730                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
731             }
732         }
733     }
734
735     public Short JavaDoc encodeOshort(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
736         if (pn == null) {
737             throw new PExceptionNaming("Impossible to encode null");
738         } else if (pn == nullPName || pn.isNull()) {
739             return (Short JavaDoc) nullValue;
740         } else {
741             PNameManager pnm = pn.getPNameManager();
742             if (pnm != this && pnm != null) {
743                 return pn.getPNameManager().encodeOshort(pn);
744             } else {
745                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
746             }
747         }
748     }
749
750     public Date JavaDoc encodeDate(PName pn) throws PExceptionNaming {
751         if (pn == null) {
752             throw new PExceptionNaming("Impossible to encode null");
753         } else if (pn == nullPName || pn.isNull()) {
754             return (Date JavaDoc) nullValue;
755         } else {
756             PNameManager pnm = pn.getPNameManager();
757             if (pnm != this && pnm != null) {
758                 return pn.getPNameManager().encodeDate(pn);
759             } else {
760                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
761             }
762         }
763     }
764
765     public BigInteger JavaDoc encodeBigInteger(PName pn) throws PExceptionNaming {
766         if (pn == null) {
767             throw new PExceptionNaming("Impossible to encode null");
768         } else if (pn == nullPName || pn.isNull()) {
769             return (BigInteger JavaDoc) nullValue;
770         } else {
771             PNameManager pnm = pn.getPNameManager();
772             if (pnm != this && pnm != null) {
773                 return pn.getPNameManager().encodeBigInteger(pn);
774             } else {
775                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
776             }
777         }
778     }
779
780     public BigDecimal JavaDoc encodeBigDecimal(PName pn) throws PExceptionNaming {
781         if (pn == null) {
782             throw new PExceptionNaming("Impossible to encode null");
783         } else if (pn == nullPName || pn.isNull()) {
784             return (BigDecimal JavaDoc) nullValue;
785         } else {
786             PNameManager pnm = pn.getPNameManager();
787             if (pnm != this && pnm != null) {
788                 return pn.getPNameManager().encodeBigDecimal(pn);
789             } else {
790                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
791             }
792         }
793     }
794
795     public byte[] encode(PName pn) throws PExceptionNaming {
796         if (pn == null) {
797             throw new PExceptionNaming("Impossible to encode null");
798         } else if (pn == nullPName || pn.isNull()) {
799             return (byte[]) nullValue;
800         } else {
801             PNameManager pnm = pn.getPNameManager();
802             if (pnm != this && pnm != null) {
803                 return pn.getPNameManager().encode(pn);
804             } else {
805                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
806             }
807         }
808     }
809
810     public char[] encodeCharArray(PName pn) throws PExceptionNaming {
811         if (pn == null) {
812             throw new PExceptionNaming("Impossible to encode null");
813         } else if (pn == nullPName || pn.isNull()) {
814             return (char[]) nullValue;
815         } else {
816             PNameManager pnm = pn.getPNameManager();
817             if (pnm != this && pnm != null) {
818                 return pn.getPNameManager().encodeCharArray(pn);
819             } else {
820                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
821             }
822         }
823     }
824
825     public Object JavaDoc encodeAbstract(PName pn) throws PExceptionNaming, UnsupportedOperationException JavaDoc {
826         if (pn == null) {
827             throw new PExceptionNaming("Impossible to encode null");
828         } else if (pn == nullPName || pn.isNull()) {
829             return nullPName;
830         } else {
831             PNameManager pnm = pn.getPNameManager();
832             if (pnm != this && pnm != null) {
833                 return pn.getPNameManager().encodeAbstract(pn);
834             } else {
835                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
836             }
837         }
838     }
839
840     public String JavaDoc encodeString(PName pn) throws PExceptionNaming {
841         if (pn == null) {
842             throw new PExceptionNaming("Impossible to encode null");
843         } else if (pn == nullValue || pn.isNull()) {
844             return (String JavaDoc) nullValue;
845         } else {
846             PNameManager pnm = pn.getPNameManager();
847             if (pnm != this && pnm != null) {
848                 return pn.getPNameManager().encodeString(pn);
849             } else {
850                 throw new PExceptionNaming("This PName should not be encoded in this PNamingContext, pname: " + pn);
851             }
852         }
853     }
854
855     public PName getNull() {
856         return nullPName;
857     }
858
859     /**
860      * @param o must be the null PName
861      */

862     public void setNullPName(Object JavaDoc o) throws PException {
863         if (!(o instanceof PName)) {
864             throw new PExceptionNaming("A KFPNC accepts only PName instance as parameter to define the null pname");
865         }
866         nullPName = (PName) o;
867     }
868
869     private void checkNullValue() throws PException {
870         switch (codingType) {
871         case CTCHAR:
872             nullValue = new Character JavaDoc(nullPName.encodeChar());
873             break;
874         case CTOCHAR:
875             nullValue = nullPName.encodeOchar();
876             break;
877         case CTBYTE:
878             nullValue = new Byte JavaDoc(nullPName.encodeByte());
879             break;
880         case CTOBYTE:
881             nullValue = nullPName.encodeObyte();
882             break;
883         case CTSHORT:
884             nullValue = new Short JavaDoc(nullPName.encodeShort());
885             break;
886         case CTOSHORT:
887             nullValue = nullPName.encodeOshort();
888             break;
889         case CTINT:
890             nullValue = new Integer JavaDoc(nullPName.encodeInt());
891             break;
892         case CTOINT:
893             nullValue = nullPName.encodeOint();
894             break;
895         case CTLONG:
896             nullValue = new Long JavaDoc(nullPName.encodeLong());
897             break;
898         case CTOLONG:
899             nullValue = nullPName.encodeOlong();
900             break;
901         case CTSTRING:
902             nullValue = nullPName.encodeString();
903             break;
904         case CTDATE:
905             nullValue = nullPName.encodeDate();
906             break;
907         case CTBIGDECIMAL:
908             nullValue = nullPName.encodeBigDecimal();
909             break;
910         case CTBIGINTEGER:
911             nullValue = nullPName.encodeBigInteger();
912             break;
913         case CTBYTEARRAY:
914             nullValue = nullPName.encode();
915             break;
916         case CTCHARARRAY:
917             nullValue = nullPName.encodeCharArray();
918             break;
919         case CTCOMPOSITE:
920             break;
921         }
922     }
923 }
924
925
Popular Tags