com.jp.protection.priv.pro.parser
Class OrderParser

java.lang.Object
  extended by com.jp.protection.priv.pro.parser.OrderParser
Direct Known Subclasses:
TextOrderParser

public abstract class OrderParser
extends java.lang.Object

The base class for all order parsers. Actual implementations should implement all of the abstract methods, implement corresponding Provider and register implementation in ProviderRegistry to make it available.


Nested Class Summary
static class OrderParser.Error
          Represents an error which occurred during the order parsing
static class OrderParser.PropertyError
          An extension of Error class intended to represents errors occurred during order property reading
static class OrderParser.PropertyValue
          Represents order property value read by parser from the order
static interface OrderParser.Provider
          Represents a provider interface intended for order parser creation
static class OrderParser.ProviderRegistry
          Represents provider's registry that holds all of the available providers.
 
Field Summary
protected  OrderParserListenerSupport fOrderParserListenerSupport
           
protected  boolean fStopped
           
static java.lang.String PROPERTY_CUSTOMER
           
static java.lang.String PROPERTY_CUSTOMER_ADDRESS
           
static java.lang.String PROPERTY_CUSTOMER_CITY
           
static java.lang.String PROPERTY_CUSTOMER_COMPANY
           
static java.lang.String PROPERTY_CUSTOMER_COUNTRY
           
static java.lang.String PROPERTY_CUSTOMER_EMAIL
           
static java.lang.String PROPERTY_CUSTOMER_FIRST_NAME
           
static java.lang.String PROPERTY_CUSTOMER_LAST_NAME
           
static java.lang.String PROPERTY_CUSTOMER_PHONE
           
static java.lang.String PROPERTY_CUSTOMER_STATE
           
static java.lang.String PROPERTY_CUSTOMER_TITLE
           
static java.lang.String PROPERTY_CUSTOMER_ZIP
           
static java.lang.String PROPERTY_LICENSE
           
static java.lang.String PROPERTY_LICENSE_NUMBER
           
static java.lang.String PROPERTY_LICENSE_NUMBER_COPIES
           
static java.lang.String PROPERTY_ORDER
           
static java.lang.String PROPERTY_ORDER_NET_SALES
           
static java.lang.String PROPERTY_ORDER_PAYMENT_TYPE
           
static java.lang.String PROPERTY_ORDER_TOTAL_SALES
           
static java.lang.String PROPERTY_PRODUCT
           
static java.lang.String PROPERTY_PRODUCT_ALIAS
           
 
Constructor Summary
OrderParser()
           
 
Method Summary
 void addOrderParserListener(OrderParserListener l)
          Adds order parser listener
protected  void fireError(OrderParser.Error anError)
           
protected  void fireParseFinished()
           
protected  void fireParseStarted()
           
protected  void firePropertyRead(OrderParser.PropertyValue aValue)
           
static java.lang.String getCustomerPropertyName(java.lang.String aName)
          Returns short name of the property by removing the PROPERTY_CUSTOMER_ prefix
static java.lang.String getLicensePropertyName(java.lang.String aName)
          Returns short name of the property by removing the PROPERTY_LICENSE_ prefix
static java.lang.String getProductPropertyName(java.lang.String aName)
          Returns short name of the property by removing the PROPERTY_PRODUCT_ prefix
static boolean isCustomerProperty(java.lang.String aName)
          Tests whether passed property name is customer one
static boolean isLicenseProperty(java.lang.String aName)
          Tests whether passed property name is a license one
static boolean isProductProperty(java.lang.String aName)
          Tests whether passed property name is product one
 boolean isStopped()
          Returns whether parser is in "stopped" state
abstract  boolean isSupportedFormat(java.io.InputStream anInputStream)
          Tests whether this parser supports format of the passed order
abstract  void parse(java.io.InputStream anInputStream)
           Parses passed order.
 void removeOrderParserListener(OrderParserListener l)
          Removes order parser listener
 void stop()
          Notify the parser that it should terminate parsing operation (if possible).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_ORDER

public static final java.lang.String PROPERTY_ORDER
See Also:
Constant Field Values

PROPERTY_ORDER_PAYMENT_TYPE

public static final java.lang.String PROPERTY_ORDER_PAYMENT_TYPE
See Also:
Constant Field Values

PROPERTY_ORDER_NET_SALES

public static final java.lang.String PROPERTY_ORDER_NET_SALES
See Also:
Constant Field Values

PROPERTY_ORDER_TOTAL_SALES

public static final java.lang.String PROPERTY_ORDER_TOTAL_SALES
See Also:
Constant Field Values

PROPERTY_PRODUCT

public static final java.lang.String PROPERTY_PRODUCT
See Also:
Constant Field Values

PROPERTY_PRODUCT_ALIAS

public static final java.lang.String PROPERTY_PRODUCT_ALIAS
See Also:
Constant Field Values

PROPERTY_CUSTOMER

public static final java.lang.String PROPERTY_CUSTOMER
See Also:
Constant Field Values

PROPERTY_CUSTOMER_FIRST_NAME

public static final java.lang.String PROPERTY_CUSTOMER_FIRST_NAME
See Also:
Constant Field Values

PROPERTY_CUSTOMER_LAST_NAME

public static final java.lang.String PROPERTY_CUSTOMER_LAST_NAME
See Also:
Constant Field Values

PROPERTY_CUSTOMER_TITLE

public static final java.lang.String PROPERTY_CUSTOMER_TITLE
See Also:
Constant Field Values

PROPERTY_CUSTOMER_COMPANY

public static final java.lang.String PROPERTY_CUSTOMER_COMPANY
See Also:
Constant Field Values

PROPERTY_CUSTOMER_PHONE

public static final java.lang.String PROPERTY_CUSTOMER_PHONE
See Also:
Constant Field Values

PROPERTY_CUSTOMER_EMAIL

public static final java.lang.String PROPERTY_CUSTOMER_EMAIL
See Also:
Constant Field Values

PROPERTY_CUSTOMER_ADDRESS

public static final java.lang.String PROPERTY_CUSTOMER_ADDRESS
See Also:
Constant Field Values

PROPERTY_CUSTOMER_CITY

public static final java.lang.String PROPERTY_CUSTOMER_CITY
See Also:
Constant Field Values

PROPERTY_CUSTOMER_ZIP

public static final java.lang.String PROPERTY_CUSTOMER_ZIP
See Also:
Constant Field Values

PROPERTY_CUSTOMER_STATE

public static final java.lang.String PROPERTY_CUSTOMER_STATE
See Also:
Constant Field Values

PROPERTY_CUSTOMER_COUNTRY

public static final java.lang.String PROPERTY_CUSTOMER_COUNTRY
See Also:
Constant Field Values

PROPERTY_LICENSE

public static final java.lang.String PROPERTY_LICENSE
See Also:
Constant Field Values

PROPERTY_LICENSE_NUMBER

public static final java.lang.String PROPERTY_LICENSE_NUMBER
See Also:
Constant Field Values

PROPERTY_LICENSE_NUMBER_COPIES

public static final java.lang.String PROPERTY_LICENSE_NUMBER_COPIES
See Also:
Constant Field Values

fStopped

protected boolean fStopped

fOrderParserListenerSupport

protected OrderParserListenerSupport fOrderParserListenerSupport
Constructor Detail

OrderParser

public OrderParser()
Method Detail

isCustomerProperty

public static boolean isCustomerProperty(java.lang.String aName)
Tests whether passed property name is customer one

Parameters:
aName - property name
Returns:
true if passed property name is customer one; false otherwise

getCustomerPropertyName

public static java.lang.String getCustomerPropertyName(java.lang.String aName)
Returns short name of the property by removing the PROPERTY_CUSTOMER_ prefix

Parameters:
aName - full name of the property
Returns:
short name of the property

isLicenseProperty

public static boolean isLicenseProperty(java.lang.String aName)
Tests whether passed property name is a license one

Parameters:
aName - property name
Returns:
true if passed property name is license one; false otherwise

getLicensePropertyName

public static java.lang.String getLicensePropertyName(java.lang.String aName)
Returns short name of the property by removing the PROPERTY_LICENSE_ prefix

Parameters:
aName - full name of the property
Returns:
short name of the property

isProductProperty

public static boolean isProductProperty(java.lang.String aName)
Tests whether passed property name is product one

Parameters:
aName - property name
Returns:
true if passed property name is product one; false otherwise

getProductPropertyName

public static java.lang.String getProductPropertyName(java.lang.String aName)
Returns short name of the property by removing the PROPERTY_PRODUCT_ prefix

Parameters:
aName - full name of the property
Returns:
short name of the property

isSupportedFormat

public abstract boolean isSupportedFormat(java.io.InputStream anInputStream)
Tests whether this parser supports format of the passed order

Parameters:
anInputStream - input stream containing an order to test
Returns:
true if this parser is capable of passed order parsing; false otherwise.

parse

public abstract void parse(java.io.InputStream anInputStream)

Parses passed order. Actual implementation of the method should:

  1. Notify interested parties about process start by calling fireParseStarted(...) method;
  2. Read order properties from the input stream and notify interested parties about each property which has been read by calling firePropertyRead(...) method. For any errors occurred during order parsing the fireError(...) method should be called to let interested parties log errors. Note it is strongly recommended to support reading all the properties with names starting with PROPERTY_PRODUCT_, PROPERTY_CUSTOMER_ and PROPERTY_LICENSE_;
  3. Notify interested parties about process finish by calling fireParseFinished(...) method;

Parameters:
anInputStream - input stream containing an order to parse

isStopped

public boolean isStopped()
Returns whether parser is in "stopped" state

Returns:
true if parser is in "stopped" state; false otherwise

stop

public void stop()
Notify the parser that it should terminate parsing operation (if possible). It is sole responsibility of parser's implementation to analyze its state by utilizing isStopped() method and terminate operation if required and if possible.


removeOrderParserListener

public void removeOrderParserListener(OrderParserListener l)
Removes order parser listener

Parameters:
l - order parser listener to remove

addOrderParserListener

public void addOrderParserListener(OrderParserListener l)
Adds order parser listener

Parameters:
l - order parser listener to add

firePropertyRead

protected void firePropertyRead(OrderParser.PropertyValue aValue)

fireError

protected void fireError(OrderParser.Error anError)

fireParseFinished

protected void fireParseFinished()

fireParseStarted

protected void fireParseStarted()