Class RuntimeModel
- java.lang.Object
-
- com.sun.jdo.api.persistence.model.Model
-
- com.sun.jdo.api.persistence.model.RuntimeModel
-
- Direct Known Subclasses:
DeploymentDescriptorModel
public class RuntimeModel extends Model
- Version:
- %I%
- Author:
- raccah
-
-
Field Summary
-
Fields inherited from class com.sun.jdo.api.persistence.model.Model
ENHANCER, messageBase, NO_ARGS, RUNTIME
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RuntimeModel()
Creates a new RuntimeModel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BufferedOutputStream
createFile(String className, String baseFileName, String extension)
Creates a file with the given base file name and extension parallel to the supplied class (if it does not yet exist).protected void
deleteFile(String className, String fileName)
Deletes the file with the given file name which is parallel to the supplied class.protected ClassLoader
findClassLoader(String className, ClassLoader classLoader)
This method returns the class loader used to find mapping information for the specified className.protected String
findPenultimateSuperclass(String className)
Returns the name of the second to top (top excluding java.lang.Object) superclass for the given class name.Object
getClass(String className, ClassLoader classLoader)
Returns the class element with the specified className.Map
getClassLoaderCache()
Returns an unmodifiable copy of the ClassLoader cache.Object
getConstructor(String className, String[] argTypeNames)
Returns the constructor element for the specified argument types in the class with the specified name.String
getDeclaringClass(Object memberElement)
Returns the string representation of declaring class of the specified member element.Object
getField(String className, String fieldName)
Returns the field element for the specified fieldName in the class with the specified className.List
getFields(String className)
Returns a list of names of all the declared field elements in the class with the specified name.protected File
getFile(String className, String fileName)
Returns a file with the given file name which is parallel to the supplied class.protected BufferedInputStream
getInputStreamForResource(String className, ClassLoader classLoader, String resourceName)
Returns the input stream with the supplied resource name found with the supplied class name.MappingClassElement
getMappingClass(String className, ClassLoader classLoader)
Returns the MappingClassElement created for the specified class name.Object
getMethod(String className, String methodName, String[] argTypeNames)
Returns the method element for the specified method name and argument types in the class with the specified name.int
getModifiers(Object memberElement)
Returns the modifier mask for the specified member element.protected String
getSuperclass(String className)
Returns the name of the superclass for the given class name.String
getType(Object element)
Returns the string representation of type of the specified element.protected Class
getTypeObject(Object element)
Returns the Class type of the specified element.boolean
hasConstructor(String className)
Determines if the class with the specified name declares a constructor.boolean
implementsInterface(Object classElement, String interfaceName)
Determines if the specified class implements the specified interface.boolean
isArray(String className, String fieldName)
Determines if a field with the specified fieldName in the class with the specified className is an array.boolean
isInterface(String className)
Determines if the specified className represents an interface type.boolean
isSerializable(Object fieldElement)
Determines if the specified field element has a serializable type.void
removeResourcesFromCaches(ClassLoader classLoader)
Removes the classes cached with the specified class loader from all caches.-
Methods inherited from class com.sun.jdo.api.persistence.model.Model
addFieldElement, convertDefaultFields, convertFields, convertToPersistenceCapable, convertToPersistenceCapable, getAllFields, getClass, getDefaultCollectionClass, getEqualsArgs, getFieldType, getFileName, getFileNameWithExtension, getInheritedField, getInheritedMethod, getMappingCache, getMappingClass, getMessages, getModifiers, getModifiersForClass, getPersistenceClass, getPersistenceClass, getPersistenceClass, getPersistenceField, getPersistenceFieldInternal, getReadObjectArgs, getRelatedClass, getResourceName, getResourceNameWithExtension, getSupportedCollectionClasses, getWriteObjectArgs, hasClass, hasClass, hasField, hasPersistentSuperclass, isByteArray, isByteArray, isCollection, isDefaultFetchGroup, isKey, isMutableSecondClassObject, isPersistenceCapableAllowed, isPersistent, isPersistent, isPersistent, isPersistentAllowed, isPersistentAllowed, isPersistentTypeAllowed, isPrimitive, isPrimitive, isSecondClassObject, isValidKeyType, lockFile, NewModel, parse, removeFieldElement, removeFromCache, removeResourcesFromCaches, shouldBePersistent, storeMappingClass, storeMappingClass, storeMappingClass, unlockFile, unlockFile, updateKeyForClass, validate, validate
-
-
-
-
Constructor Detail
-
RuntimeModel
protected RuntimeModel()
Creates a new RuntimeModel. This constructor should not be called directly; instead, the static instance accesible from the Model class should be used.- See Also:
Model.RUNTIME
-
-
Method Detail
-
isInterface
public boolean isInterface(String className)
Determines if the specified className represents an interface type.- Specified by:
isInterface
in classModel
- Parameters:
className
- the fully qualified name of the class to be checked- Returns:
true
if this class name represents an interface;false
otherwise.
-
getInputStreamForResource
protected BufferedInputStream getInputStreamForResource(String className, ClassLoader classLoader, String resourceName)
Returns the input stream with the supplied resource name found with the supplied class name. NOTE, this implementation assumes the specified class loader is not null and needs not to be validated. Any validation is done by getMappingClass which is the only caller of this method.- Specified by:
getInputStreamForResource
in classModel
- Parameters:
className
- the fully qualified name of the class which will be used as a base to find the resourceclassLoader
- the class loader used to find mapping informationresourceName
- the name of the resource to be found- Returns:
- the input stream for the specified resource,
null
if an error occurs or none exists
-
findPenultimateSuperclass
protected String findPenultimateSuperclass(String className)
Returns the name of the second to top (top excluding java.lang.Object) superclass for the given class name.- Specified by:
findPenultimateSuperclass
in classModel
- Parameters:
className
- the fully qualified name of the class to be checked- Returns:
- the top non-Object superclass for className,
className
if an error occurs or none exists
-
getSuperclass
protected String getSuperclass(String className)
Returns the name of the superclass for the given class name.- Specified by:
getSuperclass
in classModel
- Parameters:
className
- the fully qualified name of the class to be checked- Returns:
- the superclass for className,
null
if an error occurs or none exists
-
getMappingClass
public MappingClassElement getMappingClass(String className, ClassLoader classLoader)
Returns the MappingClassElement created for the specified class name. This method looks up the class in the internal cache. If not present it loads the corresponding xml file containing the mapping information.- Overrides:
getMappingClass
in classModel
- Parameters:
className
- the fully qualified name of the mapping classclassLoader
- the class loader used to find mapping information- Returns:
- the MappingClassElement for className,
null
if an error occurs or none exists - See Also:
MappingClassElementImpl.forName(String, Model)
-
getClassLoaderCache
public Map getClassLoaderCache()
Returns an unmodifiable copy of the ClassLoader cache.- Overrides:
getClassLoaderCache
in classModel
- Returns:
- unmodifiable ClassLoader cache
-
removeResourcesFromCaches
public void removeResourcesFromCaches(ClassLoader classLoader)
Removes the classes cached with the specified class loader from all caches. The method iterates the ClassLoader cache to find classes cached with the specified class loader. These classes are removed from the ClassLoader cache, the cache of MappingClassElements and the set of classes known to be non PC. The associated SchemaElements are removed from the SchemaElement cache.- Overrides:
removeResourcesFromCaches
in classModel
- Parameters:
classLoader
- used to determine the classes to be removed
-
createFile
protected BufferedOutputStream createFile(String className, String baseFileName, String extension) throws IOException
Creates a file with the given base file name and extension parallel to the supplied class (if it does not yet exist).- Specified by:
createFile
in classModel
- Parameters:
className
- the fully qualified name of the classbaseFileName
- the name of the base fileextension
- the file extension- Returns:
- the output stream for the specified resource,
null
if an error occurs or none exists - Throws:
IOException
- if there is some error creating the file
-
deleteFile
protected void deleteFile(String className, String fileName) throws IOException
Deletes the file with the given file name which is parallel to the supplied class.- Specified by:
deleteFile
in classModel
- Parameters:
className
- the fully qualified name of the classfileName
- the name of the file- Throws:
IOException
- if there is some error deleting the file
-
getFile
protected File getFile(String className, String fileName) throws IOException
Returns a file with the given file name which is parallel to the supplied class.- Parameters:
className
- the fully qualified name of the classfileName
- the name of the file- Returns:
- the file object for the specified resource,
null
if an error occurs - Throws:
IOException
- if there is some error getting the file
-
getClass
public Object getClass(String className, ClassLoader classLoader)
Returns the class element with the specified className. The class is found usingClass.forName
.
-
findClassLoader
protected ClassLoader findClassLoader(String className, ClassLoader classLoader) throws IllegalArgumentException
This method returns the class loader used to find mapping information for the specified className. If the classLoader argument is not null, the method updates the classLoaders cache and returns the specified classLoader. Otherwise it checks the cache for the specified className and returns this class loader. If there is no cached class loader it returns the current class loader.- Parameters:
className
- the fully qualified name of the class to be checkedclassLoader
- the class loader used to find mapping information- Returns:
- the class loader used to find mapping information for the specified className
- Throws:
IllegalArgumentException
- if there is class loader problem
-
implementsInterface
public boolean implementsInterface(Object classElement, String interfaceName)
Determines if the specified class implements the specified interface. Note, class element is a model specific class representation as returned by a getClass call executed on the same model instance. This implementation expects the class element being a reflection instance.- Specified by:
implementsInterface
in classModel
- Parameters:
classElement
- the class element to be checkedinterfaceName
- the fully qualified name of the interface to be checked- Returns:
true
if the class implements the interface;false
otherwise.- See Also:
getClass(java.lang.String, java.lang.ClassLoader)
-
hasConstructor
public boolean hasConstructor(String className)
Determines if the class with the specified name declares a constructor.- Specified by:
hasConstructor
in classModel
- Parameters:
className
- the name of the class to be checked- Returns:
true
if the class declares a constructor;false
otherwise.- See Also:
getClass(java.lang.String, java.lang.ClassLoader)
-
getConstructor
public Object getConstructor(String className, String[] argTypeNames)
Returns the constructor element for the specified argument types in the class with the specified name. Types are specified as type names for primitive type such as int, float or as fully qualified class names.- Specified by:
getConstructor
in classModel
- Parameters:
className
- the name of the class which contains the constructor to be checkedargTypeNames
- the fully qualified names of the argument types- Returns:
- the constructor element
- See Also:
getClass(java.lang.String, java.lang.ClassLoader)
-
getMethod
public Object getMethod(String className, String methodName, String[] argTypeNames)
Returns the method element for the specified method name and argument types in the class with the specified name. Types are specified as type names for primitive type such as int, float or as fully qualified class names. Note, the method does not return inherited methods.- Specified by:
getMethod
in classModel
- Parameters:
className
- the name of the class which contains the method to be checkedmethodName
- the name of the method to be checkedargTypeNames
- the fully qualified names of the argument types- Returns:
- the method element
- See Also:
getClass(java.lang.String, java.lang.ClassLoader)
-
getType
public String getType(Object element)
Returns the string representation of type of the specified element. If element denotes a field, it returns the type of the field. If element denotes a method, it returns the return type of the method. Note, element is either a field element as returned by getField, or a method element as returned by getMethod executed on the same model instance. This implementation expects the element being a reflection instance.- Specified by:
getType
in classModel
- Parameters:
element
- the element to be checked- Returns:
- the string representation of the type of the element
- See Also:
getField(java.lang.String, java.lang.String)
,getMethod(java.lang.String, java.lang.String, java.lang.String[])
-
getFields
public List getFields(String className)
Returns a list of names of all the declared field elements in the class with the specified name.
-
getField
public Object getField(String className, String fieldName)
Returns the field element for the specified fieldName in the class with the specified className.
-
isSerializable
public boolean isSerializable(Object fieldElement)
Determines if the specified field element has a serializable type. A type is serializable if it is a primitive type, a class that implements java.io.Serializable or an interface that inherits from java.io.Serializable. Note, the field element is a model specific field representation as returned by a getField call executed on the same model instance. This implementation expects the field element being a reflection instance.- Specified by:
isSerializable
in classModel
- Parameters:
fieldElement
- the field element to be checked- Returns:
true
if the field element has a serializable type;false
otherwise.- See Also:
getField(java.lang.String, java.lang.String)
-
isArray
public boolean isArray(String className, String fieldName)
Determines if a field with the specified fieldName in the class with the specified className is an array.- Specified by:
isArray
in classModel
- Parameters:
className
- the fully qualified name of the class which contains the field to be checkedfieldName
- the name of the field to be checked- Returns:
true
if this field name represents a java array field;false
otherwise.- See Also:
Model.getFieldType(java.lang.String, java.lang.String)
-
getDeclaringClass
public String getDeclaringClass(Object memberElement)
Returns the string representation of declaring class of the specified member element. Note, the member element is either a class element as returned by getClass, a field element as returned by getField, a constructor element as returned by getConstructor, or a method element as returned by getMethod executed on the same model instance. This implementation expects the member element to be a reflection instance.- Specified by:
getDeclaringClass
in classModel
- Parameters:
memberElement
- the member element to be checked- Returns:
- the string representation of the declaring class of the specified memberElement
- See Also:
getClass(java.lang.String, java.lang.ClassLoader)
,getField(java.lang.String, java.lang.String)
,getConstructor(java.lang.String, java.lang.String[])
,getMethod(java.lang.String, java.lang.String, java.lang.String[])
-
getModifiers
public int getModifiers(Object memberElement)
Returns the modifier mask for the specified member element. Note, the member element is either a class element as returned by getClass, a field element as returned by getField, a constructor element as returned by getConstructor, or a method element as returned by getMethod executed on the same model instance. This implementation expects the member element to be a reflection instance.- Specified by:
getModifiers
in classModel
- Parameters:
memberElement
- the member element to be checked- Returns:
- the modifier mask for the specified memberElement
- See Also:
Modifier
,getClass(java.lang.String, java.lang.ClassLoader)
,getField(java.lang.String, java.lang.String)
,getConstructor(java.lang.String, java.lang.String[])
,getMethod(java.lang.String, java.lang.String, java.lang.String[])
-
getTypeObject
protected Class getTypeObject(Object element)
Returns the Class type of the specified element. If element denotes a field, it returns the type of the field. If element denotes a method, it returns the return type of the method. Note, element is either a field element as returned by getField, or a method element as returned by getMethod executed on the same model instance.- Parameters:
element
- the element to be checked- Returns:
- the Class type of the element
- See Also:
getField(java.lang.String, java.lang.String)
,getMethod(java.lang.String, java.lang.String, java.lang.String[])
-
-