Package com.db4o.reflect.generic
Class GenericReflector
- java.lang.Object
-
- com.db4o.reflect.generic.GenericReflector
-
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 throughExtObjectContainer.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 Summary
Constructors Constructor Description GenericReflector(Transaction trans, Reflector delegateReflector)
Creates an instance of GenericReflectorGenericReflector(Reflector delegateReflector)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReflectArray
array()
returns an ReflectArray object, the equivalent to java.lang.reflect.Array.void
configuration(ReflectorConfiguration config)
java.lang.Object
deepClone(java.lang.Object obj)
Creates a clone of provided objectReflectClass
forClass(java.lang.Class clazz)
Returns a ReflectClass instance for the specified classReflectClass
forName(java.lang.String className)
Returns a ReflectClass instance for the specified class nameReflectClass
forObject(java.lang.Object obj)
Returns a ReflectClass instance for the specified class objectReflector
getDelegate()
Returns delegate reflectorboolean
hasTransaction()
If there is a transaction assosiated with the current refector.boolean
isCollection(ReflectClass candidate)
Determines if a candidate ReflectClass is a collectionReflectClass[]
knownClasses()
Returns an array of classes known to the reflectorvoid
register(GenericClass clazz)
Register a classvoid
registerCollection(ReflectClassPredicate predicate)
Register a predicate as a collectionvoid
registerCollection(java.lang.Class clazz)
Register a class as a collectionvoid
registerPrimitiveClass(int id, java.lang.String name, GenericConverter converter)
Registers primitive classvoid
setParent(Reflector reflector)
method stub: generic reflector does not have a parentvoid
setTransaction(Transaction trans)
Associated a transaction with the current reflector.
-
-
-
Constructor Detail
-
GenericReflector
public GenericReflector(Transaction trans, Reflector delegateReflector)
Creates an instance of GenericReflector- Parameters:
trans
- transactiondelegateReflector
- 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
-
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.
-
forClass
public ReflectClass forClass(java.lang.Class clazz)
Returns a ReflectClass instance for the specified class- Specified by:
forClass
in interfaceReflector
- 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 interfaceReflector
- 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 interfaceReflector
- 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 interfaceReflector
- 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 idname
- class nameconverter
- class converter
-
setParent
public void setParent(Reflector reflector)
method stub: generic reflector does not have a parent
-
configuration
public void configuration(ReflectorConfiguration config)
- Specified by:
configuration
in interfaceReflector
-
-