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

java.lang.Object
  extended by com.jp.protection.priv.pro.parser.OrderParserFacade
All Implemented Interfaces:
OrderParserListener, java.util.EventListener

public class OrderParserFacade
extends java.lang.Object
implements OrderParserListener

This class represents the entry point to the orders parsing system. It provides set of convenience methods for system initialization, orders parsing and listening for events occurred during the process.


Nested Class Summary
static class OrderParserFacade.Result
          This class represents the result of order parsing process.
 
Field Summary
protected  dev.beans.presentation.BeanPresentation fCustomerPresentation
           
protected  java.util.List fErrors
           
protected  dev.beans.presentation.BeanPresentation fLicensePresentation
           
protected  LicenseWriterFacade fLicenseWriterFacade
           
protected  OrderParserListenerSupport fOrderParserListenerSupport
           
protected  java.util.prefs.Preferences fPreferences
           
protected  ProductsStorage fProductsStorage
           
protected  dev.util.collections.HashedBoundList fPropertyValues
           
protected  boolean fVerbose
           
static java.lang.String PROPERTY_DEFAULT_PARSER_ID
           
 
Constructor Summary
OrderParserFacade(ProductsStorage aProductsStorage)
          Creates and initializes a new instance of OrderParserFacade
 
Method Summary
 void addOrderParserListener(OrderParserListener l)
          Adds order parser listener
protected  LicenseImpl createLicense(LicenseAlias aLicenseAlias)
           
static void dump(java.util.List aParseResults, java.lang.StringBuffer aStringBuffer)
          Dumps a list of parsing results to a specified string buffer.
 void error(OrderParser aSource, OrderParser.Error anError)
          Notifies interested parties about an error occurred during order parsing
protected  void error(java.lang.String aMessage)
           
protected  void fireError(OrderParser anOrderParser, OrderParser.Error anError)
           
protected  void fireParseFinished(OrderParser anOrderParser)
           
protected  void fireParseStarted(OrderParser anOrderParser)
           
protected  void firePropertyRead(OrderParser anOrderParser, OrderParser.PropertyValue aValue)
           
protected  java.lang.String getDefaultParserID()
           
 java.util.List getErrors()
          Returns the list of errors occurred during last order parsing operation
 java.util.prefs.Preferences getPreferences()
          Returns preferences that can be used to obtain/store default parser identifier
 OrderParser.PropertyValue getPropertyValue(java.lang.String aName)
          Get property value read during last order parsing operation
 java.util.List getPropertyValues()
          Returns the list of properties read during last parsing operation
 boolean isVerbose()
          Checks whether facade runs in verbose mode.
protected  void message(java.lang.String aMessage)
           
 java.util.List parse(java.io.File aFolder, java.util.List anErrors)
          Parses (not recursively) all orders found in the specified folder.
 OrderParserFacade.Result parse(java.io.InputStream anInputStream)
          Parses an order passed as an input stream.
 OrderParserFacade.Result parse(java.io.InputStream anInputStream, OrderParser aParser)
          Parses an order passed as an input stream using explicitly specified parser.
 OrderParserFacade.Result parse(java.io.InputStream anInputStream, java.lang.String aParserID)
          Parses an order passed as an input stream using parser explicitly specified by its identifier.
 void parseFinished(OrderParser aSource)
          Notifies interested parties that order parsing is finished
 void parseStarted(OrderParser aSource)
          Notifies interested parties that order parsing is started
 void propertyRead(OrderParser aSource, OrderParser.PropertyValue aValue)
          Notifies interested parties about reading of a property
protected  dev.entities.Customer readCustomer(OrderParser aParser)
           
protected  LicenseImpl readLicense(OrderParser aParser, LicenseAlias aLicenseAlias)
           
protected  LicenseAlias readLicenseAlias(OrderParser aParser)
           
 void removeOrderParserListener(OrderParserListener l)
          Removes order parser listener
protected  void setDefaultParserID(java.lang.String aParserID)
           
 void setPreferences(java.util.prefs.Preferences aPreferences)
          Optionally specifies preferences that can be used to obtain/store default parser identifier
 void setVerbose(boolean aVerbose)
          Specifies that facade should be run in verbose mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fProductsStorage

protected ProductsStorage fProductsStorage

fLicenseWriterFacade

protected LicenseWriterFacade fLicenseWriterFacade

PROPERTY_DEFAULT_PARSER_ID

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

fPreferences

protected java.util.prefs.Preferences fPreferences

fCustomerPresentation

protected dev.beans.presentation.BeanPresentation fCustomerPresentation

fLicensePresentation

protected dev.beans.presentation.BeanPresentation fLicensePresentation

fPropertyValues

protected dev.util.collections.HashedBoundList fPropertyValues

fErrors

protected java.util.List fErrors

fVerbose

protected boolean fVerbose

fOrderParserListenerSupport

protected OrderParserListenerSupport fOrderParserListenerSupport
Constructor Detail

OrderParserFacade

public OrderParserFacade(ProductsStorage aProductsStorage)
Creates and initializes a new instance of OrderParserFacade

Parameters:
aProductsStorage - a products storage instance
Method Detail

getPreferences

public java.util.prefs.Preferences getPreferences()
Returns preferences that can be used to obtain/store default parser identifier

Returns:
preferences instance

setPreferences

public void setPreferences(java.util.prefs.Preferences aPreferences)
Optionally specifies preferences that can be used to obtain/store default parser identifier

Parameters:
aPreferences - preferences instance

getDefaultParserID

protected java.lang.String getDefaultParserID()

setDefaultParserID

protected void setDefaultParserID(java.lang.String aParserID)

parse

public OrderParserFacade.Result parse(java.io.InputStream anInputStream)
                               throws java.io.IOException
Parses an order passed as an input stream. It walks trough all registered parsers to find parser that is able to support passed order format. If no suitable parser has been found - method simply returns null value.

Parameters:
anInputStream - input stream to read an order from
Returns:
a Result instance containing parsing results; null if order format is not supported
Throws:
java.io.IOException - if errors occurred during order parsing

parse

public OrderParserFacade.Result parse(java.io.InputStream anInputStream,
                                      java.lang.String aParserID)
Parses an order passed as an input stream using parser explicitly specified by its identifier.

Parameters:
anInputStream - input stream to read an order from
aParserID - specifies parser identifier
Returns:
a Result instance containing parsing results

parse

public OrderParserFacade.Result parse(java.io.InputStream anInputStream,
                                      OrderParser aParser)
Parses an order passed as an input stream using explicitly specified parser.

Parameters:
anInputStream - input stream to read an order from
aParser - specifies parser
Returns:
a Result instance containing parsing results

readCustomer

protected dev.entities.Customer readCustomer(OrderParser aParser)

readLicenseAlias

protected LicenseAlias readLicenseAlias(OrderParser aParser)

createLicense

protected LicenseImpl createLicense(LicenseAlias aLicenseAlias)

readLicense

protected LicenseImpl readLicense(OrderParser aParser,
                                  LicenseAlias aLicenseAlias)

getPropertyValue

public OrderParser.PropertyValue getPropertyValue(java.lang.String aName)
Get property value read during last order parsing operation

Parameters:
aName - name of the property to return
Returns:
an OrderParser.PropertyValue instance; null if no value with specified name was found.

getPropertyValues

public java.util.List getPropertyValues()
Returns the list of properties read during last parsing operation

Returns:
the list of OrderParser.PropertyValue instances

getErrors

public java.util.List getErrors()
Returns the list of errors occurred during last order parsing operation

Returns:
the list of OrderParser.Error instances

isVerbose

public boolean isVerbose()
Checks whether facade runs in verbose mode.

Returns:
true if it runs in verbose mode, false otherwise.

setVerbose

public void setVerbose(boolean aVerbose)
Specifies that facade should be run in verbose mode. If facade runs in verbose mode all of the messages, if any, will be printed to stdout or stderr.

Parameters:
aVerbose - true if facade should run in verbose mode, false otherwise.

error

protected void error(java.lang.String aMessage)

message

protected void message(java.lang.String aMessage)

parseStarted

public void parseStarted(OrderParser aSource)
Description copied from interface: OrderParserListener
Notifies interested parties that order parsing is started

Specified by:
parseStarted in interface OrderParserListener
Parameters:
aSource - an order parser

parseFinished

public void parseFinished(OrderParser aSource)
Description copied from interface: OrderParserListener
Notifies interested parties that order parsing is finished

Specified by:
parseFinished in interface OrderParserListener
Parameters:
aSource - an order parser

propertyRead

public void propertyRead(OrderParser aSource,
                         OrderParser.PropertyValue aValue)
Description copied from interface: OrderParserListener
Notifies interested parties about reading of a property

Specified by:
propertyRead in interface OrderParserListener
Parameters:
aSource - an order parser
aValue - a property has been read

error

public void error(OrderParser aSource,
                  OrderParser.Error anError)
Description copied from interface: OrderParserListener
Notifies interested parties about an error occurred during order parsing

Specified by:
error in interface OrderParserListener
Parameters:
aSource - an order parser
anError - an error occurred

parse

public java.util.List parse(java.io.File aFolder,
                            java.util.List anErrors)
                     throws java.io.IOException
Parses (not recursively) all orders found in the specified folder.

Parameters:
aFolder - a folder to parse orders from
anErrors - a list to place all the OrderParser.Error errors occurred during orders parsing
Returns:
a list containing Result instances those represents orders have been successfully parsed.
Throws:
java.io.IOException - for any errors occurred during orders reading

dump

public static void dump(java.util.List aParseResults,
                        java.lang.StringBuffer aStringBuffer)
Dumps a list of parsing results to a specified string buffer. In the dump each parsing result occupies one row containing license alias, license and customer attributes delimited by comma.

Parameters:
aParseResults - a list of Result instances obtained as result of bulk orders parsing.
aStringBuffer - s buffer to dump results to

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 anOrderParser,
                                OrderParser.PropertyValue aValue)

fireError

protected void fireError(OrderParser anOrderParser,
                         OrderParser.Error anError)

fireParseFinished

protected void fireParseFinished(OrderParser anOrderParser)

fireParseStarted

protected void fireParseStarted(OrderParser anOrderParser)