public class EnhancementHelper extends Object
It allows construction of instances of persistable classes without using reflection.
Persistable classes register themselves via a static method at class load time. There is no security restriction on this access. TODO Provide a mechanism to automatically deregister classes when their class loader exits? or register against the NucleusContext?
Modifier and Type | Class and Description |
---|---|
static interface |
EnhancementHelper.RegisterClassListener |
Modifier and Type | Method and Description |
---|---|
void |
addRegisterClassListener(EnhancementHelper.RegisterClassListener crl)
Add the specified
RegisterClassListener to the listener list. |
static EnhancementHelper |
getInstance() |
Collection<Class> |
getRegisteredClasses()
Returns a collection of class objects of the registered persistable classes.
|
Persistable |
newInstance(Class pcClass,
StateManager sm)
Create a new instance of the class and assign its StateManager.
|
Persistable |
newInstance(Class pcClass,
StateManager sm,
Object oid)
Create a new instance of the class and assign its StateManager and key values from the ObjectId.
|
Object |
newObjectIdInstance(Class pcClass)
Create a new instance of the ObjectId class of this
Persistable class. |
Object |
newObjectIdInstance(Class pcClass,
Object obj)
Create a new instance of the class used by the parameter Class for JDO identity, using the key constructor of the object id class.
|
static void |
registerClass(Class pcClass,
Persistable pc)
Register metadata by class.
|
void |
removeRegisterClassListener(EnhancementHelper.RegisterClassListener crl)
Remove the specified
RegisterClassListener from the listener list. |
void |
unregisterClasses(ClassLoader cl)
Unregister all classes for the specified class loader.
|
public static EnhancementHelper getInstance()
public Persistable newInstance(Class pcClass, StateManager sm)
pcClass
- the Persistable
class.sm
- the StateManager
which will own the new instance.null
if the class is not registered.Persistable.dnNewInstance(StateManager sm)
public Persistable newInstance(Class pcClass, StateManager sm, Object oid)
null
, no key values are copied.
The new instance has its dnFlags
set to LOAD_REQUIRED
.pcClass
- the Persistable
class.sm
- the StateManager
which will own the new instance.oid
- the ObjectId instance from which to copy key field values.null
if the class is not registered.Persistable.dnNewInstance(StateManager sm, Object oid)
public Object newObjectIdInstance(Class pcClass)
Persistable
class.
It is intended only for application identity.
This method should not be called for classes that use single field identity; newObjectIdInstance(Class, Object) should be used instead.
If the class has been enhanced for datastore identity, or if the class is abstract, null is returned.pcClass
- the Persistable
class.null
if the class is not registered.public Object newObjectIdInstance(Class pcClass, Object obj)
For classes that use single field identity, if the parameter is of one of the following types, the behavior must be as specified:
Number
or Character
: the parameter must be the single field type or the
wrapper class of the primitive field type; the parameter is passed to the single field identity constructorObjectIdFieldSupplier
: the field value is fetched from the
ObjectIdFieldSupplier
and passed to the single field identity constructorString
: the String is passed to the single field identity constructorobj
- the Object
form of the object idpcClass
- the Persistable
class.null
if the class is not registered.public static void registerClass(Class pcClass, Persistable pc)
Persistable
class.pcClass
- the Persistable
class used as the key for lookup.pc
- an instance of the Persistable
class. TODO We can just do pcClass.newInstance() to get one!public void unregisterClasses(ClassLoader cl)
cl
- ClassLoaderpublic void addRegisterClassListener(EnhancementHelper.RegisterClassListener crl)
RegisterClassListener
to the listener list.crl
- the listener to be addedpublic void removeRegisterClassListener(EnhancementHelper.RegisterClassListener crl)
RegisterClassListener
from the listener list.crl
- the listener to be removedpublic Collection<Class> getRegisteredClasses()
Copyright © 2020. All rights reserved.