org.objectweb.jorm.generator.lib
Class CommonHelper

java.lang.Object
  extended byTypeHelper
      extended byorg.objectweb.jorm.generator.lib.CommonHelper
All Implemented Interfaces:
Loggable
Direct Known Subclasses:
CommonJVMHelper, FosMappingMOP, MemBindingMOP, MemMappingMOP, NamingFilterExpressionHelper, RdbCommonHelper

public class CommonHelper
extends TypeHelper
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
See Also:
Serialized Form

Field Summary
protected  boolean debug
           
protected  Logger logger
           
protected  LoggerFactory loggerFactory
           
static PType[] PN_GET_TYPES
           
 
Constructor Summary
CommonHelper()
           
 
Method Summary
 PrimitiveElementMapping[] buildPemList(java.util.Collection pemcoll)
           
 boolean canBeNullValue(PType type)
           
 java.lang.String comparePE(java.lang.String val1, java.lang.String val2, PType type)
           
 boolean containsCharArrayField(Mapping m)
          This method tests if a class contains a char[] field.
 boolean containsCompositeName(Mapping mo)
          This method allows to know if a class represented by its Class meta object, contains a composite PName.
 boolean containsFieldWhichCanBeNull(Class co)
          This method tests if a class contains a serialized field.
 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.lang.String debug(java.lang.String msg)
           
 java.lang.String getCNPackageName(MetaObject mo)
          This method retrieve the package name for the meta object passed as parameter.
 java.lang.String getCoderName(PType t)
           
 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.util.ArrayList getCompositeReferences(Mapping mo)
          This method return a list containing the nameref implied in composite reference field
 java.lang.String getCTDeclaration(PType t)
           
 java.lang.String getFQNOfCompositeName(java.lang.Object o)
           
 java.lang.String getInheritedClasses(Class c)
          This method is a helper to reach the getInheritedClasses(Class, HashMap) method.
 Logger getLogger()
          Its retrives the current logger.
 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).
 int getPemPos(PrimitiveElementMapping[] pemlist, PrimitiveElement pe)
           
 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.
 PrimitiveElement getPrimitiveElement(java.lang.String fn, Class cl)
           
 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 getPTypeBigInteger()
          Its retrieves the PType object which represents the BigInteger 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.
 java.lang.String getPTypeSpaceFieldName(PType pt)
          Retrieves the name of the static field of the interface PTypeSpace corresponding to a PType.
 PType getPTypeString()
          Its retrieves the PType object which represents the string jorm type.
 NameDef getRefNameDef(Mapping mo, Reference field)
           
 java.lang.String getTupleDecoding(java.lang.String fn, PType pt, java.lang.String value)
           
 java.lang.String getTupleDecoding(java.lang.String tmpv, java.lang.String fn, java.lang.String tuplevn, PType pt, int pos)
          Builds the string representing the expression to decode a PName wrt the relevant tuple field having the right type.
 java.lang.String getTupleGetter(java.lang.String tuplevn, PType pt, int pos)
          Builds the string representing the expression to access the relevant tuple field having the right type.
 boolean isCharArrayType(PType t)
          This method checks if the PType parameter designs a Serialized type.
 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(PrimitiveElement pe)
          This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.PrimitiveElement
 boolean isNull(java.lang.Object o)
           
 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.lang.String log(java.lang.String msg)
           
 boolean not(boolean b)
           
 void setLogger(Logger l)
          Its assigns a logger.
 void setLoggerFactory(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 LoggerFactory loggerFactory

logger

protected Logger logger

debug

protected boolean debug

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.

Parameters:
mo - the meta object embeding the primitive element
c - the class embeding the meta object mo
Returns:
the primitive element
Throws:
PException

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.

getCompositeReferences

public java.util.ArrayList getCompositeReferences(Mapping mo)
                                           throws java.lang.Exception
This method return a list containing the nameref implied in composite reference field

Parameters:
mo - The meta object Mapping to be analysed.
Returns:
an ArrayList which contains all nameref related to reference fields.
Throws:
java.lang.Exception

getCNPackageName

public java.lang.String getCNPackageName(MetaObject mo)
This method retrieve the package name for the meta object passed as parameter. The meta object must be a child of a Package MetaObject.

Parameters:
mo - The meta object
Returns:
the name of the package 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.

containsCharArrayField

public boolean containsCharArrayField(Mapping m)
This method tests if a class contains a char[] field.

Parameters:
m - The meta object Mapping
Returns:
true if the class contains a serialized field.

containsFieldWhichCanBeNull

public boolean containsFieldWhichCanBeNull(Class co)
                                    throws PException
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.
Throws:
PException

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:
mo - the meta object NameDef which must be used
Throws:
java.lang.Exception

getFQNOfCompositeName

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

containsCompositeName

public boolean containsCompositeName(Mapping mo)
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.

Parameters:
mo - the Mapping which must analyzed

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:
te - 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:
te - 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:
te - 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

comparePE

public java.lang.String comparePE(java.lang.String val1,
                                  java.lang.String val2,
                                  PType type)
Parameters:
val1 - the variable name of the first element
val2 - the variable name of the second element
type - the type of the elements
Returns:
a String comparing two primitive element

isNull

public boolean isNull(java.lang.Object o)

isHiddenField

public boolean isHiddenField(PrimitiveElement pe)
This method checks if the parameter is an instance of org.objectweb.jorm.metainfo.api.PrimitiveElement

Parameters:
pe - 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:
t - the PType object which the type must be checked
Returns:
true the parameter is a PType.SERIALIZED.

isCharArrayType

public boolean isCharArrayType(PType t)
This method checks if the PType parameter designs a Serialized type.

Parameters:
t - the PType object which the type must be checked
Returns:
true the parameter is a PType.SERIALIZED.

buildPemList

public PrimitiveElementMapping[] buildPemList(java.util.Collection pemcoll)

getPemPos

public int getPemPos(PrimitiveElementMapping[] pemlist,
                     PrimitiveElement pe)
              throws PExceptionCompiler
Throws:
PExceptionCompiler

getPrimitiveElement

public PrimitiveElement getPrimitiveElement(java.lang.String fn,
                                            Class cl)
                                     throws PExceptionCompiler
Throws:
PExceptionCompiler

getRefNameDef

public NameDef getRefNameDef(Mapping mo,
                             Reference field)
                      throws PException
Throws:
PException

getTupleDecoding

public java.lang.String getTupleDecoding(java.lang.String fn,
                                         PType pt,
                                         java.lang.String value)
                                  throws PException
Throws:
PException

getTupleDecoding

public java.lang.String getTupleDecoding(java.lang.String tmpv,
                                         java.lang.String fn,
                                         java.lang.String tuplevn,
                                         PType pt,
                                         int pos)
                                  throws PException
Builds the string representing the expression to decode a PName wrt the relevant tuple field having the right type.

Parameters:
tmpv - The temporary variable that holds the tuple field value.
fn - The name of the involved application field.
tuplevn - The variable name that holds the corresponding tuple.
pt - The PType of the associated field.
pos - The position of the tuple field into this tuple.
Returns:
The string representing the getter expression.
Throws:
PException

getTupleGetter

public java.lang.String getTupleGetter(java.lang.String tuplevn,
                                       PType pt,
                                       int pos)
                                throws PException
Builds the string representing the expression to access the relevant tuple field having the right type.

Parameters:
tuplevn - The variable name that holds the corresponding tuple.
pt - The PType of the associated field.
pos - The position of the tuple field into this tuple.
Returns:
The string representing the getter expression.
Throws:
PException

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
Throws:
PException

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
Throws:
PException

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
Throws:
PException

getCoderName

public java.lang.String getCoderName(PType t)

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
Throws:
PException

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
Throws:
PException

getCTDeclaration

public java.lang.String getCTDeclaration(PType t)

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.
cfn - 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.
Throws:
java.lang.Exception

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.


getPTypeBigInteger

public PType getPTypeBigInteger()
Its retrieves the PType object which represents the BigInteger 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()

not

public boolean not(boolean b)

canBeNullValue

public boolean canBeNullValue(PType type)
                       throws PException
Throws:
PException

getInheritedClasses

public java.lang.String getInheritedClasses(Class c)
This method is a helper to reach the getInheritedClasses(Class, HashMap) method. Indeed in the velocity template is not possible to instanciate an object.


log

public java.lang.String log(java.lang.String msg)

debug

public java.lang.String debug(java.lang.String msg)

getPTypeSpaceFieldName

public java.lang.String getPTypeSpaceFieldName(PType pt)
Retrieves the name of the static field of the interface PTypeSpace corresponding to a PType.


setLoggerFactory

public void setLoggerFactory(LoggerFactory lf)
Its assigns a logger factory.

Specified by:
setLoggerFactory in interface Loggable
Parameters:
lf - the LoggerFactory object to obtain new loggers

setLogger

public void setLogger(Logger l)
Its assigns a logger.

Specified by:
setLogger in interface Loggable
Parameters:
l - the logger object

getLogger

public Logger getLogger()
Its retrives the current logger.

Specified by:
getLogger in interface Loggable

getLoggerFactory

public LoggerFactory getLoggerFactory()
Its retrives the current logger factory.

Specified by:
getLoggerFactory in interface Loggable