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.
Modifier and Type | Class and Description |
---|---|
static class |
EnhancementHelper.RegisterClassEvent |
static interface |
EnhancementHelper.RegisterClassListener |
static interface |
EnhancementHelper.StringConstructor
Construct an instance of a key class using a String as input.
|
Modifier and Type | Method and Description |
---|---|
void |
addRegisterClassListener(EnhancementHelper.RegisterClassListener crl)
Add the specified
RegisterClassListener to the listener list. |
static void |
checkAuthorizedStateManager(StateManager sm)
Check that the parameter instance is of a class that is authorized for
JDOPermission("setStateManager").
|
static void |
checkAuthorizedStateManagerClass(Class smClass)
Check that the parameter instance is a class that is authorized for JDOPermission("setStateManager").
|
static Object |
construct(String className,
String keyString)
Construct an instance of the parameter class, using the keyString as an argument to the constructor.
|
void |
copyKeyFieldsFromObjectId(Class pcClass,
Persistable.ObjectIdFieldConsumer fm,
Object oid)
Copy fields to an outside source from the key fields in the ObjectId.
|
void |
copyKeyFieldsToObjectId(Class pcClass,
Persistable.ObjectIdFieldSupplier fm,
Object oid)
Copy fields from an outside source to the key fields in the ObjectId.
|
byte[] |
getFieldFlags(Class pcClass)
Get the field flags for a
Persistable class. |
String[] |
getFieldNames(Class pcClass)
Get the field names for a
Persistable class. |
Class[] |
getFieldTypes(Class pcClass)
Get the field types for a
Persistable class. |
static EnhancementHelper |
getInstance() |
Class |
getPersistableSuperclass(Class pcClass)
Get the persistence-capable superclass for a
Persistable class. |
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 |
registerAuthorizedStateManagerClass(Class smClass)
Register a class authorized to replaceStateManager.
|
static void |
registerAuthorizedStateManagerClasses(Collection smClasses)
Register classes authorized to replaceStateManager.
|
static void |
registerClass(Class pcClass,
String[] fieldNames,
Class[] fieldTypes,
byte[] fieldFlags,
Class persistableSuperclass,
Persistable pc)
Register metadata by class.
|
void |
registerDateFormat(DateFormat df)
Register a DateFormat instance for use with constructing Date instances.
|
Object |
registerStringConstructor(Class cls,
EnhancementHelper.StringConstructor sc)
Register special StringConstructor instances.
|
void |
removeRegisterClassListener(EnhancementHelper.RegisterClassListener crl)
Remove the specified
RegisterClassListener from the listener list. |
void |
unregisterClass(Class pcClass)
Unregister metadata by class.
|
void |
unregisterClasses(ClassLoader cl)
Unregister metadata by class loader.
|
public static EnhancementHelper getInstance()
public String[] getFieldNames(Class pcClass)
Persistable
class. The order of fields is the natural ordering
of the String
class (without considering localization).pcClass
- the Persistable
class.public Class[] getFieldTypes(Class pcClass)
Persistable
class. The order of fields is the same as for field
names.pcClass
- the Persistable
class.public byte[] getFieldFlags(Class pcClass)
Persistable
class. The order of fields is the same as for field
names.pcClass
- the Persistable
class.public Class getPersistableSuperclass(Class pcClass)
Persistable
class.pcClass
- the Persistable
class.Persistable
superclass for this class, or null
if there isn't
one.public Persistable newInstance(Class pcClass, StateManager sm)
dnFlags
set to LOAD_REQUIRED
.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 void copyKeyFieldsToObjectId(Class pcClass, Persistable.ObjectIdFieldSupplier fm, Object oid)
Persistable
class to generate a call to the field manager for each key field in the
ObjectId.
For example, an ObjectId class that has three key fields (int id
, String name
, and Float salary
) would have the method generated:
void dnCopyKeyFieldsToObjectId (Object oid, ObjectIdFieldSupplier fm)
{
oid.id = fm.fetchIntField (0);
oid.name = fm.fetchStringField (1);
oid.salary = fm.fetchObjectField (2);
}
The implementation is responsible for implementing the ObjectIdFieldSupplier
to provide
the values for the key fields.
pcClass
- the Persistable Class
.oid
- the ObjectId target of the copy.fm
- the field manager that supplies the field values.public void copyKeyFieldsFromObjectId(Class pcClass, Persistable.ObjectIdFieldConsumer fm, Object oid)
Persistable
class to generate a call to the field manager for each key field in the
ObjectId. For example, an ObjectId class that has three key fields (int id
,
String name
, and Float salary
) would have the method generated:
void dnCopyKeyFieldsFromObjectId(Persistable oid, ObjectIdFieldConsumer fm)
{
fm.storeIntField (0, oid.id);
fm.storeStringField (1, oid.name);
fm.storeObjectField (2, oid.salary);
}
The implementation is responsible for implementing the ObjectIdFieldConsumer
to store the
values for the key fields.
pcClass
- the Persistable
classoid
- the ObjectId source of the copy.fm
- the field manager that receives the field values.public static void registerClass(Class pcClass, String[] fieldNames, Class[] fieldTypes, byte[] fieldFlags, Class persistableSuperclass, Persistable pc)
Persistable
class performing the
registration.pcClass
- the Persistable
class used as the key for lookup.fieldNames
- an array of String
field names for persistent and transactional fieldsfieldTypes
- an array of Class
field typesfieldFlags
- the Field Flags for persistent and transactional fieldspc
- an instance of the Persistable
classpersistableSuperclass
- the most immediate superclass that is Persistable
public void unregisterClasses(ClassLoader cl)
Persistable
classes loaded by the specified class loader. Any attempt to get metadata for unregistered classes will
result in a JDOFatalUserException
.cl
- the class loader.public void unregisterClass(Class pcClass)
JDOFatalUserException
.pcClass
- the Persistable
class to be unregistered.public 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()
public static void registerAuthorizedStateManagerClass(Class smClass)
smClass
- a Class that is authorized for JDOPermission("setStateManager").public static void registerAuthorizedStateManagerClasses(Collection smClasses)
smClasses
- a Collection of Classespublic static void checkAuthorizedStateManager(StateManager sm)
sm
- an instance of StateManager whose class is to be checked.public static void checkAuthorizedStateManagerClass(Class smClass)
smClass
- a Class to be checked for JDOPermission("setStateManager")public Object registerStringConstructor(Class cls, EnhancementHelper.StringConstructor sc)
cls
- the class to register a StringConstructor forsc
- the StringConstructor instancepublic static Object construct(String className, String keyString)
className
- the name of the classkeyString
- the String parameter for the constructorpublic void registerDateFormat(DateFormat df)
df
- the DateFormat instance to useCopyright © 2017. All rights reserved.