util.java

来自「java jdk 1.4的源码」· Java 代码 · 共 601 行 · 第 1/2 页

JAVA
601
字号
                                  ClassLoader loader)	throws ClassNotFoundException {        return JDKBridge.loadClass(className,remoteCodebase,loader);                                    }     /**     * The <tt>isLocal</tt> method has the same semantics as the ObjectImpl._is_local     * method, except that it can throw a RemoteException.     * (no it doesn't but the spec says it should.)     *        * The <tt>_is_local()</tt> method is provided so that stubs may determine if a     * particular object is implemented by a local servant and hence local     * invocation APIs may be used.     *      * @param stub the stub to test.     *     * @return The <tt>_is_local()</tt> method returns true if     * the servant incarnating the object is located in the same process as     * the stub and they both share the same ORB instance.  The <tt>_is_local()</tt>     * method returns false otherwise. The default behavior of <tt>_is_local()</tt> is     * to return false.     *     * @throws RemoteException The Java to IDL specification does to     * specify the conditions that cause a RemoteException to be thrown.     */    public boolean isLocal(javax.rmi.CORBA.Stub stub) throws RemoteException {	return false ;    }        /**     * Wraps an exception thrown by an implementation     * method.  It returns the corresponding client-side exception.      * @param orig the exception to wrap.     * @return the wrapped exception.     */    public RemoteException wrapException(Throwable orig) {        if (orig instanceof SystemException) {            return mapSystemException((SystemException)orig);        }    	    	if (orig instanceof Error) {    	    return new ServerError("Error occurred in server thread",(Error)orig);       	} else if (orig instanceof RemoteException) {	    return new ServerException("RemoteException occurred in server thread",				       (Exception)orig);       	} else if (orig instanceof RuntimeException) {            throw (RuntimeException) orig;    	}    	                return new UnexpectedException(orig.toString());    }    /**     * Copies or connects an array of objects. Used by local stubs     * to copy any number of actual parameters, preserving sharing     * across parameters as necessary to support RMI semantics.     * @param obj the objects to copy or connect.     * @param orb the ORB.     * @return the copied or connected objects.     * @exception RemoteException if any object could not be copied or connected.     */    public Object[] copyObjects (Object[] obj, ORB orb)	throws RemoteException {            boolean stringPresent = false;        org.omg.CORBA_2_3.portable.OutputStream out = null;        try {                   // Allocate a new array if we need to...	                if (obj.getClass().getComponentType() != Object.class) {                Object[] orig = obj;                obj = new Object[obj.length];                System.arraycopy(orig,0,obj,0,obj.length);            }	                // Decide what, if any, types need to be copied            // and do so. Do not write Strings in this pass,            // but connect any Remote objects...                        for (int i = 0; i < obj.length; i++) {                Object it = obj[i];                if (it == null) {                    // Do nothing                } else if (it instanceof SystemException) {                    try {			SystemException inEx = (SystemException)it;			SystemException outEx = (SystemException)inEx.getClass().newInstance();			outEx.minor = inEx.minor;			outEx.completed = inEx.completed;			obj[i] = outEx;                    } catch (Exception e) {                        throw new UnexpectedException(obj.toString());                    }                } else if (it instanceof Remote) {                                        // Make sure it is connected and converted to                    // a stub (if needed)...                                        obj[i] = Utility.autoConnect(it,orb,true);                                    } else if (it instanceof String) {                    stringPresent = true;                } else if (it instanceof org.omg.CORBA.Object) {                } else {                                        // It's a value, so must be copied. First, make sure                    // we've got our output stream...                                        if (out == null) {                        out = (org.omg.CORBA_2_3.portable.OutputStream)orb.create_output_stream();                    }                                        // Now write it...                                        out.write_value((Serializable)it);                 }            }                        // Did we write anything? If not, we're done...                        if (out != null) {                            // Yes, did we find any strings? If so, they must also be                // written...                            if (stringPresent) {                     for (int i = 0; i < obj.length; i++) {                        if (obj[i] instanceof String) {                            out.write_value((String)obj[i]);                        }                    }                }                             // Ok, now read everything that we wrote back in                // and update the array...                                org.omg.CORBA_2_3.portable.InputStream in =                     (org.omg.CORBA_2_3.portable.InputStream)out.create_input_stream();                                for (int i = 0; i < obj.length; i++) {                    Object it = obj[i];                    if (it == null) {                    } else if (it instanceof SystemException) {                    } else if (it instanceof Remote) {                    } else if (it instanceof String) {                    } else if (it instanceof org.omg.CORBA.Object) {                    } else {                        obj[i] = in.read_value();                     }                }                                if (stringPresent) {                    for (int i = 0; i < obj.length; i++) {                        if (obj[i] instanceof String) {                            obj[i] = in.read_value();            }                    }                }            }        } catch (ClassCastException ex) {            throw new MarshalException("Exception occurred in server thread",				       new NotSerializableException());        } catch (SystemException ex) {            throw mapSystemException(ex);        }                   return obj;    }    /**     * Copies or connects an object. Used by local stubs to copy      * an actual parameter, result object, or exception.     * @param obj the object to copy.     * @param orb the ORB.     * @return the copy or connected object.     * @exception RemoteException if the object could not be copied or connected.     */    public Object copyObject (Object obj, ORB orb)	throws RemoteException {        // Is it null?                if (obj == null) {                        // Yes, so do nothing...                        return obj;        }        // Is it a SystemException?                if (obj instanceof SystemException) {           	    // Yes, so copy it monomorphically...           	    try {		SystemException in = (SystemException)obj;		SystemException out = (SystemException)in.getClass().newInstance();		out.minor = in.minor;		out.completed = in.completed;		return out;	    } catch (Exception e) {                throw new UnexpectedException(obj.toString());	    }        }                // Is it a String?                if (obj instanceof String) {                    // Yes, so do nothing...                        return obj;           }                // Is it Remote?                if (obj instanceof Remote) {                        // Yes, so make sure it is connected and converted            // to a stub (if needed)...                        return Utility.autoConnect(obj,orb,true);            }         // Is it a CORBA object?                if (obj instanceof org.omg.CORBA.Object) {                    // Yes, so do nothing...                        return obj;           }          // Is it a single-dimensional primitive array?                Class componentType = obj.getClass().getComponentType();        if (componentType != null && componentType.isPrimitive()) {                    // Yes, so clone it...            if (componentType == boolean.class) return ((boolean[])obj).clone();                     if (componentType == byte.class) return ((byte[])obj).clone();                     if (componentType == char.class) return ((char[])obj).clone();                     if (componentType == short.class) return ((short[])obj).clone();                     if (componentType == int.class) return ((int[])obj).clone();                     if (componentType == long.class) return ((long[])obj).clone();                     if (componentType == float.class) return ((float[])obj).clone();                     if (componentType == double.class) return ((double[])obj).clone();                             }          // Must be a value type. Note that types which are normally        // marshalled as ANYs are handled here...         try {            org.omg.CORBA_2_3.portable.OutputStream out =                 (org.omg.CORBA_2_3.portable.OutputStream)orb.create_output_stream();                                out.write_value((Serializable)obj);                            org.omg.CORBA_2_3.portable.InputStream in =                 (org.omg.CORBA_2_3.portable.InputStream)out.create_input_stream();                            return in.read_value();        } catch (ClassCastException ex) {            throw new MarshalException("Exception occurred in server thread",				       new NotSerializableException());        } catch (SystemException ex) {            throw mapSystemException(ex);        }    }}	    class KeepAlive extends Thread {    boolean quit = false;        public KeepAlive () {        setDaemon(false);    }        public synchronized void run () {        while (!quit) {            try {                wait();            } catch (InterruptedException e) {}        }}        public synchronized void quit () {        quit = true;        notifyAll();    }  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?