Class Utility


  • public final class Utility
    extends java.lang.Object
    Handy class full of static functions.
    • Constructor Summary

      Constructors 
      Constructor Description
      Utility()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object autoConnect​(java.lang.Object obj, ORB orb, boolean convertToStub)
      Ensure that stubs, ties, and implementation objects are 'connected' to the runtime.
      static void clearCaches()  
      static java.lang.String dynamicStubName​(java.lang.String className)  
      static Tie getAndForgetTie​(Object stub)  
      static ValueFactory getFactory​(java.lang.Class clazz, java.lang.String codebase, ORB orb, java.lang.String repId)
      Get the factory for an IDLValue Throws MARSHAL exception if no factory found.
      static BoxedValueHelper getHelper​(java.lang.Class clazz, java.lang.String codebase, java.lang.String repId)
      Get the helper for an IDLValue Throws MARSHAL exception if no helper found.
      (package private) static int hexOf​(char x)
      Converts an Ascii Character into Hexadecimal digit
      static java.lang.String idlStubName​(java.lang.String className)
      Create an IDL stub name.
      static java.lang.Class loadClassForClass​(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loader, java.lang.Class relatedType, java.lang.ClassLoader relatedTypeClassLoader)
      Load a class and check that it is compatible with a given type.
      (package private) static java.lang.Class loadClassOfType​(java.lang.String className, java.lang.String remoteCodebase, java.lang.ClassLoader loader, java.lang.Class expectedType, java.lang.ClassLoader expectedTypeClassLoader)
      Load a class and check that it is assignable to a given type.
      static java.rmi.Remote loadStub​(Tie tie, PresentationManager.StubFactory stubFactory, java.lang.String remoteCodebase, boolean onlyMostDerived)
      Load an RMI-IIOP Stub given a Tie.
      static java.rmi.Remote loadStub​(Object narrowFrom, java.lang.Class narrowTo)  
      private static StubEntry loadStubAndUpdateCache​(Tie tie, PresentationManager.StubFactory stubFactory, java.lang.String remoteCodebase, boolean onlyMostDerived)
      Load an RMI-IIOP Stub given a Tie, but do not look in the cache.
      static java.lang.Class loadStubClass​(java.lang.String repID, java.lang.String remoteCodebase, java.lang.Class expectedType)  
      private static Tie loadTie​(java.lang.Class theClass)  
      static Tie loadTie​(java.rmi.Remote obj)  
      static void printStackTrace()  
      static void purgeStubForTie​(Tie tie)  
      static void purgeTieAndServant​(Tie tie)  
      static java.lang.Object readAbstractAndNarrow​(InputStream in, java.lang.Class narrowTo)
      Read an abstract interface type from the input stream and narrow it to the desired type.
      static java.lang.Object readObjectAndNarrow​(InputStream in, java.lang.Class narrowTo)
      Read an object reference from the input stream and narrow it to the desired type.
      static java.lang.String stubName​(java.lang.String className)
      Create an RMI stub name.
      private static java.lang.String stubName​(java.lang.String className, boolean isDynamic)  
      static java.lang.String stubNameForCompiler​(java.lang.String className)  
      private static java.lang.String stubNameForCompiler​(java.lang.String className, boolean isDynamic)  
      static java.lang.String stubNameFromRepID​(java.lang.String repID)  
      static void throwNotSerializableForCorba​(java.lang.String className)
      Throws the CORBA equivalent of a java.io.NotSerializableException
      static java.lang.String tieName​(java.lang.String className)
      Create an RMI tie name.
      static java.lang.String tieNameForCompiler​(java.lang.String className)  
      • Methods inherited from class java.lang.Object

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

      • DYNAMIC_STUB_SUFFIX

        public static final java.lang.String DYNAMIC_STUB_SUFFIX
        See Also:
        Constant Field Values
      • tieCache

        private static final java.util.IdentityHashMap tieCache
      • tieToStubCache

        private static final java.util.IdentityHashMap tieToStubCache
      • stubToTieCache

        private static final java.util.IdentityHashMap stubToTieCache
      • CACHE_MISS

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

      • Utility

        public Utility()
    • Method Detail

      • autoConnect

        public static java.lang.Object autoConnect​(java.lang.Object obj,
                                                   ORB orb,
                                                   boolean convertToStub)
        Ensure that stubs, ties, and implementation objects are 'connected' to the runtime. Converts implementation objects to a type suitable for sending on the wire.
        Parameters:
        obj - the object to connect.
        orb - the ORB to connect to if obj is exported to IIOP.
        convertToStub - true if implementation types should be converted to Stubs rather than just org.omg.CORBA.Object.
        Returns:
        the connected object.
        Throws:
        INV_OBJREF - if obj is an implementation which has not been exported.
      • loadTie

        public static Tie loadTie​(java.rmi.Remote obj)
      • loadTie

        private static Tie loadTie​(java.lang.Class theClass)
      • clearCaches

        public static void clearCaches()
      • loadClassOfType

        static java.lang.Class loadClassOfType​(java.lang.String className,
                                               java.lang.String remoteCodebase,
                                               java.lang.ClassLoader loader,
                                               java.lang.Class expectedType,
                                               java.lang.ClassLoader expectedTypeClassLoader)
                                        throws java.lang.ClassNotFoundException
        Load a class and check that it is assignable to a given type.
        Parameters:
        className - the class name.
        remoteCodebase - the codebase to use. May be null.
        loader - the class loader of last resort. May be null.
        expectedType - the expected type. May be null.
        Returns:
        the loaded class.
        Throws:
        java.lang.ClassNotFoundException
      • loadClassForClass

        public static java.lang.Class loadClassForClass​(java.lang.String className,
                                                        java.lang.String remoteCodebase,
                                                        java.lang.ClassLoader loader,
                                                        java.lang.Class relatedType,
                                                        java.lang.ClassLoader relatedTypeClassLoader)
                                                 throws java.lang.ClassNotFoundException
        Load a class and check that it is compatible with a given type.
        Parameters:
        className - the class name.
        remoteCodebase - the codebase to use. May be null.
        loader - the loading context. May be null.
        relatedType - Type to check compatibility with
        relatedTypeClassLoader - the related type. May be null.
        Returns:
        the loaded class.
        Throws:
        java.lang.ClassNotFoundException - If the className cannot be found
      • getHelper

        public static BoxedValueHelper getHelper​(java.lang.Class clazz,
                                                 java.lang.String codebase,
                                                 java.lang.String repId)
        Get the helper for an IDLValue Throws MARSHAL exception if no helper found.
        Parameters:
        clazz - Class to get helper for
        codebase - The codebase to use. May be null.
        repId - The repository ID
        Returns:
        The Helper
      • getFactory

        public static ValueFactory getFactory​(java.lang.Class clazz,
                                              java.lang.String codebase,
                                              ORB orb,
                                              java.lang.String repId)
        Get the factory for an IDLValue Throws MARSHAL exception if no factory found.
        Parameters:
        clazz - The Class
        codebase - The codebase to use. May be null.
        orb - the ORB
        repId - Repository ID
        Returns:
        The Factory
      • loadStub

        public static java.rmi.Remote loadStub​(Tie tie,
                                               PresentationManager.StubFactory stubFactory,
                                               java.lang.String remoteCodebase,
                                               boolean onlyMostDerived)
        Load an RMI-IIOP Stub given a Tie.
        Parameters:
        tie - the tie.
        stubFactory - the Stub factory.
        remoteCodebase - the codebase to use. May be null.
        onlyMostDerived - if true, will fail if cannot load a stub for the first repID in the tie. If false, will walk all repIDs.
        Returns:
        the stub or null if not found.
      • loadStubAndUpdateCache

        private static StubEntry loadStubAndUpdateCache​(Tie tie,
                                                        PresentationManager.StubFactory stubFactory,
                                                        java.lang.String remoteCodebase,
                                                        boolean onlyMostDerived)
        Load an RMI-IIOP Stub given a Tie, but do not look in the cache. This method must be called with the lock held for tieToStubCache.
        Parameters:
        tie - the tie.
        stubFactory - the stub factory. May be null.
        remoteCodebase - the codebase to use. May be null.
        onlyMostDerived - if true, will fail if cannot load a stub for the first repID in the tie. If false, will walk all repIDs.
        Returns:
        the StubEntry or null if not found.
      • getAndForgetTie

        public static Tie getAndForgetTie​(Object stub)
      • purgeStubForTie

        public static void purgeStubForTie​(Tie tie)
      • purgeTieAndServant

        public static void purgeTieAndServant​(Tie tie)
      • stubNameFromRepID

        public static java.lang.String stubNameFromRepID​(java.lang.String repID)
      • loadStub

        public static java.rmi.Remote loadStub​(Object narrowFrom,
                                               java.lang.Class narrowTo)
      • loadStubClass

        public static java.lang.Class loadStubClass​(java.lang.String repID,
                                                    java.lang.String remoteCodebase,
                                                    java.lang.Class expectedType)
                                             throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • stubName

        public static java.lang.String stubName​(java.lang.String className)
        Create an RMI stub name.
        Parameters:
        className - Class to create stub of
        Returns:
        RMI stub name
      • dynamicStubName

        public static java.lang.String dynamicStubName​(java.lang.String className)
      • stubName

        private static java.lang.String stubName​(java.lang.String className,
                                                 boolean isDynamic)
      • stubNameForCompiler

        public static java.lang.String stubNameForCompiler​(java.lang.String className)
      • stubNameForCompiler

        private static java.lang.String stubNameForCompiler​(java.lang.String className,
                                                            boolean isDynamic)
      • tieName

        public static java.lang.String tieName​(java.lang.String className)
        Create an RMI tie name.
        Parameters:
        className - Class used for RMI
        Returns:
        RMI Tie name
      • tieNameForCompiler

        public static java.lang.String tieNameForCompiler​(java.lang.String className)
      • throwNotSerializableForCorba

        public static void throwNotSerializableForCorba​(java.lang.String className)
        Throws the CORBA equivalent of a java.io.NotSerializableException
        Parameters:
        className - Class that is non-serializable
      • idlStubName

        public static java.lang.String idlStubName​(java.lang.String className)
        Create an IDL stub name.
        Parameters:
        className - Class to create stub name of
        Returns:
        Created stub name
      • printStackTrace

        public static void printStackTrace()
      • readObjectAndNarrow

        public static java.lang.Object readObjectAndNarrow​(InputStream in,
                                                           java.lang.Class narrowTo)
                                                    throws java.lang.ClassCastException
        Read an object reference from the input stream and narrow it to the desired type.
        Parameters:
        in - the stream to read from.
        narrowTo - Desired class
        Returns:
        Narrowed object
        Throws:
        java.lang.ClassCastException - if narrowFrom cannot be cast to narrowTo.
      • readAbstractAndNarrow

        public static java.lang.Object readAbstractAndNarrow​(InputStream in,
                                                             java.lang.Class narrowTo)
                                                      throws java.lang.ClassCastException
        Read an abstract interface type from the input stream and narrow it to the desired type.
        Parameters:
        in - the stream to read from.
        narrowTo - Desired class
        Returns:
        Narrowed object
        Throws:
        java.lang.ClassCastException - if narrowFrom cannot be cast to narrowTo.
      • hexOf

        static int hexOf​(char x)
        Converts an Ascii Character into Hexadecimal digit