KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)WireObjectKeyTemplate.java 1.19 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.OutputStream JavaDoc ;
13 import org.omg.CORBA_2_3.portable.InputStream JavaDoc ;
14
15 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
16
17 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
18 import com.sun.corba.se.spi.ior.ObjectId ;
19 import com.sun.corba.se.spi.ior.ObjectAdapterId ;
20
21 import com.sun.corba.se.spi.orb.ORB ;
22 import com.sun.corba.se.spi.orb.ORBVersion ;
23 import com.sun.corba.se.spi.orb.ORBVersionFactory ;
24
25 import com.sun.corba.se.spi.logging.CORBALogDomains ;
26
27 import com.sun.corba.se.impl.orbutil.ORBConstants ;
28
29 import com.sun.corba.se.impl.encoding.CDRInputStream ;
30
31 import com.sun.corba.se.impl.logging.IORSystemException ;
32
33 /**
34  * @author Ken Cavanaugh
35  */

36 public class WireObjectKeyTemplate implements ObjectKeyTemplate
37 {
38     private ORB orb ;
39     private IORSystemException wrapper ;
40
41     public boolean equals( Object JavaDoc obj )
42     {
43     if (obj == null)
44         return false ;
45
46     return obj instanceof WireObjectKeyTemplate ;
47     }
48
49     public int hashCode()
50     {
51     return 53 ; // All WireObjectKeyTemplates are the same, so they should
52
// have the same hashCode.
53
}
54
55     private byte[] getId( InputStream JavaDoc is )
56     {
57     CDRInputStream cis = (CDRInputStream)is ;
58     int len = cis.getBufferLength() ;
59     byte[] result = new byte[ len ] ;
60     cis.read_octet_array( result, 0, len ) ;
61     return result ;
62     }
63
64     public WireObjectKeyTemplate( ORB orb )
65     {
66     initORB( orb ) ;
67     }
68
69     public WireObjectKeyTemplate( InputStream JavaDoc is, OctetSeqHolder JavaDoc osh )
70     {
71     osh.value = getId( is ) ;
72     initORB( (ORB)(is.orb())) ;
73     }
74
75     private void initORB( ORB orb )
76     {
77     this.orb = orb ;
78     wrapper = IORSystemException.get( orb,
79         CORBALogDomains.OA_IOR ) ;
80     }
81
82     public void write( ObjectId id, OutputStream JavaDoc os )
83     {
84     byte[] key = id.getId() ;
85     os.write_octet_array( key, 0, key.length ) ;
86     }
87
88     public void write( OutputStream JavaDoc os )
89     {
90     // Does nothing
91
}
92
93     public int getSubcontractId()
94     {
95     return ORBConstants.DEFAULT_SCID ;
96     }
97
98     /** While it might make sense to throw an exception here, this causes
99     * problems since we need to check whether unusual object references
100     * are local or not. It seems that the easiest way to handle this is
101     * to return an invalid server id.
102     */

103     public int getServerId()
104     {
105     return -1 ;
106     }
107
108     public String JavaDoc getORBId()
109     {
110     throw wrapper.orbIdNotAvailable() ;
111     }
112
113     public ObjectAdapterId getObjectAdapterId()
114     {
115     throw wrapper.objectAdapterIdNotAvailable() ;
116     }
117
118     /** Adapter ID is not available, since our
119     * ORB did not implement the object carrying this key.
120     */

121     public byte[] getAdapterId()
122     {
123     throw wrapper.adapterIdNotAvailable() ;
124     }
125
126     public ORBVersion getORBVersion()
127     {
128     return ORBVersionFactory.getFOREIGN() ;
129     }
130
131     public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id )
132     {
133     byte[] bid = id.getId() ;
134     String JavaDoc str = new String JavaDoc( bid ) ;
135     return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( str ) ;
136     }
137 }
138
Popular Tags