org.objectweb.jorm.metainfo.lib
Class BasicClass

java.lang.Object
  extended byorg.objectweb.jorm.metainfo.lib.BasicMetaObject
      extended byorg.objectweb.jorm.metainfo.lib.BasicClass
All Implemented Interfaces:
Class, Loggable, MetaObject, java.io.Serializable

public class BasicClass
extends BasicMetaObject
implements Class

BasicClass is an implementation of the Class interface defined in the meta information system. This object is defined by a list of fields, a name, a list of mapping.

Author:
X. Spengler
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.objectweb.jorm.metainfo.lib.BasicMetaObject
debug, logger, loggerFactory, parent
 
Constructor Summary
BasicClass(java.lang.String className, MetaObject parent)
          Builds a new Class object.
 
Method Summary
 void addClassProject(java.lang.String projectName, ClassProject classProject)
          Adds a ClassProject object.
 void addSubClass(Class class_)
          Adds a new class to the list of the derived classes for the current class object.
 void addSuperClass(Class class_)
          Adds a new inherited class to the list of the inherited classes for the current class object.
 ClassProject createClassProject(java.lang.String projectName)
          Creates a new ClassProject object.
 ClassRef createClassRef(java.lang.String fieldName, Class class_)
          Allows to obtain a new ClassRef from a field name an its class.
 GenClassRef createGenClassRef(java.lang.String fieldName, java.lang.String genName)
          Allows to obtain a new GenClassRef from a field name an its generic class.
 ScalarField createHiddenField(java.lang.String fieldName, PType type, int size, int scale)
          Creates a new scalar field and adds it to the list of hidden fields.
 NameDef createNameDef()
          Creates a new NameDef object for the current Class object.
 PrimitiveElement createPrimitiveElement(java.lang.String fieldName, PType type, int size, int scale)
          Allows to obtain a new PrimitiveElement from a class field name an its type.
 boolean detectFilterElementNotInPK(Expression exp, NameDef nd)
          Return true if one element of the expression exp is not part of the namedef.
 boolean generateKFPNC()
          Determine if we need to generate the kfpnc.
 java.util.List getAllAncestors()
          Returns all the ancestors of the class, i.e.: A --------- | | B C ----- | D all ancestors of D are C and A.
 java.util.Collection getAllFields()
          Returns an iterator on existing class fields + fields from super classes.
 java.util.Collection getAllHiddenFields()
           
 java.util.List getAncestors()
          Return the list (most often with only one element) of ancestors.
protected  java.util.Collection getChildren()
           
 ClassMapping getClassMapping(java.lang.String projectName, java.lang.String mapperName)
          Returns a ClassMapping object.
 ClassProject getClassProject(java.lang.String projectName)
          Returns a ClassProject object.
 java.util.Collection getClassProjects()
          Returns a collection of ClassProject objects.
 java.lang.String getConstantValue(java.lang.String fieldName)
          Obtains the value of a constant PrimitiveElement, defined either in the current class or in one of its ancestors.
 int getFieldRefNumber()
          Returns the number of fields which are references to classes.
 java.util.Collection getFields()
          Returns an iterator on existing class fields.
 java.lang.String getFileName()
          Allows to retrieve the file name of this class MO.
 java.lang.String getFQName()
          Gets the fully qualified name (including the package name) associated with this class.
 ScalarField getHiddenField(java.lang.String fieldName)
          retrieve an hiddenfield from its name.
 java.util.Collection getHiddenFields()
           
 Expression getInheritanceFilter(NameDef nd)
           
 java.lang.Object getInheritanceNamingKey(NameDef nd)
           
 int getInheritedClassNumber()
          Returns the number of inherited classes for the current Class object.
 java.lang.String getName()
          Allows to know the name of the current class object.
 NameDef getNameDef(java.lang.String name)
          Returns a NameDef object.
 java.util.Collection getNameDefs()
           
 Package getPackage()
           
 PType getPType()
           
 java.util.Collection getSubClasses()
          Allows us to obtain all classes derived from the current class object.
 Class getSuperClass(java.lang.String fqcn)
          Retrieves a super class whith its name.
 java.util.Collection getSuperClasses()
          Returns a collection of Class objects.
 TypedElement getTypedElement(java.lang.String fieldName)
          Allows to obtain an existing Field.
 boolean isAbstract()
          Allows to know if the current class is an abstract class or not.
 boolean isPolymorphic()
          Returns true if the class is polymorphic, i.e. it has subclasses or superclasses
protected  java.util.List listAllFields(java.util.List allFields)
           
protected  java.util.List listAllHiddenField(java.util.List allFields)
           
protected  java.util.List listField()
          returns an ArrayList which contains the current fields.
protected  java.util.List listField(java.util.List allFields)
           
protected  java.util.List listHiddenFields(java.util.List allFields)
           
 Expression parseInheritanceFilter(java.lang.String filter, NameDef nd)
           
 ClassProject removeClassProject(java.lang.String projectname)
          Removes a ClassProject instance.
 TypedElement removeTypedElement(java.lang.String fieldName)
          Removes a typed element.
 void setAbstract(boolean isAbstract)
           
 void setConstantValue(java.lang.String fieldName, java.lang.String cv)
          Defines the value of a constant PrimitiveElement, defined either in the current class or in one of its ancestors.
 void setFileName(java.lang.String filename)
          Allows to assign the file name of this class MO.
 void setInheritanceFilter(NameDef nd, Expression e)
           
 void setInheritanceNamingKey(NameDef nd, java.lang.Object key)
           
 
Methods inherited from class org.objectweb.jorm.metainfo.lib.BasicMetaObject
getLogger, getLoggerFactory, getManager, getParent, setLogger, setLoggerFactory, setLoggingOnChild, setParent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.jorm.metainfo.api.MetaObject
getParent, setParent
 

Constructor Detail

BasicClass

public BasicClass(java.lang.String className,
                  MetaObject parent)
Builds a new Class object. This object is mainly defined by its name, if the class is abstract or not, and its parent (a schema).

Parameters:
className - the name of the current class
parent - the parent of the current object
Method Detail

getChildren

protected java.util.Collection getChildren()
Overrides:
getChildren in class BasicMetaObject

getPackage

public Package getPackage()
Specified by:
getPackage in interface Class

getFileName

public java.lang.String getFileName()
Allows to retrieve the file name of this class MO.

Specified by:
getFileName in interface Class
Returns:
The file name.

setFileName

public void setFileName(java.lang.String filename)
Allows to assign the file name of this class MO.

Specified by:
setFileName in interface Class
Parameters:
filename - The file name.

isAbstract

public boolean isAbstract()
Allows to know if the current class is an abstract class or not.

Specified by:
isAbstract in interface Class
Returns:
true, if the current class is an abstract class, and false, if the current class is not abstract

setAbstract

public void setAbstract(boolean isAbstract)
Specified by:
setAbstract in interface Class

getName

public java.lang.String getName()
Allows to know the name of the current class object.

Specified by:
getName in interface Class
Returns:
the string representation of the class name

getFQName

public java.lang.String getFQName()
Description copied from interface: Class
Gets the fully qualified name (including the package name) associated with this class.

Specified by:
getFQName in interface Class
Returns:
the string representation of the fully qualified class name

getTypedElement

public TypedElement getTypedElement(java.lang.String fieldName)
Allows to obtain an existing Field. A TypedElement is a class field, and this method finds a field with its name (fieldName). This method is a generic method to return a TypedElement object. The field can be hidden or not.

Specified by:
getTypedElement in interface Class
Parameters:
fieldName - the name of the class field
Returns:
a field object. If the field does not exist, null is returned.

removeTypedElement

public TypedElement removeTypedElement(java.lang.String fieldName)
Removes a typed element.

Specified by:
removeTypedElement in interface Class
Parameters:
fieldName - is the name of the field to be removed
Returns:
the removed element or null if the field has not been found.

createNameDef

public NameDef createNameDef()
Creates a new NameDef object for the current Class object. Here we can define if the namedef is defined outside jorm or not. In the case where the namedef is already defined for the current class, the old one is used and returned.

Specified by:
createNameDef in interface Class
Returns:
a new object used to describe the PName projection for the current Class

getNameDef

public NameDef getNameDef(java.lang.String name)
Returns a NameDef object. If the namedef does not exist, null is returned.

Specified by:
getNameDef in interface Class
Parameters:
name - the name of a NameDef object.
Returns:
a namedef object, else null is returned.

getNameDefs

public java.util.Collection getNameDefs()
Specified by:
getNameDefs in interface Class
Returns:
a collection of NameDef object

getInheritanceFilter

public Expression getInheritanceFilter(NameDef nd)
                                throws ExpressionException
Specified by:
getInheritanceFilter in interface Class
Returns:
the filter expression (Medor expression) permitting to known if instance of the parent class is in fact an instance of the current persistent class. The filter uses the field name (composite field in case of a composite or the field class name). If the current class has no parent, then this method return null;
Throws:
ExpressionException

getInheritanceNamingKey

public java.lang.Object getInheritanceNamingKey(NameDef nd)
Specified by:
getInheritanceNamingKey in interface Class
Returns:
the key matching to the current class. This value is the result of the inheritance filter evaluation.

setInheritanceFilter

public void setInheritanceFilter(NameDef nd,
                                 Expression e)
Specified by:
setInheritanceFilter in interface Class
Parameters:
e - is the filter expression (Medor expression) permitting to known if instance of the parent class is in fact an instance of the current persistent class. The filter uses the field name (composite field in case of a composite or the field class name).

setInheritanceNamingKey

public void setInheritanceNamingKey(NameDef nd,
                                    java.lang.Object key)
Specified by:
setInheritanceNamingKey in interface Class

createPrimitiveElement

public PrimitiveElement createPrimitiveElement(java.lang.String fieldName,
                                               PType type,
                                               int size,
                                               int scale)
Allows to obtain a new PrimitiveElement from a class field name an its type. A PrimitiveElement is a Class field. If the class field already exists, it is returned.

Specified by:
createPrimitiveElement in interface Class
Parameters:
fieldName - the name of the primitive field
type - the PType of the primitive field
Returns:
a new PrimitiveElement object, or the existing one if already defined

setConstantValue

public void setConstantValue(java.lang.String fieldName,
                             java.lang.String cv)
Description copied from interface: Class
Defines the value of a constant PrimitiveElement, defined either in the current class or in one of its ancestors.

The constant value is represented by a String.

Specified by:
setConstantValue in interface Class
Parameters:
fieldName - the existing PrimitiveElement
cv - the constant value

getConstantValue

public java.lang.String getConstantValue(java.lang.String fieldName)
Description copied from interface: Class
Obtains the value of a constant PrimitiveElement, defined either in the current class or in one of its ancestors.

The constant value is represented by a String.

Specified by:
getConstantValue in interface Class
Parameters:
fieldName - the existing PrimitiveElement
Returns:
the constant value as a String

createHiddenField

public ScalarField createHiddenField(java.lang.String fieldName,
                                     PType type,
                                     int size,
                                     int scale)
Creates a new scalar field and adds it to the list of hidden fields. If the field already exists, it is returned, else a new one is built.

Specified by:
createHiddenField in interface Class
Parameters:
fieldName - the name of the field to create
type - the type of the field to create
size - is the
Returns:
a new ScalarField object if this object does not already exist

createClassRef

public ClassRef createClassRef(java.lang.String fieldName,
                               Class class_)
Allows to obtain a new ClassRef from a field name an its class. A ClassRef object is a field which is represented by a reference to a Class. If the field already exists, it is returned.

Specified by:
createClassRef in interface Class
Parameters:
fieldName - the name of the field
class_ - the string representation of the class which represents the reference of the field
Returns:
a new ClassRef object, or the existing one if already defined

createGenClassRef

public GenClassRef createGenClassRef(java.lang.String fieldName,
                                     java.lang.String genName)
Allows to obtain a new GenClassRef from a field name an its generic class. A GenClassRef object is a field which is represented by a reference to a generic class. If the field already exists, it is returned.

Specified by:
createGenClassRef in interface Class
Parameters:
fieldName - the name of the field
genName - the GenClass object which represents the reference of the field
Returns:
a new GenClassRef object, or the existing one if already defined

listField

protected java.util.List listField()
returns an ArrayList which contains the current fields.

Returns:
a list of current fields

listField

protected java.util.List listField(java.util.List allFields)

listAllFields

protected java.util.List listAllFields(java.util.List allFields)

getFields

public java.util.Collection getFields()
Description copied from interface: Class
Returns an iterator on existing class fields. If no field is defined, an empty iterator is returned. This iterator contains PrimitiveElements, ClassRef and GenClassRef objects. The top level object is TypedElement.

Specified by:
getFields in interface Class
Returns:
an iterator on fields, or null if there is no defined field

getAllFields

public java.util.Collection getAllFields()
Description copied from interface: Class
Returns an iterator on existing class fields + fields from super classes. This iterator contains PrimitiveElement, ClassRef and GenClassRef objects.

Specified by:
getAllFields in interface Class
Returns:
an iterator on all defined fields, plus fields from super

listHiddenFields

protected java.util.List listHiddenFields(java.util.List allFields)

listAllHiddenField

protected java.util.List listAllHiddenField(java.util.List allFields)

getHiddenFields

public java.util.Collection getHiddenFields()
Specified by:
getHiddenFields in interface Class
Returns:
a collection of hidden field of the class WITHOUT inherited fields.

getAllHiddenFields

public java.util.Collection getAllHiddenFields()
Specified by:
getAllHiddenFields in interface Class
Returns:
a collection of hidden field of the class including inherited fields.

getHiddenField

public ScalarField getHiddenField(java.lang.String fieldName)
retrieve an hiddenfield from its name.

Specified by:
getHiddenField in interface Class
Parameters:
fieldName - the name of the hiddenfield.
Returns:
the hiddenfield or null if the field does not exist.

getSubClasses

public java.util.Collection getSubClasses()
Description copied from interface: Class
Allows us to obtain all classes derived from the current class object. This collection contains Class objects. In the case where there is no derived class, an empty collection is returned.

Specified by:
getSubClasses in interface Class
Returns:
a collection on derived classes (Class objets). If no object exists, an empty collection is returned.

getSuperClasses

public java.util.Collection getSuperClasses()
Returns a collection of Class objects. Returns only the direct super classes of this class. In the following graph, A --------- | | B C ----- | D superclass of D is C. The s in superclasses comes from the fact that in JORM a class can have many superclasses.

Specified by:
getSuperClasses in interface Class
Returns:
a collection.

getSuperClass

public Class getSuperClass(java.lang.String fqcn)
Description copied from interface: Class
Retrieves a super class whith its name.

Specified by:
getSuperClass in interface Class
Parameters:
fqcn - is the fully qualified class name of the super class
Returns:
a Class meta object instance if the specified class name is a super class of the current class. A null value if the specified class name is not a super class of the current class.

addSuperClass

public void addSuperClass(Class class_)
Adds a new inherited class to the list of the inherited classes for the current class object. If the class already exists, nothing is done.

Specified by:
addSuperClass in interface Class
Parameters:
class_ - the inherited class to add to inherited classes list

addSubClass

public void addSubClass(Class class_)
Description copied from interface: Class
Adds a new class to the list of the derived classes for the current class object. If the class already exists, nothing is done.

Specified by:
addSubClass in interface Class
Parameters:
class_ - the inherited class to add to inherited classes list

getInheritedClassNumber

public int getInheritedClassNumber()
Returns the number of inherited classes for the current Class object.

Specified by:
getInheritedClassNumber in interface Class
Returns:
the number of inherited classes

getAllAncestors

public java.util.List getAllAncestors()
Returns all the ancestors of the class, i.e.: A --------- | | B C ----- | D all ancestors of D are C and A.

Specified by:
getAllAncestors in interface Class

getAncestors

public java.util.List getAncestors()
Return the list (most often with only one element) of ancestors. In the following graph, A --------- | | B C ----- | D ancestor of D is A. The s of ancestors comes from the fact that with JORM a class can have many superclasses.

Specified by:
getAncestors in interface Class

isPolymorphic

public boolean isPolymorphic()
Description copied from interface: Class
Returns true if the class is polymorphic, i.e. it has subclasses or superclasses

Specified by:
isPolymorphic in interface Class
Returns:
true if the class is polymorphic

getPType

public PType getPType()
Specified by:
getPType in interface Class
Returns:
the PType of the persistent class

getFieldRefNumber

public int getFieldRefNumber()
Returns the number of fields which are references to classes.

Specified by:
getFieldRefNumber in interface Class
Returns:
the number of fieldRef

getClassProject

public ClassProject getClassProject(java.lang.String projectName)
Returns a ClassProject object.

Specified by:
getClassProject in interface Class
Parameters:
projectName - a project name.
Returns:
a ClassProject object.

getClassMapping

public ClassMapping getClassMapping(java.lang.String projectName,
                                    java.lang.String mapperName)
Returns a ClassMapping object.

Specified by:
getClassMapping in interface Class
Parameters:
projectName - a project name, mappername a mapper name.
Returns:
a ClassMapping object.

getClassProjects

public java.util.Collection getClassProjects()
Returns a collection of ClassProject objects.

Specified by:
getClassProjects in interface Class
Returns:
a collection.

addClassProject

public void addClassProject(java.lang.String projectName,
                            ClassProject classProject)
Adds a ClassProject object.

Specified by:
addClassProject in interface Class
Parameters:
projectName - a project name, classProject a ClassProject object.

createClassProject

public ClassProject createClassProject(java.lang.String projectName)
Creates a new ClassProject object.

Specified by:
createClassProject in interface Class
Parameters:
projectName - the name of the project.
Returns:
a new ClassProject object, or an existing one.

removeClassProject

public ClassProject removeClassProject(java.lang.String projectname)
Removes a ClassProject instance.

Specified by:
removeClassProject in interface Class
Parameters:
projectname - is the name of removed ClassProject
Returns:
The removed ClassProject

parseInheritanceFilter

public Expression parseInheritanceFilter(java.lang.String filter,
                                         NameDef nd)
                                  throws ExpressionException
Throws:
ExpressionException

generateKFPNC

public boolean generateKFPNC()
                      throws ExpressionException
Determine if we need to generate the kfpnc.

Specified by:
generateKFPNC in interface Class
Throws:
ExpressionException

detectFilterElementNotInPK

public boolean detectFilterElementNotInPK(Expression exp,
                                          NameDef nd)
                                   throws ExpressionException
Description copied from interface: Class
Return true if one element of the expression exp is not part of the namedef. Else, return false.

Specified by:
detectFilterElementNotInPK in interface Class
Throws:
ExpressionException