db4o 7.4

com.db4o.reflect.generic
Class GenericReflector

java.lang.Object
  extended by com.db4o.reflect.generic.GenericReflector
All Implemented Interfaces:
com.db4o.foundation.DeepClone, Reflector

public class GenericReflector
extends java.lang.Object
implements Reflector, com.db4o.foundation.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:



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


Constructor Summary
GenericReflector(Reflector delegateReflector)
           
GenericReflector(com.db4o.internal.Transaction trans, Reflector delegateReflector)
          Creates an instance of GenericReflector
 
Method Summary
 ReflectArray array()
          returns an ReflectArray object, the equivalent to java.lang.reflect.Array.
 int collectionUpdateDepth(ReflectClass candidate)
          Determines collection update depth for the specified class
 void configuration(ReflectorConfiguration config)
           
 java.lang.Object deepClone(java.lang.Object obj)
          Creates a clone of provided object
 ReflectClass forClass(java.lang.Class clazz)
          Returns a ReflectClass instance for the specified class
 ReflectClass forName(java.lang.String className)
          Returns a ReflectClass instance for the specified class name
 ReflectClass forObject(java.lang.Object obj)
          Returns a ReflectClass instance for the specified class object
 Reflector getDelegate()
          Returns delegate reflector
 boolean hasTransaction()
          If there is a transaction assosiated with the current refector.
 boolean isCollection(ReflectClass candidate)
          Determines if a candidate ReflectClass is a collection
 ReflectClass[] knownClasses()
          Returns an array of classes known to the reflector
 void register(com.db4o.reflect.generic.GenericClass clazz)
          Register a class
 void registerCollection(java.lang.Class clazz)
          Register a class as a collection
 void registerCollection(ReflectClassPredicate predicate)
          Register a predicate as a collection
 void registerCollectionUpdateDepth(java.lang.Class clazz, int depth)
          Register update depth for a collection class
 void registerCollectionUpdateDepth(ReflectClassPredicate predicate, int depth)
          Register update depth for a collection class
 void registerPrimitiveClass(int id, java.lang.String name, com.db4o.reflect.generic.GenericConverter converter)
          Registers primitive class
 void setParent(Reflector reflector)
          method stub: generic reflector does not have a parent
 void setTransaction(com.db4o.internal.Transaction trans)
          Associated a transaction with the current reflector.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericReflector

public GenericReflector(com.db4o.internal.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 com.db4o.foundation.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(com.db4o.internal.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.

collectionUpdateDepth

public int collectionUpdateDepth(ReflectClass candidate)
Determines collection update depth for the specified class

Parameters:
candidate - candidate class
Returns:
collection update depth for the specified class

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

registerCollectionUpdateDepth

public void registerCollectionUpdateDepth(java.lang.Class clazz,
                                          int depth)
Register update depth for a collection class

Parameters:
clazz - class
depth - update depth

registerCollectionUpdateDepth

public void registerCollectionUpdateDepth(ReflectClassPredicate predicate,
                                          int depth)
Register update depth for a collection class

Parameters:
predicate - class predicate
depth - update depth

register

public void register(com.db4o.reflect.generic.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,
                                   com.db4o.reflect.generic.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

configuration

public void configuration(ReflectorConfiguration config)
Specified by:
configuration in interface Reflector

db4o 7.4

Copyright 2007 db4objects Inc. All rights reserved.