src/share/classes/javax/rmi/CORBA/Stub.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 2030
6a4286d4ceb1
parent 748
6845b95cba6b
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset 146eabb0a016

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 /*
aoqi@0 27 * Licensed Materials - Property of IBM
aoqi@0 28 * RMI-IIOP v1.0
aoqi@0 29 * Copyright IBM Corp. 1998 1999 All Rights Reserved
aoqi@0 30 *
aoqi@0 31 */
aoqi@0 32
aoqi@0 33 package javax.rmi.CORBA;
aoqi@0 34
aoqi@0 35 import org.omg.CORBA.ORB;
aoqi@0 36 import org.omg.CORBA.INITIALIZE;
aoqi@0 37 import org.omg.CORBA_2_3.portable.ObjectImpl;
aoqi@0 38
aoqi@0 39 import java.io.IOException;
aoqi@0 40 import java.rmi.RemoteException;
aoqi@0 41 import java.io.File;
aoqi@0 42 import java.io.FileInputStream;
aoqi@0 43 import java.net.MalformedURLException ;
aoqi@0 44 import java.security.AccessController;
aoqi@0 45 import java.security.PrivilegedAction;
aoqi@0 46 import java.util.Properties;
aoqi@0 47 import java.rmi.server.RMIClassLoader;
aoqi@0 48
aoqi@0 49 import com.sun.corba.se.impl.orbutil.GetPropertyAction;
aoqi@0 50
aoqi@0 51
aoqi@0 52 /**
aoqi@0 53 * Base class from which all RMI-IIOP stubs must inherit.
aoqi@0 54 */
aoqi@0 55 public abstract class Stub extends ObjectImpl
aoqi@0 56 implements java.io.Serializable {
aoqi@0 57
aoqi@0 58 private static final long serialVersionUID = 1087775603798577179L;
aoqi@0 59
aoqi@0 60 // This can only be set at object construction time (no sync necessary).
aoqi@0 61 private transient StubDelegate stubDelegate = null;
aoqi@0 62 private static Class stubDelegateClass = null;
aoqi@0 63 private static final String StubClassKey = "javax.rmi.CORBA.StubClass";
aoqi@0 64
aoqi@0 65 static {
aoqi@0 66 Object stubDelegateInstance = createDelegate(StubClassKey);
aoqi@0 67 if (stubDelegateInstance != null)
aoqi@0 68 stubDelegateClass = stubDelegateInstance.getClass();
aoqi@0 69 }
aoqi@0 70
aoqi@0 71
aoqi@0 72 /**
aoqi@0 73 * Returns a hash code value for the object which is the same for all stubs
aoqi@0 74 * that represent the same remote object.
aoqi@0 75 * @return the hash code value.
aoqi@0 76 */
aoqi@0 77 public int hashCode() {
aoqi@0 78
aoqi@0 79 if (stubDelegate == null) {
aoqi@0 80 setDefaultDelegate();
aoqi@0 81 }
aoqi@0 82
aoqi@0 83 if (stubDelegate != null) {
aoqi@0 84 return stubDelegate.hashCode(this);
aoqi@0 85 }
aoqi@0 86
aoqi@0 87 return 0;
aoqi@0 88 }
aoqi@0 89
aoqi@0 90 /**
aoqi@0 91 * Compares two stubs for equality. Returns <code>true</code> when used to compare stubs
aoqi@0 92 * that represent the same remote object, and <code>false</code> otherwise.
aoqi@0 93 * @param obj the reference object with which to compare.
aoqi@0 94 * @return <code>true</code> if this object is the same as the <code>obj</code>
aoqi@0 95 * argument; <code>false</code> otherwise.
aoqi@0 96 */
aoqi@0 97 public boolean equals(java.lang.Object obj) {
aoqi@0 98
aoqi@0 99 if (stubDelegate == null) {
aoqi@0 100 setDefaultDelegate();
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 if (stubDelegate != null) {
aoqi@0 104 return stubDelegate.equals(this, obj);
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 return false;
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Returns a string representation of this stub. Returns the same string
aoqi@0 112 * for all stubs that represent the same remote object.
aoqi@0 113 * @return a string representation of this stub.
aoqi@0 114 */
aoqi@0 115 public String toString() {
aoqi@0 116
aoqi@0 117
aoqi@0 118 if (stubDelegate == null) {
aoqi@0 119 setDefaultDelegate();
aoqi@0 120 }
aoqi@0 121
aoqi@0 122 String ior;
aoqi@0 123 if (stubDelegate != null) {
aoqi@0 124 ior = stubDelegate.toString(this);
aoqi@0 125 if (ior == null) {
aoqi@0 126 return super.toString();
aoqi@0 127 } else {
aoqi@0 128 return ior;
aoqi@0 129 }
aoqi@0 130 }
aoqi@0 131 return super.toString();
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 /**
aoqi@0 135 * Connects this stub to an ORB. Required after the stub is deserialized
aoqi@0 136 * but not after it is demarshalled by an ORB stream. If an unconnected
aoqi@0 137 * stub is passed to an ORB stream for marshalling, it is implicitly
aoqi@0 138 * connected to that ORB. Application code should not call this method
aoqi@0 139 * directly, but should call the portable wrapper method
aoqi@0 140 * {@link javax.rmi.PortableRemoteObject#connect}.
aoqi@0 141 * @param orb the ORB to connect to.
aoqi@0 142 * @exception RemoteException if the stub is already connected to a different
aoqi@0 143 * ORB, or if the stub does not represent an exported remote or local object.
aoqi@0 144 */
aoqi@0 145 public void connect(ORB orb) throws RemoteException {
aoqi@0 146
aoqi@0 147 if (stubDelegate == null) {
aoqi@0 148 setDefaultDelegate();
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 if (stubDelegate != null) {
aoqi@0 152 stubDelegate.connect(this, orb);
aoqi@0 153 }
aoqi@0 154
aoqi@0 155 }
aoqi@0 156
aoqi@0 157 /**
aoqi@0 158 * Serialization method to restore the IOR state.
aoqi@0 159 */
aoqi@0 160 private void readObject(java.io.ObjectInputStream stream)
aoqi@0 161 throws IOException, ClassNotFoundException {
aoqi@0 162
aoqi@0 163 if (stubDelegate == null) {
aoqi@0 164 setDefaultDelegate();
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 if (stubDelegate != null) {
aoqi@0 168 stubDelegate.readObject(this, stream);
aoqi@0 169 }
aoqi@0 170
aoqi@0 171 }
aoqi@0 172
aoqi@0 173 /**
aoqi@0 174 * Serialization method to save the IOR state.
aoqi@0 175 * @serialData The length of the IOR type ID (int), followed by the IOR type ID
aoqi@0 176 * (byte array encoded using ISO8859-1), followed by the number of IOR profiles
aoqi@0 177 * (int), followed by the IOR profiles. Each IOR profile is written as a
aoqi@0 178 * profile tag (int), followed by the length of the profile data (int), followed
aoqi@0 179 * by the profile data (byte array).
aoqi@0 180 */
aoqi@0 181 private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
aoqi@0 182
aoqi@0 183 if (stubDelegate == null) {
aoqi@0 184 setDefaultDelegate();
aoqi@0 185 }
aoqi@0 186
aoqi@0 187 if (stubDelegate != null) {
aoqi@0 188 stubDelegate.writeObject(this, stream);
aoqi@0 189 }
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 private void setDefaultDelegate() {
aoqi@0 193 if (stubDelegateClass != null) {
aoqi@0 194 try {
aoqi@0 195 stubDelegate = (javax.rmi.CORBA.StubDelegate) stubDelegateClass.newInstance();
aoqi@0 196 } catch (Exception ex) {
aoqi@0 197 // what kind of exception to throw
aoqi@0 198 // delegate not set therefore it is null and will return default
aoqi@0 199 // values
aoqi@0 200 }
aoqi@0 201 }
aoqi@0 202 }
aoqi@0 203
aoqi@0 204 // Same code as in PortableRemoteObject. Can not be shared because they
aoqi@0 205 // are in different packages and the visibility needs to be package for
aoqi@0 206 // security reasons. If you know a better solution how to share this code
aoqi@0 207 // then remove it from PortableRemoteObject. Also in Util.java
aoqi@0 208 private static Object createDelegate(String classKey) {
aoqi@0 209 String className = (String)
aoqi@0 210 AccessController.doPrivileged(new GetPropertyAction(classKey));
aoqi@0 211 if (className == null) {
aoqi@0 212 Properties props = getORBPropertiesFile();
aoqi@0 213 if (props != null) {
aoqi@0 214 className = props.getProperty(classKey);
aoqi@0 215 }
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 if (className == null) {
aoqi@0 219 return new com.sun.corba.se.impl.javax.rmi.CORBA.StubDelegateImpl();
aoqi@0 220 }
aoqi@0 221
aoqi@0 222 try {
aoqi@0 223 return loadDelegateClass(className).newInstance();
aoqi@0 224 } catch (ClassNotFoundException ex) {
aoqi@0 225 INITIALIZE exc = new INITIALIZE( "Cannot instantiate " + className);
aoqi@0 226 exc.initCause( ex ) ;
aoqi@0 227 throw exc ;
aoqi@0 228 } catch (Exception ex) {
aoqi@0 229 INITIALIZE exc = new INITIALIZE( "Error while instantiating" + className);
aoqi@0 230 exc.initCause( ex ) ;
aoqi@0 231 throw exc ;
aoqi@0 232 }
aoqi@0 233
aoqi@0 234 }
aoqi@0 235
aoqi@0 236 private static Class loadDelegateClass( String className ) throws ClassNotFoundException
aoqi@0 237 {
aoqi@0 238 try {
aoqi@0 239 ClassLoader loader = Thread.currentThread().getContextClassLoader();
aoqi@0 240 return Class.forName(className, false, loader);
aoqi@0 241 } catch (ClassNotFoundException e) {
aoqi@0 242 // ignore, then try RMIClassLoader
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 try {
aoqi@0 246 return RMIClassLoader.loadClass(className);
aoqi@0 247 } catch (MalformedURLException e) {
aoqi@0 248 String msg = "Could not load " + className + ": " + e.toString();
aoqi@0 249 ClassNotFoundException exc = new ClassNotFoundException( msg ) ;
aoqi@0 250 throw exc ;
aoqi@0 251 }
aoqi@0 252 }
aoqi@0 253
aoqi@0 254 /**
aoqi@0 255 * Load the orb.properties file.
aoqi@0 256 */
aoqi@0 257 private static Properties getORBPropertiesFile () {
aoqi@0 258 return (Properties) AccessController.doPrivileged(new GetORBPropertiesFileAction());
aoqi@0 259 }
aoqi@0 260
aoqi@0 261 }

mercurial