Class Util

  • All Implemented Interfaces:
    UtilDelegate

    public class Util
    extends java.lang.Object
    implements UtilDelegate
    Provides utility methods that can be used by stubs and ties to perform common operations.
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void cleanUpTie​(Tie cachedTie)  
      java.lang.Object copyObject​(java.lang.Object obj, ORB orb)
      Copies or connects an object.
      java.lang.Object[] copyObjects​(java.lang.Object[] obj, ORB orb)
      Copies or connects an array of objects.
      private java.rmi.RemoteException createTransactionException​(java.lang.String className, java.lang.String message)
      Tries to find the correct remote exception to instantiate depending on whether javax.transaction or jakarta.transaction is on the classpath
      private TypeCode createTypeCode​(java.io.Serializable obj, Any any, ORB orb)
      When using our own ORB and Any implementations, we need to get the ORB version and create the type code appropriately.
      private TypeCode createTypeCodeForNull​(ORB orb)
      This is used to create the TypeCode for a null reference.
      ValueHandler createValueHandler()
      Returns a singleton instance of a class that implements the ValueHandler interface.
      java.lang.String getCodebase​(java.lang.Class clz)
      Returns the codebase, if any, for the given class.
      static Util getInstance()  
      Tie getTie​(java.rmi.Remote target)
      Returns the tie (if any) for a given target object.
      boolean isLocal​(Stub stub)
      The isLocal method has the same semantics as the ObjectImpl._is_local method, except that it can throw a RemoteException.
      java.lang.Class loadClass​(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loader)
      Returns a class instance for the specified class.
      private static Tie lookupTie​(java.rmi.Remote target)
      An unsynchronized version of getTie() for internal use.
      java.rmi.RemoteException mapSystemException​(SystemException ex)
      Maps a SystemException to a RemoteException.
      java.lang.Object readAny​(InputStream in)
      Reads a java.lang.Object as a CORBA any.
      void registerTarget​(Tie tie, java.rmi.Remote target)
      Registers a target for a tie.
      void unexportObject​(java.rmi.Remote target)
      Removes the associated tie from an internal table and calls Tie.deactivate() to deactivate the object.
      void unregisterTargetsForORB​(ORB orb)  
      java.rmi.RemoteException wrapException​(java.lang.Throwable orig)
      Wraps an exception thrown by an implementation method.
      void writeAbstractObject​(OutputStream out, java.lang.Object obj)
      Writes a java.lang.Object as either a value or a CORBA Object.
      void writeAny​(OutputStream out, java.lang.Object obj)
      Writes any java.lang.Object as a CORBA any.
      void writeRemoteObject​(OutputStream out, java.lang.Object obj)
      Writes a java.lang.Object as a CORBA Object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • keepAlive

        private static KeepAlive keepAlive
      • exportedServants

        private static final java.util.IdentityHashMap<java.rmi.Remote,​Tie> exportedServants
      • valueHandlerSingleton

        private static ValueHandler valueHandlerSingleton
      • instance

        private static Util instance
      • annotationMap

        private java.util.WeakHashMap<java.lang.Class<?>,​java.lang.String> annotationMap
      • annotObj

        private static final java.lang.Object annotObj
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • getInstance

        public static Util getInstance()
      • unregisterTargetsForORB

        public void unregisterTargetsForORB​(ORB orb)
      • mapSystemException

        public java.rmi.RemoteException mapSystemException​(SystemException ex)
        Maps a SystemException to a RemoteException.
        Specified by:
        mapSystemException in interface UtilDelegate
        Parameters:
        ex - the SystemException to map.
        Returns:
        the mapped exception.
      • writeAny

        public void writeAny​(OutputStream out,
                             java.lang.Object obj)
        Writes any java.lang.Object as a CORBA any.
        Specified by:
        writeAny in interface UtilDelegate
        Parameters:
        out - the stream in which to write the any.
        obj - the object to write as an any.
      • createTypeCode

        private TypeCode createTypeCode​(java.io.Serializable obj,
                                        Any any,
                                        ORB orb)
        When using our own ORB and Any implementations, we need to get the ORB version and create the type code appropriately. This is to overcome a bug in which the JDK 1.3.x ORBs used a tk_char rather than a tk_wchar to describe a Java char field. This only works in RMI-IIOP with Util.writeAny since we actually know what ORB and stream we're writing with when we insert the value. Returns null if it wasn't possible to create the TypeCode (means it wasn't our ORB or Any implementation). This does not handle null objs.
      • createTypeCodeForNull

        private TypeCode createTypeCodeForNull​(ORB orb)
        This is used to create the TypeCode for a null reference. It also handles backwards compatibility with JDK 1.3.x. This method will not return null.
      • readAny

        public java.lang.Object readAny​(InputStream in)
        Reads a java.lang.Object as a CORBA any.
        Specified by:
        readAny in interface UtilDelegate
        Parameters:
        in - the stream from which to read the any.
        Returns:
        the object read from the stream.
      • writeRemoteObject

        public void writeRemoteObject​(OutputStream out,
                                      java.lang.Object obj)
        Writes a java.lang.Object as a CORBA Object. If obj is an exported RMI-IIOP server object, the tie is found and wired to obj, then written to out.write_Object(org.omg.CORBA.Object). If obj is a CORBA Object, it is written to out.write_Object(org.omg.CORBA.Object).
        Specified by:
        writeRemoteObject in interface UtilDelegate
        Parameters:
        out - the stream in which to write the object.
        obj - the object to write.
      • writeAbstractObject

        public void writeAbstractObject​(OutputStream out,
                                        java.lang.Object obj)
        Writes a java.lang.Object as either a value or a CORBA Object. If obj is a value object or a stub object, it is written to out.write_abstract_interface(java.lang.Object). If obj is an exported RMI-IIOP server object, the tie is found and wired to obj, then written to out.write_abstract_interface(java.lang.Object).
        Specified by:
        writeAbstractObject in interface UtilDelegate
        Parameters:
        out - the stream in which to write the object.
        obj - the object to write.
      • registerTarget

        public void registerTarget​(Tie tie,
                                   java.rmi.Remote target)
        Registers a target for a tie. Adds the tie to an internal table and calls Tie.setTarget(java.rmi.Remote) on the tie object.
        Specified by:
        registerTarget in interface UtilDelegate
        Parameters:
        tie - the tie to register.
        target - the target for the tie.
      • unexportObject

        public void unexportObject​(java.rmi.Remote target)
                            throws java.rmi.NoSuchObjectException
        Removes the associated tie from an internal table and calls Tie.deactivate() to deactivate the object.
        Specified by:
        unexportObject in interface UtilDelegate
        Parameters:
        target - the object to unexport.
        Throws:
        java.rmi.NoSuchObjectException - if the target object does not exist
      • cleanUpTie

        protected void cleanUpTie​(Tie cachedTie)
                           throws java.rmi.NoSuchObjectException
        Throws:
        java.rmi.NoSuchObjectException
      • getTie

        public Tie getTie​(java.rmi.Remote target)
        Returns the tie (if any) for a given target object.
        Specified by:
        getTie in interface UtilDelegate
        Parameters:
        target - the object to get the tie for
        Returns:
        the tie or null if no tie is registered for the given target.
      • lookupTie

        private static Tie lookupTie​(java.rmi.Remote target)
        An unsynchronized version of getTie() for internal use.
      • createValueHandler

        public ValueHandler createValueHandler()
        Returns a singleton instance of a class that implements the ValueHandler interface.
        Specified by:
        createValueHandler in interface UtilDelegate
        Returns:
        a class which implements the ValueHandler interface.
      • getCodebase

        public java.lang.String getCodebase​(java.lang.Class clz)
        Returns the codebase, if any, for the given class.
        Specified by:
        getCodebase in interface UtilDelegate
        Parameters:
        clz - the class to get a codebase for.
        Returns:
        a space-separated list of URLs, or null.
      • loadClass

        public java.lang.Class loadClass​(java.lang.String className,
                                         java.lang.String remoteCodebase,
                                         java.lang.ClassLoader loader)
                                  throws java.lang.ClassNotFoundException
        Returns a class instance for the specified class.
        Specified by:
        loadClass in interface UtilDelegate
        Parameters:
        className - the name of the class.
        remoteCodebase - a space-separated list of URLs at which the class might be found. May be null.
        loader - a ClassLoader who may be used to load the class if all other methods fail.
        Returns:
        the Class object representing the loaded class.
        Throws:
        java.lang.ClassNotFoundException - if class cannot be loaded.
      • isLocal

        public boolean isLocal​(Stub stub)
                        throws java.rmi.RemoteException
        The isLocal 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 _is_local() 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.
        Specified by:
        isLocal in interface UtilDelegate
        Parameters:
        stub - the stub to test.
        Returns:
        The _is_local() 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 _is_local() method returns false otherwise. The default behavior of _is_local() is to return false.
        Throws:
        java.rmi.RemoteException - The Java to IDL specification does to specify the conditions that cause a RemoteException to be thrown.
      • wrapException

        public java.rmi.RemoteException wrapException​(java.lang.Throwable orig)
        Wraps an exception thrown by an implementation method. It returns the corresponding client-side exception.
        Specified by:
        wrapException in interface UtilDelegate
        Parameters:
        orig - the exception to wrap.
        Returns:
        the wrapped exception.
      • copyObjects

        public java.lang.Object[] copyObjects​(java.lang.Object[] obj,
                                              ORB orb)
                                       throws java.rmi.RemoteException
        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.
        Specified by:
        copyObjects in interface UtilDelegate
        Parameters:
        obj - the objects to copy or connect.
        orb - the ORB.
        Returns:
        the copied or connected objects.
        Throws:
        java.rmi.RemoteException - if any object could not be copied or connected.
      • copyObject

        public java.lang.Object copyObject​(java.lang.Object obj,
                                           ORB orb)
                                    throws java.rmi.RemoteException
        Copies or connects an object. Used by local stubs to copy an actual parameter, result object, or exception.
        Specified by:
        copyObject in interface UtilDelegate
        Parameters:
        obj - the object to copy.
        orb - the ORB.
        Returns:
        the copy or connected object.
        Throws:
        java.rmi.RemoteException - if the object could not be copied or connected.
      • createTransactionException

        private java.rmi.RemoteException createTransactionException​(java.lang.String className,
                                                                    java.lang.String message)
        Tries to find the correct remote exception to instantiate depending on whether javax.transaction or jakarta.transaction is on the classpath
        Parameters:
        className - Base class name of the exception
        message - Message to add to the exception
        Returns: