com.sun.jdo.api.persistence.model
Class Model

java.lang.Object
  extended by com.sun.jdo.api.persistence.model.Model
Direct Known Subclasses:
RuntimeModel

public abstract class Model
extends Object

Version:
%I%
Author:
raccah

Field Summary
static Model ENHANCER
          Default instance of the model used by the enhancer.
static String messageBase
          I18N message base
static String[] NO_ARGS
          Standard set of empty arguments (for comparison with hashCode method and no-arg constructor).
static Model RUNTIME
          Default instance of the model for use at runtime.
 
Constructor Summary
Model()
           
 
Method Summary
 boolean addFieldElement(PersistenceClassElement element, String fieldName)
          Adds a PersistenceFieldElement for the specified field to the supplied PersistenceClassElement, creating a RelationshipElement if necessary.
 void convertDefaultFields(String className)
          Adds the default allowable persistent fields to the persistent class with the specified name.
 void convertFields(String className, List fields)
          Adds the allowable persistent fields from the supplied list to the persistent class with the specified name.
 void convertToPersistenceCapable(String className)
          Converts the class with the supplied name to persistence-capable, then convert its default fields and save it to the xml file.
 void convertToPersistenceCapable(String className, boolean flag)
          Converts the class with the supplied name to or from persistence capable depending on the flag.
protected abstract  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 abstract  void deleteFile(String className, String fileName)
          Deletes the file with the given file name which is parallel to the supplied class.
protected abstract  String findPenultimateSuperclass(String className)
          Returns the name of the second to top (top excluding java.lang.Object) superclass for the given class name.
 List getAllFields(String className)
          Returns a list of names of all the field elements in the class with the specified name.
 Object getClass(String className)
          Returns the class element with the specified className.
abstract  Object getClass(String className, ClassLoader classLoader)
          Returns the class element with the specified className.
 Map getClassLoaderCache()
          Returns an unmodifiable copy of the ClassLoader cache.
abstract  Object getConstructor(String className, String[] argTypeNames)
          Returns the constructor element for the specified argument types in the class with the specified name.
abstract  String getDeclaringClass(Object memberElement)
          Returns the string representation of declaring class of the specified member element.
 String getDefaultCollectionClass(String className)
          Returns the default collection class for the specified class.
static String[] getEqualsArgs()
          Standard set of arguments for comparison with equals method.
abstract  Object getField(String className, String fieldName)
          Returns the field element for the specified fieldName in the class with the specified className.
abstract  List getFields(String className)
          Returns a list of names of all the declared field elements in the class with the specified name.
 String getFieldType(String className, String fieldName)
          Returns the field type for the specified fieldName in the class with the specified className.
protected  String getFileName(String className)
          Computes the base file name (without extension) for the supplied class name by converting the package name to a path name.
protected  String getFileNameWithExtension(String className)
          Computes the mapping file name (with extension) for the supplied class name by converting the package name to a path name.
 Object getInheritedField(String className, String fieldName)
          Returns the inherited field element for the specified fieldName in the class with the specified className.
 Object getInheritedMethod(String className, String methodName, String[] argTypeNames)
          Returns the inherited method element for the specified method name and argument types in the class with the specified name.
protected abstract  BufferedInputStream getInputStreamForResource(String className, ClassLoader classLoader, String resourceName)
          Returns the input stream with the supplied resource name found with the supplied class name.
 Map getMappingCache()
          Returns an unmodifiable copy of the MappingClassElement cache.
 MappingClassElement getMappingClass(String className)
          Returns the MappingClassElement created for the specified class name.
 MappingClassElement getMappingClass(String className, ClassLoader classLoader)
          Returns the MappingClassElement created for the specified class name.
protected static ResourceBundle getMessages()
           
abstract  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.
abstract  int getModifiers(Object memberElement)
          Returns the modifier mask for the specified member element.
protected  int getModifiers(String className, String fieldName)
          Returns the modifier mask for the specified fieldName in the class with the specified className.
 int getModifiersForClass(String className)
          Returns the modifier mask for the specified className.
protected  PersistenceClassElement getPersistenceClass(MappingClassElement mappingClass)
          Returns a PersistenceClassElement created from the mapping class.
 PersistenceClassElement getPersistenceClass(String className)
          Returns a PersistenceClassElement created from the specified class name.
 PersistenceClassElement getPersistenceClass(String className, ClassLoader classLoader)
          Returns a PersistenceClassElement created from the specified class name.
 PersistenceFieldElement getPersistenceField(String className, String fieldName)
          Returns the PersistenceFieldElement with the supplied fieldName found in the supplied className.
protected  PersistenceFieldElement getPersistenceFieldInternal(String className, String fieldName)
          Returns the PersistenceFieldElement with the supplied fieldName found in the supplied className.
static String[] getReadObjectArgs()
          Standard set of arguments for comparison with readObject method.
 String getRelatedClass(RelationshipElement element)
          Gets the name of the related class for a relationship element.
protected  String getResourceName(String className)
          Computes the base resource name (without extension) for the supplied class name by converting the package name to a resource name.
protected  String getResourceNameWithExtension(String className)
          Computes the mapping file resource name (with extension) for the supplied class name by converting the package name to a resource name.
protected abstract  String getSuperclass(String className)
          Returns the name of the superclass for the given class name.
 ArrayList getSupportedCollectionClasses(String className)
          Computes the list of names of the possible collection classes for the specified class.
abstract  String getType(Object element)
          Returns the string representation of type of the specified element.
static String[] getWriteObjectArgs()
          Standard set of arguments for comparison with writeObject method.
 boolean hasClass(String className)
          Determines if a class with the specified className exists.
 boolean hasClass(String className, ClassLoader classLoader)
          Determines if a class with the specified className exists.
abstract  boolean hasConstructor(String className)
          Determines if the class with the specified name declares a constructor.
 boolean hasField(String className, String fieldName)
          Determines if a field with the specified fieldName exists in the class with the specified className.
 boolean hasPersistentSuperclass(String className)
          Determines if the specified className has a persistent superclass.
abstract  boolean implementsInterface(Object classElement, String interfaceName)
          Determines if the specified class implements the specified interface.
abstract  boolean isArray(String className, String fieldName)
          Determines if a field with the specified fieldName in the class with the specified className is an array.
protected  boolean isByteArray(String className)
          Determines if the specified className represents a byte array.
 boolean isByteArray(String className, String fieldName)
          Determines if a field with the specified fieldName in the class with the specified className is a byte array.
 boolean isCollection(String className)
          Determines if the class name represents a collection.
 boolean isDefaultFetchGroup(String className, String fieldName)
          Determines if the specified className and fieldName pair represent a field which is part of the default fetch group.
abstract  boolean isInterface(String className)
          Determines if the specified className represents an interface type.
 boolean isKey(String className, String fieldName)
          Determines if the specified className and fieldName pair represent a key field.
 boolean isMutableSecondClassObject(String className)
          Determines if the specified className represents a mutable second class object.
 boolean isPersistenceCapableAllowed(String className)
          Determines if the specified className represents a legal candidate for becoming a persistence capable class.
 boolean isPersistent(String className)
          Determines if the specified className represents a persistence capable class.
 boolean isPersistent(String className, ClassLoader classLoader)
          Determines if the specified className represents a persistence capable class.
 boolean isPersistent(String className, String fieldName)
          Determines if the specified className and fieldName pair represent a persistent field.
 boolean isPersistentAllowed(String className, ClassLoader classLoader, String fieldName)
          Returns true if the specified field can be made persistent, false otherwise.
 boolean isPersistentAllowed(String className, String fieldName)
          Returns true if the specified field can be made persistent, false otherwise.
protected  boolean isPersistentTypeAllowed(String className, ClassLoader classLoader)
          Returns true if the a field of the specified class or type can be made persistent, false otherwise.
protected  boolean isPrimitive(String className)
          Determines if the specified className represents a primitive type.
 boolean isPrimitive(String className, String fieldName)
          Determines if a field with the specified fieldName in the class with the specified className has a primitive type.
 boolean isSecondClassObject(String className)
          Determines if the specified className represents a second class object.
abstract  boolean isSerializable(Object fieldElement)
          Determines if the specified field element has a serializable type.
 boolean isValidKeyType(String className, String fieldName)
          Determines if the specified className and fieldName pair represent a field which has a type which is valid for key fields.
 void lockFile(String className)
           
protected static Model NewModel(String testName, String modelName)
          Create a new Model of the requested type.
 boolean parse(String className)
          Parses the combination of java (or class) information and mapping/jdo information by running through a subset of the full validation check and aborting (and returning false at the first error or warning.
 void removeFieldElement(PersistenceFieldElement element)
          Removes the specified PersistenceFieldElement from its declaring class.
 void removeFromCache(String className)
          Removes the class with the supplied name from the cache of classes known to be non PC.
 void removeResourcesFromCaches(ClassLoader classLoader)
          Removes the classes cached with the specified class loader from all caches.
protected  void removeResourcesFromCaches(Collection classNames)
          Removes the specified classes from all caches.
 boolean shouldBePersistent(String className, String fieldName)
          Returns true if the specified field should be made persistent (i.e.
 void storeMappingClass(MappingClassElement mappingClass)
          Stores the supplied MappingClassElement to an xml file, creating the file if necessary.
 void storeMappingClass(MappingClassElement mappingClass, OutputStream stream)
          Stores the supplied MappingClassElement to an xml file in the specified output stream.
 void storeMappingClass(String className)
          Stores the MappingClassElement for the specified class name to an xml file, creating the file if necessary.
 void unlockFile(OutputStream stream, String className)
           
 void unlockFile(String className)
           
 void updateKeyForClass(MappingClassElement mappingClass, String oldName)
          Updates the key in the cache for the supplied MappingClassElement.
 Collection validate(String className, ClassLoader classLoader, ResourceBundle bundle)
          Validates the combination of java (or class) information and mapping/jdo information by running through the full validation check and returning a collection of ModelValidationExceptions containing any errors or warnings encountered.
 Collection validate(String className, ResourceBundle bundle)
          Validates the combination of java (or class) information and mapping/jdo information by running through the full validation check and returning a collection of ModelValidationExceptions containing any errors or warnings encountered.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RUNTIME

public static final Model RUNTIME
Default instance of the model for use at runtime.


ENHANCER

public static final Model ENHANCER
Default instance of the model used by the enhancer.


NO_ARGS

public static final String[] NO_ARGS
Standard set of empty arguments (for comparison with hashCode method and no-arg constructor).


messageBase

public static final String messageBase
I18N message base

See Also:
Constant Field Values
Constructor Detail

Model

public Model()
Method Detail

NewModel

protected static Model NewModel(String testName,
                                String modelName)
Create a new Model of the requested type. If the class definition exists in the class path of the environment, then this method will create a new instance of the Model.

Parameters:
modelName - the fully qualified name of the class to be instantiated.
testName - the fully qualified name of the class to be tested as a precondition to loading.
Returns:
a new instance of the requested class (which implements Model).

getMessages

protected static final ResourceBundle getMessages()
Returns:
I18N message handler for this element

getInputStreamForResource

protected abstract BufferedInputStream getInputStreamForResource(String className,
                                                                 ClassLoader classLoader,
                                                                 String resourceName)
Returns the input stream with the supplied resource name found with the supplied class name.

Parameters:
className - the fully qualified name of the class which will be used as a base to find the resource
classLoader - the class loader used to find mapping information
resourceName - the name of the resource to be found
Returns:
the input stream for the specified resource, null if an error occurs or none exists

isInterface

public abstract boolean isInterface(String className)
Determines if the specified className represents an interface type.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class name represents an interface; false otherwise.

hasPersistentSuperclass

public boolean hasPersistentSuperclass(String className)
Determines if the specified className has a persistent superclass.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class name represents a class which has a persistent superclass (anywhere in the inheritance chain); false otherwise.

findPenultimateSuperclass

protected abstract String findPenultimateSuperclass(String className)
Returns the name of the second to top (top excluding java.lang.Object) superclass for the given class name.

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 abstract String getSuperclass(String className)
Returns the name of the superclass for the given class name.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
thesuperclass for className, null if an error occurs or none exists

getPersistenceClass

public PersistenceClassElement getPersistenceClass(String className)
Returns a PersistenceClassElement created from the specified class name. Since our implementation of the mapping model class includes the persistence class, this method finds the persistence class by extracting it from the mapping class for the supplied name.

Parameters:
className - the fully qualified name of the persistence capable class to be returned
Returns:
the PersistenceClassElement for className, null if an error occurs or none exists
See Also:
getMappingClass(java.lang.String)

getPersistenceClass

public PersistenceClassElement getPersistenceClass(String className,
                                                   ClassLoader classLoader)
Returns a PersistenceClassElement created from the specified class name. Since our implementation of the mapping model class includes the persistence class, this method finds the persistence class by extracting it from the mapping class for the supplied name.

Parameters:
className - the fully qualified name of the persistence capable class to be returned
classLoader - the class loader used to find mapping information
Returns:
the PersistenceClassElement for className, null if an error occurs or none exists
See Also:
getMappingClass(java.lang.String)

getPersistenceClass

protected PersistenceClassElement getPersistenceClass(MappingClassElement mappingClass)
Returns a PersistenceClassElement created from the mapping class.

Parameters:
mappingClass - the mapping class element to which the persistence class is associated
Returns:
the PersistenceClassElement for mappingClass, null if an error occurs or none exists
See Also:
getMappingClass(java.lang.String)

getMappingClass

public MappingClassElement getMappingClass(String className)
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.

Parameters:
className - the fully qualified name of the mapping class
Returns:
the MappingClassElement for class, 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.

Parameters:
className - the fully qualified name of the mapping class
classLoader - 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(java.lang.String, com.sun.jdo.api.persistence.model.Model)

getMappingCache

public Map getMappingCache()
Returns an unmodifiable copy of the MappingClassElement cache.

Returns:
unmodifiable MappingClassElement cache

getClassLoaderCache

public Map getClassLoaderCache()
Returns an unmodifiable copy of the ClassLoader cache. This implementation returns null, but subclasses (such as RuntimeModel) can override this method if they support a class loader cache.

Returns:
unmodifiable ClassLoader cache

removeResourcesFromCaches

public void removeResourcesFromCaches(ClassLoader classLoader)
Removes the classes cached with the specified class loader from all caches. This implementation does nothing, but subclasses (such as RuntimeModel) can override this method if they support a class loader cache.

Parameters:
classLoader - used to determine the classes to be removed

removeResourcesFromCaches

protected void removeResourcesFromCaches(Collection classNames)
Removes the specified classes from all caches. The specified collection includes the fully qualified class names of the classes to be removed. The method removes each class from the cache of MappingClassElements and the set of classes known to be non PC. Furthermore it removes the SchemaElement associated with this class from the SchemaElement cache. The next call getMappingClass will determine the status of the classes.

Parameters:
classNames - a collection of fully qualified class names

removeFromCache

public void removeFromCache(String className)
Removes the class with the supplied name from the cache of classes known to be non PC. The next call getMappingClass will determine the status of the class.

Parameters:
className - the fully qualified name of the class

storeMappingClass

public void storeMappingClass(MappingClassElement mappingClass)
                       throws IOException
Stores the supplied MappingClassElement to an xml file, creating the file if necessary. The caller is responsible for updating the cache by calling updateKeyForClass, if necessary.

Parameters:
mappingClass - the mapping class to be saved
Throws:
IOException - if there is some error saving the class
See Also:
createFile(java.lang.String, java.lang.String, java.lang.String)

storeMappingClass

public void storeMappingClass(MappingClassElement mappingClass,
                              OutputStream stream)
                       throws IOException
Stores the supplied MappingClassElement to an xml file in the specified output stream. The caller is responsible for updating the cache by calling updateKeyForClass, if necessary.

Parameters:
mappingClass - the mapping class to be saved
stream - the output stream
Throws:
IOException - if there is some error saving the class
See Also:
createFile(java.lang.String, java.lang.String, java.lang.String)

unlockFile

public void unlockFile(OutputStream stream,
                       String className)
                throws IOException
Throws:
IOException

lockFile

public void lockFile(String className)
              throws IOException
Throws:
IOException

unlockFile

public void unlockFile(String className)

storeMappingClass

public void storeMappingClass(String className)
                       throws IOException
Stores the MappingClassElement for the specified class name to an xml file, creating the file if necessary. The MappingClassElement must be present in the HashMap of classes known by the Model in order to stored.

Parameters:
className - the fully qualified name of the mapping class
Throws:
IOException - if there is some error saving the class
See Also:
storeMappingClass(com.sun.jdo.api.persistence.model.mapping.MappingClassElement)

updateKeyForClass

public void updateKeyForClass(MappingClassElement mappingClass,
                              String oldName)
Updates the key in the cache for the supplied MappingClassElement.

Parameters:
mappingClass - the mapping class to be put in the cache (the new name is extracted from this element). The corresponding handling of the files is automatically handled by the data object. (use null to remove the old key but not replace it)
oldName - the fully qualified name of the old key for the mapping class (use null to add the new key but not replace it)

isPersistent

public boolean isPersistent(String className)
Determines if the specified className represents a persistence capable class. A class is persistence capable only if it is directly marked as such -- not by inheritance.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class name represents a persistence capable class; false otherwise.

isPersistent

public boolean isPersistent(String className,
                            ClassLoader classLoader)
Determines if the specified className represents a persistence capable class. A class is persistence capable only if it is directly marked as such -- not by inheritance.

Parameters:
className - the fully qualified name of the class to be checked
classLoader - the class loader used to find mapping information
Returns:
true if this class name represents a persistence capable class; false otherwise.

isPersistenceCapableAllowed

public boolean isPersistenceCapableAllowed(String className)
Determines if the specified className represents a legal candidate for becoming a persistence capable class. A class may not become persistence capable if it is declared as static or abstract, an interface, a subclass of another persistence capable class (either direct or indirect), an exception subclass, or a subclass of ejb, swing, awt, or applet classes.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class name represents a legal candidate for becoming a persistence capable class; false otherwise.
See Also:
getModifiersForClass(java.lang.String), isInterface(java.lang.String), findPenultimateSuperclass(java.lang.String)

getResourceNameWithExtension

protected String getResourceNameWithExtension(String className)
Computes the mapping file resource name (with extension) for the supplied class name by converting the package name to a resource name.

Parameters:
className - the fully qualified name of the class
Returns:
the mapping file resource name (with extension) for the supplied class name
See Also:
MappingClassElement.MAPPING_EXTENSION

getResourceName

protected String getResourceName(String className)
Computes the base resource name (without extension) for the supplied class name by converting the package name to a resource name.

Parameters:
className - the fully qualified name of the class
Returns:
the base resource name (without extension) for the supplied class name

getFileNameWithExtension

protected String getFileNameWithExtension(String className)
Computes the mapping file name (with extension) for the supplied class name by converting the package name to a path name.

Parameters:
className - the fully qualified name of the class
Returns:
the mapping file name (with extension) for the supplied class name
See Also:
getFileName(java.lang.String), MappingClassElement.MAPPING_EXTENSION

getFileName

protected String getFileName(String className)
Computes the base file name (without extension) for the supplied class name by converting the package name to a path name.

Parameters:
className - the fully qualified name of the class
Returns:
the base file name (without extension) for the supplied class name

convertToPersistenceCapable

public void convertToPersistenceCapable(String className,
                                        boolean flag)
                                 throws IOException
Converts the class with the supplied name to or from persistence capable depending on the flag.

Parameters:
className - the fully qualified name of the class
flag - if true, convert this class to be persistence capable, if false, convert this class to be non-persistence capable
Throws:
IOException - if there is some error converting the class

convertToPersistenceCapable

public void convertToPersistenceCapable(String className)
                                 throws IOException
Converts the class with the supplied name to persistence-capable, then convert its default fields and save it to the xml file.

Parameters:
className - the fully qualified name of the class
Throws:
IOException - if there is some error storing the class

convertDefaultFields

public void convertDefaultFields(String className)
Adds the default allowable persistent fields to the persistent class with the specified name. This is the second phase of converting a class to be persistence-capable.

Parameters:
className - the fully qualified name of the class
See Also:
createSkeletonMappingClass(java.lang.String), convertFields(java.lang.String, java.util.List)

convertFields

public void convertFields(String className,
                          List fields)
Adds the allowable persistent fields from the supplied list to the persistent class with the specified name.

Parameters:
className - the fully qualified name of the class
fields - a list of (short) field names
See Also:
convertDefaultFields(java.lang.String)

addFieldElement

public boolean addFieldElement(PersistenceClassElement element,
                               String fieldName)
Adds a PersistenceFieldElement for the specified field to the supplied PersistenceClassElement, creating a RelationshipElement if necessary.

Parameters:
element - the persistence class element to be used
fieldName - the name of the field to be added

removeFieldElement

public void removeFieldElement(PersistenceFieldElement element)
                        throws ModelException
Removes the specified PersistenceFieldElement from its declaring class. This method is added so that there is a common way to do this which checks if the argument is a relationship element with an inverse (in which case the inverse should first be cleared). This should really be handled by the jdo model directly, but the removeField method doesn't have access to the Model which is necessary for setting (or clearing) inverse relationships.

Parameters:
element - the persistence field element to be removed
Throws:
ModelException - if there is some error removing the field

getRelatedClass

public String getRelatedClass(RelationshipElement element)
Gets the name of the related class for a relationship element. This method is added so that there is a common way to do this. It checks if the argument is a collection relationship element (in which case the element class should be returned) or not (in which case the type should be returned). This should really be handled by the jdo model directly, but it doesn't have access to the Model which is necessary for finding the field type and whether it is a collection or not.

Parameters:
element - the relationship element to be examined
Returns:
the name of the related class

getSupportedCollectionClasses

public ArrayList getSupportedCollectionClasses(String className)
Computes the list of names of the possible collection classes for the specified class.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
an array of supported collection classes for the specified class name.
See Also:
getFieldType(java.lang.String, java.lang.String), getDefaultCollectionClass(java.lang.String)

getDefaultCollectionClass

public String getDefaultCollectionClass(String className)
Returns the default collection class for the specified class. If the specified class is an unspecified Collection type, the return will be HashSet.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
the name of the default supported collection class for the specified class name.
See Also:
getFieldType(java.lang.String, java.lang.String), getSupportedCollectionClasses(java.lang.String)

createFile

protected abstract 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).

Parameters:
className - the fully qualified name of the class
baseFileName - the name of the base file
extension - 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 abstract void deleteFile(String className,
                                   String fileName)
                            throws IOException
Deletes the file with the given file name which is parallel to the supplied class.

Parameters:
className - the fully qualified name of the class
fileName - the name of the file
Throws:
IOException - if there is some error deleting the file

getFields

public abstract List getFields(String className)
Returns a list of names of all the declared field elements in the class with the specified name.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
the names of the field elements for the specified class

getAllFields

public List getAllFields(String className)
Returns a list of names of all the field elements in the class with the specified name. This list includes the inherited fields.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
the names of the field elements for the specified class

getClass

public Object getClass(String className)
Returns the class element with the specified className.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
the class element for the specified className

getClass

public abstract Object getClass(String className,
                                ClassLoader classLoader)
Returns the class element with the specified className.

Parameters:
className - the fully qualified name of the class to be checked
classLoader - the class loader used to find mapping information
Returns:
the class element for the specified className

hasClass

public boolean hasClass(String className)
Determines if a class with the specified className exists.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class name represents a valid class; false otherwise.

hasClass

public boolean hasClass(String className,
                        ClassLoader classLoader)
Determines if a class with the specified className exists.

Parameters:
className - the fully qualified name of the class to be checked
classLoader - the class loader used to find mapping information
Returns:
true if this class name represents a valid class; false otherwise.

implementsInterface

public abstract 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.

Parameters:
classElement - the class element to be checked
interfaceName - 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)

hasConstructor

public abstract boolean hasConstructor(String className)
Determines if the class with the specified name declares a constructor.

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)

getConstructor

public abstract 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.

Parameters:
className - the name of the class which contains the constructor to be checked
argTypeNames - the fully qualified names of the argument types
Returns:
the constructor element
See Also:
getClass(java.lang.String)

getMethod

public abstract 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.

Parameters:
className - the name of the class which contains the method to be checked
methodName - the name of the method to be checked
argTypeNames - the fully qualified names of the argument types
Returns:
the method element
See Also:
getClass(java.lang.String)

getInheritedMethod

public Object getInheritedMethod(String className,
                                 String methodName,
                                 String[] argTypeNames)
Returns the inherited 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 that the class with the specified className is not checked for this method, only superclasses are checked.

Parameters:
className - the name of the class which contains the method to be checked
methodName - the name of the method to be checked
argTypeNames - the fully qualified names of the argument types
Returns:
the method element
See Also:
getClass(java.lang.String)

getType

public abstract 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.

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[])

getField

public abstract Object getField(String className,
                                String fieldName)
Returns the field element for the specified fieldName in the class with the specified className.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
the field element for the specified fieldName

getInheritedField

public Object getInheritedField(String className,
                                String fieldName)
Returns the inherited field element for the specified fieldName in the class with the specified className. Note that the class with the specified className is not checked for this field, only superclasses are checked.

Parameters:
className - the fully qualified name of the class which contains a superclass with the field to be checked
fieldName - the name of the field to be checked
Returns:
the field element for the specified fieldName

hasField

public boolean hasField(String className,
                        String fieldName)
Determines if a field with the specified fieldName exists in the class with the specified className.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a valid field; false otherwise.

getFieldType

public String getFieldType(String className,
                           String fieldName)
Returns the field type for the specified fieldName in the class with the specified className.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
the field type for the specified fieldName

isSerializable

public abstract 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.

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)

isPrimitive

public boolean isPrimitive(String className,
                           String fieldName)
Determines if a field with the specified fieldName in the class with the specified className has a primitive type.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a primitive field; false otherwise.
See Also:
getFieldType(java.lang.String, java.lang.String)

isPrimitive

protected boolean isPrimitive(String className)
Determines if the specified className represents a primitive type.

Parameters:
className - the fully qualified name of the class or type to be checked
Returns:
true if this class represents a primitive; false otherwise.
See Also:
getFieldType(java.lang.String, java.lang.String)

isArray

public abstract boolean isArray(String className,
                                String fieldName)
Determines if a field with the specified fieldName in the class with the specified className is an array.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a java array field; false otherwise.
See Also:
getFieldType(java.lang.String, java.lang.String)

isByteArray

public boolean isByteArray(String className,
                           String fieldName)
Determines if a field with the specified fieldName in the class with the specified className is a byte array.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a byte array field; false otherwise.
See Also:
getFieldType(java.lang.String, java.lang.String)

isByteArray

protected boolean isByteArray(String className)
Determines if the specified className represents a byte array.

Parameters:
className - the fully qualified name of the class or type to be checked
Returns:
true if this class represents a byte array; false otherwise.

isCollection

public boolean isCollection(String className)
Determines if the class name represents a collection.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class represents a collection; false otherwise.
See Also:
getFieldType(java.lang.String, java.lang.String)

isSecondClassObject

public boolean isSecondClassObject(String className)
Determines if the specified className represents a second class object. For this release, the class name is checked against a list of supported second class objects since user-defined second class objects are not supported.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class represents a second class object; false otherwise.
See Also:
isMutableSecondClassObject(java.lang.String), isCollection(java.lang.String), getFieldType(java.lang.String, java.lang.String)

isMutableSecondClassObject

public boolean isMutableSecondClassObject(String className)
Determines if the specified className represents a mutable second class object. For this release, the class name is checked against a list of supported mutable second class objects since user-defined second class objects are not supported.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if this class represents a mutable second class object; false otherwise.
See Also:
isSecondClassObject(java.lang.String), isCollection(java.lang.String), getFieldType(java.lang.String, java.lang.String)

getDeclaringClass

public abstract 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.

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), 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 abstract 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.

Parameters:
memberElement - the member element to be checked
Returns:
the modifier mask for the specified memberElement
See Also:
Modifier, getClass(java.lang.String), getField(java.lang.String, java.lang.String), getConstructor(java.lang.String, java.lang.String[]), getMethod(java.lang.String, java.lang.String, java.lang.String[])

getModifiersForClass

public int getModifiersForClass(String className)
Returns the modifier mask for the specified className.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
the modifier mask for the specified class
See Also:
Modifier

getModifiers

protected int getModifiers(String className,
                           String fieldName)
Returns the modifier mask for the specified fieldName in the class with the specified className.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
the modifier mask for the specified field
See Also:
Modifier

isPersistentAllowed

public boolean isPersistentAllowed(String className,
                                   String fieldName)
Returns true if the specified field can be made persistent, false otherwise. This computation is based on the modifier and type of the field. Fields which are non-final and non-static and are primitive, persistence capable, or second class objects and not arrays return true.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
whether the specified field can be made persistent
See Also:
getModifiers(String,String), isPrimitive(java.lang.String, java.lang.String), isArray(java.lang.String, java.lang.String), isPersistent(java.lang.String), isSecondClassObject(java.lang.String), shouldBePersistent(java.lang.String, java.lang.String)

isPersistentAllowed

public boolean isPersistentAllowed(String className,
                                   ClassLoader classLoader,
                                   String fieldName)
Returns true if the specified field can be made persistent, false otherwise. This computation is based on the modifier and type of the field. Fields which are non-final and non-static and are primitive, persistence capable, byte arrays, or second class objects and not arrays return true.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
classLoader - the class loader used to find mapping information
fieldName - the name of the field to be checked
Returns:
whether the specified field can be made persistent
See Also:
getModifiers(String,String), getFieldType(java.lang.String, java.lang.String), isPersistentTypeAllowed(java.lang.String, java.lang.ClassLoader), shouldBePersistent(java.lang.String, java.lang.String)

isPersistentTypeAllowed

protected boolean isPersistentTypeAllowed(String className,
                                          ClassLoader classLoader)
Returns true if the a field of the specified class or type can be made persistent, false otherwise. Fields which are primitive, persistence capable, byte arrays, or second class objects and not arrays return true.

Parameters:
className - the fully qualified name of the class or type to be checked
classLoader - the class loader used to find mapping information
Returns:
true if this class represents a type which can be made persistent; false otherwise.
See Also:
isPrimitive(java.lang.String, java.lang.String), isByteArray(java.lang.String, java.lang.String), isPersistent(java.lang.String), isSecondClassObject(java.lang.String)

shouldBePersistent

public boolean shouldBePersistent(String className,
                                  String fieldName)
Returns true if the specified field should be made persistent (i.e. does it make sense), false otherwise. This computation is based solely on the modifier: those which are not volatile return true.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
whether the specified field should be made persistent see #getModifiers(String,String)

getPersistenceField

public PersistenceFieldElement getPersistenceField(String className,
                                                   String fieldName)
Returns the PersistenceFieldElement with the supplied fieldName found in the supplied className.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
the PersistenceFieldElement for the specified field, null if an error occurs or none exists

getPersistenceFieldInternal

protected PersistenceFieldElement getPersistenceFieldInternal(String className,
                                                              String fieldName)
Returns the PersistenceFieldElement with the supplied fieldName found in the supplied className.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
the PersistenceFieldElement for the specified field, null if an error occurs or none exists

isPersistent

public boolean isPersistent(String className,
                            String fieldName)
Determines if the specified className and fieldName pair represent a persistent field.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a persistent field; false otherwise.

isKey

public boolean isKey(String className,
                     String fieldName)
Determines if the specified className and fieldName pair represent a key field.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a key field; false otherwise.

isValidKeyType

public boolean isValidKeyType(String className,
                              String fieldName)
Determines if the specified className and fieldName pair represent a field which has a type which is valid for key fields. Valid key field types include non-collection SCOs (wrappers, Date, Time, etc.) and primitives.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a field with a valid type for a key field; false otherwise.

isDefaultFetchGroup

public boolean isDefaultFetchGroup(String className,
                                   String fieldName)
Determines if the specified className and fieldName pair represent a field which is part of the default fetch group.

Parameters:
className - the fully qualified name of the class which contains the field to be checked
fieldName - the name of the field to be checked
Returns:
true if this field name represents a field in the default fetch group; false otherwise.

parse

public boolean parse(String className)
Parses the combination of java (or class) information and mapping/jdo information by running through a subset of the full validation check and aborting (and returning false at the first error or warning.

Parameters:
className - the fully qualified name of the class to be checked
Returns:
true if no errors or warnings occur, false otherwise.

validate

public Collection validate(String className,
                           ResourceBundle bundle)
Validates the combination of java (or class) information and mapping/jdo information by running through the full validation check and returning a collection of ModelValidationExceptions containing any errors or warnings encountered.

Parameters:
className - the fully qualified name of the class to be checked
bundle - the overridden resource bundle file - specify null if the default one should be used
Returns:
a collection of ModelValidationExceptions containing any errors or warnings encountered. If no errors or warnings were encountered, the collection will be empty, not null.

validate

public Collection validate(String className,
                           ClassLoader classLoader,
                           ResourceBundle bundle)
Validates the combination of java (or class) information and mapping/jdo information by running through the full validation check and returning a collection of ModelValidationExceptions containing any errors or warnings encountered.

Parameters:
className - the fully qualified name of the class to be checked
classLoader - the class loader used to find mapping information
bundle - the overridden resource bundle file - specify null if the default one should be used
Returns:
a collection of ModelValidationExceptions containing any errors or warnings encountered. If no errors or warnings were encountered, the collection will be empty, not null.

getReadObjectArgs

public static String[] getReadObjectArgs()
Standard set of arguments for comparison with readObject method.


getEqualsArgs

public static String[] getEqualsArgs()
Standard set of arguments for comparison with equals method.


getWriteObjectArgs

public static String[] getWriteObjectArgs()
Standard set of arguments for comparison with writeObject method.



Copyright © 2012 GlassFish Community. All Rights Reserved.