KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > runtime > common > lib > IDLTypeCodec


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.runtime.common.lib;
28
29
30 /**
31  * This class encode some IDL Types into byte array to make
32  * them serializable.
33  *
34  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
35  *
36  * @version 0.1
37  */

38 public class IDLTypeCodec
39 {
40     // ==================================================================
41
//
42
// Internal state.
43
//
44
// ==================================================================
45

46     private static org.omg.IOP.Codec JavaDoc codec = null;
47
48     // ==================================================================
49
//
50
// Constructor.
51
//
52
// ==================================================================
53

54     /**
55      * The default constructor.
56      */

57     public IDLTypeCodec()
58     {
59     }
60
61     // ==================================================================
62
//
63
// Internal methods.
64
//
65
// ==================================================================
66

67     static
68     {
69         org.omg.IOP.CodecFactory JavaDoc cf = null;
70         org.omg.IOP.Encoding JavaDoc enc = null;
71
72         try{
73         cf = (org.omg.IOP.CodecFactory JavaDoc) org.objectweb.openccm.corba.TheORB.getORB().
74                     resolve_initial_references("CodecFactory");
75         }catch(org.omg.CORBA.ORBPackage.InvalidName JavaDoc ex){
76             ex.printStackTrace();
77         }
78
79         try{
80             // Try Version 1.2
81
enc = new org.omg.IOP.Encoding JavaDoc(
82                         org.omg.IOP.ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 2);
83             codec = cf.create_codec(enc);
84         }catch(org.omg.IOP.CodecFactoryPackage.UnknownEncoding JavaDoc ex1){
85             try{
86                 // Try Version 1.1
87
enc = new org.omg.IOP.Encoding JavaDoc(
88                             org.omg.IOP.ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 1);
89                 codec = cf.create_codec(enc);
90             }catch(org.omg.IOP.CodecFactoryPackage.UnknownEncoding JavaDoc ex2){
91                 // Try Version 1.0
92
enc = new org.omg.IOP.Encoding JavaDoc(
93                             org.omg.IOP.ENCODING_CDR_ENCAPS.value, (byte) 1, (byte) 0);
94                 try{
95                     codec = cf.create_codec(enc);
96                 }catch(org.omg.IOP.CodecFactoryPackage.UnknownEncoding JavaDoc ex3){
97                     ex3.printStackTrace();
98                 }
99             }
100         }
101     }
102
103     // ==================================================================
104
//
105
// Public methods.
106
//
107
// ==================================================================
108

109     /**
110      * Get the codec singleton.
111      *
112      * @return A CDR codec.
113      */

114     public static org.omg.IOP.Codec JavaDoc
115     getCodec()
116     {
117         return codec;
118     }
119 }
120
Popular Tags