KickJava   Java API By Example, From Geeks To Geeks.

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


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.PNameGetterConverter;
21 import org.objectweb.jorm.naming.api.PNameGetter;
22 import org.objectweb.jorm.naming.api.PExceptionNaming;
23 import org.objectweb.jorm.api.PException;
24
25 import java.util.Date JavaDoc;
26 import java.math.BigInteger JavaDoc;
27 import java.math.BigDecimal JavaDoc;
28
29 /**
30  * is a simple PNameGetterConverter which does not make any translation
31  *
32  * @author S.Chassande-Barrioz
33  */

34 public class SimplePNGConverter implements PNameGetterConverter {
35
36     private class MyPNG implements PNameGetter {
37         Object JavaDoc value;
38
39         public MyPNG(Object JavaDoc o) {
40             this.value = o;
41         }
42
43         public byte pngetByteField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
44             return ((Byte JavaDoc) value).byteValue();
45         }
46
47         public Byte JavaDoc pngetObyteField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
48             return (Byte JavaDoc) value;
49         }
50
51         public char pngetCharField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
52             return ((Character JavaDoc) value).charValue();
53         }
54
55         public Character JavaDoc pngetOcharField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
56             return (Character JavaDoc) value;
57         }
58
59         public short pngetShortField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
60             return ((Short JavaDoc) value).shortValue();
61         }
62
63         public Short JavaDoc pngetOshortField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
64             return (Short JavaDoc) value;
65         }
66
67         public int pngetIntField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
68             return ((Integer JavaDoc) value).intValue();
69         }
70
71         public Integer JavaDoc pngetOintField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
72             return (Integer JavaDoc) value;
73         }
74
75         public long pngetLongField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
76             return ((Long JavaDoc) value).longValue();
77         }
78
79         public Long JavaDoc pngetOlongField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
80             return (Long JavaDoc) value;
81         }
82
83         public String JavaDoc pngetStringField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
84             return (String JavaDoc) value;
85         }
86
87         public byte[] pngetByteArrayField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
88             return (byte[]) value;
89         }
90
91         public char[] pngetCharArrayField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
92             return (char[]) value;
93         }
94
95         public Date JavaDoc pngetDateField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
96             return (Date JavaDoc) value;
97         }
98
99         public BigInteger JavaDoc pngetBigIntegerField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
100             return (BigInteger JavaDoc) value;
101         }
102
103         public BigDecimal JavaDoc pngetBigDecimalField(String JavaDoc fn, Object JavaDoc ctxt) throws PException {
104             return (BigDecimal JavaDoc) value;
105         }
106     }
107
108     public PNameGetter convert(PNameGetter png) throws PExceptionNaming {
109         return png;
110     }
111
112     public PNameGetter convert(Object JavaDoc o) throws PExceptionNaming {
113         return new MyPNG(o);
114     }
115
116     public PNameGetter convert(byte o) throws PExceptionNaming {
117         return new MyPNG(new Byte JavaDoc(o));
118     }
119
120     public PNameGetter convert(char o) throws PExceptionNaming {
121         return new MyPNG(new Character JavaDoc(o));
122     }
123
124     public PNameGetter convert(short o) throws PExceptionNaming {
125         return new MyPNG(new Short JavaDoc(o));
126     }
127
128     public PNameGetter convert(int o) throws PExceptionNaming {
129         return new MyPNG(new Integer JavaDoc(o));
130     }
131
132     public PNameGetter convert(long o) throws PExceptionNaming {
133         return new MyPNG(new Long JavaDoc(o));
134     }
135 }
136
Popular Tags