Class DeploymentDescriptorModel

java.lang.Object
com.sun.jdo.api.persistence.model.Model
com.sun.jdo.api.persistence.model.RuntimeModel
com.sun.jdo.spi.persistence.support.ejb.model.DeploymentDescriptorModel

public class DeploymentDescriptorModel extends com.sun.jdo.api.persistence.model.RuntimeModel
This is a subclass of RuntimeModel which uses the deployment descriptor to augment the java metadata for a non-existent persistence-capable java/class file. It is primarily used at ejbc time, though it could be used at any time as long as sufficient mapping and deployment descriptor information is available. See the javadoc for individual methods below for differences and translations between persistence-capable and ejb names and behavior. There are different answers to methods depending on whether they are called on the persistence-capable or the ejb. These are primarily for the handling of serializable, non-primitive, non-wrapper type fields: isByteArray, getFieldType (returning byte array), isPersistentTypeAllowed and isPersistentAllowed (returning true) which return answers about the byte array when called on the persistence-capable and return answers about the serializable type when called on the ejb.
Author:
Rochelle Raccah 2001
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Signature with CVS keyword substitution for identifying the generated code

    Fields inherited from class com.sun.jdo.api.persistence.model.Model

    ENHANCER, messageBase, NO_ARGS, RUNTIME
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of DeploymentDescriptorModel
  • Method Summary

    Modifier and Type
    Method
    Description
    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
    Returns the name of the second to top (top excluding java.lang.Object) superclass for the given class name.
    getAllFields(String className)
    Returns a list of names of all the field elements in the class with the specified name.
    getClass(String className, ClassLoader classLoader)
    Returns the class element with the specified className.
    getConstructor(String className, String[] argTypeNames)
    Returns a wrapped constructor element for the specified argument types in the class with the specified name.
    getDeclaringClass(Object memberElement)
    Returns the string representation of declaring class of the specified member element.
    getField(String className, String fieldName)
    Returns a wrapped field element for the specified fieldName in the class with the specified className.
    getFields(String className)
    Returns a list of names of all the declared field elements in the class with the specified name.
    getFieldType(String className, String fieldName)
    Returns the field type for the specified fieldName in the class with the specified className.
    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.
    getInputStreamForResource(String className, ClassLoader classLoader, String resourceName)
    getMethod(String className, String methodName, String[] argTypeNames)
    Returns a wrapped 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.
    int
    Returns the modifier mask for the specified className.
    protected String
    getSuperclass(String className)
    Returns the name of the superclass for the given class name.
    protected Class
    Returns the Class type of the specified element.
    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.

    Methods inherited from class com.sun.jdo.api.persistence.model.RuntimeModel

    getClassLoaderCache, getFile, getMappingClass, getType, hasConstructor, implementsInterface, isArray, isInterface, isSerializable, removeResourcesFromCaches

    Methods inherited from class com.sun.jdo.api.persistence.model.Model

    addFieldElement, convertDefaultFields, convertFields, convertToPersistenceCapable, convertToPersistenceCapable, getClass, getDefaultCollectionClass, getEqualsArgs, getFileName, getFileNameWithExtension, getInheritedField, getMappingCache, getMappingClass, getMessages, getModifiers, 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, lockFile, NewModel, parse, removeFieldElement, removeFromCache, removeResourcesFromCaches, shouldBePersistent, storeMappingClass, storeMappingClass, storeMappingClass, unlockFile, unlockFile, updateKeyForClass, validate, validate

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SIGNATURE

      public static final String SIGNATURE
      Signature with CVS keyword substitution for identifying the generated code
      See Also:
  • Constructor Details

    • DeploymentDescriptorModel

      public DeploymentDescriptorModel(NameMapper nameMapper, ClassLoader classLoader)
      Creates a new instance of DeploymentDescriptorModel
      Parameters:
      nameMapper - the name mapper to be used as a helper for translation between persistence class and ejb names.
      classLoader - the class loader object which is used for the application.
  • Method Details

    • getInputStreamForResource

      protected BufferedInputStream getInputStreamForResource(String className, ClassLoader classLoader, String resourceName)
      Overrides:
      getInputStreamForResource in class com.sun.jdo.api.persistence.model.RuntimeModel
      Parameters:
      classLoader - ignored parameter, using CL provided in constructor instead
    • 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. This method overrides the one in RuntimeModel in order to return the supplied className if it represents a persistence-capable class. This is because the persistence-capable classes don't mirror the inheritance hierarchy of the ejbs.
      Overrides:
      findPenultimateSuperclass in class com.sun.jdo.api.persistence.model.RuntimeModel
      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. This method overrides the one in RuntimeModel in order to return java.lang.Object if the supplied className represents a persistence-capable class. This is because the persistence-capable classes don't mirror the inheritance hierarchy of the ejbs.
      Overrides:
      getSuperclass in class com.sun.jdo.api.persistence.model.RuntimeModel
      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
    • 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). This method overrides the one in RuntimeModel and throws UnsupportedOperationException in the case where the file doesn't yet exist. If the file exists (even if it has just been "touched"), this method will return that output stream, but it is not capable of using the supplied class as a sibling location.
      Overrides:
      createFile in class com.sun.jdo.api.persistence.model.RuntimeModel
      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 void deleteFile(String className, String fileName) throws IOException
      Deletes the file with the given file name which is parallel to the supplied class. This method overrides the one in RuntimeModel and throws UnsupportedOperationException.
      Overrides:
      deleteFile in class com.sun.jdo.api.persistence.model.RuntimeModel
      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
    • getClass

      public Object getClass(String className, ClassLoader classLoader)
      Returns the class element with the specified className. If the specified className represents a persistence-capable class, the abstract bean class for the corresponding ejb is always returned (even if there is a Class object available for the persistence-capable). If there is an ejb name and an abstract bean class with the same name, the abstract bean class which is associated with the ejb will be returned, not the abstract bean class which corresponds to the supplied name (directly). If the specified className represents a persistence-capable key class name, the corresponding bean's key class is returned.
      Overrides:
      getClass in class com.sun.jdo.api.persistence.model.RuntimeModel
      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
    • getConstructor

      public Object getConstructor(String className, String[] argTypeNames)
      Returns a wrapped constructor element for the specified argument types in the class with the specified name. If the specified class name is a persistence-capable key class name which corresponds to a bean with an unknown primary key class a dummy constructor will also be returned. Types are specified as type names for primitive type such as int, float or as fully qualified class names.
      Overrides:
      getConstructor in class com.sun.jdo.api.persistence.model.RuntimeModel
      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:
    • getMethod

      public Object getMethod(String className, String methodName, String[] argTypeNames)
      Returns a wrapped method element for the specified method name and argument types in the class with the specified name. If the specified className represents a persistence-capable class and the requested methodName is readObject or writeObject, a dummy method will be returned. Similarly, if the specified class name is a persistence-capable key class name which corresponds to a bean with an unknown primary key class or a primary key field (in both cases there is no user defined primary key class) and the requested method is equals or hashCode, a dummy method will also be returned. 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.
      Overrides:
      getMethod in class com.sun.jdo.api.persistence.model.RuntimeModel
      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:
    • 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. This method overrides the one in Model in order to do special handling for a persistence-capable key class name which corresponds to a bean with a primary key field. In that case, we don't want to climb the inheritance of the primary key field type.
      Overrides:
      getInheritedMethod in class com.sun.jdo.api.persistence.model.Model
      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:
    • getFields

      public List getFields(String className)
      Returns a list of names of all the declared field elements in the class with the specified name. If the specified className represents a persistence-capable class, the list of field names from the corresponding ejb is returned (even if there is a Class object available for the persistence-capable).
      Overrides:
      getFields in class com.sun.jdo.api.persistence.model.RuntimeModel
      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. If the specified className represents a persistence-capable class, the list of field names from the corresponding ejb is returned (even if there is a Class object available for the persistence-capable). This method overrides the one in Model in order to do special handling for a persistence-capable key class name which corresponds to a bean with a primary key field. In that case, we don't want to climb the inheritance hierarchy of the primary key field type.
      Overrides:
      getAllFields in class com.sun.jdo.api.persistence.model.Model
      Parameters:
      className - the fully qualified name of the class to be checked
      Returns:
      the names of the field elements for the specified class
    • getField

      public Object getField(String className, String fieldName)
      Returns a wrapped field element for the specified fieldName in the class with the specified className. If the specified className represents a persistence-capable class, a field representing the field in the abstract bean class for the corresponding ejb is always returned (even if there is a Field object available for the persistence-capable). If there is an ejb name and an abstract bean class with the same name, the abstract bean class which is associated with the ejb will be used, not the abstract bean class which corresponds to the supplied name (directly).
      Overrides:
      getField in class com.sun.jdo.api.persistence.model.RuntimeModel
      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 wrapped field element for the specified fieldName
    • getFieldType

      public String getFieldType(String className, String fieldName)
      Returns the field type for the specified fieldName in the class with the specified className. This method is overrides the one in Model in order to do special handling for non-collection relationship fields. If it's a generated relationship that case, the returned MemberWrapper from getField contains a type of the abstract bean and it's impossible to convert that into the persistence capable class name, so here that case is detected, and if found, the ejb name is extracted and used to find the corresponding persistence capable class. For a relationship which is of type of the local interface, we do the conversion from local interface to persistence-capable class. In the case of a collection relationship (generated or not), the superclass' implementation which provides the java type is sufficient.
      Overrides:
      getFieldType in class com.sun.jdo.api.persistence.model.Model
      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
    • 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 or a wrapped member instance.
      Overrides:
      getDeclaringClass in class com.sun.jdo.api.persistence.model.RuntimeModel
      Parameters:
      memberElement - the member element to be checked
      Returns:
      the string representation of the declaring class of the specified memberElement
      See Also:
    • 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 member wrapper element as returned by getField or getMethod, a constructor element as returned by getConstructor executed on the same model instance. This implementation expects the member element being a reflection instance or a wrapped member instance.
      Overrides:
      getModifiers in class com.sun.jdo.api.persistence.model.RuntimeModel
      Parameters:
      memberElement - the member element to be checked
      Returns:
      the modifier mask for the specified memberElement
      See Also:
    • getModifiersForClass

      public int getModifiersForClass(String className)
      Returns the modifier mask for the specified className. This method overrides the one in Model to strip out the abstract modifier when the persistence capable class is represented by the abstract bean. It also adds the static modifier when the specified class represents the persistence capable key class which will be generated.
      Overrides:
      getModifiersForClass in class com.sun.jdo.api.persistence.model.Model
      Parameters:
      className - the fully qualified name of the class to be checked
      Returns:
      the modifier mask for the specified class
      See Also:
    • 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 for user defined key classes. This method overrides the one in Model in order to do special handling for a persistence-capable key class name which corresponds to a bean with a primary key field. In that case, we want to restrict the list of allowable types not to include primitives.
      Overrides:
      isValidKeyType in class com.sun.jdo.api.persistence.model.Model
      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.
    • 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.
      Overrides:
      getTypeObject in class com.sun.jdo.api.persistence.model.RuntimeModel
      Parameters:
      element - the element to be checked
      Returns:
      the Class type of the element
      See Also:
    • findClassLoader

      protected ClassLoader findClassLoader(String className, ClassLoader classLoader)
      This method returns the class loader used to find mapping information for the specified className. This implementation overrides the one in RuntimeModel so that it always returns the ClassLoader provided at construction time.
      Overrides:
      findClassLoader in class com.sun.jdo.api.persistence.model.RuntimeModel
      Parameters:
      className - the fully qualified name of the class to be checked
      classLoader - the class loader used to find mapping information
      Returns:
      the class loader used to find mapping information for the specified className