KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > ior > OldJIDLObjectKeyTemplate


1 /*
2  * @(#)OldJIDLObjectKeyTemplate.java 1.13 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.ior;
9
10 import org.omg.CORBA.OctetSeqHolder JavaDoc ;
11
12 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
13 import org.omg.CORBA_2_3.portable.OutputStream JavaDoc ;
14
15 import com.sun.corba.se.spi.ior.ObjectId ;
16 import com.sun.corba.se.spi.ior.ObjectKeyFactory ;
17
18 import com.sun.corba.se.spi.orb.ORB ;
19 import com.sun.corba.se.spi.orb.ORBVersion ;
20 import com.sun.corba.se.spi.orb.ORBVersionFactory ;
21
22 import com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl ;
23
24 import com.sun.corba.se.impl.encoding.CDRInputStream ;
25
26 /**
27  * Handles object keys created by JDK ORBs from before JDK 1.4.0.
28  */

29 public final class OldJIDLObjectKeyTemplate extends OldObjectKeyTemplateBase
30 {
31     /**
32      * JDK 1.3.1 FCS did not include a version byte at the end of
33      * its object keys. JDK 1.3.1_01 included the byte with the
34      * value 1. Anything below 1 is considered an invalid value.
35      */

36     public static final byte NULL_PATCH_VERSION = 0;
37
38     byte patchVersion = OldJIDLObjectKeyTemplate.NULL_PATCH_VERSION;
39
40     public OldJIDLObjectKeyTemplate( ORB orb, int magic, int scid,
41     InputStream JavaDoc is, OctetSeqHolder JavaDoc osh )
42     {
43     this( orb, magic, scid, is );
44
45     osh.value = readObjectKey( is ) ;
46         
47         /**
48          * Beginning with JDK 1.3.1_01, a byte was placed at the end of
49          * the object key with a value indicating the patch version.
50          * JDK 1.3.1_01 had the value 1. If other patches are necessary
51          * which involve ORB versioning changes, they should increment
52          * the patch version.
53          *
54          * Note that if we see a value greater than 1 in this code, we
55          * will treat it as if we're talking to the most recent ORB version.
56          *
57          * WARNING: This code is sensitive to changes in CDRInputStream
58          * getPosition. It assumes that the CDRInputStream is an
59          * encapsulation whose position can be compared to the object
60          * key array length.
61          */

62         if (magic == ObjectKeyFactoryImpl.JAVAMAGIC_NEW &&
63             osh.value.length > ((CDRInputStream)is).getPosition()) {
64
65             patchVersion = is.read_octet();
66
67             if (patchVersion == ObjectKeyFactoryImpl.JDK1_3_1_01_PATCH_LEVEL)
68                 setORBVersion(ORBVersionFactory.getJDK1_3_1_01());
69             else if (patchVersion > ObjectKeyFactoryImpl.JDK1_3_1_01_PATCH_LEVEL)
70                 setORBVersion(ORBVersionFactory.getORBVersion());
71             else
72         throw wrapper.invalidJdk131PatchLevel( new Integer JavaDoc( patchVersion ) ) ;
73         }
74     }
75     
76     
77     public OldJIDLObjectKeyTemplate( ORB orb, int magic, int scid, int serverid)
78     {
79     super( orb, magic, scid, serverid, JIDL_ORB_ID, JIDL_OAID ) ;
80     }
81    
82     public OldJIDLObjectKeyTemplate(ORB orb, int magic, int scid, InputStream JavaDoc is)
83     {
84     this( orb, magic, scid, is.read_long() ) ;
85     }
86    
87     protected void writeTemplate( OutputStream JavaDoc os )
88     {
89     os.write_long( getMagic() ) ;
90     os.write_long( getSubcontractId() ) ;
91     os.write_long( getServerId() ) ;
92     }
93
94     public void write(ObjectId objectId, OutputStream JavaDoc os)
95     {
96         super.write(objectId, os);
97
98         if (patchVersion != OldJIDLObjectKeyTemplate.NULL_PATCH_VERSION)
99            os.write_octet( patchVersion ) ;
100     }
101 }
102
Popular Tags