org.salespointframework.core.data
Class AbstractCurrency

java.lang.Object
  extended by org.salespointframework.core.data.AbstractNameable
      extended by org.salespointframework.core.data.CatalogItemImpl
          extended by org.salespointframework.core.data.CatalogImpl<CurrencyItemImpl>
              extended by org.salespointframework.core.data.AbstractCurrency
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable<java.lang.Object>, java.lang.Iterable<CurrencyItemImpl>, Recoverable, DatasourceChangeListener, ExternalModificationListener, Catalog<CurrencyItemImpl>, CatalogItem, Currency<CurrencyItemImpl>, DataBasketEntryDestination, DataBasketEntrySource, DataBasketKeys, ListenableCatalog<CurrencyItemImpl>, Nameable, NameContext, SpAggregate, SpItem, SelfManagingDBEDestination<CurrencyItemImpl>, SelfManagingDBESource<CurrencyItemImpl>
Direct Known Subclasses:
EUROCurrencyImpl

public abstract class AbstractCurrency
extends CatalogImpl<CurrencyItemImpl>
implements Currency<CurrencyItemImpl>

Abstract Java implementation of the Currency interface.

Version:
3.0
Author:
Thomas Medack

Nested Class Summary
protected  class AbstractCurrency.CurrencyItemData
          Data container for names and values of CurrencyItems.
 
Field Summary
private  java.text.NumberFormat m_nfFormatter
          Tool used to format and parse currency values.
 
Fields inherited from class org.salespointframework.core.data.CatalogImpl
m_lhListeners, m_nModCount
 
Fields inherited from class org.salespointframework.core.data.AbstractNameable
m_ncContext, m_pcsPropertyListeners, SOME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.CatalogItem
VALUE_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.Nameable
NAME_PROPERTY
 
Fields inherited from interface org.salespointframework.core.data.interfaces.DataBasketKeys
CATALOG_ITEM_MAIN_KEY, STOCK_ITEM_MAIN_KEY
 
Constructor Summary
AbstractCurrency(java.lang.String sName)
          Create a new AbstractCurrency with a default locale of Locale.GERMANY and fill it.
AbstractCurrency(java.lang.String sName, java.util.Locale l)
          Create a new, initially empty AbstractCurrency for the given locale.
 
Method Summary
static java.lang.String format(java.text.NumberFormat formatter, NumberValue nv)
          Convert the given value into a String representation according to the currency format of the specific currency.
protected abstract  AbstractCurrency.CurrencyItemData[] getCurrencyItemData()
          This abstract method allows the programmer to choose the names and values of the CurrencyItems (EURO, DM, ...).
 void initCurrencyItems()
          Initializes all CurrencyItems in this container with names and values.
 NumberValue parse(java.lang.String s)
          Try to interpret the given String according to the currency format of the specific currency.
 java.lang.String toString(NumberValue nv)
          Convert the given value into a String representation according to the currency format of the specific currency.
 
Methods inherited from class org.salespointframework.core.data.CatalogImpl
add, addCatalogChangeListener, checkNameChange, commitAdd, commitRemove, contains, createPeer, DatasourceChanged, externalModificationOccurred, fireCanEditCatalogItem, fireCanRemoveCatalogItem, fireCatalogItemAddCommit, fireCatalogItemAdded, fireCatalogItemAddRollback, fireCatalogItemDataChanged, fireCatalogItemRemoveCommit, fireCatalogItemRemoved, fireCatalogItemRemoveRollback, fireCommitEditCatalogItem, fireEditingCatalogItem, fireRollbackEditCatalogItem, get, getEditableCopy, getEditingItemsContainer, getItemsContainer, getItemsLock, getNCMonitor, getShallowClone, getTemporaryAddedItemsContainer, getTemporaryRemovedItemsContainer, isPersistent, iterator, iterator, keySet, nameHasChanged, remove, remove, removeCatalogChangeListener, rollbackAdd, rollbackRemove, setCatalog, size, toString
 
Methods inherited from class org.salespointframework.core.data.CatalogItemImpl
addValueListener, compareTo, equals, firePropertyChanged, getCatalog, getImage, getImageBytes, getInternalShallowClone, getValue, isEditable, recover, removeValueListener, setImage, setImageBytes, setValue
 
Methods inherited from class org.salespointframework.core.data.AbstractNameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.salespointframework.core.data.interfaces.Catalog
add, contains, get, iterator, keySet, remove, remove, size
 
Methods inherited from interface org.salespointframework.core.data.interfaces.CatalogItem
addValueListener, firePropertyChanged, getCatalog, getImage, getValue, removeValueListener, setImage
 
Methods inherited from interface org.salespointframework.core.data.interfaces.Nameable
addNameListener, addPropertyChangeListener, attach, detachNC, getName, removeNameListener, removePropertyChangeListener, setName
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.salespointframework.core.data.interfaces.SpItem
getName
 
Methods inherited from interface org.salespointframework.core.data.events.DatasourceChangeListener
DatasourceChanged
 
Methods inherited from interface org.salespointframework.core.data.events.ExternalModificationListener
externalModificationOccurred
 
Methods inherited from interface java.lang.Iterable
iterator
 

Field Detail

m_nfFormatter

private java.text.NumberFormat m_nfFormatter
Tool used to format and parse currency values.

Constructor Detail

AbstractCurrency

public AbstractCurrency(java.lang.String sName,
                        java.util.Locale l)
Create a new, initially empty AbstractCurrency for the given locale.

Parameters:
sName - the name of the currency to create.
l - the locale that determines how currency values will be formatted.

AbstractCurrency

public AbstractCurrency(java.lang.String sName)
Create a new AbstractCurrency with a default locale of Locale.GERMANY and fill it.

Parameters:
sName - the name of the new currency.
Method Detail

initCurrencyItems

public void initCurrencyItems()
Initializes all CurrencyItems in this container with names and values.


parse

public NumberValue parse(java.lang.String s)
                  throws java.text.ParseException
Try to interpret the given String according to the currency format of the specific currency.

Specified by:
parse in interface Currency<CurrencyItemImpl>
Parameters:
s - the text to be parsed
Returns:
the interpreted value in the smallest unit of the currency.
Throws:
java.text.ParseException - if the input could not be parsed.

toString

public java.lang.String toString(NumberValue nv)
Convert the given value into a String representation according to the currency format of the specific currency. nv must be given in the smallest unit of the currency, i.e. if you want to specify 5,05 DM nv should be 505.

Specified by:
toString in interface Currency<CurrencyItemImpl>
Parameters:
nv - the value to be converted
Returns:
formatted String.

format

public static java.lang.String format(java.text.NumberFormat formatter,
                                      NumberValue nv)
Convert the given value into a String representation according to the currency format of the specific currency. nv must be given in the smallest unit of the currency, i.e. if you want to specify 5,05 DM nv should be 505.

Parameters:
formatter - the formatter used for conversion
nv - the value to be converted
Returns:
formatted String.

getCurrencyItemData

protected abstract AbstractCurrency.CurrencyItemData[] getCurrencyItemData()
This abstract method allows the programmer to choose the names and values of the CurrencyItems (EURO, DM, ...). A complete list of data containers, which always contain pairs of name and value, has to be returned. The single CurrencyItems can be found in the Catalog (Currency) with those names.

Returns:
an Array of data containers that contain names and values of CurrencyItems to be added.