Class GenericReflector

  • All Implemented Interfaces:
    DeepClone, Reflector

    public class GenericReflector
    extends java.lang.Object
    implements Reflector, DeepClone
    db4o provides GenericReflector as a wrapper around specific reflector (delegate). GenericReflector is set when an ObjectContainer is opened. All subsequent reflector calls are routed through this interface.

    An instance of GenericReflector can be obtained through ExtObjectContainer.reflector().

    GenericReflector keeps list of known classes in memory. When the GenericReflector is called, it first checks its list of known classes. If the class cannot be found, the task is transferred to the delegate reflector. If the delegate fails as well, generic objects are created, which hold simulated "field values" in an array of objects.

    Generic reflector makes possible the following usecases:
    • running a db4o server without deploying application classes;
    • running db4o on Java dialects without reflection (J2ME CLDC, MIDP);
    • easier access to stored objects where classes or fields are not available;
    • running refactorings in the reflector;
    • building interfaces to db4o from any programming language.


    One of the live usecases is ObjectManager, which uses GenericReflector to read C# objects from Java.
    • Constructor Detail

      • GenericReflector

        public GenericReflector​(Transaction trans,
                                Reflector delegateReflector)
        Creates an instance of GenericReflector
        Parameters:
        trans - transaction
        delegateReflector - delegate reflector, providing specific reflector functionality. For example
      • GenericReflector

        public GenericReflector​(Reflector delegateReflector)
    • Method Detail

      • deepClone

        public java.lang.Object deepClone​(java.lang.Object obj)
        Creates a clone of provided object
        Specified by:
        deepClone in interface DeepClone
        Parameters:
        obj - object to copy
        Returns:
        copy of the submitted object
      • hasTransaction

        public boolean hasTransaction()
        If there is a transaction assosiated with the current refector.
        Returns:
        true if there is a transaction assosiated with the current refector.
      • setTransaction

        public void setTransaction​(Transaction trans)
        Associated a transaction with the current reflector.
        Parameters:
        trans -
      • array

        public ReflectArray array()
        Description copied from interface: Reflector
        returns an ReflectArray object, the equivalent to java.lang.reflect.Array.
        Specified by:
        array in interface Reflector
        Returns:
        generic reflect array instance.
      • forClass

        public ReflectClass forClass​(java.lang.Class clazz)
        Returns a ReflectClass instance for the specified class
        Specified by:
        forClass in interface Reflector
        Parameters:
        clazz - class
        Returns:
        a ReflectClass instance for the specified class
        See Also:
        ReflectClass
      • forName

        public ReflectClass forName​(java.lang.String className)
        Returns a ReflectClass instance for the specified class name
        Specified by:
        forName in interface Reflector
        Parameters:
        className - class name
        Returns:
        a ReflectClass instance for the specified class name
        See Also:
        ReflectClass
      • forObject

        public ReflectClass forObject​(java.lang.Object obj)
        Returns a ReflectClass instance for the specified class object
        Specified by:
        forObject in interface Reflector
        Parameters:
        obj - class object
        Returns:
        a ReflectClass instance for the specified class object
        See Also:
        ReflectClass
      • getDelegate

        public Reflector getDelegate()
        Returns delegate reflector
        Returns:
        delegate reflector
      • isCollection

        public boolean isCollection​(ReflectClass candidate)
        Determines if a candidate ReflectClass is a collection
        Specified by:
        isCollection in interface Reflector
        Parameters:
        candidate - candidate ReflectClass
        Returns:
        true if a candidate ReflectClass is a collection.
      • registerCollection

        public void registerCollection​(java.lang.Class clazz)
        Register a class as a collection
        Parameters:
        clazz - class to be registered
      • registerCollection

        public void registerCollection​(ReflectClassPredicate predicate)
        Register a predicate as a collection
        Parameters:
        predicate - predicate to be registered
      • register

        public void register​(GenericClass clazz)
        Register a class
        Parameters:
        clazz - class
      • knownClasses

        public ReflectClass[] knownClasses()
        Returns an array of classes known to the reflector
        Returns:
        an array of classes known to the reflector
      • registerPrimitiveClass

        public void registerPrimitiveClass​(int id,
                                           java.lang.String name,
                                           GenericConverter converter)
        Registers primitive class
        Parameters:
        id - class id
        name - class name
        converter - class converter
      • setParent

        public void setParent​(Reflector reflector)
        method stub: generic reflector does not have a parent
        Specified by:
        setParent in interface Reflector