org.pm4j.core.pm.impl
Class PmAttrBase<T_PM_VALUE,T_BEAN_VALUE>

java.lang.Object
  extended by org.pm4j.core.pm.impl.PmObjectBase
      extended by org.pm4j.core.pm.impl.PmAttrBase<T_PM_VALUE,T_BEAN_VALUE>
Type Parameters:
T_PM_VALUE - The external PM api type.
Examples:
For a string field: the type String;
For a bean reference: the PM class for the referenced bean.
T_BEAN_VALUE - The bean field type.
Examples:
For a string field: the type String;
For a reference: The referenced class.
All Implemented Interfaces:
java.lang.Comparable<PmObject>, PmAttr<T_PM_VALUE>, PmDataInput, PmObject
Direct Known Subclasses:
PmAttrBooleanImpl, PmAttrDateBase, PmAttrEnumImpl, PmAttrImpl, PmAttrListImpl, PmAttrNumBase, PmAttrPmListImpl, PmAttrPmRefImpl, PmAttrStringImpl

public abstract class PmAttrBase<T_PM_VALUE,T_BEAN_VALUE>
extends PmObjectBase
implements PmAttr<T_PM_VALUE>

Basic implementation for PM attributes.

Note: If you are looking for a generic PmAttr implementation for use in client code, use PmAttrImpl, not this base class.

TODOC:

Author:
olaf boede

Nested Class Summary
protected static class PmAttrBase.MetaData
          Shared meta data for all attributes of the same kind.
 
Nested classes/interfaces inherited from class org.pm4j.core.pm.impl.PmObjectBase
PmObjectBase.NameBuilder, PmObjectBase.NameBuilderAbsoluteName, PmObjectBase.NameBuilderShortName, PmObjectBase.NameBuilderTitle
 
Nested classes/interfaces inherited from interface org.pm4j.core.pm.PmAttr
PmAttr.Converter<T>
 
Field Summary
 
Fields inherited from class org.pm4j.core.pm.impl.PmObjectBase
pmCacheLog
 
Fields inherited from interface org.pm4j.core.pm.PmObject
STYLE_CLASS_DISABLED, STYLE_CLASS_ERROR, STYLE_CLASS_INFO, STYLE_CLASS_REQUIRED, STYLE_CLASS_WARN
 
Constructor Summary
PmAttrBase(PmObject pmParent)
           
 
Method Summary
 void accept(PmVisitor visitor)
           
protected  void clearCachedPmValues(java.util.Set<PmCacheApi.CacheKind> cacheSet)
          Clears cached content (if there was something cached).
Causes a reload of the content with the next request.
 void clearPmInvalidValues()
          Clears not yet validated values within the scope of this PM.
 void commitBufferedPmChanges()
          Commits all changed values to the data store behind the presentation model.
 int compareTo(PmObject otherPm)
          The default implementation compares the results of getValueLocalized() according to the collation sequence of the current Locale.
 T_PM_VALUE convertBackingValueToPmValue(T_BEAN_VALUE backingValue)
           
 T_BEAN_VALUE convertPmValueToBackingValue(T_PM_VALUE pmAttrValue)
           
protected  boolean equalValues(T_PM_VALUE v1, T_PM_VALUE v2)
          Checks if two instances represent the same value.
 T_BEAN_VALUE getBackingValue()
           
protected  T_BEAN_VALUE getBackingValueImpl()
          Provides the internal (non PM) data type representation of the attribute value.
protected  PmAttr.Converter<T_PM_VALUE> getConverter()
           
protected  T_PM_VALUE getDefaultValue()
          The default implementation provides the default value provided by the annotation PmAttrCfg.defaultValue().
protected  T_PM_VALUE getDefaultValueImpl()
          The default implementation provides the default value provided by the annotation PmAttrCfg.defaultPath() and (if that was null) the value provided by PmAttrCfg.defaultValue().
protected  java.lang.String getFormatDefaultResKey()
          Concrete attribute classes may specify here a default format resource key as a fallback for unspecified format localizations.
 java.lang.String getFormatString()
          Returns a localized format string for attribute values provided as strings.
The localized format string is based on a resource key which may be defined as follows: You may specify it using the annotation PmAttrCfg.formatResKey(). You may define it within the resource file, using a resource key with a '_format' postfix.
Example: myPm.myNumber_format=#,##0.## For some types such as PmAttrDate and PmAttrDouble you may specify default formats.
(Attribute classes may specify this by implementing getFormatDefaultResKey().)
See: PmAttrDate.RESKEY_DEFAULT_FORMAT_PATTERN and PmAttrDouble.RESKEY_DEFAULT_FORMAT_PATTERN. The resource key gets evaluated in the sequence specified above.
 int getMaxLen()
           
 int getMinLen()
          The default implementation returns 0.
 PmOptionCfg.NullOption getNullOptionDefault()
          Provides the attribute type specific default definition, if an option set should contain a null option definition or not.
 PmOptionSet getOptionSet()
          Provides the set of value options the user may choose from.
protected  PmOptionSet getOptionSetImpl()
           
 java.lang.Iterable<?> getOptionValues()
          A combination of PmOptionCfg and the implementation of this method may be used to define the options for the attribute value.
protected  PmElement getPmParentElement()
           
protected  void getPmStyleClassesImpl(java.util.Set<java.lang.String> styleClassSet)
          Provides subclass specific style class definitions.
 T_PM_VALUE getUncachedValidValue()
          Gets attribute value directly from the bound data source.
 T_PM_VALUE getValue()
          Provides the actual value of the attribute.
 java.lang.String getValueAsString()
           
protected  T_PM_VALUE getValueImpl()
           
 java.lang.String getValueLocalized()
          The default implementation returns the result of getValueAsString().
protected  void initMetaData(PmObjectBase.MetaData metaData)
           
protected  void initMetaDataBeanConstraint( cd)
          Gets called for each found ConstraintDescriptor.
The default implementation just checks the NotNull restrictions.
Sub classes override this method to consider other restrictions.
 boolean isBufferedPmValueMode()
           
protected  boolean isEmptyValue(T_PM_VALUE value)
          Checks the attribute type specific null or empty value condition.
protected  boolean isPmEnabledImpl()
           
protected  boolean isPmReadonlyImpl()
          Sub classes may implement their specific read-only definition here.
 boolean isPmValueChanged()
          Indicates an attribute value change.
protected  boolean isPmVisibleImpl()
           
 boolean isRequired()
           
 boolean isSupportingAsStringValues()
          Defaults to true.
protected  boolean isValidatingOnSetPmValue()
          If this method returns true, each setValue(Object) will cause an immediate call to pmValidate().
protected abstract  PmObjectBase.MetaData makeMetaData()
          It's abstract because specific attribute types have to create their specific meta data.
protected  PmOptionSetDef<?> makeOptionSetDef(PmOptionCfg cfg, java.lang.reflect.Method getOptionValuesMethod)
           
 void pmValidate()
          Validates this PM.
Generates error messages in case of validation problems.
Fires PmEvent.VALIDATION_STATE_CHANGE events in case of a change of the valid-state.
 void resetPmValues()
          Reset the value to null or the optional default value definition.
 void rollbackBufferedPmChanges()
          Clears all uncommitted changes.
 void setBackingValue(T_BEAN_VALUE value)
           
protected  void setBackingValueImpl(T_BEAN_VALUE value)
          Sets the internal (non PM) data type representation of the attribute value.
 void setPmValueChanged(boolean newChangedState)
          Sets an attribute explicitly to a change or unchanged state.
 void setValue(T_PM_VALUE value)
           
 void setValueAsString(java.lang.String text)
          Sets the value with a string value.
protected  boolean setValueImpl(SetValueContainer<T_PM_VALUE> value)
          Performs a smart set operation.
protected  void validate(T_PM_VALUE value)
          The default validation checks just the required condition.
 
Methods inherited from class org.pm4j.core.pm.impl.PmObjectBase
addToPmComposite, canSetPmTitle, ensurePmMetaDataInitialization, findAnnotationsInPmHierarchy, getPmConversation, getPmConversationImpl, getPmIconPath, getPmMetaData, getPmMetaDataWithoutPmInitCall, getPmName, getPmParent, getPmProperty, getPmRelativeName, getPmResKey, getPmResKeyBase, getPmResLoaderCtxtClasses, getPmShortTitle, getPmStyleClasses, getPmTitle, getPmTitleDef, getPmTitleImpl, getPmTooltip, getPmTooltipImpl, getVisiblePmCommands, getVisiblePmCommands, isMetaDataInitialized, isPmEnabled, isPmReadonly, isPmValid, isPmVisible, onPmChildStateChange, onPmInit, onPmValueChange, readCacheStrategy, removePmChild, setPmEnabled, setPmParent, setPmProperty, setPmTitle, setPmVisible, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.pm4j.core.pm.PmObject
canSetPmTitle, getPmConversation, getPmIconPath, getPmName, getPmParent, getPmProperty, getPmRelativeName, getPmShortTitle, getPmStyleClasses, getPmTitle, getPmTooltip, isPmEnabled, isPmReadonly, isPmValid, isPmVisible, setPmEnabled, setPmParent, setPmProperty, setPmTitle, setPmVisible
 

Constructor Detail

PmAttrBase

public PmAttrBase(PmObject pmParent)
Method Detail

getPmParentElement

protected PmElement getPmParentElement()
Returns:
The next parent of type PmElement.

getOptionSet

public final PmOptionSet getOptionSet()
Description copied from interface: PmAttr
Provides the set of value options the user may choose from.

Some attributes (e.g. attributes representing enums or references to other objects) usually provide an option set.

Most PM view components use the string value of the provided option IDs to set the value of the attribute using PmAttr.setValueAsString(String).
(For multiple value attribute types the PM view components usually use the 'setListValueAsString' method signatures to set the selected option values.)

Specified by:
getOptionSet in interface PmAttr<T_PM_VALUE>
Returns:
The attribute options.
In case of no options an empty option set.

getOptionSetImpl

protected PmOptionSet getOptionSetImpl()
Returns:
An option set. In case of no options an empty option set.

getOptionValues

public java.lang.Iterable<?> getOptionValues()
A combination of PmOptionCfg and the implementation of this method may be used to define the options for the attribute value.

The id, title and value attributes of the annotation will be applied to the items of the provided object set to create the option set.

Returns:
The object to generate the options from.
May return null in case of no option values.

getNullOptionDefault

public PmOptionCfg.NullOption getNullOptionDefault()
Provides the attribute type specific default definition, if an option set should contain a null option definition or not.

Usualy non-list attributes provide the default PmOptionCfg.NullOption#FOR_OPTIONAL_ATTR and list attributes PmOptionCfg.NullOption#NO.

Returns:
The attribute type specific null-option generation default value.

isRequired

public boolean isRequired()
Specified by:
isRequired in interface PmAttr<T_PM_VALUE>
Returns:
true if the attribute value needs to be set to a value that is not null.

isPmReadonlyImpl

protected boolean isPmReadonlyImpl()
Description copied from class: PmObjectBase
Sub classes may implement their specific read-only definition here.

Overrides:
isPmReadonlyImpl in class PmObjectBase
Returns:
true if the PM is in read-only state.

isPmEnabledImpl

protected boolean isPmEnabledImpl()
Overrides:
isPmEnabledImpl in class PmObjectBase

isPmVisibleImpl

protected boolean isPmVisibleImpl()
Overrides:
isPmVisibleImpl in class PmObjectBase

getPmStyleClassesImpl

protected void getPmStyleClassesImpl(java.util.Set<java.lang.String> styleClassSet)
Description copied from class: PmObjectBase
Provides subclass specific style class definitions.

Overrides:
getPmStyleClassesImpl in class PmObjectBase
Parameters:
styleClassSet - The container to add the style classes to.

accept

public void accept(PmVisitor visitor)
Specified by:
accept in interface PmObject
Overrides:
accept in class PmObjectBase
Parameters:
visitor - A visitor to call back.

clearPmInvalidValues

public void clearPmInvalidValues()
Description copied from class: PmObjectBase
Clears not yet validated values within the scope of this PM.

Overrides:
clearPmInvalidValues in class PmObjectBase

compareTo

public int compareTo(PmObject otherPm)
The default implementation compares the results of getValueLocalized() according to the collation sequence of the current Locale.

Specified by:
compareTo in interface java.lang.Comparable<PmObject>
Specified by:
compareTo in interface PmObject
Overrides:
compareTo in class PmObjectBase
Parameters:
otherPm - The PM to compare.
Returns:
The usual Comparable result: a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

equalValues

protected boolean equalValues(T_PM_VALUE v1,
                              T_PM_VALUE v2)
Checks if two instances represent the same value.

Sub classes may override this method to provide their specific equals-conditions.

This correct implementation of this method is important for the changed state handling.

Parameters:
v1 - A value. May be null.
v2 - Another value. May be null.
Returns:
true if both parameters represent the same value.
See Also:
isPmValueChanged(), PmObjectBase.onPmValueChange(PmEvent), PmEvent.VALUE_CHANGE

getValue

public final T_PM_VALUE getValue()
Description copied from interface: PmAttr
Provides the actual value of the attribute.

For details on how to provide values see: getValue()

Specified by:
getValue in interface PmAttr<T_PM_VALUE>
Returns:
The attribute value.

setValue

public final void setValue(T_PM_VALUE value)
Specified by:
setValue in interface PmAttr<T_PM_VALUE>
Parameters:
value - The new value.

getValueAsString

public final java.lang.String getValueAsString()
Specified by:
getValueAsString in interface PmAttr<T_PM_VALUE>
Returns:
The string for the current value.

getValueLocalized

public java.lang.String getValueLocalized()
The default implementation returns the result of getValueAsString().

Specified by:
getValueLocalized in interface PmAttr<T_PM_VALUE>
Returns:
The localized string value for the current value.

getMinLen

public int getMinLen()
The default implementation returns 0.

Specified by:
getMinLen in interface PmAttr<T_PM_VALUE>
Returns:
The minimal string representation length.

getMaxLen

public int getMaxLen()
Specified by:
getMaxLen in interface PmAttr<T_PM_VALUE>
Returns:
The maximum string representation length.

setValueAsString

public final void setValueAsString(java.lang.String text)
Description copied from interface: PmAttr
Sets the value with a string value.

Specified by:
setValueAsString in interface PmAttr<T_PM_VALUE>
Parameters:
text - The new value as string.

resetPmValues

public void resetPmValues()
Description copied from interface: PmAttr
Reset the value to null or the optional default value definition.

Specified by:
resetPmValues in interface PmAttr<T_PM_VALUE>
Specified by:
resetPmValues in interface PmDataInput

clearCachedPmValues

protected void clearCachedPmValues(java.util.Set<PmCacheApi.CacheKind> cacheSet)
Description copied from class: PmObjectBase
Clears cached content (if there was something cached).
Causes a reload of the content with the next request.

Overrides:
clearCachedPmValues in class PmObjectBase

getUncachedValidValue

public final T_PM_VALUE getUncachedValidValue()
Gets attribute value directly from the bound data source. Does not use the cache and does not consider any temporarily set invalid values.

Returns:
The current attribute value.

getValueImpl

protected T_PM_VALUE getValueImpl()

setValueImpl

protected boolean setValueImpl(SetValueContainer<T_PM_VALUE> value)
Performs a smart set operation. Validates the value before applying it.

Parameters:
value - The new value.
Returns:
true when the attribute value was really changed.

isPmValueChanged

public boolean isPmValueChanged()
Description copied from interface: PmAttr
Indicates an attribute value change.

Will be cleared when

Specified by:
isPmValueChanged in interface PmAttr<T_PM_VALUE>
Specified by:
isPmValueChanged in interface PmDataInput
Returns:
true if the attribute value was changed in the live time of the PM (or since the previous value or changed state reset).

setPmValueChanged

public void setPmValueChanged(boolean newChangedState)
Description copied from interface: PmAttr
Sets an attribute explicitly to a change or unchanged state.

Is usually used for the following scenarios:

An event with the type-flag PmEvent.VALUE_CHANGED_STATE_CHANGE will be fired if the call changed this state.

Specified by:
setPmValueChanged in interface PmAttr<T_PM_VALUE>

getDefaultValue

protected final T_PM_VALUE getDefaultValue()
The default implementation provides the default value provided by the annotation PmAttrCfg.defaultValue().

Subclasses may override the method getDefaultValueImpl() to provide some special implementation.
For example an internationalized value...

Returns:
The default value for this attribute.

getDefaultValueImpl

protected T_PM_VALUE getDefaultValueImpl()
The default implementation provides the default value provided by the annotation PmAttrCfg.defaultPath() and (if that was null) the value provided by PmAttrCfg.defaultValue().

Subclasses may override this method to provide some special implementation.
For example an internationalized value...

The default implemenation internally handles the injection of request values to the attributes.

Returns:
The default value for this attribute.

isEmptyValue

protected boolean isEmptyValue(T_PM_VALUE value)
Checks the attribute type specific null or empty value condition.

Returns:
true when the value is a null or empty value equivalent.

isValidatingOnSetPmValue

protected boolean isValidatingOnSetPmValue()
If this method returns true, each setValue(Object) will cause an immediate call to pmValidate().

Alternatively validation is usually triggered by a command.


validate

protected void validate(T_PM_VALUE value)
                 throws org.pm4j.core.exception.PmValidationException
The default validation checks just the required condition. More specific attribute classes have to add their specific validation by overriding this method.

Parameters:
value - The value to validate.
Throws:
org.pm4j.core.exception.PmValidationException

pmValidate

public void pmValidate()
Description copied from interface: PmDataInput
Validates this PM.
Generates error messages in case of validation problems.
Fires PmEvent.VALIDATION_STATE_CHANGE events in case of a change of the valid-state.

Specified by:
pmValidate in interface PmDataInput

isSupportingAsStringValues

public boolean isSupportingAsStringValues()
Defaults to true.

Subclasses that don't implement the 'toString' methods should return false.

Returns:
true when the 'asString' operations are supported.

getConverter

protected PmAttr.Converter<T_PM_VALUE> getConverter()
Returns:
The converter that translates from and to the corresponding string representation.

isBufferedPmValueMode

public boolean isBufferedPmValueMode()
Specified by:
isBufferedPmValueMode in interface PmDataInput
Returns:
true when each pm value modification will be applied to an edit buffer only. Changed values will be applied when PmDataInput.commitBufferedPmChanges() is called.

commitBufferedPmChanges

public void commitBufferedPmChanges()
Description copied from interface: PmDataInput
Commits all changed values to the data store behind the presentation model.

Specified by:
commitBufferedPmChanges in interface PmDataInput

rollbackBufferedPmChanges

public void rollbackBufferedPmChanges()
Description copied from interface: PmDataInput
Clears all uncommitted changes.

Does not change values of the data store behind the presentation model.

Specified by:
rollbackBufferedPmChanges in interface PmDataInput

convertBackingValueToPmValue

public T_PM_VALUE convertBackingValueToPmValue(T_BEAN_VALUE backingValue)

convertPmValueToBackingValue

public T_BEAN_VALUE convertPmValueToBackingValue(T_PM_VALUE pmAttrValue)

getBackingValue

public final T_BEAN_VALUE getBackingValue()

setBackingValue

public final void setBackingValue(T_BEAN_VALUE value)

getBackingValueImpl

protected T_BEAN_VALUE getBackingValueImpl()
Provides the internal (non PM) data type representation of the attribute value.

Attributes may override this method to provide a specific implementation.

Returns:
The value (internal data type representation).

setBackingValueImpl

protected void setBackingValueImpl(T_BEAN_VALUE value)
Sets the internal (non PM) data type representation of the attribute value.

Attributes may override this method to provide a specific implementation.

Parameters:
value - The value to assign (internal data type representation).

getFormatString

public java.lang.String getFormatString()
Description copied from interface: PmAttr
Returns a localized format string for attribute values provided as strings.
The localized format string is based on a resource key which may be defined as follows:
  1. You may specify it using the annotation PmAttrCfg.formatResKey().
  2. You may define it within the resource file, using a resource key with a '_format' postfix.
    Example: myPm.myNumber_format=#,##0.##
  3. For some types such as PmAttrDate and PmAttrDouble you may specify default formats.
    (Attribute classes may specify this by implementing getFormatDefaultResKey().)
    See: PmAttrDate.RESKEY_DEFAULT_FORMAT_PATTERN and PmAttrDouble.RESKEY_DEFAULT_FORMAT_PATTERN.
The resource key gets evaluated in the sequence specified above. The first resource key match wins.

Specified by:
getFormatString in interface PmAttr<T_PM_VALUE>
Returns:
A localized format string or null if there is no format definition.

getFormatDefaultResKey

protected java.lang.String getFormatDefaultResKey()
Concrete attribute classes may specify here a default format resource key as a fallback for unspecified format localizations.

Returns:
The fallback resource key or null if there is none.

makeOptionSetDef

protected PmOptionSetDef<?> makeOptionSetDef(PmOptionCfg cfg,
                                             java.lang.reflect.Method getOptionValuesMethod)

makeMetaData

protected abstract PmObjectBase.MetaData makeMetaData()
It's abstract because specific attribute types have to create their specific meta data.

Specified by:
makeMetaData in class PmObjectBase
Returns:
A static data container for this presentation model.

initMetaData

protected void initMetaData(PmObjectBase.MetaData metaData)
Overrides:
initMetaData in class PmObjectBase

initMetaDataBeanConstraint

protected void initMetaDataBeanConstraint( cd)
Gets called for each found ConstraintDescriptor.
The default implementation just checks the NotNull restrictions.
Sub classes override this method to consider other restrictions.

Parameters:
cd - The ConstraintDescriptor to consider for this attribute.