KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.objectweb.jorm.naming.lib;
24
25 import org.objectweb.jorm.type.api.PType;
26 import org.objectweb.jorm.naming.api.PNameCoder;
27
28 /**
29  * This class is a helper which permits to convert PType code to a pname coding
30  * type.
31  *
32  * @author S.Chassande-Barrioz
33  */

34 public class CTHelper {
35
36     /**
37      * It convertes a Coding type to a PType code
38      */

39     public static int ct2ptc(int ct) {
40         switch (ct) {
41         case PNameCoder.CTCHAR:
42             return PType.TYPECODE_CHAR;
43         case PNameCoder.CTOCHAR:
44             return PType.TYPECODE_OBJCHAR;
45
46         case PNameCoder.CTBYTE:
47             return PType.TYPECODE_BYTE;
48         case PNameCoder.CTOBYTE:
49             return PType.TYPECODE_OBJBYTE;
50
51         case PNameCoder.CTSHORT:
52             return PType.TYPECODE_SHORT;
53         case PNameCoder.CTOSHORT:
54             return PType.TYPECODE_OBJSHORT;
55
56         case PNameCoder.CTINT:
57             return PType.TYPECODE_INT;
58         case PNameCoder.CTOINT:
59             return PType.TYPECODE_OBJINT;
60
61         case PNameCoder.CTLONG:
62             return PType.TYPECODE_LONG;
63         case PNameCoder.CTOLONG:
64             return PType.TYPECODE_OBJLONG;
65
66         case PNameCoder.CTSTRING:
67             return PType.TYPECODE_STRING;
68
69         case PNameCoder.CTBYTEARRAY:
70             return PType.TYPECODE_BYTEARRAY;
71         case PNameCoder.CTCHARARRAY:
72             return PType.TYPECODE_CHARARRAY;
73         case PNameCoder.CTDATE:
74             return PType.TYPECODE_DATE;
75         case PNameCoder.CTBIGDECIMAL:
76             return PType.TYPECODE_BIGDECIMAL;
77         case PNameCoder.CTBIGINTEGER:
78             return PType.TYPECODE_BIGINTEGER;
79         default:
80             return -1;
81         }
82     }
83
84     /**
85      * It convertes a PType code to a Coding type.
86      */

87     public static int ptc2ct(int tpc) {
88         switch (tpc) {
89         case PType.TYPECODE_CHAR:
90             return PNameCoder.CTCHAR;
91         case PType.TYPECODE_OBJCHAR:
92             return PNameCoder.CTOCHAR;
93
94         case PType.TYPECODE_BYTE:
95             return PNameCoder.CTBYTE;
96         case PType.TYPECODE_OBJBYTE:
97             return PNameCoder.CTOBYTE;
98
99         case PType.TYPECODE_SHORT:
100             return PNameCoder.CTSHORT;
101         case PType.TYPECODE_OBJSHORT:
102             return PNameCoder.CTOSHORT;
103
104         case PType.TYPECODE_INT:
105             return PNameCoder.CTINT;
106         case PType.TYPECODE_OBJINT:
107             return PNameCoder.CTOINT;
108
109         case PType.TYPECODE_LONG:
110             return PNameCoder.CTLONG;
111         case PType.TYPECODE_OBJLONG:
112             return PNameCoder.CTOLONG;
113
114         case PType.TYPECODE_STRING:
115             return PNameCoder.CTSTRING;
116
117         case PType.TYPECODE_BYTEARRAY:
118             return PNameCoder.CTBYTEARRAY;
119         case PType.TYPECODE_CHARARRAY:
120             return PNameCoder.CTCHARARRAY;
121         case PType.TYPECODE_DATE:
122             return PNameCoder.CTDATE;
123         case PType.TYPECODE_BIGDECIMAL:
124             return PNameCoder.CTBIGDECIMAL;
125         case PType.TYPECODE_BIGINTEGER:
126             return PNameCoder.CTBIGINTEGER;
127         default:
128             return -1;
129         }
130     }
131 }
132
Popular Tags