org.caleigo.core
Class AbstractCalculatedFieldDescriptor

java.lang.Object
  extended byorg.caleigo.core.FieldDescriptor
      extended byorg.caleigo.core.AbstractCalculatedFieldDescriptor
All Implemented Interfaces:
ICalculatedFieldDescriptor, IFieldDescriptor, java.io.Serializable

public abstract class AbstractCalculatedFieldDescriptor
extends FieldDescriptor
implements ICalculatedFieldDescriptor

Abstract class for calculated fields. Use it if you want to have a virtual field in an entity that has data that isn't persistent but dependent and calculated from one or more often several other fields. E.g. Totalcost = UnitPrice * Quantity

Version:
1.00
Author:
Niklas Norberg
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class org.caleigo.core.FieldDescriptor
FieldDescriptor.Dezerializer, FieldDescriptor.FieldRelationIterator
 
Field Summary
(package private)  IFieldDescriptor[] mRequiredFields
           
 
Fields inherited from interface org.caleigo.core.IFieldDescriptor
AUTOGEN, HIDDEN_FIELD, HINT_FIELD, IDENTITY_FIELD, INDEXED, NAME_FIELD, NATURAL_ORDER, OVERVIEW_FIELD, READ_ONLY_FIELD, REQUIRED
 
Constructor Summary
protected AbstractCalculatedFieldDescriptor(java.lang.String codeName, java.lang.String displayName, java.lang.String entityDescriptorName, DataType dataType, int length, boolean readOnly, IFieldDescriptor[] requiredFields)
          Alternative constructor for CalculatedFieldDescriptor.
protected AbstractCalculatedFieldDescriptor(java.lang.String codeName, java.lang.String displayName, java.lang.String entityDescriptorName, DataType dataType, int length, int flags, IFieldDescriptor[] requiredFields)
          Default constructor for CalculatedFieldDescriptor.
 
Method Summary
abstract  java.lang.Object getFieldDataFrom(IEntity entity)
          This one must always be overridden since there would be no sence in creating a subclass without a coherent getFieldDataFrom-method!
 IFieldDescriptor[] getRequiredFields()
          Should return an array of the field descriptors required for the "calculation" of the descriptors value.
 boolean isValidFor(IEntityDescriptor descriptor)
          Should Returns true if the descriptor is "valid for" = can be a part of and calculate its value based on the data defined by the submited entity descriptor.
 void setFieldDataTo(IEntity entity, java.lang.Object data)
          This one should never be called unless it's overridden!
 
Methods inherited from class org.caleigo.core.FieldDescriptor
addValidator, canValidate, getCodeName, getDataType, getDefaultValue, getDisplayName, getEntityDescriptor, getFieldRelations, getLength, getReferenceFieldRelation, getSourceName, isAutoGenerated, isHiddenField, isHintField, isIdentityField, isIndexed, isNameField, isNaturalOrder, isOverviewField, isReadOnly, isReferenceField, isRequired, performBaseValidation, toString, validateData, 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.IFieldDescriptor
canValidate, getCodeName, getDataType, getDefaultValue, getDisplayName, getEntityDescriptor, getFieldRelations, getLength, getReferenceFieldRelation, getSourceName, isAutoGenerated, isHiddenField, isHintField, isIdentityField, isIndexed, isNameField, isNaturalOrder, isOverviewField, isReadOnly, isReferenceField, isRequired, validateData
 

Field Detail

mRequiredFields

IFieldDescriptor[] mRequiredFields
Constructor Detail

AbstractCalculatedFieldDescriptor

protected AbstractCalculatedFieldDescriptor(java.lang.String codeName,
                                            java.lang.String displayName,
                                            java.lang.String entityDescriptorName,
                                            DataType dataType,
                                            int length,
                                            int flags,
                                            IFieldDescriptor[] requiredFields)
Default constructor for CalculatedFieldDescriptor. Not all flags are relevant and are therefor removed if given.


AbstractCalculatedFieldDescriptor

protected AbstractCalculatedFieldDescriptor(java.lang.String codeName,
                                            java.lang.String displayName,
                                            java.lang.String entityDescriptorName,
                                            DataType dataType,
                                            int length,
                                            boolean readOnly,
                                            IFieldDescriptor[] requiredFields)
Alternative constructor for CalculatedFieldDescriptor. Normally only used if one want to implement a calculated fields that only uses the getFieldDataFrom-method. The parameter readOnly sets the corresponding flag.

Method Detail

getFieldDataFrom

public abstract java.lang.Object getFieldDataFrom(IEntity entity)
This one must always be overridden since there would be no sence in creating a subclass without a coherent getFieldDataFrom-method! Normally this method would have some logic and math that calculate the data in this field from others.

Specified by:
getFieldDataFrom in interface ICalculatedFieldDescriptor

setFieldDataTo

public void setFieldDataTo(IEntity entity,
                           java.lang.Object data)
This one should never be called unless it's overridden! Could be used to force changes in other fields. Normally the inverse of the logic and math in the getFieldDataFrom-method.

Specified by:
setFieldDataTo in interface ICalculatedFieldDescriptor

isValidFor

public boolean isValidFor(IEntityDescriptor descriptor)
Should Returns true if the descriptor is "valid for" = can be a part of and calculate its value based on the data defined by the submited entity descriptor.

Specified by:
isValidFor in interface ICalculatedFieldDescriptor

getRequiredFields

public IFieldDescriptor[] getRequiredFields()
Should return an array of the field descriptors required for the "calculation" of the descriptors value.

Specified by:
getRequiredFields in interface ICalculatedFieldDescriptor


Copyright © 2005 Caleigo. All Rights Reserved.