org.caleigo.core
Class CompositeEntityDescriptor

java.lang.Object
  extended byorg.caleigo.core.AbstractEntityDescriptor
      extended byorg.caleigo.core.CompositeEntityDescriptor
All Implemented Interfaces:
ICompositeEntityDescriptor, IEntityDescriptor, java.io.Serializable

public final class CompositeEntityDescriptor
extends AbstractEntityDescriptor
implements ICompositeEntityDescriptor

The CompositeEntityDescriptor can be used to make composite entities based on fields in base entity descriptors or another composite entity descriptor. The entities will be Creatable, Delatable & Editable according to this scheme:
An entity is:
-Deletable if the root group's primary key is present and the root field group's entity descriptor is deletable.
-Creatable if the root group's primary key is present and all required fields in the root group are present and the root group's entity descriptor is creatable.
-Editable if any of the field group's primary key is present and there is, in that group, at least one field that isn't read only.
Deleting an entity will delete the root field group's "base entity".
Creating a new entity will fill the new entity with default values.
Editing of a field is allowed if the field's composite field descriptor isn't a read only field (the READ_ONLY_FIELD-flag) and the field group that the field belongs to has a primary key present and that field group's base entity descriptor is editable. Therefor this CompositeEntityDescriptor is editable if any of it's field is editable. Upon saving each field group is saved separately, this is done by copying the data to new entities that has the field group's underlying base entity descriptor as entity descriptor.

Version:
1.00
Author:
Dennis Zikovic, Niklas Norberg
See Also:
Serialized Form

Nested Class Summary
static class CompositeEntityDescriptor.Builder
          The FieldGroupBuilder is a builder that builds a tree (of fields- and field-groups) in a top-down manner.
static class CompositeEntityDescriptor.CompositeDeleteEntityAction
          The default delete action used by the CompositeEntityDescriptor class.
static class CompositeEntityDescriptor.CompositeFieldGroup
          The ICompositeFieldGroup is used to group sets of fields belonging to a single entity-descriptor (of the class ICompositeEntityDescriptor) together and to define their relation with each other.
protected static class CompositeEntityDescriptor.CompositeFieldRelation
          Basic implementation of the IFieldRelation for Composite Field Relations.
static class CompositeEntityDescriptor.CompositeStoreEntityAction
          The default store action used by the CompositeEntityDescriptor class.
 
Nested classes inherited from class org.caleigo.core.AbstractEntityDescriptor
AbstractEntityDescriptor.DeleteEntityAction, AbstractEntityDescriptor.Dezerializer, AbstractEntityDescriptor.StoreEntityAction
 
Nested classes inherited from class org.caleigo.core.ICompositeEntityDescriptor
ICompositeEntityDescriptor.ICompositeFieldDescriptor, ICompositeEntityDescriptor.ICompositeFieldGroup
 
Field Summary
 
Fields inherited from class org.caleigo.core.AbstractEntityDescriptor
CACHEABLE, CREATABLE, DELETABLE, EDITABLE, LISTABLE, SCANABLE, SELECTABLE
 
Fields inherited from interface org.caleigo.core.IEntityDescriptor
CUSTOM_ENTITY, DELETE_ACTION, LINK_ENTITY, MASTER_ENTITY, NO_TIME_LIMIT, SLAVE_ENTITY, STATIC_ENTITY, STORE_ACTION
 
Constructor Summary
CompositeEntityDescriptor(java.lang.String displayName, java.lang.String dataSourceClassName, IEntityDescriptor entityDescriptor, IFieldDescriptor[] joinedFieldDescriptors)
          This constructor make joins with an entity descriptor and fields.
CompositeEntityDescriptor(java.lang.String displayName, java.lang.String dataSourceClassName, IFieldDescriptor[] fieldDescriptors)
          This constructor creates a CompositeEntityDescriptor from a fieldArray.
CompositeEntityDescriptor(java.lang.String codeName, java.lang.String displayName, java.lang.String dataSourceClassName, int entityType, IFieldDescriptor[] fieldDescriptors)
           
 
Method Summary
protected static ICompositeEntityDescriptor.ICompositeFieldDescriptor[] buildFieldArray(ICompositeEntityDescriptor.ICompositeFieldGroup rootFieldGroup)
          Builds an array of all fields in the root field group and it's descendent children.
protected static java.util.List buildFieldArray(ICompositeEntityDescriptor.ICompositeFieldGroup fieldGroup, java.util.List fieldList)
          Help-method, call the tree's nodes recursively.
protected static IEntityRelation[] buildRelationArray(CompositeEntityDescriptor.CompositeFieldGroup rootFieldGroup)
          Builds all relations that a composite entity desriptor should have.
protected static void buildRelationForIdFieldsList(CompositeEntityDescriptor.CompositeFieldGroup fieldGroup, java.util.Map referenceFieldMap, java.util.List relationList)
          Method makes recursive call to itself and make reference relation for id fields from the composite to the field group's base entity descriptor.
protected static void buildRelationList(CompositeEntityDescriptor.CompositeFieldGroup fieldGroup, java.util.List referenceRelationList, java.util.List targetRelationList)
          Recursive method for collecting relations.
protected static int calculateEntityDescriptorFlags(IEntityDescriptor entityDescriptor)
          Calculate which flag's are set.
static int calculateFieldDescriptorFlags(IFieldDescriptor field)
           
protected static int calculateSizeTypeFlags(IEntityDescriptor entityDescriptor)
          Calculate which of the size type flag's that are set.
protected  IEntityAction createDeleteAction()
          Creates and returns the delete action for composite entity objects of the custom type: composite entity descriptor.
 IEntity createEntity()
          Creates an entity of the type described by this descriptor and loads it with default data.
 IEntity createEntity(IDataProvider propertySource)
          Creates an entity of the type described by this descriptor and loads it with data from the provided property source.
protected  IEntityAction createStoreAction()
          Creates and returns the store action for composite entity objects of the custom type: composite entity descriptor.
 IDataSourceDescriptor getDataSourceDescriptor()
          Returns the data source descriptor that this entity is a part of.
 Qualifier getDefaultQualifier()
          Returns a qualifier that defines the default filter for this entity.
static CompositeQualifier getKeyForFieldGroup(ICompositeEntityDescriptor.ICompositeFieldGroup group, IEntity iEntity)
           
 ICompositeEntityDescriptor.ICompositeFieldGroup getRootFieldGroup()
          Returns the root field group for the tree of field groups that defines this CompositeEntityDescriptor.
static java.lang.String increaseStringEndingWithNumber(java.lang.String anIdentity)
          Increases (+1) the last number (if any) in a String.
 boolean isCreatable()
          Returns true if entities described by the called descriptor may be created.
 boolean isDeletable()
          Returns true if entities described by the called descriptor may be deleted.
 boolean isEditable()
          Returns true if entities described by the called descriptor may be updated.
static java.lang.String makeLogString(IEntity entity)
          Makes a descriptive log string for the provided entity object.
static java.lang.String printFlags(IEntityDescriptor entityDescriptor)
          Makes a descriptive log string that tells what flags are set on the provided entity object.
 void setDefaultQualifier(Qualifier defaultQualifier)
          This method sets the default qualifer for this composite entity descriptor.
 
Methods inherited from class org.caleigo.core.AbstractEntityDescriptor
addEntityAction, contains, createCalculatedFieldDescriptors, createEntityRelation, createEntityRelation, createEntityRelation, createFieldDescriptor, createFieldRelation, defineEntityActions, getAction, getAction, getActionCount, getActions, getCacheTime, getCodeName, getDataFieldCount, getDisplayName, getEntityClass, getEntityRelation, getEntityRelationCount, getEntityRelationIndex, getEntityRelations, getEntityType, getFieldCount, getFieldDescriptor, getFieldDescriptor, getFieldDescriptors, getFieldIndex, getFieldIndex, getHomeClass, getJNDIName, getNaturalOrder, getRemoteClass, getSourceName, isCacheable, isListable, isScanable, isSelectable, loadEntity, loadSelection, setCacheTime, setFlags, toString, writeReplace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.caleigo.core.IEntityDescriptor
contains, getAction, getAction, getActionCount, getActions, getCacheTime, getCodeName, getDataFieldCount, getDisplayName, getEntityClass, getEntityRelation, getEntityRelationCount, getEntityRelationIndex, getEntityRelations, getEntityType, getFieldCount, getFieldDescriptor, getFieldDescriptor, getFieldDescriptors, getFieldIndex, getFieldIndex, getHomeClass, getJNDIName, getNaturalOrder, getRemoteClass, getSourceName, isCacheable, isListable, isScanable, isSelectable, loadEntity, loadSelection
 

Constructor Detail

CompositeEntityDescriptor

public CompositeEntityDescriptor(java.lang.String displayName,
                                 java.lang.String dataSourceClassName,
                                 IEntityDescriptor entityDescriptor,
                                 IFieldDescriptor[] joinedFieldDescriptors)
This constructor make joins with an entity descriptor and fields.

Parameters:
displayName - screen name.
dataSourceClassName - the class name of the underlying data source that this composite entity descriptor use.
entityDescriptor - all fields from this will be included if the parameter joinedFieldDescriptors doesn't contain fields belonging to this entity descriptor.
joinedFieldDescriptors - an array of fields to join with and make a selection from.

CompositeEntityDescriptor

public CompositeEntityDescriptor(java.lang.String displayName,
                                 java.lang.String dataSourceClassName,
                                 IFieldDescriptor[] fieldDescriptors)
This constructor creates a CompositeEntityDescriptor from a fieldArray. Fields can be from different base entity descriptor's, if all belongs to the same base entity descriptor the result will be a selection! The first field descriptor's base entity descriptor will be the root group's base entity descriptor.

Parameters:
displayName - screen name.
dataSourceClassName - the class name of the underlying data source that this composite entity descriptor use.
fieldDescriptors - fields that are to be joined/selected.

CompositeEntityDescriptor

public CompositeEntityDescriptor(java.lang.String codeName,
                                 java.lang.String displayName,
                                 java.lang.String dataSourceClassName,
                                 int entityType,
                                 IFieldDescriptor[] fieldDescriptors)
Parameters:
codeName - the code name should be used for programitic identification.
entityType - the entity type entities of this descriptor should have.
See Also:
CompositeEntityDescriptor(String displayName, String dataSourceClassName, IFieldDescriptor[] fieldDescriptors), entityType.
Method Detail

setDefaultQualifier

public void setDefaultQualifier(Qualifier defaultQualifier)
This method sets the default qualifer for this composite entity descriptor.

Specified by:
setDefaultQualifier in interface ICompositeEntityDescriptor
Parameters:
defaultQualifier - the qualifer that directly qualifies this composite entity descriptor

buildFieldArray

protected static ICompositeEntityDescriptor.ICompositeFieldDescriptor[] buildFieldArray(ICompositeEntityDescriptor.ICompositeFieldGroup rootFieldGroup)
Builds an array of all fields in the root field group and it's descendent children.

Parameters:
rootFieldGroup - the root in the ICompositeEntityDescriptor-object.
Returns:
an array of fields in breadth-first order.

buildFieldArray

protected static java.util.List buildFieldArray(ICompositeEntityDescriptor.ICompositeFieldGroup fieldGroup,
                                                java.util.List fieldList)
Help-method, call the tree's nodes recursively.


buildRelationArray

protected static IEntityRelation[] buildRelationArray(CompositeEntityDescriptor.CompositeFieldGroup rootFieldGroup)
Builds all relations that a composite entity desriptor should have.

Parameters:
rootFieldGroup - the root of the wrapped field group tree.
Returns:
an entity relation array that contains all possible relations in a field group tree i.e. all slave-, reference- and id-fields-relation. Obs that setting of entity relations on field relations are done in the createEntityRelation()-method.

buildRelationList

protected static void buildRelationList(CompositeEntityDescriptor.CompositeFieldGroup fieldGroup,
                                        java.util.List referenceRelationList,
                                        java.util.List targetRelationList)
Recursive method for collecting relations.

Parameters:
fieldGroup - the field group to get relation's from.
referenceRelationList - the list that holds and get matching field groups and their belonging reference entity relation's.
targetRelationList - the list that holds and get matching field groups and their belonging target entity relation's.

buildRelationForIdFieldsList

protected static void buildRelationForIdFieldsList(CompositeEntityDescriptor.CompositeFieldGroup fieldGroup,
                                                   java.util.Map referenceFieldMap,
                                                   java.util.List relationList)
Method makes recursive call to itself and make reference relation for id fields from the composite to the field group's base entity descriptor.

Parameters:
fieldGroup - field group to look for exactly one id field in.
referenceFieldMap - map containing composite field descriptors that already are referencefields.
relationList - the list to append the found relations to.

calculateEntityDescriptorFlags

protected static int calculateEntityDescriptorFlags(IEntityDescriptor entityDescriptor)
Calculate which flag's are set.

Parameters:
entityDescriptor - the IEntityDescriptor that are examined.
Returns:
an int representing all flag's that are set.

calculateSizeTypeFlags

protected static int calculateSizeTypeFlags(IEntityDescriptor entityDescriptor)
Calculate which of the size type flag's that are set.

Parameters:
entityDescriptor - the IEntityDescriptor that are examined.
Returns:
an int representing the size type flag that are set.

calculateFieldDescriptorFlags

public static int calculateFieldDescriptorFlags(IFieldDescriptor field)
Returns:
and integer representing all flags for the field.

increaseStringEndingWithNumber

public static java.lang.String increaseStringEndingWithNumber(java.lang.String anIdentity)
Increases (+1) the last number (if any) in a String. If there are no number "1" will be added to the String i.e. "alias12" -> "alias13" and "alias" -> "alias1" .

Returns:
a new String with increased number.

makeLogString

public static java.lang.String makeLogString(IEntity entity)
Makes a descriptive log string for the provided entity object. Will display the data for all field descriptors.


printFlags

public static java.lang.String printFlags(IEntityDescriptor entityDescriptor)
Makes a descriptive log string that tells what flags are set on the provided entity object.

Parameters:
entityDescriptor -

createEntity

public IEntity createEntity()
Creates an entity of the type described by this descriptor and loads it with default data.

Specified by:
createEntity in interface IEntityDescriptor
Overrides:
createEntity in class AbstractEntityDescriptor

createEntity

public IEntity createEntity(IDataProvider propertySource)
Creates an entity of the type described by this descriptor and loads it with data from the provided property source.

Specified by:
createEntity in interface IEntityDescriptor
Overrides:
createEntity in class AbstractEntityDescriptor

getDataSourceDescriptor

public IDataSourceDescriptor getDataSourceDescriptor()
Returns the data source descriptor that this entity is a part of.

Specified by:
getDataSourceDescriptor in interface IEntityDescriptor
Overrides:
getDataSourceDescriptor in class AbstractEntityDescriptor

createStoreAction

protected IEntityAction createStoreAction()
Creates and returns the store action for composite entity objects of the custom type: composite entity descriptor.

Overrides:
createStoreAction in class AbstractEntityDescriptor
Returns:
The IEntityAction object that is used to store entity objects for the called entity.

createDeleteAction

protected IEntityAction createDeleteAction()
Creates and returns the delete action for composite entity objects of the custom type: composite entity descriptor.

Overrides:
createDeleteAction in class AbstractEntityDescriptor
Returns:
The IEntityAction object that is used to delete entity objects for the called entity.

isCreatable

public boolean isCreatable()
Returns true if entities described by the called descriptor may be created. If a store operation is called on a non-persistent entity of the described type an exception should be thrown.

Specified by:
isCreatable in interface IEntityDescriptor
Overrides:
isCreatable in class AbstractEntityDescriptor

isEditable

public boolean isEditable()
Returns true if entities described by the called descriptor may be updated. If a store operation is called on a persistent entity of the described type an exception should be thrown.

Specified by:
isEditable in interface IEntityDescriptor
Overrides:
isEditable in class AbstractEntityDescriptor

isDeletable

public boolean isDeletable()
Returns true if entities described by the called descriptor may be deleted. If a store operation is called on a persistent entity of the described type an exception should be thrown.

Specified by:
isDeletable in interface IEntityDescriptor
Overrides:
isDeletable in class AbstractEntityDescriptor

getRootFieldGroup

public ICompositeEntityDescriptor.ICompositeFieldGroup getRootFieldGroup()
Returns the root field group for the tree of field groups that defines this CompositeEntityDescriptor.

Specified by:
getRootFieldGroup in interface ICompositeEntityDescriptor

getDefaultQualifier

public Qualifier getDefaultQualifier()
Returns a qualifier that defines the default filter for this entity. Setting is done in the constructors. If a constructor without a qualifier-parameter is choosen or the parameter is null, the default value is null i.e. no discarding of the entities are made. It might make sence e.g. to filter out all orders older than a discontinued date.

Specified by:
getDefaultQualifier in interface ICompositeEntityDescriptor

getKeyForFieldGroup

public static CompositeQualifier getKeyForFieldGroup(ICompositeEntityDescriptor.ICompositeFieldGroup group,
                                                     IEntity iEntity)


Copyright © 2005 Caleigo. All Rights Reserved.