Class OldReflectObjectCopierImpl

  • All Implemented Interfaces:
    org.glassfish.pfl.dynamic.copyobject.spi.ObjectCopier

    public class OldReflectObjectCopierImpl
    extends java.lang.Object
    implements org.glassfish.pfl.dynamic.copyobject.spi.ObjectCopier
    Provides the functionality of copying objects using reflection. NOTE: Currently the implementation does not implement this copying functionality for objects which have fields whose types are based on inner classes. If for any reason copying cannot be done using reflection it uses the original ORB serialization to implement the copying
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) class  OldReflectObjectCopierImpl.ReflectAttrs
      Provides the functionality of a cache for storing the various reflection attributes of a class so that access to these methods is not done repeatedly
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.glassfish.pfl.basic.reflection.Bridge bridge
      Bridge is used to access the reflection factory for obtaining serialization constructors.
      private java.util.IdentityHashMap objRefs  
      private ORB orb  
      private static java.util.Map<java.lang.Class,​OldReflectObjectCopierImpl.ReflectAttrs> reflectCache
      reflectCache is used to cache the reflection attributes of a class
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.Object arrayCopy​(java.lang.Object obj, java.lang.Class aClass)
      Utility to copy array of primitive types or objects.
      java.lang.Object copy​(java.lang.Object obj)  
      java.lang.Object copy​(java.lang.Object obj, boolean debug)  
      private java.lang.Object copyAnyClass​(OldReflectObjectCopierImpl.ReflectAttrs attrs, java.lang.Object obj)  
      private void copyFields​(java.lang.Class cls, java.lang.reflect.Field[] fields, java.lang.Object obj, java.lang.Object copy)
      Utility to copy fields of an object.
      private java.lang.Object copyMap​(java.lang.Object obj)  
      private OldReflectObjectCopierImpl.ReflectAttrs getClassAttrs​(java.lang.Class cls)
      Gets the reflection attributes for a class from the cache or if it is not in the cache yet, computes the attributes and populates the cache
      private java.lang.reflect.Constructor getExternalizableConstructor​(java.lang.Class cl)
      Returns public no-arg constructor of given class, or null if none found.
      private java.lang.reflect.Constructor getSerializableConstructor​(java.lang.Class cl)
      Returns subclass-accessible no-arg constructor of first non-serializable superclass, or null if none found.
      static boolean isImmutable​(java.lang.String classname)  
      private java.lang.Object makeInstanceOfClass​(java.lang.Class cls)  
      private boolean packageEquals​(java.lang.Class cl1, java.lang.Class cl2)
      Returns true if classes are defined in the same package, false otherwise.
      private java.lang.Object reflectCopy​(java.lang.Object obj)
      Utility to copy objects using Java reflection.
      • Methods inherited from class java.lang.Object

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

      • objRefs

        private final java.util.IdentityHashMap objRefs
      • orb

        private final ORB orb
      • bridge

        private static final org.glassfish.pfl.basic.reflection.Bridge bridge
        Bridge is used to access the reflection factory for obtaining serialization constructors. This must be carefully protected!
    • Constructor Detail

      • OldReflectObjectCopierImpl

        public OldReflectObjectCopierImpl​(ORB orb)
    • Method Detail

      • getExternalizableConstructor

        private java.lang.reflect.Constructor getExternalizableConstructor​(java.lang.Class cl)
        Returns public no-arg constructor of given class, or null if none found. Access checks are disabled on the returned constructor (if any), since the defining class may still be non-public.
      • packageEquals

        private boolean packageEquals​(java.lang.Class cl1,
                                      java.lang.Class cl2)
        Returns true if classes are defined in the same package, false otherwise. Copied from the Merlin java.io.ObjectStreamClass.
      • getSerializableConstructor

        private java.lang.reflect.Constructor getSerializableConstructor​(java.lang.Class cl)
        Returns subclass-accessible no-arg constructor of first non-serializable superclass, or null if none found. Access checks are disabled on the returned constructor (if any).
      • getClassAttrs

        private OldReflectObjectCopierImpl.ReflectAttrs getClassAttrs​(java.lang.Class cls)
        Gets the reflection attributes for a class from the cache or if it is not in the cache yet, computes the attributes and populates the cache
        Parameters:
        cls - the class whose attributes are needed
        Returns:
        the attributes needed for reflection This method must be synchronized so that reflectCache.put can safely update the reflectCache.
      • isImmutable

        public static boolean isImmutable​(java.lang.String classname)
      • arrayCopy

        private java.lang.Object arrayCopy​(java.lang.Object obj,
                                           java.lang.Class aClass)
                                    throws java.rmi.RemoteException,
                                           java.lang.InstantiationException,
                                           java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException
        Utility to copy array of primitive types or objects. Used by local stubs to copy objects
        Parameters:
        obj - the object to copy or connect.
        Returns:
        the copied object.
        Throws:
        java.rmi.RemoteException - if any object could not be copied.
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • copyFields

        private void copyFields​(java.lang.Class cls,
                                java.lang.reflect.Field[] fields,
                                java.lang.Object obj,
                                java.lang.Object copy)
                         throws java.rmi.RemoteException,
                                java.lang.IllegalAccessException,
                                java.lang.InstantiationException,
                                java.lang.reflect.InvocationTargetException
        Utility to copy fields of an object. Used by local stub to copy objects
        Parameters:
        obj - the object whose fields need to be copied
        Throws:
        java.rmi.RemoteException - if any object could not be copied.
        java.lang.IllegalAccessException
        java.lang.InstantiationException
        java.lang.reflect.InvocationTargetException
      • makeInstanceOfClass

        private java.lang.Object makeInstanceOfClass​(java.lang.Class cls)
                                              throws java.lang.IllegalAccessException,
                                                     java.lang.InstantiationException
        Throws:
        java.lang.IllegalAccessException
        java.lang.InstantiationException
      • copyMap

        private java.lang.Object copyMap​(java.lang.Object obj)
                                  throws java.rmi.RemoteException,
                                         java.lang.InstantiationException,
                                         java.lang.IllegalAccessException,
                                         java.lang.reflect.InvocationTargetException
        Throws:
        java.rmi.RemoteException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • copyAnyClass

        private java.lang.Object copyAnyClass​(OldReflectObjectCopierImpl.ReflectAttrs attrs,
                                              java.lang.Object obj)
                                       throws java.rmi.RemoteException,
                                              java.lang.InstantiationException,
                                              java.lang.IllegalAccessException,
                                              java.lang.reflect.InvocationTargetException
        Throws:
        java.rmi.RemoteException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • reflectCopy

        private java.lang.Object reflectCopy​(java.lang.Object obj)
                                      throws java.rmi.RemoteException,
                                             java.lang.InstantiationException,
                                             java.lang.IllegalAccessException,
                                             java.lang.reflect.InvocationTargetException
        Utility to copy objects using Java reflection. Used by the local stub to copy objects
        Parameters:
        obj - the object to copy or connect.
        Returns:
        the copied object.
        Throws:
        java.rmi.RemoteException
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.reflect.InvocationTargetException
      • copy

        public java.lang.Object copy​(java.lang.Object obj,
                                     boolean debug)
                              throws org.glassfish.pfl.dynamic.copyobject.spi.ReflectiveCopyException
        Throws:
        org.glassfish.pfl.dynamic.copyobject.spi.ReflectiveCopyException
      • copy

        public java.lang.Object copy​(java.lang.Object obj)
                              throws org.glassfish.pfl.dynamic.copyobject.spi.ReflectiveCopyException
        Specified by:
        copy in interface org.glassfish.pfl.dynamic.copyobject.spi.ObjectCopier
        Throws:
        org.glassfish.pfl.dynamic.copyobject.spi.ReflectiveCopyException