KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jorm > generator > lib > CommonHelper


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.generator.lib;
25
26 import org.objectweb.jorm.api.PException;
27 import org.objectweb.jorm.metainfo.api.Class;
28 import org.objectweb.jorm.metainfo.api.Package;
29 import org.objectweb.jorm.metainfo.api.ClassRef;
30 import org.objectweb.jorm.metainfo.api.CompositeName;
31 import org.objectweb.jorm.metainfo.api.FieldName;
32 import org.objectweb.jorm.metainfo.api.GenClassRef;
33 import org.objectweb.jorm.metainfo.api.Manager;
34 import org.objectweb.jorm.metainfo.api.MetaObject;
35 import org.objectweb.jorm.metainfo.api.NameDef;
36 import org.objectweb.jorm.metainfo.api.NameRef;
37 import org.objectweb.jorm.metainfo.api.PrimitiveElement;
38 import org.objectweb.jorm.metainfo.api.Reference;
39 import org.objectweb.jorm.metainfo.api.TypedElement;
40 import org.objectweb.jorm.metainfo.api.Mapping;
41 import org.objectweb.jorm.metainfo.api.ReferenceMapping;
42 import org.objectweb.jorm.metainfo.api.PrimitiveElementMapping;
43 import org.objectweb.jorm.type.api.PExceptionTyping;
44 import org.objectweb.jorm.type.api.PType;
45 import org.objectweb.jorm.type.api.PTypeSpace;
46 import org.objectweb.jorm.util.api.Loggable;
47 import org.objectweb.jorm.compiler.api.PExceptionCompiler;
48 import org.objectweb.util.monolog.api.BasicLevel;
49 import org.objectweb.util.monolog.api.Logger;
50 import org.objectweb.util.monolog.api.LoggerFactory;
51
52 import java.util.ArrayList JavaDoc;
53 import java.util.Iterator JavaDoc;
54 import java.util.Map JavaDoc;
55 import java.util.Collection JavaDoc;
56 import java.util.HashMap JavaDoc;
57
58 /**
59  * This class is a helper for the generation. All methods provided in this
60  * class are shortcut or facilties which simplify the generation.
61  * @author Sebastien Chassande-Barrioz
62  */

63 public class CommonHelper implements Loggable {
64
65     protected LoggerFactory loggerFactory = null;
66     protected Logger logger = null;
67     protected boolean debug = false;
68
69     public final static PType[] PN_GET_TYPES = {
70         PTypeSpace.BYTE,
71         PTypeSpace.CHAR,
72         PTypeSpace.DATE,
73         PTypeSpace.INT,
74         PTypeSpace.LONG,
75         PTypeSpace.OBJBYTE,
76         PTypeSpace.OBJCHAR,
77         PTypeSpace.OBJINT,
78         PTypeSpace.OBJLONG,
79         PTypeSpace.OBJSHORT,
80         PTypeSpace.SHORT,
81         PTypeSpace.STRING,
82         PTypeSpace.BYTEARRAY,
83         PTypeSpace.CHARARRAY,
84         PTypeSpace.BIGDECIMAL,
85         PTypeSpace.BIGINTEGER
86     };
87
88     /**
89      * This methods returns the word specified in parameter with the first
90      * character in upper-case. This method is used for the generation of
91      * accessor methods.
92      * @param word The String which the first character must be set in
93      * upper-case
94      * @return The String whith the first character in upper-case
95      */

96     public String JavaDoc upperFL(String JavaDoc word) {
97         if (word != null && word.length() > 0)
98             return word.substring(0, 1).toUpperCase() + word.substring(1);
99         else
100             return word;
101     }
102
103     /**
104      * This method allow to retrieve a primitive element from th meta object mo.
105      * if this metaobject is a primitive element, it is returned itself.
106      * if this meta object is a single namedef the primitive element composing the namedef is returned.
107      * This method does not work with composite pname.
108      * @param mo the meta object embeding the primitive element
109      * @param c the class embeding the meta object mo
110      * @return the primitive element
111      */

112
113     public PrimitiveElement getPrimitiveElement(Object JavaDoc mo,
114                                                 Class JavaDoc c,
115                                                 boolean canBeFieldName)
116             throws PException {
117         if (mo instanceof PrimitiveElement)
118             return (PrimitiveElement) mo;
119         else if (mo instanceof NameDef) {
120             NameDef nd = ((NameDef) mo);
121             if (nd.isFieldName())
122                 return (PrimitiveElement) (c.getTypedElement(nd.getFieldName()));
123             else
124                 throw new PException("This is composite name !" + mo);
125         } else
126             throw new PException(
127                     "impossible to obtain a PrimitiveElement with " + mo);
128     }
129
130     /**
131      * This method tests if a class contains a reference. A reference can be a
132      * designs a generic class or a class.
133      * @param co The meta object Class
134      * @return true if the class contains a reference.
135      */

136     public boolean containsReference(Class JavaDoc co) {
137         Iterator JavaDoc it = co.getAllFields().iterator();
138         while (it.hasNext()) {
139             if (it.next() instanceof Reference)
140                 return true;
141         }
142         return false;
143     }
144
145     /**
146      * This method tests if a class contains a composite reference. A reference can be a
147      * designs a generic class or a class.
148      * @param mo The meta object Mapping
149      * @return true if the class contains the namedef for the composite reference.
150      *
151      public boolean containsCompositeReference(Mapping mo) throws Exception {
152      Iterator it = mo.getClassMapping().getReferenceMappings().iterator();
153      while (it.hasNext()) {
154      ReferenceMapping rm = (ReferenceMapping) it.next();
155      if (((NameDef) rm.getLinkedMO()).isNameRef()) {
156      return true;
157      }
158      }
159      return false;
160      }
161      */

162
163     /**
164      * This method return a list containing the nameref implied in composite reference field
165      * @param mo The meta object Mapping to be analysed.
166      * @return an ArrayList which contains all nameref related to reference fields.
167      */

168
169     public ArrayList JavaDoc getCompositeReferences(Mapping mo) throws Exception JavaDoc {
170         ArrayList JavaDoc res = new ArrayList JavaDoc();
171         Iterator JavaDoc it = mo.getClassMapping().getReferenceMappings().iterator();
172         while (it.hasNext()) {
173             ReferenceMapping rm = (ReferenceMapping) it.next();
174             if (((NameDef) rm.getLinkedMO()).isNameRef()) {
175                 res.add(((NameDef) rm.getLinkedMO()).getNameRef());
176             }
177         }
178         return res;
179     }
180
181     /**
182      * This method return a SET containing the full name of compositename implied
183      * in the reference field of the class.
184      * @param moc The meta object Class
185      * @param cp the compiler parameter
186      * @return an iterator which contains all pname related to the Reference.
187      *
188      public Set getCompositeNames(Class moc, JormCompilerParameter cp) throws Exception {
189
190      Set res = new HashSet();
191      NameDef nd = moc.getNameDef(cp.projectName);
192      if (nd.isNameRef()) {
193      String cn = nd.getNameRef().getCompositeName().getFQName();
194      if (res.add(cn)) {
195      res.add(cn + "PNG");
196      }
197      }
198      Iterator it = moc.iterateAllField();
199      while (it.hasNext()) {
200      TypedElement te = (TypedElement) it.next();
201      if (te instanceof Reference) {
202      nd = ((Reference) te).getRefNameDef(cp.projectName);
203      if (nd.isNameRef()) {
204      res.add(nd.getNameRef().getCompositeName().getFQName()
205      + "PNG");
206      }
207      }
208      }
209      return res;
210      }
211      */

212
213     /**
214      * This method retrieve the package name for the meta object passed as parameter.
215      * The meta object must be a child of a Package MetaObject.
216      * @param mo The meta object
217      * @return the name of the package if it exist, null otherwise.
218      */

219     public String JavaDoc getCNPackageName(MetaObject mo) {
220         if (mo instanceof Manager) return null;
221         while (!(mo instanceof Package JavaDoc)) {
222             mo = mo.getParent();
223         }
224         if (mo instanceof Package JavaDoc)
225             return ((Package JavaDoc) mo).getName();
226         else
227             return null;
228     }
229
230     /**
231      * This method tests if a class contains a serialized field.
232      * @param co The meta object Class
233      * @return true if the class contains a serialized field.
234      */

235     public boolean containsSerializedField(Class JavaDoc co) {
236         Iterator JavaDoc it = co.getAllFields().iterator();
237         while (it.hasNext()) {
238             if (((TypedElement) it.next()).getType().getTypeCode()
239                     == PType.TYPECODE_SERIALIZED)
240                 return true;
241         }
242         return false;
243     }
244
245     /**
246      * This method tests if a class contains a char[] field.
247      * @param m The meta object Mapping
248      * @return true if the class contains a serialized field.
249      */

250     public boolean containsCharArrayField(Mapping m) {
251         Class JavaDoc co = (Class JavaDoc) m.getClassMapping().getLinkedMO();
252         Iterator JavaDoc it = co.getAllFields().iterator();
253         while (it.hasNext()) {
254             TypedElement te = (TypedElement) it.next();
255             if (te == null) {
256                 throw new NullPointerException JavaDoc(
257                         "A field of the class '" + co.getFQName() + "' is null.");
258             }
259             if (te.getType() == null) {
260                 throw new NullPointerException JavaDoc(
261                         "the type of field '" + te.getName()
262                         + "' of the class '" + co.getFQName() + "' is null.");
263             }
264             if (te.getType().getTypeCode() == PType.TYPECODE_CHARARRAY)
265                 return true;
266         }
267         it = co.getAllHiddenFields().iterator();
268         while (it.hasNext()) {
269             if (((TypedElement) it.next()).getType().getTypeCode()
270                     == PType.TYPECODE_CHARARRAY)
271                 return true;
272         }
273         NameDef nd = (NameDef)
274                 m.getClassMapping().getIdentifierMapping().getLinkedMO();
275         if (nd.isNameRef()) {
276             it = nd.getNameRef().getCompositeName().getAllFields().iterator();
277             while (it.hasNext()) {
278                 if (((TypedElement) it.next()).getType().getTypeCode()
279                         == PType.TYPECODE_CHARARRAY)
280                     return true;
281             }
282         }
283         return false;
284     }
285
286     /**
287      * This method tests if a class contains a serialized field.
288      * @param co The meta object Class
289      * @return true if the class contains a serialized field.
290      */

291     public boolean containsFieldWhichCanBeNull(Class JavaDoc co) throws PException {
292         for (Iterator JavaDoc it = co.getAllFields().iterator(); it.hasNext();) {
293             if (canBeNullValue(((TypedElement) it.next()).getType()))
294                 return true;
295         }
296         for (Iterator JavaDoc it = co.getAllHiddenFields().iterator(); it.hasNext();) {
297             if (canBeNullValue(((TypedElement) it.next()).getType()))
298                 return true;
299         }
300         return false;
301     }
302
303     /**
304      * This method tests if a String is valid. A String is valid if it is not
305      * null and if the length is greater than 0.
306      * @param str The string which must be checked
307      * @return true if the string is valid
308      */

309     public boolean isValidString(String JavaDoc str) {
310         return str != null && str.length() > 0;
311     }
312
313     /**
314      * This method tests if a class references to a generic class.
315      * @param co The meta object Class
316      * @return true if the class references a generic class.
317      */

318     public boolean containsGenClassRef(Class JavaDoc co) {
319         Iterator JavaDoc it = co.getAllFields().iterator();
320         while (it.hasNext()) {
321             if (it.next() instanceof GenClassRef)
322                 return true;
323         }
324         return false;
325     }
326
327     /**
328      * This method checks if the NameDef is composed by several fields.
329      * @param nd the meta object NameDef which must be tested
330      * @return true if the NameDef is composed by several fields.
331      */

332     public boolean isCompositeName(NameDef nd) {
333         return nd.isNameRef();
334     }
335
336     /**
337      * This method provides an iterator over the map entries which associated
338      * a composite field name (key) to the class field name (value). These map
339      * elements describe the projection of a name definition.
340      *
341      * @param mo the meta object NameDef which must be used
342      */

343
344     public Collection JavaDoc getCompositeNameDefEntries(NameDef mo) throws Exception JavaDoc {
345         if (mo == null)
346             throw new PException("Null NameDef Parameter");
347         else if (mo.isNameRef())
348             return mo.getNameRef().getProjection().entrySet();
349         else if (mo.isFieldName())
350             throw new PException("The NameDef is a FieldName ("
351                                  + mo.getFieldName() + ")");
352         else if (mo.isSystem())
353             throw new PException("System identifier unmanaged");
354         else
355             throw new PException("Unknown NameDef: " + mo);
356     }
357
358     public String JavaDoc getFQNOfCompositeName(Object JavaDoc o) {
359         CompositeName cn = null;
360         if (o instanceof CompositeName)
361             cn = (CompositeName) o;
362         else if (o instanceof NameDef)
363             cn = ((NameDef) o).getNameRef().getCompositeName();
364         else
365             return "";
366
367         String JavaDoc packName = ((Package JavaDoc) cn.getParent()).getName();
368         if (packName == null || packName.length() == 0) {
369             return cn.getName();
370         } else {
371             return packName + "." + cn.getName();
372         }
373     }
374
375     /**
376      * This method allows to know if a class represented by its Class meta
377      * object, contains a composite PName. This method analyzes the NameDef of
378      * the @c class parameter and the NameDef of all reference fields.
379      * @param mo the Mapping which must analyzed
380      */

381     public boolean containsCompositeName(Mapping mo) {
382         if (mo == null) {
383             return false;
384         }
385         NameDef nd = (NameDef)
386                 mo.getClassMapping().getIdentifierMapping().getLinkedMO();
387         if (nd.isNameRef())
388             return true;
389         if (logger != null)
390             logger.log(BasicLevel.DEBUG, "PName class has a single field");
391         Iterator JavaDoc it = mo.getClassMapping().getReferenceMappings().iterator();
392         while (it.hasNext()) {
393             ReferenceMapping rm = (ReferenceMapping) it.next();
394             nd = (NameDef) rm.getLinkedMO();
395             if (nd.isNameRef()) {
396                 return true;
397             }
398         }
399         return false;
400     }
401
402     /**
403      * This method checks if the parameter is an instance of
404      * org.objectweb.jorm.metainfo.api.Class
405      * @param o the object which the type must be checked
406      * @return true the parameter is an instance of Class
407      */

408     public boolean isClass(Object JavaDoc o) {
409         return o instanceof Class JavaDoc;
410     }
411
412     /**
413      * This method checks if the parameter is an instance of
414      * org.objectweb.jorm.metainfo.api.Reference
415      * @param te the object which the type must be checked
416      * @return true the parameter is an instance of Reference
417      */

418     public boolean isReference(TypedElement te) {
419         return te instanceof Reference;
420     }
421
422     /**
423      * This method checks if the parameter is an instance of
424      * org.objectweb.jorm.metainfo.api.ClassRef
425      * @param te the object which the type must be checked
426      * @return true the parameter is an instance of ClassRef
427      */

428     public boolean isClassRef(TypedElement te) {
429         return te instanceof ClassRef;
430     }
431
432     /**
433      * This method checks if the parameter is an instance of
434      * org.objectweb.jorm.metainfo.api.GenClassRef
435      * @param te the object which the type must be checked
436      * @return true the parameter is an instance of GenClassRef
437      */

438     public boolean isGenClassRef(TypedElement te) {
439         return te instanceof GenClassRef;
440     }
441
442     /**
443      * This method checks if the parameter is an instance of
444      * org.objectweb.jorm.metainfo.api.PrimitiveElement
445      * @param o the object which the type must be checked
446      * @return true the parameter is an instance of PrimitiveElement
447      */

448     public boolean isPrimitiveElement(Object JavaDoc o) {
449         return o instanceof PrimitiveElement;
450     }
451
452     /**
453      * @param val1 the variable name of the first element
454      * @param val2 the variable name of the second element
455      * @param type the type of the elements
456      * @return a String comparing two primitive element
457      */

458     public String JavaDoc comparePE(String JavaDoc val1, String JavaDoc val2, PType type) {
459         if (isObjectType(type)) {
460             return "((" + val1 + " == null && " + val2 + " == null) || ("
461                     + val1 + " !=null && " + val1 + ".equals(" + val2 + ")))";
462         } else {
463             return val1 + " == " + val2;
464         }
465     }
466
467     public boolean isObjectType(PType type) {
468         switch(type.getTypeCode()) {
469         case PType.TYPECODE_OBJBOOLEAN:
470         case PType.TYPECODE_OBJBYTE:
471         case PType.TYPECODE_OBJCHAR:
472         case PType.TYPECODE_DATE:
473         case PType.TYPECODE_CHARARRAY:
474         case PType.TYPECODE_BYTEARRAY:
475         case PType.TYPECODE_OBJSHORT:
476         case PType.TYPECODE_OBJINT:
477         case PType.TYPECODE_OBJLONG:
478         case PType.TYPECODE_OBJFLOAT:
479         case PType.TYPECODE_OBJDOUBLE:
480         case PType.TYPECODE_STRING:
481         case PType.TYPECODE_SERIALIZED:
482         case PType.TYPECODE_BIGDECIMAL:
483         case PType.TYPECODE_BIGINTEGER:
484             return true;
485         case PType.TYPECODE_BOOLEAN:
486         case PType.TYPECODE_BYTE:
487         case PType.TYPECODE_CHAR:
488         case PType.TYPECODE_SHORT:
489         case PType.TYPECODE_INT:
490         case PType.TYPECODE_LONG:
491         case PType.TYPECODE_FLOAT:
492         case PType.TYPECODE_DOUBLE:
493         default:
494             return false;
495         }
496     }
497
498     public boolean isNull(Object JavaDoc o) {
499         return o == null;
500     }
501
502     /**
503      * This method checks if the parameter is an instance of
504      * org.objectweb.jorm.metainfo.api.PrimitiveElement
505      * @param pe the object which the type must be checked
506      * @return true the parameter is an instance of PrimitiveElement
507      */

508     public boolean isHiddenField(PrimitiveElement pe) {
509         return ((Class JavaDoc) pe.getParent()).getHiddenField(pe.getName()) != null;
510     }
511
512     /**
513      * This method checks if the parameter is an instance of
514      * org.objectweb.jorm.metainfo.api.FieldName
515      * @param o the object which the type must be checked
516      * @return true the parameter is an instance of FieldName
517      */

518     public boolean isFieldName(Object JavaDoc o) {
519         return o instanceof FieldName;
520     }
521
522     /**
523      * This method checks if the parameter designs a Serialized field.
524      * @param o the object which the type must be checked
525      * @return true the parameter is an instance of PrimitiveElement and if its
526      * PType is SERIALIZED.
527      */

528     public boolean isSerializedField(Object JavaDoc o) {
529         return (o instanceof PrimitiveElement)
530                 && (((PrimitiveElement) o).getType().getTypeCode()
531                 == PType.TYPECODE_SERIALIZED);
532     }
533
534     /**
535      * This method checks if the PType parameter designs a Serialized type.
536      * @param t the PType object which the type must be checked
537      * @return true the parameter is a PType.SERIALIZED.
538      */

539     public boolean isSerializedType(PType t) {
540         return t.getTypeCode() == PType.TYPECODE_SERIALIZED;
541     }
542
543     /**
544      * This method checks if the PType parameter designs a Serialized type.
545      * @param t the PType object which the type must be checked
546      * @return true the parameter is a PType.SERIALIZED.
547      */

548     public boolean isCharArrayType(PType t) {
549         return t.getTypeCode() == PType.TYPECODE_CHARARRAY;
550     }
551
552     public PrimitiveElementMapping[] buildPemList(Collection JavaDoc pemcoll) {
553         return (PrimitiveElementMapping[]) pemcoll.toArray(new PrimitiveElementMapping[0]);
554     }
555
556     public int getPemPos(PrimitiveElementMapping[] pemlist, PrimitiveElement pe) throws PExceptionCompiler {
557         for (int i = 0; i < pemlist.length; i++) {
558             if (pemlist[i].getLinkedMO() == pe) {
559                 return i + 1;
560             }
561         }
562         throw new PExceptionCompiler("Cannot find a mapping for field: " + pe.getName());
563     }
564
565     public PrimitiveElement getPrimitiveElement(String JavaDoc fn, Class JavaDoc cl) throws PExceptionCompiler {
566         TypedElement res = cl.getTypedElement(fn);
567         if (res == null) {
568             throw new PExceptionCompiler("NameDef with field name does not correspond to any field - searched field: " + fn);
569         }
570         if (!(res instanceof PrimitiveElement)) {
571             throw new PExceptionCompiler("NameDef with field name does not correspond to any primitive field - searched field: " + fn);
572         }
573         return (PrimitiveElement) res;
574     }
575
576     public NameDef getRefNameDef(Mapping mo, Reference field) throws PException {
577         if (field == null) {
578             return null;
579         }
580         if (mo == null) {
581             return null;
582         }
583         ReferenceMapping rm = mo.getClassMapping().getReferenceMapping(field.getName());
584         NameDef nd = null;
585         if (rm != null) {
586             nd = (NameDef) rm.getLinkedMO();
587         }
588         if (nd == null) {
589             throw new PException("No NameDef found for the reference field '"
590                 + field.getName() +"' of the persistent class '"
591                 + ((Class JavaDoc) mo.getClassMapping().getLinkedMO()).getFQName()
592                 + "'.");
593         }
594         return nd;
595     }
596
597     public String JavaDoc getTupleDecoding(String JavaDoc fn, PType pt, String JavaDoc value)
598         throws PException {
599         if (pt == null) {
600             throw new PException("Unauthorized null PType");
601         }
602         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
603         sb.append(fn);
604         sb.append("Pnc.decode");
605         sb.append(pt.getCodingName());
606         sb.append("((");
607         sb.append(pt.getJavaName());
608         sb.append(") ");
609         sb.append(value);
610         sb.append(")");
611         return sb.toString();
612     }
613
614     /**
615      * Builds the string representing the expression to decode a PName wrt the
616      * relevant tuple field having the right type.
617      * @param tmpv The temporary variable that holds the tuple field value.
618      * @param fn The name of the involved application field.
619      * @param tuplevn The variable name that holds the corresponding tuple.
620      * @param pt The PType of the associated field.
621      * @param pos The position of the tuple field into this tuple.
622      * @return The string representing the getter expression.
623      */

624     public String JavaDoc getTupleDecoding(String JavaDoc tmpv, String JavaDoc fn, String JavaDoc tuplevn, PType pt, int pos)
625             throws PException {
626         if (pt == null)
627             throw new PException("Unauthorized null PType");
628         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
629         switch (pt.getTypeCode()) {
630         case PType.TYPECODE_BYTE:
631         case PType.TYPECODE_CHAR:
632         case PType.TYPECODE_SHORT:
633         case PType.TYPECODE_INT:
634         case PType.TYPECODE_LONG:
635             sb.append(fn);
636             sb.append("Pnc.decode");
637             sb.append(pt.getCodingName());
638             sb.append("(");
639             sb.append(getTupleGetter(tuplevn, pt, pos) );
640             sb.append(")");
641             return sb.toString();
642         case PType.TYPECODE_OBJBYTE:
643         case PType.TYPECODE_OBJCHAR:
644         case PType.TYPECODE_OBJSHORT:
645         case PType.TYPECODE_OBJINT:
646         case PType.TYPECODE_OBJLONG:
647         case PType.TYPECODE_STRING:
648         case PType.TYPECODE_DATE:
649         case PType.TYPECODE_BIGDECIMAL:
650         case PType.TYPECODE_BIGINTEGER:
651             sb.append("(((");
652             sb.append(tmpv);
653             sb.append(" = ");
654             sb.append(getTupleGetter(tuplevn, pt, pos) );
655             sb.append(") == null) ? ");
656             sb.append(fn);
657             sb.append("Pnc.getNull() : ");
658             sb.append(fn);
659             sb.append("Pnc.decode");
660             sb.append(pt.getCodingName());
661             sb.append("((");
662             sb.append(pt.getJavaName());
663             sb.append(") ");
664             sb.append(tmpv);
665             sb.append("))");
666             return sb.toString();
667         }
668         throw new PExceptionTyping("Unauthorized PType " + pt);
669     }
670
671     /**
672      * Builds the string representing the expression to access the relevant
673      * tuple field having the right type.
674      * @param tuplevn The variable name that holds the corresponding tuple.
675      * @param pt The PType of the associated field.
676      * @param pos The position of the tuple field into this tuple.
677      * @return The string representing the getter expression.
678      */

679     public String JavaDoc getTupleGetter(String JavaDoc tuplevn, PType pt, int pos)
680             throws PException {
681         if (pt == null)
682             throw new PException("Unauthorized null PType");
683         switch (pt.getTypeCode()) {
684         case PType.TYPECODE_BOOLEAN:
685             return tuplevn + ".getBoolean(" + pos + ")";
686         case PType.TYPECODE_OBJBOOLEAN:
687             return "(new Boolean(" + tuplevn + ".getBoolean(" + pos + ")))";
688         case PType.TYPECODE_BYTE:
689             return tuplevn + ".getByte(" + pos + ")";
690         case PType.TYPECODE_OBJBYTE:
691             return "(new Byte(" + tuplevn + ".getByte(" + pos + ")))";
692         case PType.TYPECODE_CHAR:
693             return tuplevn + ".getChar(" + pos + ")";
694         case PType.TYPECODE_OBJCHAR:
695             return "(new Character(" + tuplevn + ".getChar(" + pos + ")))";
696         case PType.TYPECODE_DATE:
697             return tuplevn + ".getDate(" + pos + ")";
698         case PType.TYPECODE_CHARARRAY:
699             return tuplevn + ".getCharArray(" + pos + ")";
700         case PType.TYPECODE_BYTEARRAY:
701             return tuplevn + ".getByteArray(" + pos + ")";
702         case PType.TYPECODE_SHORT:
703             return tuplevn + ".getShort(" + pos + ")";
704         case PType.TYPECODE_OBJSHORT:
705             return "(new Short(" + tuplevn + ".getShort(" + pos + ")))";
706         case PType.TYPECODE_INT:
707             return tuplevn + ".getInt(" + pos + ")";
708         case PType.TYPECODE_OBJINT:
709             return "(new Integer( " + tuplevn + ".getInt(" + pos + ")))";
710         case PType.TYPECODE_LONG:
711             return tuplevn + ".getLong(" + pos + ")";
712         case PType.TYPECODE_OBJLONG:
713             return "(new Long(" + tuplevn + ".getLong(" + pos + ")))";
714         case PType.TYPECODE_FLOAT:
715             return tuplevn + ".getFloat(" + pos + ")";
716         case PType.TYPECODE_OBJFLOAT:
717             return "(new Float(" + tuplevn + ".getFloat(" + pos + ")))";
718         case PType.TYPECODE_DOUBLE:
719             return tuplevn + ".getDouble(" + pos + ")";
720         case PType.TYPECODE_OBJDOUBLE:
721             return "(new Double(" + tuplevn + ".getDouble(" + pos + ")))";
722         case PType.TYPECODE_STRING:
723             return tuplevn + ".getString(" + pos + ")";
724         case PType.TYPECODE_SERIALIZED:
725             return "(Serializable) " + tuplevn + ".getObject(" + pos + ")";
726         case PType.TYPECODE_BIGDECIMAL:
727             return tuplevn + ".getBigDecimal(" + pos + ")";
728         case PType.TYPECODE_BIGINTEGER:
729             return tuplevn + ".getBigInteger(" + pos + ")";
730         }
731         throw new PExceptionTyping("Unauthorized PType " + pt);
732     }
733
734     /**
735      * This method does the conversion between a PType @pt and the getter
736      * function to use on a PAccessorGen (generic accessor).
737      * @param pt the ptype which helps to find the right paccessor method
738      * @return The string which represents the paccessor method associated
739      * to pt parameter
740      */

741     public String JavaDoc getPaGetMethod(PType pt) throws PException {
742         if (pt == null)
743             throw new PException("Unauthorized null PType");
744         switch (pt.getTypeCode()) {
745         case PType.TYPECODE_BOOLEAN:
746             return "paGetBooleanField";
747         case PType.TYPECODE_OBJBOOLEAN:
748             return "paGetObooleanField";
749         case PType.TYPECODE_BYTE:
750             return "paGetByteField";
751         case PType.TYPECODE_OBJBYTE:
752             return "paGetObyteField";
753         case PType.TYPECODE_CHAR:
754             return "paGetCharField";
755         case PType.TYPECODE_OBJCHAR:
756             return "paGetOcharField";
757         case PType.TYPECODE_DATE:
758             return "paGetDateField";
759         case PType.TYPECODE_CHARARRAY:
760             return "paGetCharArrayField";
761         case PType.TYPECODE_BYTEARRAY:
762             return "paGetByteArrayField";
763         case PType.TYPECODE_SHORT:
764             return "paGetShortField";
765  &nbs