SalesPoint Framework v3.1

sale
Class SalesPoint

java.lang.Object
  extended bysale.SalesPoint
All Implemented Interfaces:
EventListener, FormSheetListener, ProcessContext, Serializable, SerializableListener

public class SalesPoint
extends Object
implements ProcessContext, FormSheetListener, SerializableListener

A single point of sale in a shop.

SalesPoints represent single points of 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 data and 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
Author:
Steffen Zschaler
See Also:
Serialized Form

Field Summary
protected  SaleProcess m_pCurProcess
          The process currently running on this SalesPoint, if any.
 
Constructor Summary
SalesPoint(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(Collection 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 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.
 Catalog getCatalog(String sName)
          Return a Catalog for a given name.
 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.
 int getID()
          Return the ID of this SalesPoint;
 String getName()
          Return the name of this SalesPoint.
 Object getProcessData(String sKey)
          Get an object from the ProcessContext.
protected  Object getProcessLock()
          Return the monitor synchronizing process access.
 Rectangle getSalesPointFrameBounds()
          Returns the Framebounds of the SalesPoints assoziated Display(JDisplayFrame).
 Stock getStock(String sName)
          Return a Stock for a given name.
 User getUser()
          Get the user currently attached to this SalesPoint.
 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.
 void setFormSheet(SaleProcess p, FormSheet fs)
          Allow a process to set a FormSheet on the SalesPoint's current display.
 void setMenuSheet(SaleProcess p, MenuSheet ms)
          Allow a process to set a MenuSheet on the SalesPoint's current display.
 void setProcessData(String sKey, Object oData)
          Put an object into the ProcessContext.
 void setSalesPointFrameBounds(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.
 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.

Constructor Detail

SalesPoint

public SalesPoint(String sName)
Create a new SalesPoint.

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

getProcessLock

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

Override:
Never

getName

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

Override:
Never

getID

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


createNewID

public void createNewID(Collection points)
Computes a new ID for this SalesPoint.

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

canQuit

protected 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.
Override:
Sometimes See above for an description of the default implementation.

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.
Override:
Sometimes The default implementation opens a MsgForm asking the user if they really want to close the SalesPoint.

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.

Override:
Never

logSalesPointOpened

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

See Also:
Shop.addSalesPoint(sale.SalesPoint), Log, LogEntry
Override:
Sometimes The default implementation does nothing.

logSalesPointClosed

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

See Also:
Shop.removeSalesPoint(sale.SalesPoint), Log, LogEntry
Override:
Sometimes The default implementation does nothing.

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.
Override:
Never

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
Override:
Never

getCurrentProcess

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

Override:
Never

suspend

public void suspend()
             throws 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:
InterruptedException - if an interrupt occurred while waiting for the SalesPoint to be suspended.
Override:
Never

resume

public void resume()
Resume the SalesPoint.

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

Override:
Never

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.
Override:
Never

detachUser

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

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

getUser

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

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

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.
Override:
Never

detachBasket

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

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

getBasket

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

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

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.
Override:
Never

detachStatusDisplay

protected Display detachStatusDisplay()
Detach the current status display.

Returns:
the previous status display, if any.
Override:
Never

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.
Override:
Never

setStatusMenuSheet

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

Parameters:
ms - the MenuSheet to be set.
Override:
Never

getDefaultStatusMenuSheet

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

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

See Also:
attachStatusDisplay(sale.Display)
Override:
Sometimes The default implementation returns null to indicate no MenuSheet.

getDefaultStatusFormSheet

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

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

See Also:
attachStatusDisplay(sale.Display)
Override:
Sometimes The default implementation returns an empty FormSheet.

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.
Override:
Never

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()
Override:
Never

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.
Override:
Never

getDisplay

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

Returns:
the display of this SalesPoint.

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.
Override:
Always The default implementation returns a FormSheet that simply states the name of the SalesPoint.

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.
Override:
Always The default implementation returns null indicating no MenuSheet.

setFormSheet

public void setFormSheet(SaleProcess p,
                         FormSheet fs)
                  throws 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:
InterruptedException - if an interrupt occurred while waiting for the FormSheet to be closed.
See Also:
Action, FormSheet.waitResponse()
Override:
Never

setSalesPointFrameBounds

public void setSalesPointFrameBounds(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).

Override:
Sometimes

getSalesPointFrameBounds

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

Override:
Sometimes

popUpFormSheet

public void popUpFormSheet(SaleProcess p,
                           FormSheet fs)
                    throws 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:
InterruptedException - if an interrupt occurred while waiting for the FormSheet to be closed.
See Also:
Action, FormSheet.waitResponse()
Override:
Never

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
Override:
Never

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()
Override:
Never

log

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

The given loggable object will be logged into the global 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:
IOException - if an error occurs while trying to write the log data.
Override:
Sometimes

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()
Override:
Never

getStock

public Stock getStock(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.
Override:
Sometimes

getCatalog

public Catalog getCatalog(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.
Override:
Sometimes

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.
Override:
Never

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.
Override:
Never

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.
Override:
Never

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.
Override:
Never

toString

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

Override:
Sometimes

setProcessData

public void setProcessData(String sKey,
                           Object oData)
Put an object into the ProcessContext.

Specified by:
setProcessData in interface ProcessContext
Parameters:
sKey - object's identifier
oData - the data object
Override:
Never

getProcessData

public Object getProcessData(String sKey)
Get an object from the ProcessContext.

Specified by:
getProcessData in interface ProcessContext
Parameters:
sKey - object's key
Returns:
the object from ProcessContext
Override:
Never

SalesPoint Framework v3.1