org.salespointframework.core
Class SalesPoint

java.lang.Object
  extended by org.salespointframework.core.SalesPoint
All Implemented Interfaces:
java.util.EventListener, FormSheetListener, ProcessContext

public class SalesPoint
extends java.lang.Object
implements ProcessContext, FormSheetListener, java.util.EventListener

A single point of org.salespointframework.sale in a shop.

SalesPoints represent single points of org.salespointframework.sale in a Shop at which user interaction occurs. Examples for such SalesPoints are cash counters, box offices, ticket vending machines etc.

Normally, you will have at least one SalesPoint in your application.

Services available at SalesPoints are implemented as processes. There can be at most one process running at a SalesPoint at any given point of time.

SalesPoints are process contexts to the processes running at them. They provide org.salespointframework.data and org.salespointframework.log access, as well as a display and current user. When a SalesPoint is created, a display is attached to it, which will be used by the process.

A user can be attached to the SalesPoint. Its capabilities will determine what can and cannot be done at the SalesPoint.

Since:
v1.0
Version:
2.0 15/07/1999
Author:
Steffen Zschaler

Field Summary
private  boolean hideCloseIcon
          hide the close icon of the salespoint in tabbed mode
private  DataBasket m_dbBasket
          The DataBasket currently attached to this SalesPoint, if any.
private  Display m_dDisplay
          The display currently attached to this SalesPoint, if any.
private  Display m_dStatus
          The status display currently attached to this SalesPoint, if any.
private  boolean m_fIsClosing
          Flag indicating whether or not the SalesPoint is currently closing.
private  boolean m_fSuspended
          Flag indicating whether or not the SalesPoint is currently suspended.
private  int m_iID
          ID of this SalesPoint.
private  java.lang.Object m_oBasketLock
          The monitor synchronizing access to the DataBasket.
private  java.lang.Object m_oCloseLock
          The monitor synchronizing access to the closing-process.
private  java.lang.Object m_oDisplayLock
          The monitor synchronizing access to the display.
private  java.lang.Object m_oProcessLock
          The monitor synchronizing process access.
private  java.lang.Object m_oStatusDisplayLock
          The monitor synchronizing access to the status display.
private  java.lang.Object m_oUserLock
          The monitor synchronizing access to the User.
protected  SaleProcess m_pCurProcess
          The process currently running on this SalesPoint, if any.
private  java.awt.Rectangle m_rSalesPointFrameBounds
          The SalesPoints Framebounds.
private  java.lang.String m_sName
          The name of this SalesPoint.
private  java.util.Stack<SaleProcess> m_stkProcess
          A stack which saves the process on this SalesPoint.
private  User m_usrUser
          The User currently attached to this SalesPoint, if any.
 
Constructor Summary
SalesPoint(java.lang.String sName)
          Create a new SalesPoint.
 
Method Summary
 DataBasket attach(DataBasket db)
          Attach a DataBasket to this SalesPoint.
 Display attach(Display d)
           
 Display attach(Display d, boolean fSetDefaultSheets)
          Attach a new display to the SalesPoint.
 User attach(User usr)
          Attach a user to this SalesPoint.
 void attachLoadedDisplay(Display d)
          Internal communication method called by Shop to attach a display during restoration of the Shop from a stream.
protected  Display attachStatusDisplay(Display dStatus)
          Attach a status display to the SalesPoint.
protected  boolean canQuit(boolean fNoPersistence)
          Check whether this SalesPoint can be closed.
 void createNewID(java.util.Collection<SalesPoint> points)
          Computes a new ID for this SalesPoint.
 DataBasket detachBasket()
          Detach any DataBasket currently attached to this SalesPoint.
 Display detachDisplay()
          Detach the current display.
protected  Display detachStatusDisplay()
          Detach the current status display.
 User detachUser()
          Detach any user currently attached to this SalesPoint.
 void forceProcessTermination()
          This method terminates all running processes on the salespoint
 void formSheetRemoved(FormSheetEvent e)
          Implemented to make sure there always is a FormSheet.
 void formSheetSet(FormSheetEvent e)
          Dummy interface to conform by the FormSheetListener interface.
 DataBasket getBasket()
          Get the DataBasket currently attached to this SalesPoint.
private  java.lang.Object getBasketLock()
          Return the monitor synchronizing access to the DataBasket.
 Catalog getCatalog(java.lang.String sName)
          Return a Catalog for a given name.
private  java.lang.Object getCloseLock()
          Return the monitor synchronizing access to the closing-process.
 SaleProcess getCurrentProcess()
          Get the process currently running on this SalesPoint, if any.
 User getCurrentUser(SaleProcess p)
          Get the current user for the given process.
protected  FormSheet getDefaultFormSheet()
          Get the default FormSheet for this SalesPoint.
protected  MenuSheet getDefaultMenuSheet()
          Get the default MenuSheet for this SalesPoint.
protected  FormSheet getDefaultStatusFormSheet()
          Get the default status FormSheet for this SalesPoint.
protected  MenuSheet getDefaultStatusMenuSheet()
          Get the default status MenuSheet for this SalesPoint.
 Display getDisplay()
          Return the display of this SalesPoint.
private  java.lang.Object getDisplayLock()
          Return the monitor synchronizing access to the display.
 boolean getHideCloseIcon()
          get value of hideCloseIcon
 int getID()
          Return the ID of this SalesPoint;
 java.lang.String getName()
          Return the name of this SalesPoint.
protected  java.lang.Object getProcessLock()
          Return the monitor synchronizing process access.
 java.awt.Rectangle getSalesPointFrameBounds()
          Returns the Framebounds of the SalesPoints assoziated Display(JDisplayFrame).
private  java.lang.Object getStatusDisplayLock()
          Return the monitor synchronizing access to the status display.
 Stock getStock(java.lang.String sName)
          Return a Stock for a given name.
 User getUser()
          Get the user currently attached to this SalesPoint.
private  java.lang.Object getUserLock()
          Return the monitor synchronizing access to the User.
 boolean hasUseableDisplay(SaleProcess p)
          True, if the SalesPoint currently has a display and this display is useable.
 void log(SaleProcess p, Loggable la)
          Log the given Loggable.
protected  void logSalesPointClosed()
          Hook method called when the SalesPoint is removed from a Shop.
protected  void logSalesPointOpened()
          Hook method called when the SalesPoint is added to a Shop.
protected  boolean onCanQuit()
          Hook method called to determine whether a SalesPoint with no process running on it can be closed by an explicit quit call.
 void popUpFormSheet(SaleProcess p, FormSheet fs)
          Allow a process to pop up a FormSheet on the SalesPoint's current display.
 void processFinished(SaleProcess p)
          Notification that a process finished running on this SalesPoint.
 void processStarted(SaleProcess p)
          Notification that a process started on a SalesPoint.
 void quit()
          Close the SalesPoint.
 void resume()
          Resume the SalesPoint.
 void runProcess(SaleProcess p)
          Starts a process on this SalesPoint.
 void runProcess(SaleProcess p, DataBasket db)
          Starts a process on this SalesPoint.
private  void setDefaultSheets()
          Set the default Form- and MenuSheet on the currently attached display.
 void setFormSheet(SaleProcess p, FormSheet fs)
          Allow a process to set a FormSheet on the SalesPoint's current display.
 void setHideCloseIcon(boolean val)
          set hideCloseIcon value
 void setMenuSheet(SaleProcess p, MenuSheet ms)
          Allow a process to set a MenuSheet on the SalesPoint's current display.
 void setSalesPointFrameBounds(java.awt.Rectangle r)
          Sets the Framebounds of the SalesPoints assoziated Display (JDisplayFrame).
protected  void setStatusFormSheet(FormSheet fs)
          Set a FormSheet in the SalesPoint's status display.
protected  void setStatusMenuSheet(MenuSheet ms)
          Set a MenuSheet in the SalesPoint's status display.
 void suspend()
          Suspend the SalesPoint.
 java.lang.String toString()
          Return a String description of this SalesPoint: the name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_pCurProcess

protected SaleProcess m_pCurProcess
The process currently running on this SalesPoint, if any.


m_oProcessLock

private transient java.lang.Object m_oProcessLock
The monitor synchronizing process access.


hideCloseIcon

private boolean hideCloseIcon
hide the close icon of the salespoint in tabbed mode


m_sName

private java.lang.String m_sName
The name of this SalesPoint.


m_iID

private int m_iID
ID of this SalesPoint. As SalesPoints can share the same name, the ID is used as unique identifier.


m_stkProcess

private java.util.Stack<SaleProcess> m_stkProcess
A stack which saves the process on this SalesPoint. When a new process is started on the SalesPoint the currently running process is pushed onto the stack.


m_dDisplay

private transient Display m_dDisplay
The display currently attached to this SalesPoint, if any. This will be saved/restored by the Shop.


m_oDisplayLock

private transient java.lang.Object m_oDisplayLock
The monitor synchronizing access to the display.


m_dStatus

private Display m_dStatus
The status display currently attached to this SalesPoint, if any.


m_oStatusDisplayLock

private transient java.lang.Object m_oStatusDisplayLock
The monitor synchronizing access to the status display.


m_fSuspended

private boolean m_fSuspended
Flag indicating whether or not the SalesPoint is currently suspended.


m_oCloseLock

private transient java.lang.Object m_oCloseLock
The monitor synchronizing access to the closing-process.


m_fIsClosing

private boolean m_fIsClosing
Flag indicating whether or not the SalesPoint is currently closing.


m_dbBasket

private DataBasket m_dbBasket
The DataBasket currently attached to this SalesPoint, if any.


m_oBasketLock

private transient java.lang.Object m_oBasketLock
The monitor synchronizing access to the DataBasket.


m_usrUser

private User m_usrUser
The User currently attached to this SalesPoint, if any.


m_oUserLock

private transient java.lang.Object m_oUserLock
The monitor synchronizing access to the User.


m_rSalesPointFrameBounds

private java.awt.Rectangle m_rSalesPointFrameBounds
The SalesPoints Framebounds.

Constructor Detail

SalesPoint

public SalesPoint(java.lang.String sName)
Create a new SalesPoint.

Parameters:
sName - the name of the SalesPoint.
Method Detail

getProcessLock

protected final java.lang.Object getProcessLock()
Return the monitor synchronizing process access.


getDisplayLock

private final java.lang.Object getDisplayLock()
Return the monitor synchronizing access to the display.


getStatusDisplayLock

private final java.lang.Object getStatusDisplayLock()
Return the monitor synchronizing access to the status display.


getCloseLock

private final java.lang.Object getCloseLock()
Return the monitor synchronizing access to the closing-process.


getBasketLock

private final java.lang.Object getBasketLock()
Return the monitor synchronizing access to the DataBasket.


getUserLock

private final java.lang.Object getUserLock()
Return the monitor synchronizing access to the User.


getName

public java.lang.String getName()
Return the name of this SalesPoint.


getID

public int getID()
Return the ID of this SalesPoint;


createNewID

public void createNewID(java.util.Collection<SalesPoint> points)
Computes a new ID for this SalesPoint.

Parameters:
points - The SalesPoints to be taken into consideration when computing a unique ID.

canQuit

protected final boolean canQuit(boolean fNoPersistence)
Check whether this SalesPoint can be closed. Unless the SalesPoint has been suspended before calling canQuit the result of this method may not be reliable.

By default, if a process runs on the SalesPoint its canQuit method is called. If no process is running, and fNoPersistence is true, onCanQuit() is called which opens a MsgForm to ask the user whether he/she really wants to close the SalesPoint. If fNoPersistence is false and no process is running on the SalesPoint, the default implementation always returns true.

This method is usually not called directly.

Parameters:
fNoPersistence - true if the call to canQuit resulted from an explicit call to quit() or from a call to Shop.shutdown (false). If fNoPersistence == false you can assume, the state of the SalesPoint will be made persistent before it is closed.

onCanQuit

protected boolean onCanQuit()
Hook method called to determine whether a SalesPoint with no process running on it can be closed by an explicit quit call. In this method you can assume that the state of the SalesPoint will not be saved and therefore will not be restoreable.

Returns:
true if the SalesPoint can be closed, false otherwise.

quit

public void quit()
Close the SalesPoint.

First suspends the SalesPoint, then calls canQuit(boolean). If that returns false, quit will resume() the SalesPoint and return. Otherwise, it quits the current process, if any, and removes the SalesPoint from the Shop.


logSalesPointOpened

protected void logSalesPointOpened()
Hook method called when the SalesPoint is added to a Shop. You can write a org.salespointframework.log entry here.

See Also:
Shop.addSalesPoint(org.salespointframework.core.SalesPoint), Log, LogEntry

logSalesPointClosed

protected void logSalesPointClosed()
Hook method called when the SalesPoint is removed from a Shop. You can write a org.salespointframework.log entry here.

See Also:
Shop.removeSalesPoint(org.salespointframework.core.SalesPoint), Log, LogEntry

runProcess

public final void runProcess(SaleProcess p)
Starts a process on this SalesPoint.

The process will run in the context of this SalesPoint, and with the DataBasket attached to this SalesPoint.

If there is already a process running on this SalesPoint it will be suspended until the new process has finished.

Parameters:
p - the process to be run.

runProcess

public final void runProcess(SaleProcess p,
                             DataBasket db)
Starts a process on this SalesPoint.

The process will run in the context of this SalesPoint, and with the DataBasket attached to this SalesPoint.

If there is already a process running on this SalesPoint it will be suspended until the new process has finished.

Parameters:
p - the process to be run.
db - the DataBasket to be attached to the new process

getCurrentProcess

public final SaleProcess getCurrentProcess()
Get the process currently running on this SalesPoint, if any.


suspend

public void suspend()
             throws java.lang.InterruptedException
Suspend the SalesPoint.

If a process is running on the SalesPoint, it is suspended. The method will only return when the SalesPoint has been properly suspended.

Throws:
java.lang.InterruptedException - if an interrupt occurred while waiting for the SalesPoint to be suspended.

resume

public void resume()
Resume the SalesPoint.

If a process is running on the SalesPoint, it is resumed.


attach

public User attach(User usr)
Attach a user to this SalesPoint.

The user attached to a SalesPoint can be accessed by processes running on the SalesPoint an can be used to determine capabilities etc.

Parameters:
usr - the user to be attached.
Returns:
the user that was previously attached to this SalesPoint, if any.

detachUser

public User detachUser()
Detach any user currently attached to this SalesPoint.

Returns:
the user that was previously attached to this SalesPoint, if any.

getUser

public User getUser()
Get the user currently attached to this SalesPoint.

Returns:
the user currently attached to this SalesPoint, if any.

attach

public DataBasket attach(DataBasket db)
Attach a DataBasket to this SalesPoint.

Parameters:
db - the DataBasket to be attached.
Returns:
the DataBasket that was previously attached to this SalesPoint, if any.

detachBasket

public DataBasket detachBasket()
Detach any DataBasket currently attached to this SalesPoint.

Returns:
the DataBasket that was previously attached to this SalesPoint, if any.

getBasket

public DataBasket getBasket()
Get the DataBasket currently attached to this SalesPoint.

Returns:
the DataBasket currently attached to this SalesPoint, if any.

attachStatusDisplay

protected Display attachStatusDisplay(Display dStatus)
Attach a status display to the SalesPoint.

This display can be used to give status information about the SalesPoint. It can also be used to trigger background processes for the SalesPoint. It should not be used to trigger processes on the SalesPoint.

If the given display is not null, it must be useable.

Parameters:
dStatus - the new status display for this SalesPoint.
Returns:
the previous status display, if any.

detachStatusDisplay

protected Display detachStatusDisplay()
Detach the current status display.

Returns:
the previous status display, if any.

setStatusFormSheet

protected void setStatusFormSheet(FormSheet fs)
Set a FormSheet in the SalesPoint's status display.

Status display FormSheet's are always nonmodal, which is why this method returns immediately after setting the FormSheet and can never throw an InterruptedException.

Parameters:
fs - the FormSheet to be set.

setStatusMenuSheet

protected void setStatusMenuSheet(MenuSheet ms)
Set a MenuSheet in the SalesPoint's status display.

Parameters:
ms - the MenuSheet to be set.

getDefaultStatusMenuSheet

protected MenuSheet getDefaultStatusMenuSheet()
Get the default status MenuSheet for this SalesPoint.

Unless you specify differently through an explicit call to setStatusMenuSheet(org.salespointframework.core.MenuSheet), the Framework will use this MenuSheet for the SalesPoint's status display.

See Also:
attachStatusDisplay(org.salespointframework.core.Display)

getDefaultStatusFormSheet

protected FormSheet getDefaultStatusFormSheet()
Get the default status FormSheet for this SalesPoint.

Unless you specify differently through an explicit call to setStatusFormSheet(org.salespointframework.core.FormSheet), the Framework will use this FormSheet for the SalesPoint's status display.

See Also:
attachStatusDisplay(org.salespointframework.core.Display)

attachLoadedDisplay

public void attachLoadedDisplay(Display d)
Internal communication method called by Shop to attach a display during restoration of the Shop from a stream.

Parameters:
d - the display just loaded.

attach

public Display attach(Display d,
                      boolean fSetDefaultSheets)
Attach a new display to the SalesPoint.

Any Form- or MenuSheets displayed on the current display will be removed, and the SalesPoint's default sheets will be set on the new display.

Parameters:
d - the new display
Returns:
the previously attached display, if any.
See Also:
getDefaultFormSheet(), getDefaultMenuSheet()

attach

public Display attach(Display d)

detachDisplay

public Display detachDisplay()
Detach the current display.

Any Form- or MenuSheet on the current display will be removed before detaching the display.

Returns:
the detached display, if any.

getDisplay

public Display getDisplay()
Return the display of this SalesPoint.

Returns:
the display of this SalesPoint.

setDefaultSheets

private void setDefaultSheets()
Set the default Form- and MenuSheet on the currently attached display.

See Also:
getDefaultMenuSheet(), getDefaultFormSheet()

getDefaultFormSheet

protected FormSheet getDefaultFormSheet()
Get the default FormSheet for this SalesPoint.

The default FormSheet will be displayed whenever there is a current user (and, thus, a display), but no process is running and no other FormSheet is being displayed.

Returns:
the default FormSheet, if any.

getDefaultMenuSheet

protected MenuSheet getDefaultMenuSheet()
Get the default MenuSheet for this SalesPoint.

The default MenuSheet will be displayed whenever there is a current user (and, thus, a display), but no process is running.

Returns:
the default MenuSheet, if any.

setHideCloseIcon

public void setHideCloseIcon(boolean val)
set hideCloseIcon value

Parameters:
val -

getHideCloseIcon

public boolean getHideCloseIcon()
get value of hideCloseIcon

Returns:

setFormSheet

public void setFormSheet(SaleProcess p,
                         FormSheet fs)
                  throws java.lang.InterruptedException
Allow a process to set a FormSheet on the SalesPoint's current display.

The process launching the FormSheet as well as this SalesPoint will be attached to the FormSheet prior to displaying it. Thus, Actions triggered by the FormSheet will run in the correct context and will be able to access the process and the SalesPoint.

If the FormSheet requests that the Framework wait for it being closed, setFormSheet() will block until the FormSheet was closed or an interrupt occured.

Specified by:
setFormSheet in interface ProcessContext
Parameters:
p - the process that wants to display the FormSheet.
fs - the FormSheet to be displayed.
Throws:
java.lang.InterruptedException - if an interrupt occurred while waiting for the FormSheet to be closed.
See Also:
Action, FormSheet.waitResponse()

setSalesPointFrameBounds

public void setSalesPointFrameBounds(java.awt.Rectangle r)
Sets the Framebounds of the SalesPoints assoziated Display (JDisplayFrame).

Example:

sp.setSalesPointFrameBounds (new Rectangle (10,10,200,200)); This moves the SalesPointFrame to Position (10,10) with a size of (200,200).


getSalesPointFrameBounds

public java.awt.Rectangle getSalesPointFrameBounds()
Returns the Framebounds of the SalesPoints assoziated Display(JDisplayFrame).


popUpFormSheet

public void popUpFormSheet(SaleProcess p,
                           FormSheet fs)
                    throws java.lang.InterruptedException
Allow a process to pop up a FormSheet on the SalesPoint's current display.

The process launching the FormSheet as well as this SalesPoint will be attached to the FormSheet prior to displaying it. Thus, Actions triggered by the FormSheet will run in the correct context and will be able to access the process and the SalesPoint.

If the FormSheet requests that the Framework wait for it being closed, popUpFormSheet will block until the FormSheet was closed or an interrupt occured.

Specified by:
popUpFormSheet in interface ProcessContext
Parameters:
p - the process that wants to display the FormSheet.
fs - the FormSheet to be displayed.
Throws:
java.lang.InterruptedException - if an interrupt occurred while waiting for the FormSheet to be closed.
See Also:
Action, FormSheet.waitResponse()

setMenuSheet

public void setMenuSheet(SaleProcess p,
                         MenuSheet ms)
Allow a process to set a MenuSheet on the SalesPoint's current display.

The process setting the MenuSheet as well as this SalesPoint will be attached to the MenuSheet prior to displaying it. Thus, Actions triggered by the MenuSheet will run in the correct context and will be able to access the process and the SalesPoint.

Specified by:
setMenuSheet in interface ProcessContext
Parameters:
p - the process that wants to display the MenuSheet.
ms - the MenuSheet to be displayed.
See Also:
Action

hasUseableDisplay

public boolean hasUseableDisplay(SaleProcess p)
True, if the SalesPoint currently has a display and this display is useable.

Specified by:
hasUseableDisplay in interface ProcessContext
Parameters:
p - the process querying, unused.
See Also:
Display.isUseableDisplay()

log

public void log(SaleProcess p,
                Loggable la)
         throws java.io.IOException
Log the given Loggable.

The given loggable object will be logged into the global org.salespointframework.log file unless you override this method.

Specified by:
log in interface ProcessContext
Parameters:
p - the SalesProcess demanding logging, unused.
la - the object to be logged.
Throws:
java.io.IOException - if an error occurs while trying to write the org.salespointframework.log org.salespointframework.data.

getCurrentUser

public final User getCurrentUser(SaleProcess p)
Get the current user for the given process. This is the user, if any, previously attached with the attach(User) method.

Specified by:
getCurrentUser in interface ProcessContext
Parameters:
p - the process querying, unused.
Returns:
the current user
See Also:
getUser()

getStock

public Stock getStock(java.lang.String sName)
Return a Stock for a given name.

Specified by:
getStock in interface ProcessContext
Parameters:
sName - the name of the Stock.
Returns:
the Stock that was found for the given name, if any.

getCatalog

public Catalog getCatalog(java.lang.String sName)
Return a Catalog for a given name.

Specified by:
getCatalog in interface ProcessContext
Parameters:
sName - the name of the Catalog.
Returns:
the Catalog that was found for the given name, if any.

forceProcessTermination

public void forceProcessTermination()
This method terminates all running processes on the salespoint


processStarted

public void processStarted(SaleProcess p)
Notification that a process started on a SalesPoint.

This will remove all SalesPoint owned Form- and MenuSheets from the display, as to make room for the process' sheets.

Specified by:
processStarted in interface ProcessContext
Parameters:
p - the process that was just launched.

processFinished

public void processFinished(SaleProcess p)
Notification that a process finished running on this SalesPoint.

This will restore a previously interrupted SaleProcess or the SalesPoint's default sheets if there is no more pending process.

Specified by:
processFinished in interface ProcessContext
Parameters:
p - the process that was finished.

formSheetSet

public void formSheetSet(FormSheetEvent e)
Dummy interface to conform by the FormSheetListener interface.

Specified by:
formSheetSet in interface FormSheetListener
Parameters:
e - the event object.

formSheetRemoved

public void formSheetRemoved(FormSheetEvent e)
Implemented to make sure there always is a FormSheet.

Specified by:
formSheetRemoved in interface FormSheetListener
Parameters:
e - the event object.

toString

public java.lang.String toString()
Return a String description of this SalesPoint: the name.

Overrides:
toString in class java.lang.Object