org.pm4j.core.pm.impl
Class PmConversationImpl

java.lang.Object
  extended by org.pm4j.core.pm.impl.PmObjectBase
      extended by org.pm4j.core.pm.impl.PmDataInputBase
          extended by org.pm4j.core.pm.impl.PmElementBase
              extended by org.pm4j.core.pm.impl.PmConversationImpl
All Implemented Interfaces:
java.lang.Comparable<PmObject>, PmConversation, PmDataInput, PmElement, PmObject, PmTreeNode
Direct Known Subclasses:
PmConversationImpl.ChildSession

public class PmConversationImpl
extends PmElementBase
implements PmConversation

Basic PM conversation implementation.

TODO: Move code for message and invalid value handling out to a separate class. The current code mix is too complex.

Author:
olaf boede

Nested Class Summary
static class PmConversationImpl.ChildSession<T_PARENT extends PmConversation>
          Deprecated. 
 
Nested classes/interfaces inherited from class org.pm4j.core.pm.impl.PmObjectBase
PmObjectBase.MetaData, PmObjectBase.NameBuilder, PmObjectBase.NameBuilderAbsoluteName, PmObjectBase.NameBuilderShortName, PmObjectBase.NameBuilderTitle
 
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
PmConversationImpl()
          Default constructor for some limited dependency injection frameworks that don't support constructor parameters.
PmConversationImpl(java.lang.Class<?>... pmFactoryClasses)
          Constructor for not annotation based creation of root conversations.
Used for very small sample and test applications.
PmConversationImpl(PmObject pmParent)
           
PmConversationImpl(PmObject pmParent, java.lang.Class<?>... pmFactoryClasses)
          Constructor for not annotation based creation of conversations.
Used for very small sample and test applications.
 
Method Summary
 PmMessage addPmMessage(PmMessage.Severity severity, java.lang.String resKey, java.lang.Object... resArgs)
          Adds a message to the conversation.
 void addPmMessage(PmMessage pmMessage)
          Adds a message to the conversation.
 void clearPmInvalidValues()
          Clears: All messages of all models within this conversation. The not validated attribute values of all elements within this conversation.
 void clearPmMessages(PmObject pm, PmMessage.Severity severity)
          Clears the messages with the given severity.
 void commitBufferedPmChanges()
          Commits all changed values to the data store behind the presentation model.
 boolean getHasPmErrors()
           
protected  org.pm4j.core.pm.impl.BeanPmFactory getOwnPmElementFactory()
           
 PmCommandHistory getPmCommandHistory()
           
 PmConversation getPmConversation()
          Optimization: Cached session navigation.
 PmDefaults getPmDefaults()
          The default definitions may be defined for a tree of PMs.
 PmExceptionHandler getPmExceptionHandler()
           
 java.util.Locale getPmLocale()
          Provides the language to be used for the for titles, tool tips etc.
 java.util.List<PmMessage> getPmMessages()
          Gets all active messages within this conversation.
 java.util.List<PmMessage> getPmMessages(PmObject forPm, PmMessage.Severity severity)
          Gets all messages for the given model.
 java.lang.Object getPmNamedObject(java.lang.Object key)
           
 org.pm4j.navi.NaviHistory getPmNaviHistory()
           
 PmConversation getPmParentConversation()
           
 PmToViewTechnologyConnector getViewConnector()
           
protected  void handleNamedPmObjectNotFound(java.lang.String name)
          Will be called when #findNamedPmObject(String) did not find a value for the given name.
An implementation may use this method to generate the requested object on the fly.
 boolean isBufferedPmValueMode()
           
 void rollbackBufferedPmChanges()
          Clears all uncommitted changes.
 void setBufferedPmValueMode(boolean bufferedMode)
          Defines if changes should be applied to the buffer only or to the data container behind the presentation model.
 void setPmDefaults(PmDefaults pmDefaults)
           
 void setPmExceptionHandler(PmExceptionHandler localPmExceptionHandler)
          Defines a handler that will be called whenever an exception occurs with an PM layer operation that is related to this conversation.
 void setPmLocale(java.util.Locale locale)
           
 java.lang.Object setPmNamedObject(java.lang.Object key, java.lang.Object value)
          Sets a property that is stored within this conversation instance.
 void setPmViewConnector(PmToViewTechnologyConnector navigationHandler)
           
 
Methods inherited from class org.pm4j.core.pm.impl.PmElementBase
accept, clearCachedPmValues, findAnnotationsInPmHierarchy, getNodeDetailsPm, getPmAttribute, getPmAttributes, getPmChildNodes, getPmChildNodesImpl, getPmKey, isPmReadonlyImpl, isPmTreeLeaf, isValidatingOnSetPmValue, makeMetaData
 
Methods inherited from class org.pm4j.core.pm.impl.PmDataInputBase
isPmValueChanged, pmValidate, resetPmValues
 
Methods inherited from class org.pm4j.core.pm.impl.PmObjectBase
addToPmComposite, canSetPmTitle, compareTo, ensurePmMetaDataInitialization, getPmConversationImpl, getPmIconPath, getPmMetaData, getPmMetaDataWithoutPmInitCall, getPmName, getPmParent, getPmProperty, getPmRelativeName, getPmResKey, getPmResKeyBase, getPmResLoaderCtxtClasses, getPmShortTitle, getPmStyleClasses, getPmStyleClassesImpl, getPmTitle, getPmTitleDef, getPmTitleImpl, getPmTooltip, getPmTooltipImpl, getVisiblePmCommands, getVisiblePmCommands, initMetaData, isMetaDataInitialized, isPmEnabled, isPmEnabledImpl, isPmReadonly, isPmValid, isPmVisible, isPmVisibleImpl, 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.PmElement
getPmAttribute, getPmAttributes, getPmKey
 
Methods inherited from interface org.pm4j.core.pm.PmDataInput
isPmValueChanged, pmValidate, resetPmValues
 
Methods inherited from interface org.pm4j.core.pm.PmTreeNode
getNodeDetailsPm, getPmChildNodes, isPmTreeLeaf
 
Methods inherited from interface org.pm4j.core.pm.PmObject
accept, canSetPmTitle, compareTo, getPmIconPath, getPmName, getPmParent, getPmProperty, getPmRelativeName, getPmShortTitle, getPmStyleClasses, getPmTitle, getPmTooltip, isPmEnabled, isPmReadonly, isPmValid, isPmVisible, setPmEnabled, setPmParent, setPmProperty, setPmTitle, setPmVisible
 

Constructor Detail

PmConversationImpl

public PmConversationImpl()
Default constructor for some limited dependency injection frameworks that don't support constructor parameters.


PmConversationImpl

public PmConversationImpl(java.lang.Class<?>... pmFactoryClasses)
Constructor for not annotation based creation of root conversations.
Used for very small sample and test applications.

Parameters:
pmFactoryClasses - The PM classes, used to initialize the internal PM-Bean factory.

PmConversationImpl

public PmConversationImpl(PmObject pmParent,
                          java.lang.Class<?>... pmFactoryClasses)
Constructor for not annotation based creation of conversations.
Used for very small sample and test applications.

Parameters:
pmParent - The optional parent context PM.
pmFactoryClasses - The PM classes, used to initialize the internal PM-Bean factory.

PmConversationImpl

public PmConversationImpl(PmObject pmParent)
Parameters:
pmParent - The optional parent context PM.
Method Detail

getPmConversation

public PmConversation getPmConversation()
Description copied from class: PmElementBase
Optimization: Cached session navigation.

Specified by:
getPmConversation in interface PmObject
Overrides:
getPmConversation in class PmElementBase
Returns:
The conversation context of this model element. Never null.

getPmDefaults

public PmDefaults getPmDefaults()
Description copied from interface: PmConversation
The default definitions may be defined for a tree of PMs.

Specified by:
getPmDefaults in interface PmConversation
Returns:
The PmDefaults definitions to be used.

setPmDefaults

public void setPmDefaults(PmDefaults pmDefaults)
Parameters:
pmDefaults - The settings to be used for the PM tree of this conversation object.

getPmNaviHistory

public org.pm4j.navi.NaviHistory getPmNaviHistory()
Specified by:
getPmNaviHistory in interface PmConversation
Returns:
The history of visited pages.

getPmLocale

public java.util.Locale getPmLocale()
Description copied from interface: PmConversation
Provides the language to be used for the for titles, tool tips etc. of the PMs within the scope of this conversation.

If no language is defined for this conversation and all (optionally existing) parent conversations, the default language of the Java VM will be used.

Specified by:
getPmLocale in interface PmConversation
Returns:
The locale that is used within this conversation.
Returns never null.

setPmLocale

public void setPmLocale(java.util.Locale locale)
Specified by:
setPmLocale in interface PmConversation
Parameters:
locale - The locale to be used within the scope of this conversation.
May be null for sub conversations to switch back to the locale of the parent conversation or (in case of a root conversation) to the language of the Java VM.

getPmCommandHistory

public PmCommandHistory getPmCommandHistory()
Specified by:
getPmCommandHistory in interface PmConversation
Returns:
The undo/redo command history of this conversation.

setPmExceptionHandler

public void setPmExceptionHandler(PmExceptionHandler localPmExceptionHandler)
Defines a handler that will be called whenever an exception occurs with an PM layer operation that is related to this conversation.

Views may define specific handlers to render exception related information.

Parameters:
pmExceptionHandler -

getPmExceptionHandler

public PmExceptionHandler getPmExceptionHandler()
Returns:
The PmExceptionHandler that handles exceptions for this conversation. If no local handler is defined, the handler of the parent conversation or the default handler will be returned.
Will never return null.

setPmViewConnector

public void setPmViewConnector(PmToViewTechnologyConnector navigationHandler)

getViewConnector

public PmToViewTechnologyConnector getViewConnector()
Returns:
The platform and/or conversation specific PmToViewTechnologyConnector. If no local handler is defined, the handler of the parent conversation or the default handler will be returned.
Will never return null.

getPmParentConversation

public PmConversation getPmParentConversation()
Specified by:
getPmParentConversation in interface PmConversation
Returns:
The optional parent conversation context.

null if this is the top most conversation instance.


getOwnPmElementFactory

protected org.pm4j.core.pm.impl.BeanPmFactory getOwnPmElementFactory()

addPmMessage

public void addPmMessage(PmMessage pmMessage)
Description copied from interface: PmConversation
Adds a message to the conversation.

Specified by:
addPmMessage in interface PmConversation
Parameters:
pmMessage - The message to add.

addPmMessage

public PmMessage addPmMessage(PmMessage.Severity severity,
                              java.lang.String resKey,
                              java.lang.Object... resArgs)
Adds a message to the conversation.

Creates internally a message that uses this conversation as pm context. That means that it should be possible to find the resource string in relation to the concrete conversation class. (In its directory or above it.)

Parameters:
severity - Severity of the message.
resKey - Resource key for the localized message.
resArgs - Resource string arguments.
Returns:
The added message instance.

getPmMessages

public java.util.List<PmMessage> getPmMessages()
Description copied from interface: PmConversation
Gets all active messages within this conversation.

Specified by:
getPmMessages in interface PmConversation
Returns:
The messages. An empty collection if there are no messages.

getPmMessages

public java.util.List<PmMessage> getPmMessages(PmObject forPm,
                                               PmMessage.Severity severity)
Gets all messages for the given model.

Specified by:
getPmMessages in interface PmConversation
Parameters:
severity - Severities to return. If null is passed here all messages will be returned.
Returns:
The messages. An empty collection if there are no messages.

clearPmMessages

public void clearPmMessages(PmObject pm,
                            PmMessage.Severity severity)
Clears the messages with the given severity.

Parameters:
pm - The presentation model the messages should be cleaned for or null if all messages have to be cleared.
severity - The severity level to clear. Clears all messages if null is passed here.

clearPmInvalidValues

public void clearPmInvalidValues()
Clears:

handleNamedPmObjectNotFound

protected void handleNamedPmObjectNotFound(java.lang.String name)
Will be called when #findNamedPmObject(String) did not find a value for the given name.
An implementation may use this method to generate the requested object on the fly.

TODO: describe a conversation scope scenario...

Parameters:
name - Name of the missing property.

getHasPmErrors

public boolean getHasPmErrors()
Specified by:
getHasPmErrors in interface PmConversation
Returns:
true when any validation has failed and/or another error message exists.

getPmNamedObject

public java.lang.Object getPmNamedObject(java.lang.Object key)
Specified by:
getPmNamedObject in interface PmConversation
Parameters:
key - The property key.
Returns:
The found property value. May be null when the property is not set.
See Also:
for more detailed information.

setPmNamedObject

public java.lang.Object setPmNamedObject(java.lang.Object key,
                                         java.lang.Object value)
Description copied from interface: PmConversation
Sets a property that is stored within this conversation instance.

ATTENTION for Web application developers: If your PmConversation is used in session scope, this property value will be shared for all opened tabs and windows of the user session.
If you want to manage specific property values for each tab or window, consider the usage of conversation or navigation scoped properties.

If you have configured a NaviHistory, you may use conversation and navigation scoped variables.
See NaviHistory.setNaviScopeProperty(String, Object) for more information.

Alternatively you may consider the usage of dialog specific memory scopes provided by your application framework.
Frameworks like Seem and Spring Webflow offer some solutions.

Specified by:
setPmNamedObject in interface PmConversation
Parameters:
key - The property key.
value - The property value. When it is null, the property will be removed.
Returns:
The value that was bound to the given key before this call.
null if the property was set for the first time.

isBufferedPmValueMode

public boolean isBufferedPmValueMode()
Specified by:
isBufferedPmValueMode in interface PmDataInput
Overrides:
isBufferedPmValueMode in class PmDataInputBase
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.

setBufferedPmValueMode

public void setBufferedPmValueMode(boolean bufferedMode)
Description copied from interface: PmConversation
Defines if changes should be applied to the buffer only or to the data container behind the presentation model.

Specified by:
setBufferedPmValueMode in interface PmConversation
Parameters:
bufferedMode - true switches to buffered mode.
false switches to unbuffered mode.

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
Overrides:
rollbackBufferedPmChanges in class PmDataInputBase

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
Overrides:
commitBufferedPmChanges in class PmDataInputBase