public class JDOImplHelper
extends java.lang.Object
JDOImplHelper
allows construction of instances of
persistence-capable classes without using reflection.
Persistence-capable classes register themselves via a static method at class load time. There is no security restriction on this access. JDO implementations get access to the functions provided by this class only if they are authorized by the security manager. To avoid having every call go through the security manager, only the call to get an instance is checked. Once an implementation has an instance, any of the methods can be invoked without security checks.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
JDOImplHelper.Meta
This is a helper class to manage metadata per persistence-capable
class.
|
static interface |
JDOImplHelper.StateInterrogationBooleanReturn
This is an interface used to interrogate the state of an instance
that does not implement PersistenceCapable.
|
static interface |
JDOImplHelper.StateInterrogationObjectReturn
This is an interface used to interrogate the state of an instance
that does not implement PersistenceCapable.
|
static interface |
JDOImplHelper.StringConstructor
Construct an instance of a key class using a String as input.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map |
authorizedStateManagerClasses
This Set contains all classes that have registered for setStateManager
permissions via authorizeStateManagerClass.
|
private static java.text.DateFormat |
dateFormat
The default DateFormat instance.
|
private static java.lang.String |
dateFormatPattern
The DateFormat pattern.
|
private static javax.xml.parsers.DocumentBuilderFactory |
documentBuilderFactory
The DocumentBuilderFactory used during jdoconfig.xml parsing.
|
private static org.xml.sax.ErrorHandler |
errorHandler
The ErrorHandler used during jdoconfig.xml parsing.
|
private static JDOImplHelper |
jdoImplHelper
The singleton
JDOImplHelper instance. |
private static java.util.List |
listeners
This list contains the registered listeners for
RegisterClassEvent s. |
private static I18NHelper |
msg
The Internationalization message helper.
|
private static java.util.Map |
registeredClasses
This synchronized
HashMap contains a static mapping of
PersistenceCapable class to
metadata for the class used for constructing new instances. |
private static java.util.List |
stateInterrogations
The list of registered StateInterrogation instances
|
(package private) static java.util.Map |
stringConstructorMap
Special StringConstructor instances for use with specific
classes that have no public String constructor.
|
Modifier | Constructor and Description |
---|---|
private |
JDOImplHelper()
Creates new JDOImplHelper
|
Modifier and Type | Method and Description |
---|---|
void |
addRegisterClassListener(RegisterClassListener crl)
Add the specified
RegisterClassListener to the listener
list. |
void |
addStateInterrogation(StateInterrogation si)
Add a StateInterrogation to the list.
|
static void |
checkAuthorizedStateManager(StateManager sm)
Check that the parameter instance is of a class that is authorized for
JDOPermission("setStateManager").
|
static void |
checkAuthorizedStateManagerClass(java.lang.Class smClass)
Check that the parameter instance is a class that is authorized for
JDOPermission("setStateManager").
|
static java.lang.Object |
construct(java.lang.String className,
java.lang.String keyString)
Construct an instance of the parameter class, using the keyString
as an argument to the constructor.
|
void |
copyKeyFieldsFromObjectId(java.lang.Class pcClass,
PersistenceCapable.ObjectIdFieldConsumer fm,
java.lang.Object oid)
Copy fields to an outside source from the key fields in the ObjectId.
|
void |
copyKeyFieldsToObjectId(java.lang.Class pcClass,
PersistenceCapable.ObjectIdFieldSupplier fm,
java.lang.Object oid)
Copy fields from an outside source to the key fields in the ObjectId.
|
(package private) static java.text.DateFormat |
getDateTimeInstance()
Get the DateFormat instance for the default locale from the VM.
|
byte[] |
getFieldFlags(java.lang.Class pcClass)
Get the field flags for a
PersistenceCapable class. |
java.lang.String[] |
getFieldNames(java.lang.Class pcClass)
Get the field names for a
PersistenceCapable class. |
java.lang.Class[] |
getFieldTypes(java.lang.Class pcClass)
Get the field types for a
PersistenceCapable class. |
static JDOImplHelper |
getInstance()
Get an instance of
JDOImplHelper . |
private static java.util.Locale |
getLocale(java.lang.String s)
Parse the String to a Locale.
|
private static JDOImplHelper.Meta |
getMeta(java.lang.Class pcClass)
Look up the metadata for a
PersistenceCapable class. |
java.lang.Class |
getPersistenceCapableSuperclass(java.lang.Class pcClass)
Get the persistence-capable superclass for a
PersistenceCapable class. |
java.util.Collection |
getRegisteredClasses()
Returns a collection of class objects of the registered
persistence-capable classes.
|
static javax.xml.parsers.DocumentBuilderFactory |
getRegisteredDocumentBuilderFactory()
Return the registered instance of DocumentBuilderFactory.
|
static org.xml.sax.ErrorHandler |
getRegisteredErrorHandler()
Return the registered instance of ErrorHandler.
|
private java.util.Iterator |
getStateInterrogationIterator()
Return an Iterator over all StateInterrogation instances.
|
private static boolean |
isClassLoadable(java.lang.String className)
Determine if a class is loadable in the current environment.
|
PersistenceCapable |
newInstance(java.lang.Class pcClass,
StateManager sm)
Create a new instance of the class and assign its
jdoStateManager . |
PersistenceCapable |
newInstance(java.lang.Class pcClass,
StateManager sm,
java.lang.Object oid)
Create a new instance of the class and assign its
jdoStateManager and key values from the ObjectId. |
java.lang.Object |
newObjectIdInstance(java.lang.Class pcClass)
Create a new instance of the ObjectId class of this
PersistenceCapable class. |
java.lang.Object |
newObjectIdInstance(java.lang.Class pcClass,
java.lang.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.
|
java.lang.Object |
nonBinaryCompatibleGet(java.lang.Object pc,
JDOImplHelper.StateInterrogationObjectReturn sibr)
Return an object associated with a non-binary-compatible instance.
|
boolean |
nonBinaryCompatibleIs(java.lang.Object pc,
JDOImplHelper.StateInterrogationBooleanReturn sibr)
Determine the state of a non-binary-compatible instance.
|
void |
nonBinaryCompatibleMakeDirty(java.lang.Object pc,
java.lang.String fieldName)
Mark a non-binary-compatible instance dirty.
|
static void |
registerAuthorizedStateManagerClass(java.lang.Class smClass)
Register a class authorized to replaceStateManager.
|
static void |
registerAuthorizedStateManagerClasses(java.util.Collection smClasses)
Register classes authorized to replaceStateManager.
|
static void |
registerClass(java.lang.Class pcClass,
java.lang.String[] fieldNames,
java.lang.Class[] fieldTypes,
byte[] fieldFlags,
java.lang.Class persistenceCapableSuperclass,
PersistenceCapable pc)
Register metadata by class.
|
void |
registerDateFormat(java.text.DateFormat df)
Register a DateFormat instance for use with constructing Date
instances.
|
void |
registerDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory factory)
Register a DocumentBuilderFactory instance for use in parsing the
resource(s) META-INF/jdoconfig.xml.
|
void |
registerErrorHandler(org.xml.sax.ErrorHandler handler)
Register an ErrorHandler instance for use in parsing the
resource(s) META-INF/jdoconfig.xml.
|
java.lang.Object |
registerStringConstructor(java.lang.Class cls,
JDOImplHelper.StringConstructor sc)
Register special StringConstructor instances.
|
void |
removeRegisterClassListener(RegisterClassListener crl)
Remove the specified
RegisterClassListener from the listener
list. |
void |
removeStateInterrogation(StateInterrogation si)
Remove a StateInterrogation from the list.
|
void |
unregisterClass(java.lang.Class pcClass)
Unregister metadata by class.
|
void |
unregisterClasses(java.lang.ClassLoader cl)
Unregister metadata by class loader.
|
private static java.util.Map registeredClasses
HashMap
contains a static mapping of
PersistenceCapable
class to
metadata for the class used for constructing new instances. New entries
are added by the static method in each PersistenceCapable
class. Entries are never removed.private static java.util.Map authorizedStateManagerClasses
private static java.util.List listeners
RegisterClassEvent
s.private static java.util.List stateInterrogations
private static JDOImplHelper jdoImplHelper
JDOImplHelper
instance.private static final I18NHelper msg
private static java.lang.String dateFormatPattern
private static java.text.DateFormat dateFormat
private static javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory
private static org.xml.sax.ErrorHandler errorHandler
static java.util.Map stringConstructorMap
public static JDOImplHelper getInstance() throws java.lang.SecurityException
JDOImplHelper
. This method
checks that the caller is authorized for
JDOPermission("getMetadata")
, and if not, throws
SecurityException
.JDOImplHelper
.java.lang.SecurityException
- if the caller is not authorized for
JDOPermission("getMetadata").public java.lang.String[] getFieldNames(java.lang.Class pcClass)
PersistenceCapable
class. The
order of fields is the natural ordering of the String
class
(without considering localization).pcClass
- the PersistenceCapable
class.public java.lang.Class[] getFieldTypes(java.lang.Class pcClass)
PersistenceCapable
class. The
order of fields is the same as for field names.pcClass
- the PersistenceCapable
class.public byte[] getFieldFlags(java.lang.Class pcClass)
PersistenceCapable
class. The
order of fields is the same as for field names.pcClass
- the PersistenceCapable
class.public java.lang.Class getPersistenceCapableSuperclass(java.lang.Class pcClass)
PersistenceCapable
class.pcClass
- the PersistenceCapable
class.PersistenceCapable
superclass for this class,
or null
if there isn't one.public PersistenceCapable newInstance(java.lang.Class pcClass, StateManager sm)
jdoStateManager
. The new instance has its
jdoFlags
set to LOAD_REQUIRED
.pcClass
- the PersistenceCapable
class.sm
- the StateManager
which will own the new instance.null
if the class is not
registered.PersistenceCapable.jdoNewInstance(StateManager sm)
public PersistenceCapable newInstance(java.lang.Class pcClass, StateManager sm, java.lang.Object oid)
jdoStateManager
and key values from the ObjectId. If the
oid parameter is null
, no key values are copied.
The new instance has its jdoFlags
set to
LOAD_REQUIRED
.pcClass
- the PersistenceCapable
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.PersistenceCapable.jdoNewInstance(StateManager sm, Object oid)
public java.lang.Object newObjectIdInstance(java.lang.Class pcClass)
PersistenceCapable
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 PersistenceCapable
class.null
if the class
is not registered.public java.lang.Object newObjectIdInstance(java.lang.Class pcClass, java.lang.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 constructor
ObjectIdFieldSupplier
: the field value
is fetched from the ObjectIdFieldSupplier
and passed to the
single field identity constructor
String
: the String is passed to the
single field identity constructor
obj
- the Object
form of the object idpcClass
- the PersistenceCapable
class.null
if the class is not registered.public void copyKeyFieldsToObjectId(java.lang.Class pcClass, PersistenceCapable.ObjectIdFieldSupplier fm, java.lang.Object oid)
PersistenceCapable
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 jdoCopyKeyFieldsToObjectId (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 PersistenceCapable Class
.oid
- the ObjectId target of the copy.fm
- the field manager that supplies the field values.public void copyKeyFieldsFromObjectId(java.lang.Class pcClass, PersistenceCapable.ObjectIdFieldConsumer fm, java.lang.Object oid)
PersistenceCapable
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 jdoCopyKeyFieldsFromObjectId
(PersistenceCapable 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 PersistenceCapable
classoid
- the ObjectId source of the copy.fm
- the field manager that receives the field values.public static void registerClass(java.lang.Class pcClass, java.lang.String[] fieldNames, java.lang.Class[] fieldTypes, byte[] fieldFlags, java.lang.Class persistenceCapableSuperclass, PersistenceCapable pc)
JDOImplHelper
loaded by the same or an
ancestor class loader as the PersistenceCapable
class
performing the registration.pcClass
- the PersistenceCapable
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 PersistenceCapable
classpersistenceCapableSuperclass
- the most immediate superclass that is
PersistenceCapable
public void unregisterClasses(java.lang.ClassLoader cl)
PersistenceCapable
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(java.lang.Class pcClass)
JDOFatalUserException
.pcClass
- the PersistenceCapable
class to be
unregistered.public void addRegisterClassListener(RegisterClassListener crl)
RegisterClassListener
to the listener
list.crl
- the listener to be addedpublic void removeRegisterClassListener(RegisterClassListener crl)
RegisterClassListener
from the listener
list.crl
- the listener to be removedpublic java.util.Collection getRegisteredClasses()
private static JDOImplHelper.Meta getMeta(java.lang.Class pcClass)
PersistenceCapable
class.pcClass
- the Class
.Meta
for the Class
.public static void registerAuthorizedStateManagerClass(java.lang.Class smClass) throws java.lang.SecurityException
smClass
- a Class that is authorized for
JDOPermission("setStateManager").java.lang.SecurityException
- if the caller is not authorized for
JDOPermission("setStateManager").public static void registerAuthorizedStateManagerClasses(java.util.Collection smClasses) throws java.lang.SecurityException
smClasses
- a Collection of Classes that are authorized for
JDOPermission("setStateManager").java.lang.SecurityException
- if the caller is not authorized for
JDOPermission("setStateManager").public void registerDocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory factory)
factory
- the DocumentBuilderFactory instance to usepublic static javax.xml.parsers.DocumentBuilderFactory getRegisteredDocumentBuilderFactory()
public void registerErrorHandler(org.xml.sax.ErrorHandler handler)
handler
- the ErrorHandler instance to usepublic static org.xml.sax.ErrorHandler getRegisteredErrorHandler()
public static void checkAuthorizedStateManager(StateManager sm)
sm
- an instance of StateManager whose class is to be checked.public static void checkAuthorizedStateManagerClass(java.lang.Class smClass)
smClass
- a Class to be checked for JDOPermission("setStateManager")public java.lang.Object registerStringConstructor(java.lang.Class cls, JDOImplHelper.StringConstructor sc)
cls
- the class to register a StringConstructor forsc
- the StringConstructor instanceprivate static java.util.Locale getLocale(java.lang.String s)
s
- the name of the Localeprivate static boolean isClassLoadable(java.lang.String className)
className
- the fully-qualified name of the classpublic static java.lang.Object construct(java.lang.String className, java.lang.String keyString)
className
- the name of the classkeyString
- the String parameter for the constructorstatic java.text.DateFormat getDateTimeInstance()
public void registerDateFormat(java.text.DateFormat df)
df
- the DateFormat instance to usepublic void addStateInterrogation(StateInterrogation si)
si
- the StateInterrogation to addpublic void removeStateInterrogation(StateInterrogation si)
si
- the StateInterrogation to removeprivate java.util.Iterator getStateInterrogationIterator()
public void nonBinaryCompatibleMakeDirty(java.lang.Object pc, java.lang.String fieldName)
pc
- the instance to mark dirtyfieldName
- the field to mark dirtypublic boolean nonBinaryCompatibleIs(java.lang.Object pc, JDOImplHelper.StateInterrogationBooleanReturn sibr)
pc
- the instance to be checkedsibr
- the method object that delegates to the
non-binary-compatible implementationpublic java.lang.Object nonBinaryCompatibleGet(java.lang.Object pc, JDOImplHelper.StateInterrogationObjectReturn sibr)
pc
- the instance whose associated object is neededsibr
- the method object that delegates to the
non-binary-compatible implementation