Class RuntimeModel
- java.lang.Object
-
- com.sun.jdo.api.persistence.model.Model
-
- com.sun.jdo.api.persistence.model.RuntimeModel
-
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 protectedRuntimeModel()Creates a new RuntimeModel.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BufferedOutputStreamcreateFile(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 voiddeleteFile(String className, String fileName)Deletes the file with the given file name which is parallel to the supplied class.protected ClassLoaderfindClassLoader(String className, ClassLoader classLoader)This method returns the class loader used to find mapping information for the specified className.protected StringfindPenultimateSuperclass(String className)Returns the name of the second to top (top excluding java.lang.Object) superclass for the given class name.ObjectgetClass(String className, ClassLoader classLoader)Returns the class element with the specified className.MapgetClassLoaderCache()Returns an unmodifiable copy of the ClassLoader cache.ObjectgetConstructor(String className, String[] argTypeNames)Returns the constructor element for the specified argument types in the class with the specified name.StringgetDeclaringClass(Object memberElement)Returns the string representation of declaring class of the specified member element.ObjectgetField(String className, String fieldName)Returns the field element for the specified fieldName in the class with the specified className.ListgetFields(String className)Returns a list of names of all the declared field elements in the class with the specified name.protected FilegetFile(String className, String fileName)Returns a file with the given file name which is parallel to the supplied class.protected BufferedInputStreamgetInputStreamForResource(String className, ClassLoader classLoader, String resourceName)Returns the input stream with the supplied resource name found with the supplied class name.MappingClassElementgetMappingClass(String className, ClassLoader classLoader)Returns the MappingClassElement created for the specified class name.ObjectgetMethod(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.intgetModifiers(Object memberElement)Returns the modifier mask for the specified member element.protected StringgetSuperclass(String className)Returns the name of the superclass for the given class name.StringgetType(Object element)Returns the string representation of type of the specified element.protected ClassgetTypeObject(Object element)Returns the Class type of the specified element.booleanhasConstructor(String className)Determines if the class with the specified name declares a constructor.booleanimplementsInterface(Object classElement, String interfaceName)Determines if the specified class implements the specified interface.booleanisArray(String className, String fieldName)Determines if a field with the specified fieldName in the class with the specified className is an array.booleanisInterface(String className)Determines if the specified className represents an interface type.booleanisSerializable(Object fieldElement)Determines if the specified field element has a serializable type.voidremoveResourcesFromCaches(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:
isInterfacein classModel- Parameters:
className- the fully qualified name of the class to be checked- Returns:
trueif this class name represents an interface;falseotherwise.
-
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:
getInputStreamForResourcein 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,
nullif 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:
findPenultimateSuperclassin classModel- Parameters:
className- the fully qualified name of the class to be checked- Returns:
- the top non-Object superclass for className,
classNameif 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:
getSuperclassin classModel- Parameters:
className- the fully qualified name of the class to be checked- Returns:
- the superclass for className,
nullif 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:
getMappingClassin classModel- Parameters:
className- the fully qualified name of the mapping classclassLoader- the class loader used to find mapping information- Returns:
- the MappingClassElement for className,
nullif 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:
getClassLoaderCachein 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:
removeResourcesFromCachesin 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:
createFilein 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,
nullif 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:
deleteFilein 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,
nullif 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:
implementsInterfacein classModel- Parameters:
classElement- the class element to be checkedinterfaceName- the fully qualified name of the interface to be checked- Returns:
trueif the class implements the interface;falseotherwise.- 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:
hasConstructorin classModel- Parameters:
className- the name of the class to be checked- Returns:
trueif the class declares a constructor;falseotherwise.- 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:
getConstructorin 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:
getMethodin 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:
getTypein 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:
isSerializablein classModel- Parameters:
fieldElement- the field element to be checked- Returns:
trueif the field element has a serializable type;falseotherwise.- 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:
isArrayin 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:
trueif this field name represents a java array field;falseotherwise.- 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:
getDeclaringClassin 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:
getModifiersin 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[])
-
-