KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > interceptors > CodecFactoryImpl


1 /*
2  * @(#)CodecFactoryImpl.java 1.15 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.interceptors;
9
10 import org.omg.IOP.Codec JavaDoc;
11 import org.omg.IOP.CodecFactory JavaDoc;
12 import org.omg.IOP.CodecFactoryPackage.UnknownEncoding JavaDoc;
13 import org.omg.IOP.Encoding JavaDoc;
14 import org.omg.IOP.ENCODING_CDR_ENCAPS JavaDoc;
15
16 import com.sun.corba.se.spi.logging.CORBALogDomains;
17
18 import com.sun.corba.se.impl.logging.ORBUtilSystemException;
19
20 import org.omg.CORBA.ORB JavaDoc;
21 import org.omg.CORBA.LocalObject JavaDoc;
22
23 /**
24  * CodecFactoryImpl is the implementation of the Codec Factory, as described
25  * in orbos/99-12-02.
26  */

27 public final class CodecFactoryImpl
28     extends org.omg.CORBA.LocalObject JavaDoc
29     implements CodecFactory JavaDoc
30 {
31     // The ORB that created this Codec Factory
32
private ORB JavaDoc orb;
33     private ORBUtilSystemException wrapper ;
34
35     // The maximum minor version of GIOP supported by this codec factory.
36
// Currently, this is 1.2.
37
private static final int MAX_MINOR_VERSION_SUPPORTED = 2;
38
39     // The pre-created minor versions of Codec version 1.0, 1.1, ...,
40
// 1.(MAX_MINOR_VERSION_SUPPORTED)
41
private Codec JavaDoc codecs[] = new Codec JavaDoc[MAX_MINOR_VERSION_SUPPORTED + 1];
42
43     /**
44      * Creates a new CodecFactory implementation. Stores the ORB that
45      * created this factory, for later use by the Codec.
46      */

47     public CodecFactoryImpl( ORB JavaDoc orb ) {
48         this.orb = orb;
49     wrapper = ORBUtilSystemException.get(
50         (com.sun.corba.se.spi.orb.ORB)orb,
51         CORBALogDomains.RPC_PROTOCOL ) ;
52
53     // Precreate a codec for version 1.0 through
54
// 1.(MAX_MINOR_VERSION_SUPPORTED). This can be
55
// done since Codecs are immutable in their current implementation.
56
// This is an optimization that eliminates the overhead of creating
57
// a new Codec each time create_codec is called.
58
for( int minor = 0; minor <= MAX_MINOR_VERSION_SUPPORTED; minor++ ) {
59         codecs[minor] = new CDREncapsCodec( orb, 1, minor );
60         }
61     }
62
63     /**
64      * Creates a codec of the given encoding. The only format recognized
65      * by this factory is ENCODING_CDR_ENCAPS, versions 1.0 through
66      * 1.(MAX_MINOR_VERSION_SUPPORTED).
67      *
68      * @exception UnknownEncoding Thrown if this factory cannot create a
69      * Codec of the given encoding.
70      */

71     public Codec JavaDoc create_codec ( Encoding JavaDoc enc )
72         throws UnknownEncoding JavaDoc
73     {
74         if( enc == null ) nullParam();
75
76     Codec JavaDoc result = null;
77
78     // This is the only format we can currently create codecs for:
79
if( (enc.format == ENCODING_CDR_ENCAPS.value) &&
80             (enc.major_version == 1) )
81         {
82         if( (enc.minor_version >= 0) &&
83         (enc.minor_version <= MAX_MINOR_VERSION_SUPPORTED) )
84             {
85         result = codecs[enc.minor_version];
86         }
87     }
88
89     if( result == null ) {
90         throw new UnknownEncoding JavaDoc();
91     }
92
93     return result;
94     }
95
96     /**
97      * Called when an invalid null parameter was passed. Throws a
98      * BAD_PARAM with a minor code of 1
99      */

100     private void nullParam()
101     {
102     throw wrapper.nullParam() ;
103     }
104 }
105
Popular Tags