Class DeploymentDescriptorModel


  • public class DeploymentDescriptorModel
    extends 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
    • Field Detail

      • SIGNATURE

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

      • 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 Detail

      • 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. This method overrides the one in RuntimeModel to enforce using the class loader provided at construction time instead of the one specified in this method.
        Overrides:
        getInputStreamForResource in class RuntimeModel
        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 This parameter is ignored in this implementation - instead the class loader supplied at construction time is used.
        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
      • 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 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 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 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 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 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 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:
        getClass(java.lang.String, java.lang.ClassLoader)
      • 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 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:
        getClass(java.lang.String, java.lang.ClassLoader)
      • 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 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:
        getClass(java.lang.String, java.lang.ClassLoader)
      • 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 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 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 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 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
      • 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 Model
        Parameters:
        className - the fully qualified name of the class to be checked
        Returns:
        the modifier mask for the specified class
        See Also:
        Modifier
      • 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 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.
      • 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 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