org.objectweb.jorm.comp.generator.lib
Class CommonHelper

java.lang.Object
  |
  +--org.objectweb.jorm.comp.generator.lib.CommonHelper
All Implemented Interfaces:
Loggable
Direct Known Subclasses:
FileBindingMOP, FileMappingMOP, MemoryBindingMOP, MemoryMappingMOP, RdbCommonHelper

public class CommonHelper
extends java.lang.Object
implements Loggable

This class is a helper for the generation. All methods provided in this class are shortcut or facilties which simplify the generation.

Author:
Sebastien Chassande-Barrioz

Inner Class Summary
 class CommonHelper.PNGDesc
           
 
Field Summary
protected  org.objectweb.util.monolog.api.Logger logger
           
protected  org.objectweb.util.monolog.api.LoggerFactory loggerFactory
           
static PType[] PN_GET_TYPES
           
 
Constructor Summary
CommonHelper()
           
 
Method Summary
 boolean canBeNullValue(PType type)
           
 boolean containsCompositeName(Class c, CompilerParameter cp)
          This method allows to know if a class represented by its Class meta object, contains a composite PName.
 boolean containsCompositeReference(Class moc, CompilerParameter cp)
          This method tests if a class contains a composite reference.
 boolean containsGenClassRef(Class co)
          This method tests if a class references to a generic class.
 boolean containsReference(Class co)
          This method tests if a class contains a reference.
 boolean containsSerializedField(Class co)
          This method tests if a class contains a serialized field.
 java.util.Collection getCompositeNameDefEntries(NameDef mo)
          This method provides an iterator over the map entries which associated a composite field name (key) to the class field name (value).
 java.lang.String getFQNOfCompositeName(java.lang.Object o)
           
 org.objectweb.util.monolog.api.Logger getLogger()
          Its retrives the current logger.
 org.objectweb.util.monolog.api.LoggerFactory getLoggerFactory()
          Its retrives the current logger factory.
 java.lang.String getPaGetMethod(PType pt)
          This method does the conversion between a PType @pt and the getter function to use on a PAccessorGen (generic accessor).
 java.lang.String getPaSetMethod(PType pt)
          This method does the conversion between a PType @pt and the setter function to use on a PAccessorGen (generic accessor).
 java.lang.String getPNameDecodeFunction(PType pt)
          This method permits to find the right decode function either the PType specified by the parameter @pt.
 java.lang.String getPNameEncodeFunction(PType pt)
          This method permits to find the right encode function either the PType specified by the parameter @pt.
 java.lang.String getPNameGetterGetFunction(PType pt)
          This method permits to find the right pngetXField function either the PType specified by the parameter @pt.
 PType[] getPNGTypes()
           
 PrimitiveElement getPrimitiveElement(java.lang.Object mo, Class c, boolean canBeFieldName)
          This method allow to retrieve a primitive element from th meta object mo.
 java.lang.String getProjectionField(NameDef nd, java.lang.String cfn)
          This method provides the projection of the field name belonging to the class over a field name belonging to the composite name corresponding definition.
 PType getPType(java.lang.String ptn)
           
 PType getPTypeBigDecimal()
          Its retrieves the PType object which represents the BigDecimal jorm type.
 PType getPTypeBoolean()
          Its retrieves the PType object which represents the boolean jorm type.
 PType getPTypeByte()
          Its retrieves the PType object which represents the byte jorm type.
 PType getPTypeByteArray()
          Its retrieves the PType object which represents the bytearray jorm type.
 PType getPTypeChar()
          Its retrieves the PType object which represents the char jorm type.
 PType getPTypeCharArray()
          Its retrieves the PType object which represents the chararray jorm type.
 PType getPTypeDate()
          Its retrieves the PType object which represents the date jorm type.
 PType getPTypeDouble()
          Its retrieves the PType object which represents the double jorm type.
 PType getPTypeFloat()
          Its retrieves the PType object which represents the float jorm type.
 PType getPTypeInt()
          Its retrieves the PType object which represents the int jorm type.
 PType getPTypeLong()
          Its retrieves the PType object which represents the long jorm type.
 PType getPTypeOboolean()
          Its retrieves the PType object which represents the Boolean jorm type.
 PType getPTypeObyte()
          Its retrieves the PType object which represents the Byte jorm type.
 PType getPTypeOchar()
          Its retrieves the PType object which represents the Character jorm type.
 PType getPTypeOdouble()
          Its retrieves the PType object which represents the Double jorm type.
 PType getPTypeOfloat()
          Its retrieves the PType object which represents the Float jorm type.
 PType getPTypeOint()
          Its retrieves the PType object which represents the Integer jorm type.
 PType getPTypeOlong()
          Its retrieves the PType object which represents the Long jorm type.
 PType getPTypeOshort()
          Its retrieves the PType object which represents the Short jorm type.
 PType getPTypeReference()
          Its retrieves the PType object which represents a reference.
 PType getPTypeSerialized()
          Its retrieves the PType object which represents the serialized jorm type.
 PType getPTypeShort()
          Its retrieves the PType object which represents the short jorm type.
 PType getPTypeString()
          Its retrieves the PType object which represents the string jorm type.
 java.lang.String getSchemaName(MetaObject mo)
          This method retrieve the schema name for the meta object passed as parameter.
 boolean isClass(java.lang.Object o)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.Class
 boolean isClassRef(TypedElement te)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.ClassRef
 boolean isCompositeName(NameDef nd)
          This method checks if the NameDef is composed by several fields.
 boolean isFieldName(java.lang.Object o)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.FieldName
 boolean isGenClassRef(TypedElement te)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.GenClassRef
 boolean isHiddenField(Class c, PrimitiveElement pe)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.PrimitiveElement
 boolean isPrimitiveElement(java.lang.Object o)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.PrimitiveElement
 boolean isReference(TypedElement te)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.Reference
 boolean isSerializedField(java.lang.Object o)
          This method checks if the parameter designs a Serialized field.
 boolean isSerializedType(PType t)
          This method checks if the PType parameter designs a Serialized type.
 boolean isValidString(java.lang.String str)
          This method tests if a String is valid.
 java.util.Iterator iterateCompositeName(Class moc, CompilerParameter cp)
          This method return a SET containing the full name of compositename implied in the reference field of the class.
 java.util.ArrayList iterateCompositeReference(Class moc, CompilerParameter cp)
          This method return a list containing the nameref implied in composite reference field
 void setLogger(org.objectweb.util.monolog.api.Logger l)
          Its assigns a logger.
 void setLoggerFactory(org.objectweb.util.monolog.api.LoggerFactory lf)
          Its assigns a logger factory.
 java.lang.String upperFL(java.lang.String word)
          This methods returns the word specified in parameter with the first character in upper-case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

loggerFactory

protected org.objectweb.util.monolog.api.LoggerFactory loggerFactory

logger

protected org.objectweb.util.monolog.api.Logger logger

PN_GET_TYPES

public static final PType[] PN_GET_TYPES
Constructor Detail

CommonHelper

public CommonHelper()
Method Detail

upperFL

public java.lang.String upperFL(java.lang.String word)
This methods returns the word specified in parameter with the first character in upper-case. This method is used for the generation of accessor methods.
Parameters:
word - The String which the first character must be set in upper-case
Returns:
The String whith the first character in upper-case

getPrimitiveElement

public PrimitiveElement getPrimitiveElement(java.lang.Object mo,
                                            Class c,
                                            boolean canBeFieldName)
                                     throws PException
This method allow to retrieve a primitive element from th meta object mo. if this metaobject is a primitive element, it is returned itself. if this meta object is a single namedef the primitive element composing the namedef is returned. This method does not work with composite pname.
Returns:
the primitive element

containsReference

public boolean containsReference(Class co)
This method tests if a class contains a reference. A reference can be a designs a generic class or a class.
Parameters:
co - The meta object Class
Returns:
true if the class contains a reference.

containsCompositeReference

public boolean containsCompositeReference(Class moc,
                                          CompilerParameter cp)
                                   throws java.lang.Exception
This method tests if a class contains a composite reference. A reference can be a designs a generic class or a class.
Parameters:
moc - The meta object Class
Returns:
true if the class contains the namedef for the composite reference.

iterateCompositeReference

public java.util.ArrayList iterateCompositeReference(Class moc,
                                                     CompilerParameter cp)
                                              throws java.lang.Exception
This method return a list containing the nameref implied in composite reference field
Parameters:
moc - The meta object Class to be analysed.
cp - the compiler parameter
Returns:
an ArrayList which contains all nameref related to reference fields.

iterateCompositeName

public java.util.Iterator iterateCompositeName(Class moc,
                                               CompilerParameter cp)
                                        throws java.lang.Exception
This method return a SET containing the full name of compositename implied in the reference field of the class.
Parameters:
moc - The meta object Class
cp - the compiler parameter
Returns:
an iterator which contains all pname related to the Reference.

getSchemaName

public java.lang.String getSchemaName(MetaObject mo)
This method retrieve the schema name for the meta object passed as parameter. The meta object must be a child of a Schema MetaObject.
Parameters:
mo - The meta object
Returns:
the name of the schema if it exist, null otherwise.

containsSerializedField

public boolean containsSerializedField(Class co)
This method tests if a class contains a serialized field.
Parameters:
co - The meta object Class
Returns:
true if the class contains a serialized field.

isValidString

public boolean isValidString(java.lang.String str)
This method tests if a String is valid. A String is valid if it is not null and if the length is greater than 0.
Parameters:
str - The string which must be checked
Returns:
true if the string is valid

containsGenClassRef

public boolean containsGenClassRef(Class co)
This method tests if a class references to a generic class.
Parameters:
co - The meta object Class
Returns:
true if the class references a generic class.

isCompositeName

public boolean isCompositeName(NameDef nd)
This method checks if the NameDef is composed by several fields.
Parameters:
nd - the meta object NameDef which must be tested
Returns:
true if the NameDef is composed by several fields.

getCompositeNameDefEntries

public java.util.Collection getCompositeNameDefEntries(NameDef mo)
                                                throws java.lang.Exception
This method provides an iterator over the map entries which associated a composite field name (key) to the class field name (value). These map elements describe the projection of a name definition.
Parameters:
nd - the meta object NameDef which must be used

getFQNOfCompositeName

public java.lang.String getFQNOfCompositeName(java.lang.Object o)

containsCompositeName

public boolean containsCompositeName(Class c,
                                     CompilerParameter cp)
This method allows to know if a class represented by its Class meta object, contains a composite PName. This method analyzes the NameDef of the @c class parameter and the NameDef of all reference fields.

isClass

public boolean isClass(java.lang.Object o)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.Class
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of Class

isReference

public boolean isReference(TypedElement te)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.Reference
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of Reference

isClassRef

public boolean isClassRef(TypedElement te)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.ClassRef
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of ClassRef

isGenClassRef

public boolean isGenClassRef(TypedElement te)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.GenClassRef
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of GenClassRef

isPrimitiveElement

public boolean isPrimitiveElement(java.lang.Object o)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.PrimitiveElement
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of PrimitiveElement

isHiddenField

public boolean isHiddenField(Class c,
                             PrimitiveElement pe)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.PrimitiveElement
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of PrimitiveElement

isFieldName

public boolean isFieldName(java.lang.Object o)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.FieldName
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of FieldName

isSerializedField

public boolean isSerializedField(java.lang.Object o)
This method checks if the parameter designs a Serialized field.
Parameters:
o - the object which the type must be checked
Returns:
true the parameter is an instance of PrimitiveElement and if its PType is SERIALIZED.

isSerializedType

public boolean isSerializedType(PType t)
This method checks if the PType parameter designs a Serialized type.
Parameters:
o - the PType object which the type must be checked
Returns:
true the parameter is a PType.SERIALIZED.

getPaGetMethod

public java.lang.String getPaGetMethod(PType pt)
                                throws PException
This method does the conversion between a PType @pt and the getter function to use on a PAccessorGen (generic accessor).
Parameters:
pt - the ptype which helps to find the right paccessor method
Returns:
The string which represents the paccessor method associated to pt parameter

getPaSetMethod

public java.lang.String getPaSetMethod(PType pt)
                                throws PException
This method does the conversion between a PType @pt and the setter function to use on a PAccessorGen (generic accessor).
Parameters:
pt - the ptype which helps to find the right paccessor method
Returns:
The string which represents the paccessor method associated to pt parameter

getPNameDecodeFunction

public java.lang.String getPNameDecodeFunction(PType pt)
                                        throws PException
This method permits to find the right decode function either the PType specified by the parameter @pt. These functions name are available on a PName interface. Be carefull the only jorm types support for the naming are the scalar types (char, byte, short, int, long and string) !
Parameters:
pt - the ptype which helps to find the right decode method
Returns:
The string which represents the decode method associated to pt parameter

getPNameGetterGetFunction

public java.lang.String getPNameGetterGetFunction(PType pt)
                                           throws PException
This method permits to find the right pngetXField function either the PType specified by the parameter @pt. These functions name are available on a PNameGetter interface. Be carefull the only jorm types support for the naming are the scalar types (char, byte, short, int, long and string) !
Parameters:
pt - the ptype which helps to find the right pname getter method
Returns:
The string which represents the pname getter method associated to pt parameter

getPNameEncodeFunction

public java.lang.String getPNameEncodeFunction(PType pt)
                                        throws PException
This method permits to find the right encode function either the PType specified by the parameter @pt. These functions name are available on a PName interface. Be carefull the only jorm types support for the naming are the scalar types (char, byte, short, int, long and string) !
Parameters:
pt - the ptype which helps to find the right encode method
Returns:
The string which represents the encode method associated to pt parameter

getProjectionField

public java.lang.String getProjectionField(NameDef nd,
                                           java.lang.String cfn)
                                    throws java.lang.Exception
This method provides the projection of the field name belonging to the class over a field name belonging to the composite name corresponding definition.
Parameters:
nd - the meta object NameDef embeding a nameref with a projection.
cnf - the field name belonging to the pname in the class.
Returns:
the field name of the projection. this field name is a field belonging to the class.

getPType

public PType getPType(java.lang.String ptn)

getPTypeBoolean

public PType getPTypeBoolean()
Its retrieves the PType object which represents the boolean jorm type.

getPTypeOboolean

public PType getPTypeOboolean()
Its retrieves the PType object which represents the Boolean jorm type.

getPTypeChar

public PType getPTypeChar()
Its retrieves the PType object which represents the char jorm type.

getPTypeOchar

public PType getPTypeOchar()
Its retrieves the PType object which represents the Character jorm type.

getPTypeByte

public PType getPTypeByte()
Its retrieves the PType object which represents the byte jorm type.

getPTypeObyte

public PType getPTypeObyte()
Its retrieves the PType object which represents the Byte jorm type.

getPTypeShort

public PType getPTypeShort()
Its retrieves the PType object which represents the short jorm type.

getPTypeOshort

public PType getPTypeOshort()
Its retrieves the PType object which represents the Short jorm type.

getPTypeInt

public PType getPTypeInt()
Its retrieves the PType object which represents the int jorm type.

getPTypeOint

public PType getPTypeOint()
Its retrieves the PType object which represents the Integer jorm type.

getPTypeLong

public PType getPTypeLong()
Its retrieves the PType object which represents the long jorm type.

getPTypeOlong

public PType getPTypeOlong()
Its retrieves the PType object which represents the Long jorm type.

getPTypeFloat

public PType getPTypeFloat()
Its retrieves the PType object which represents the float jorm type.

getPTypeOfloat

public PType getPTypeOfloat()
Its retrieves the PType object which represents the Float jorm type.

getPTypeDouble

public PType getPTypeDouble()
Its retrieves the PType object which represents the double jorm type.

getPTypeOdouble

public PType getPTypeOdouble()
Its retrieves the PType object which represents the Double jorm type.

getPTypeString

public PType getPTypeString()
Its retrieves the PType object which represents the string jorm type.

getPTypeDate

public PType getPTypeDate()
Its retrieves the PType object which represents the date jorm type.

getPTypeCharArray

public PType getPTypeCharArray()
Its retrieves the PType object which represents the chararray jorm type.

getPTypeByteArray

public PType getPTypeByteArray()
Its retrieves the PType object which represents the bytearray jorm type.

getPTypeSerialized

public PType getPTypeSerialized()
Its retrieves the PType object which represents the serialized jorm type.

getPTypeBigDecimal

public PType getPTypeBigDecimal()
Its retrieves the PType object which represents the BigDecimal jorm type.

getPTypeReference

public PType getPTypeReference()
Its retrieves the PType object which represents a reference.

getPNGTypes

public PType[] getPNGTypes()

canBeNullValue

public boolean canBeNullValue(PType type)
                       throws PException

setLoggerFactory

public void setLoggerFactory(org.objectweb.util.monolog.api.LoggerFactory lf)
Its assigns a logger factory.
Specified by:
setLoggerFactory in interface Loggable
Following copied from interface: org.objectweb.jorm.util.api.Loggable
Parameters:
loggerfactory - the LoggerFactory object to obtain new loggers

setLogger

public void setLogger(org.objectweb.util.monolog.api.Logger l)
Its assigns a logger.
Specified by:
setLogger in interface Loggable
Following copied from interface: org.objectweb.jorm.util.api.Loggable
Parameters:
logger - the logger object

getLogger

public org.objectweb.util.monolog.api.Logger getLogger()
Its retrives the current logger.
Specified by:
getLogger in interface Loggable
Following copied from interface: org.objectweb.jorm.util.api.Loggable
Parameters:
logger - the logger object

getLoggerFactory

public org.objectweb.util.monolog.api.LoggerFactory getLoggerFactory()
Its retrives the current logger factory.
Specified by:
getLoggerFactory in interface Loggable
Following copied from interface: org.objectweb.jorm.util.api.Loggable
Parameters:
loggerfactory - the LoggerFactory object to obtain new loggers