org.progeeks.hibernate
Class HibernateMappingGenerator

java.lang.Object
  extended by org.progeeks.hibernate.HibernateMappingGenerator

public class HibernateMappingGenerator
extends java.lang.Object

Class for generating a Hibernate mapping (*.hbm.xml) from annotated meta-classes.

Version:
$Revision: 1.7 $
Author:
Paul Wisneskey

Field Summary
protected static java.util.Map BASE_TYPE_MAPPINGS
          Mappings of basic property types to Hibernate types.
protected static java.lang.String CLASS_ELEMENT
          Class element name.
protected static java.lang.String CLASS_ENTITY_NAME
          Class entity-name attribute.
protected static java.lang.String EXTRACTION_ROOT_TAG
          Root tag of the transformed meta-class list document.
protected static java.lang.String EXTRACTION_XSL
          XSL used to extract only the meta-class definitions from the incoming XML configuration file.
protected static java.lang.String ID_ELEMENT
          Id element name.
protected static java.lang.String ID_GENERATOR_CLASS
          Generator class attribute.
protected static java.lang.String ID_GENERATOR_ELEMENT
          Generator element name used in the id element.
protected static java.lang.String ID_GENERATOR_PARAM
          Generator param element.
protected static java.lang.String ID_GENERATOR_PARAM_NAME
          Generator param element name.
protected static java.lang.String ID_NAME
           
protected static java.lang.String KEY_ELEMENT
          Key element.
protected static java.lang.String MAP_ELEMENT
          Map element.
protected static java.lang.String PROPERTY_ELEMENT
          Property element.
protected static java.lang.String PROPERTY_NAME
          Property element name.
protected static java.lang.String PUBLIC_ID
          Public id of the the Hibernate mapping XML.
protected static java.lang.String ROOT_TAG
          Root tag of the Hibernate configuration.
protected static java.lang.String[] STANDARD_IMPORTS
          Standard list of package imports for reading the meta-class objects from XML.
protected static java.lang.String SYSTEM_LITERAL
          System literal of the Hibernate mapping XML.
protected static java.lang.String VERSION_ATTRIBUTE
          Version attribute for the XML processing instruction.
protected static java.lang.String VERSION_VALUE
          Version value for the version attribute.
protected static java.lang.String XML_PROCESSING_INSTRUCTION
          XML processing instruction used in the output XML.
 
Constructor Summary
HibernateMappingGenerator()
           
 
Method Summary
protected static java.lang.String determineHibernatePropertyType(PropertyType type)
          Determinates the appropriate hibernate type as best as it can from the property type.
protected static void generateClassElement(MetaClass metaClass, MetaObject classAnnotation, XmlPrintWriter xmlWriter)
          Generates the class Hibernate mapping XML element for an individual meta-class.
protected static void generateIdElement(PropertyInfo propertyInfo, MetaObject idAnnotation, XmlPrintWriter xmlWriter)
          Generates the id element (and its nested generator element) based on any id property annotations.
protected static void generateMapElement(PropertyInfo propertyInfo, MetaObject mapAnnotation, XmlPrintWriter xmlWriter)
          Generates the map element based on any map property annotations.
static void generateMapping(java.util.List metaClasses, java.io.Writer writer)
          Generates a hibernate XML mapping configuration from the supplied list of meta-classes.
protected static void generateNonPropertyElement(java.lang.String elementName, MetaObject element, XmlPrintWriter xmlWriter)
          Write out a general hibernate configuration element that is not linked to an individual property.
protected static void generatePropertyElement(PropertyInfo propertyInfo, MetaObject propertyAnnotation, XmlPrintWriter xmlWriter)
          Generates the property element based on any property property annotations.
static void main(java.lang.String[] args)
          Main method for generating a hibernate mapping from source XML.
protected static void writeAttribute(MetaObject annotation, java.lang.String propertyName, java.lang.Object defaultValue, XmlPrintWriter xmlWriter)
          Write an attribute out to the output XML with an optional default value if it has no value set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTRACTION_XSL

protected static final java.lang.String EXTRACTION_XSL
XSL used to extract only the meta-class definitions from the incoming XML configuration file. This is done so that the ObjectXmlReader does not have to try and instantiate the rest of the configuration since that might require all sorts of specialty handlers we don't know about. Note that this transformation also preserves all importPackage xml.config directives just in case they're for any annotation object classes.

See Also:
Constant Field Values

EXTRACTION_ROOT_TAG

protected static final java.lang.String EXTRACTION_ROOT_TAG
Root tag of the transformed meta-class list document.

See Also:
Constant Field Values

STANDARD_IMPORTS

protected static final java.lang.String[] STANDARD_IMPORTS
Standard list of package imports for reading the meta-class objects from XML.


XML_PROCESSING_INSTRUCTION

protected static final java.lang.String XML_PROCESSING_INSTRUCTION
XML processing instruction used in the output XML.

See Also:
Constant Field Values

VERSION_ATTRIBUTE

protected static final java.lang.String VERSION_ATTRIBUTE
Version attribute for the XML processing instruction.

See Also:
Constant Field Values

VERSION_VALUE

protected static final java.lang.String VERSION_VALUE
Version value for the version attribute.

See Also:
Constant Field Values

ROOT_TAG

protected static final java.lang.String ROOT_TAG
Root tag of the Hibernate configuration.

See Also:
Constant Field Values

PUBLIC_ID

protected static final java.lang.String PUBLIC_ID
Public id of the the Hibernate mapping XML.

See Also:
Constant Field Values

SYSTEM_LITERAL

protected static final java.lang.String SYSTEM_LITERAL
System literal of the Hibernate mapping XML.

See Also:
Constant Field Values

CLASS_ELEMENT

protected static final java.lang.String CLASS_ELEMENT
Class element name.

See Also:
Constant Field Values

CLASS_ENTITY_NAME

protected static final java.lang.String CLASS_ENTITY_NAME
Class entity-name attribute.

See Also:
Constant Field Values

ID_ELEMENT

protected static final java.lang.String ID_ELEMENT
Id element name.

See Also:
Constant Field Values

ID_NAME

protected static final java.lang.String ID_NAME
See Also:
Constant Field Values

ID_GENERATOR_ELEMENT

protected static final java.lang.String ID_GENERATOR_ELEMENT
Generator element name used in the id element.

See Also:
Constant Field Values

ID_GENERATOR_CLASS

protected static final java.lang.String ID_GENERATOR_CLASS
Generator class attribute.

See Also:
Constant Field Values

ID_GENERATOR_PARAM

protected static final java.lang.String ID_GENERATOR_PARAM
Generator param element.

See Also:
Constant Field Values

ID_GENERATOR_PARAM_NAME

protected static final java.lang.String ID_GENERATOR_PARAM_NAME
Generator param element name.

See Also:
Constant Field Values

PROPERTY_ELEMENT

protected static final java.lang.String PROPERTY_ELEMENT
Property element.

See Also:
Constant Field Values

PROPERTY_NAME

protected static final java.lang.String PROPERTY_NAME
Property element name.

See Also:
Constant Field Values

MAP_ELEMENT

protected static final java.lang.String MAP_ELEMENT
Map element.

See Also:
Constant Field Values

KEY_ELEMENT

protected static final java.lang.String KEY_ELEMENT
Key element.

See Also:
Constant Field Values

BASE_TYPE_MAPPINGS

protected static final java.util.Map BASE_TYPE_MAPPINGS
Mappings of basic property types to Hibernate types.

Constructor Detail

HibernateMappingGenerator

public HibernateMappingGenerator()
Method Detail

generateMapping

public static void generateMapping(java.util.List metaClasses,
                                   java.io.Writer writer)
                            throws java.io.IOException
Generates a hibernate XML mapping configuration from the supplied list of meta-classes.

Throws:
java.io.IOException

generateClassElement

protected static void generateClassElement(MetaClass metaClass,
                                           MetaObject classAnnotation,
                                           XmlPrintWriter xmlWriter)
Generates the class Hibernate mapping XML element for an individual meta-class.


generateIdElement

protected static void generateIdElement(PropertyInfo propertyInfo,
                                        MetaObject idAnnotation,
                                        XmlPrintWriter xmlWriter)
Generates the id element (and its nested generator element) based on any id property annotations.


generatePropertyElement

protected static void generatePropertyElement(PropertyInfo propertyInfo,
                                              MetaObject propertyAnnotation,
                                              XmlPrintWriter xmlWriter)
Generates the property element based on any property property annotations.


generateMapElement

protected static void generateMapElement(PropertyInfo propertyInfo,
                                         MetaObject mapAnnotation,
                                         XmlPrintWriter xmlWriter)
Generates the map element based on any map property annotations.


generateNonPropertyElement

protected static void generateNonPropertyElement(java.lang.String elementName,
                                                 MetaObject element,
                                                 XmlPrintWriter xmlWriter)
Write out a general hibernate configuration element that is not linked to an individual property. This is generated some type of nested configuration element.


determineHibernatePropertyType

protected static java.lang.String determineHibernatePropertyType(PropertyType type)
Determinates the appropriate hibernate type as best as it can from the property type. Currently only handles really basic conversions.


writeAttribute

protected static void writeAttribute(MetaObject annotation,
                                     java.lang.String propertyName,
                                     java.lang.Object defaultValue,
                                     XmlPrintWriter xmlWriter)
Write an attribute out to the output XML with an optional default value if it has no value set. If no default value is supplied and the property is not set, nothing will be output.


main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Main method for generating a hibernate mapping from source XML.

Throws:
java.lang.Exception


Copyright © 2002-2003 Paul Speed. All Rights Reserved.