org.hibernate.tool.hbm2x.pojo
Class BasicPOJOClass

java.lang.Object
  extended by org.hibernate.tool.hbm2x.pojo.BasicPOJOClass
All Implemented Interfaces:
MetaAttributeConstants, ImportContext, POJOClass
Direct Known Subclasses:
ComponentPOJOClass, EntityPOJOClass

public abstract class BasicPOJOClass
extends Object
implements POJOClass, MetaAttributeConstants

Abstract implementation of POJOClass. To be extended by ComponentPOJO and EntityPOJO

Author:
max, Amit Bhayani

Field Summary
protected  Cfg2JavaTool c2j
           
protected  ImportContext importContext
           
protected  org.hibernate.mapping.MetaAttributable meta
           
 
Fields inherited from interface org.hibernate.tool.hbm2x.MetaAttributeConstants
CLASS_DESCRIPTION, CLASS_MODIFIER, EXTENDS, GEN_PROPERTY, GENERATED_CLASS, IMPLEMENTS, INTERFACE, SCOPE_CLASS
 
Constructor Summary
BasicPOJOClass(org.hibernate.mapping.MetaAttributable ma, Cfg2JavaTool c2j)
           
 
Method Summary
protected  void appendCommonColumnInfo(StringBuffer annotations, org.hibernate.mapping.Column column, boolean insertable, boolean updatable)
           
static String beanCapitalize(String fieldname)
          foo -> Foo FOo -> FOo
 String generateAnnColumnAnnotation(org.hibernate.mapping.Property property)
           
 String generateBasicAnnotation(org.hibernate.mapping.Property property)
           
 String generateEquals(String thisName, String otherName, boolean useGenerics)
           
protected  String generateEquals(String thisName, String otherName, Iterator allPropertiesIterator, boolean useGenerics)
           
 String generateHashCode(org.hibernate.mapping.Property property, String result, String thisName, boolean jdk5)
           
 String generateImports()
           
abstract  Iterator getAllPropertiesIterator()
          returns the properties that would be visible on this entity as a pojo.
 String getClassJavaDoc(String fallback, int indent)
          Returns the javadoc associated with the class.
 String getClassModifiers()
           
 String getCollectionNameFor(org.hibernate.mapping.Property property)
           
 String getDeclarationName()
           
 String getDeclarationType()
           
 Iterator getEqualsHashCodePropertiesIterator()
           
abstract  String getExtends()
           
 String getExtendsDeclaration()
           
 String getExtraClassCode()
           
 String getFieldDescription(org.hibernate.mapping.Property property)
           
 String getFieldInitialization(org.hibernate.mapping.Property p, boolean useGenerics)
           
 String getFieldJavaDoc(org.hibernate.mapping.Property property, int indent)
           
 String getFieldModifiers(org.hibernate.mapping.Property property)
           
protected  String getGeneratedClassName()
           
 String getGetterSignature(org.hibernate.mapping.Property p)
          Method getGetterSignature.
abstract  String getImplements()
           
 String getImplementsDeclaration()
           
 String getJavaTypeName(org.hibernate.mapping.Property p, boolean useGenerics)
           
protected abstract  String getMappedClassName()
           
 boolean getMetaAsBool(String attribute)
           
 boolean getMetaAsBool(String attribute, boolean defaultValue)
           
 String getMetaAsString(String attribute)
           
 String getMetaAsString(String attribute, String seperator)
           
 boolean getMetaAttribAsBool(org.hibernate.mapping.MetaAttributable pc, String attribute, boolean defaultValue)
           
 String getPackageDeclaration()
          Returns "package packagename;" where packagename is either the declared packagename, or the one provide via meta attribute "generated-class".
protected  String getPackageDeclaration(String pkgName)
           
 String getPackageName()
          Return package name.
 String getPropertyGetModifiers(org.hibernate.mapping.Property property)
           
 String getPropertyName(org.hibernate.mapping.Property p)
           
 String getPropertySetModifiers(org.hibernate.mapping.Property property)
           
 String getQualifiedDeclarationName()
           
 String getShortName()
           
 Iterator getToStringPropertiesIterator()
           
 boolean hasFieldInitializor(org.hibernate.mapping.Property p, boolean useGenerics)
           
 boolean hasFieldJavaDoc(org.hibernate.mapping.Property property)
           
 boolean hasMetaAttribute(org.hibernate.mapping.MetaAttributable pc, String attribute)
           
 boolean hasMetaAttribute(String attribute)
           
 String importType(String fqcn)
          Add fqcn to the import list.
protected  void init()
           
 boolean isComponent(org.hibernate.mapping.Property property)
           
 boolean isInterface()
           
protected  boolean isRequiredInConstructor(org.hibernate.mapping.Property field)
           
 boolean needsEqualsHashCode()
           
 boolean needsFullConstructor()
           
 boolean needsMinimalConstructor()
           
 boolean needsToString()
           
protected  String qualifyInnerClass(String className)
           
 String staticImport(String fqcn, String member)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.hibernate.tool.hbm2x.pojo.POJOClass
generateAnnIdGenerator, generateAnnTableUniqueConstraint, getDecoratedObject, getIdentifierProperty, getPropertiesForFullConstructor, getPropertiesForMinimalConstructor, getPropertyClosureForFullConstructor, getPropertyClosureForMinimalConstructor, getPropertyClosureForSuperclassFullConstructor, getPropertyClosureForSuperclassMinimalConstructor, getSuperClass, getVersionProperty, hasIdentifierProperty, hasVersionProperty, isComponent, isSubclass
 

Field Detail

importContext

protected ImportContext importContext

meta

protected org.hibernate.mapping.MetaAttributable meta

c2j

protected final Cfg2JavaTool c2j
Constructor Detail

BasicPOJOClass

public BasicPOJOClass(org.hibernate.mapping.MetaAttributable ma,
                      Cfg2JavaTool c2j)
Method Detail

init

protected void init()

getPackageDeclaration

protected String getPackageDeclaration(String pkgName)

getPackageDeclaration

public String getPackageDeclaration()
Description copied from interface: POJOClass
Returns "package packagename;" where packagename is either the declared packagename, or the one provide via meta attribute "generated-class". Returns "// default package" if no package declarition available.

Specified by:
getPackageDeclaration in interface POJOClass
Returns:

getPackageName

public String getPackageName()
Return package name. Note: Does not handle inner classes

Specified by:
getPackageName in interface POJOClass

getShortName

public String getShortName()
Specified by:
getShortName in interface POJOClass

getQualifiedDeclarationName

public String getQualifiedDeclarationName()
Specified by:
getQualifiedDeclarationName in interface POJOClass

getDeclarationName

public String getDeclarationName()
Specified by:
getDeclarationName in interface POJOClass
Returns:
unqualified classname for this class (can be changed by meta attribute "generated-class")

getGeneratedClassName

protected String getGeneratedClassName()

qualifyInnerClass

protected String qualifyInnerClass(String className)

getMappedClassName

protected abstract String getMappedClassName()

getMetaAsString

public String getMetaAsString(String attribute)

hasMetaAttribute

public boolean hasMetaAttribute(String attribute)

getMetaAsString

public String getMetaAsString(String attribute,
                              String seperator)

getMetaAsBool

public boolean getMetaAsBool(String attribute)

getMetaAsBool

public boolean getMetaAsBool(String attribute,
                             boolean defaultValue)

getClassJavaDoc

public String getClassJavaDoc(String fallback,
                              int indent)
Description copied from interface: POJOClass
Returns the javadoc associated with the class.

Specified by:
getClassJavaDoc in interface POJOClass
Parameters:
fallback - the default text if nothing else is found
indent - how many spaces should be added
Returns:

getClassModifiers

public String getClassModifiers()
Specified by:
getClassModifiers in interface POJOClass

getDeclarationType

public String getDeclarationType()
Specified by:
getDeclarationType in interface POJOClass
Returns:
declaration type "interface" or "class"

isInterface

public boolean isInterface()
Specified by:
isInterface in interface POJOClass

getExtendsDeclaration

public String getExtendsDeclaration()
Specified by:
getExtendsDeclaration in interface POJOClass

getImplementsDeclaration

public String getImplementsDeclaration()
Specified by:
getImplementsDeclaration in interface POJOClass

generateEquals

public String generateEquals(String thisName,
                             String otherName,
                             boolean useGenerics)
Specified by:
generateEquals in interface POJOClass

getAllPropertiesIterator

public abstract Iterator getAllPropertiesIterator()
returns the properties that would be visible on this entity as a pojo. This does not return *all* properties since hibernate has certain properties that are only relevant in context of persistence.

Specified by:
getAllPropertiesIterator in interface POJOClass

generateEquals

protected String generateEquals(String thisName,
                                String otherName,
                                Iterator allPropertiesIterator,
                                boolean useGenerics)

getExtraClassCode

public String getExtraClassCode()
Specified by:
getExtraClassCode in interface POJOClass

needsEqualsHashCode

public boolean needsEqualsHashCode()
Specified by:
needsEqualsHashCode in interface POJOClass

getExtends

public abstract String getExtends()
Specified by:
getExtends in interface POJOClass

getImplements

public abstract String getImplements()
Specified by:
getImplements in interface POJOClass

importType

public String importType(String fqcn)
Description copied from interface: ImportContext
Add fqcn to the import list. Returns fqcn as needed in source code. Attempts to handle fqcn with array and generics references. e.g. java.util.Collection imports java.util.Collection and returns Collection org.marvel.Hulk[] imports org.marvel.Hulk and returns Hulk

Specified by:
importType in interface ImportContext
Returns:
import string

generateImports

public String generateImports()
Specified by:
generateImports in interface ImportContext

staticImport

public String staticImport(String fqcn,
                           String member)
Specified by:
staticImport in interface ImportContext

generateBasicAnnotation

public String generateBasicAnnotation(org.hibernate.mapping.Property property)
Specified by:
generateBasicAnnotation in interface POJOClass

generateAnnColumnAnnotation

public String generateAnnColumnAnnotation(org.hibernate.mapping.Property property)
Specified by:
generateAnnColumnAnnotation in interface POJOClass

appendCommonColumnInfo

protected void appendCommonColumnInfo(StringBuffer annotations,
                                      org.hibernate.mapping.Column column,
                                      boolean insertable,
                                      boolean updatable)

getToStringPropertiesIterator

public Iterator getToStringPropertiesIterator()
Specified by:
getToStringPropertiesIterator in interface POJOClass

getEqualsHashCodePropertiesIterator

public Iterator getEqualsHashCodePropertiesIterator()
Specified by:
getEqualsHashCodePropertiesIterator in interface POJOClass

needsToString

public boolean needsToString()
Specified by:
needsToString in interface POJOClass

hasMetaAttribute

public boolean hasMetaAttribute(org.hibernate.mapping.MetaAttributable pc,
                                String attribute)

getMetaAttribAsBool

public boolean getMetaAttribAsBool(org.hibernate.mapping.MetaAttributable pc,
                                   String attribute,
                                   boolean defaultValue)

hasFieldJavaDoc

public boolean hasFieldJavaDoc(org.hibernate.mapping.Property property)

getFieldJavaDoc

public String getFieldJavaDoc(org.hibernate.mapping.Property property,
                              int indent)
Specified by:
getFieldJavaDoc in interface POJOClass

getFieldDescription

public String getFieldDescription(org.hibernate.mapping.Property property)
Specified by:
getFieldDescription in interface POJOClass

getGetterSignature

public String getGetterSignature(org.hibernate.mapping.Property p)
Method getGetterSignature.

Returns:
String

getPropertyName

public String getPropertyName(org.hibernate.mapping.Property p)
Parameters:
p -
Returns:
foo -> Foo, FOo -> FOo

getCollectionNameFor

public String getCollectionNameFor(org.hibernate.mapping.Property property)

beanCapitalize

public static String beanCapitalize(String fieldname)
foo -> Foo FOo -> FOo


isComponent

public boolean isComponent(org.hibernate.mapping.Property property)

generateHashCode

public String generateHashCode(org.hibernate.mapping.Property property,
                               String result,
                               String thisName,
                               boolean jdk5)

getFieldModifiers

public String getFieldModifiers(org.hibernate.mapping.Property property)

getPropertyGetModifiers

public String getPropertyGetModifiers(org.hibernate.mapping.Property property)

getPropertySetModifiers

public String getPropertySetModifiers(org.hibernate.mapping.Property property)

isRequiredInConstructor

protected boolean isRequiredInConstructor(org.hibernate.mapping.Property field)

needsMinimalConstructor

public boolean needsMinimalConstructor()
Specified by:
needsMinimalConstructor in interface POJOClass

needsFullConstructor

public boolean needsFullConstructor()
Specified by:
needsFullConstructor in interface POJOClass

getJavaTypeName

public String getJavaTypeName(org.hibernate.mapping.Property p,
                              boolean useGenerics)
Specified by:
getJavaTypeName in interface POJOClass

hasFieldInitializor

public boolean hasFieldInitializor(org.hibernate.mapping.Property p,
                                   boolean useGenerics)

getFieldInitialization

public String getFieldInitialization(org.hibernate.mapping.Property p,
                                     boolean useGenerics)
Specified by:
getFieldInitialization in interface POJOClass