Thu, 31 Aug 2017 18:10:36 +0800
merge
1 /*
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.corba.se.impl.ior;
28 import org.omg.CORBA.OctetSeqHolder ;
30 import org.omg.CORBA_2_3.portable.OutputStream ;
31 import org.omg.CORBA_2_3.portable.InputStream ;
33 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
35 import com.sun.corba.se.spi.ior.ObjectKeyTemplate ;
36 import com.sun.corba.se.spi.ior.ObjectId ;
37 import com.sun.corba.se.spi.ior.ObjectAdapterId ;
39 import com.sun.corba.se.spi.orb.ORB ;
40 import com.sun.corba.se.spi.orb.ORBVersion ;
41 import com.sun.corba.se.spi.orb.ORBVersionFactory ;
43 import com.sun.corba.se.spi.logging.CORBALogDomains ;
45 import com.sun.corba.se.impl.orbutil.ORBConstants ;
47 import com.sun.corba.se.impl.encoding.CDRInputStream ;
49 import com.sun.corba.se.impl.logging.IORSystemException ;
51 /**
52 * @author Ken Cavanaugh
53 */
54 public class WireObjectKeyTemplate implements ObjectKeyTemplate
55 {
56 private ORB orb ;
57 private IORSystemException wrapper ;
59 public boolean equals( Object obj )
60 {
61 if (obj == null)
62 return false ;
64 return obj instanceof WireObjectKeyTemplate ;
65 }
67 public int hashCode()
68 {
69 return 53 ; // All WireObjectKeyTemplates are the same, so they should
70 // have the same hashCode.
71 }
73 private byte[] getId( InputStream is )
74 {
75 CDRInputStream cis = (CDRInputStream)is ;
76 int len = cis.getBufferLength() ;
77 byte[] result = new byte[ len ] ;
78 cis.read_octet_array( result, 0, len ) ;
79 return result ;
80 }
82 public WireObjectKeyTemplate( ORB orb )
83 {
84 initORB( orb ) ;
85 }
87 public WireObjectKeyTemplate( InputStream is, OctetSeqHolder osh )
88 {
89 osh.value = getId( is ) ;
90 initORB( (ORB)(is.orb())) ;
91 }
93 private void initORB( ORB orb )
94 {
95 this.orb = orb ;
96 wrapper = IORSystemException.get( orb,
97 CORBALogDomains.OA_IOR ) ;
98 }
100 public void write( ObjectId id, OutputStream os )
101 {
102 byte[] key = id.getId() ;
103 os.write_octet_array( key, 0, key.length ) ;
104 }
106 public void write( OutputStream os )
107 {
108 // Does nothing
109 }
111 public int getSubcontractId()
112 {
113 return ORBConstants.DEFAULT_SCID ;
114 }
116 /** While it might make sense to throw an exception here, this causes
117 * problems since we need to check whether unusual object references
118 * are local or not. It seems that the easiest way to handle this is
119 * to return an invalid server id.
120 */
121 public int getServerId()
122 {
123 return -1 ;
124 }
126 public String getORBId()
127 {
128 throw wrapper.orbIdNotAvailable() ;
129 }
131 public ObjectAdapterId getObjectAdapterId()
132 {
133 throw wrapper.objectAdapterIdNotAvailable() ;
134 }
136 /** Adapter ID is not available, since our
137 * ORB did not implement the object carrying this key.
138 */
139 public byte[] getAdapterId()
140 {
141 throw wrapper.adapterIdNotAvailable() ;
142 }
144 public ORBVersion getORBVersion()
145 {
146 return ORBVersionFactory.getFOREIGN() ;
147 }
149 public CorbaServerRequestDispatcher getServerRequestDispatcher( ORB orb, ObjectId id )
150 {
151 byte[] bid = id.getId() ;
152 String str = new String( bid ) ;
153 return orb.getRequestDispatcherRegistry().getServerRequestDispatcher( str ) ;
154 }
155 }