com.jp.protection.priv
Class LicenseWriterFacade

java.lang.Object
  extended by com.jp.protection.priv.LicenseWriterFacade

public class LicenseWriterFacade
extends java.lang.Object

This class represents a "facade" that significantly simplifies licenses generation and licenses writing process to files or output streams


Field Summary
protected  ProductsStorage fProductsStorage
           
protected  boolean fSkipEncryption
           
protected  boolean fVerbose
           
 
Constructor Summary
LicenseWriterFacade(java.io.File aProductsStorageFile)
          Creates a new instance of the LicenseWriterFacade and loads a product storage from the specified file
LicenseWriterFacade(java.io.InputStream aProductsStorageInputStream)
          Creates a new instance of the LicenseWriterFacade and loads a product storage from the specified stream
LicenseWriterFacade(java.io.InputStream aProductsStorageInputStream, ProductsStorage.PasswordResolver aPasswordResolver)
          Creates a new instance of the LicenseWriterFacade and loads a product storage from the specified stream
LicenseWriterFacade(ProductsStorage aProductsStorage)
          Creates a new instance of the LicenseWriterFacade and associates it with the specified products storage
 
Method Summary
 LicenseImpl createLicense(LicenseBase aLicenseInfo)
          Creates new license according to the specified license information
static LicenseImpl createLicense(Product aProduct, int aLicenseType)
           Creates a license for specified product.
static LicenseImpl createLicense(Product aProduct, java.lang.String aProductEditionID, int aLicenseType)
           Creates a license for specified product and product edition.
 LicenseImpl createLicense(java.lang.String aProductID, java.lang.String aProductEditionID, int aLicenseType)
           Creates a license for the specified product and product edition.
 LicenseImpl createLicenseForAlias(java.lang.String aLicenseAlias, java.lang.String aLicenseNumber)
           Creates a license for the specified alias (e.g.
protected  LicenseImpl createLicenseForSerialNumber(SerialNumber aSerialNumber)
           
 LicenseImpl createLicenseForSerialNumber(java.lang.String aSerialNumber)
          Creates license for given S/N.
 LicenseImpl createLicenseForSerialNumber(java.lang.String aSerialNumber, int aSerialNumberVersion)
          Creates license for given S/N.
protected  ProductLicenseWriter getLicenseWriter(Product product)
           
 ProductsStorage getProductsStorage()
          Returns products storage
 boolean isSkipEncryption()
          Checks whether license encryption should be skipped.
 boolean isVerbose()
          Checks whether writer runs in verbose mode.
 void setSkipEncryption(boolean aSkipEncryption)
          Specifies that license encryption should be skipped.
 void setVerbose(boolean aVerbose)
          Specifies that writer should run in verbose mode.
 void writeLicense(License aLicense, java.io.File aFile)
          Encodes license and writes it to the specified file
 void writeLicense(License aLicense, java.io.OutputStream anOutputStream)
          Encodes license and writes it to the specified stream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fSkipEncryption

protected boolean fSkipEncryption

fProductsStorage

protected ProductsStorage fProductsStorage

fVerbose

protected boolean fVerbose
Constructor Detail

LicenseWriterFacade

public LicenseWriterFacade(ProductsStorage aProductsStorage)
Creates a new instance of the LicenseWriterFacade and associates it with the specified products storage

Parameters:
aProductsStorage - products storage to work

LicenseWriterFacade

public LicenseWriterFacade(java.io.InputStream aProductsStorageInputStream)
                    throws java.io.IOException
Creates a new instance of the LicenseWriterFacade and loads a product storage from the specified stream

Parameters:
aProductsStorageInputStream - input stream to load a products storage from
Throws:
java.io.IOException - in case of errors during a products storage loading process

LicenseWriterFacade

public LicenseWriterFacade(java.io.InputStream aProductsStorageInputStream,
                           ProductsStorage.PasswordResolver aPasswordResolver)
                    throws java.io.IOException
Creates a new instance of the LicenseWriterFacade and loads a product storage from the specified stream

Parameters:
aProductsStorageInputStream - input stream to load a products storage from
aPasswordResolver - password resolver to allow opening of read-protected product storage
Throws:
java.io.IOException - in case of errors during a products storage loading process

LicenseWriterFacade

public LicenseWriterFacade(java.io.File aProductsStorageFile)
                    throws java.io.IOException
Creates a new instance of the LicenseWriterFacade and loads a product storage from the specified file

Parameters:
aProductsStorageFile - file to load a products storage from
Throws:
java.io.IOException - in case of errors a products storage loading process
Method Detail

getProductsStorage

public ProductsStorage getProductsStorage()
Returns products storage

Returns:
products storage

createLicenseForAlias

public LicenseImpl createLicenseForAlias(java.lang.String aLicenseAlias,
                                         java.lang.String aLicenseNumber)

Creates a license for the specified alias (e.g. UPC code). In the process of the license creation it:

It's responsibility of the developer to assign all other license attributes.

Parameters:
aLicenseAlias - license alias such as store inventory identifier or UPC code
aLicenseNumber - license number to assign
Returns:
new instance of the License

createLicenseForSerialNumber

public LicenseImpl createLicenseForSerialNumber(java.lang.String aSerialNumber)
                                         throws SerialNumberException
Creates license for given S/N. It uses products storage's S/N version to decide which S/N implementation should be used

Parameters:
aSerialNumber - serial number in textual form to create license for
Returns:
created license
Throws:
SerialNumberException - if S/N is invalid

createLicenseForSerialNumber

public LicenseImpl createLicenseForSerialNumber(java.lang.String aSerialNumber,
                                                int aSerialNumberVersion)
                                         throws SerialNumberException
Creates license for given S/N. It uses passed S/N version to decide which S/N implementation should be used

Parameters:
aSerialNumber - serial number in textual form to create license for
aSerialNumberVersion - version of S/N
Returns:
created license
Throws:
SerialNumberException - if S/N is invalid

createLicenseForSerialNumber

protected LicenseImpl createLicenseForSerialNumber(SerialNumber aSerialNumber)
                                            throws SerialNumberException
Throws:
SerialNumberException

createLicense

public LicenseImpl createLicense(java.lang.String aProductID,
                                 java.lang.String aProductEditionID,
                                 int aLicenseType)

Creates a license for the specified product and product edition. In the process of the license creation it:

It's responsibility of the developer to assign all other license attributes.

Parameters:
aProductID - identifier of the product for which license would be created
aProductEditionID - identifier of the product edition for which license would be created. aProductEditionID can be initialized to null if the product has no defined editions.
aLicenseType - license type to be created; should be one of the License.TYPE_ constants
Returns:
new instance of the License

createLicense

public static LicenseImpl createLicense(Product aProduct,
                                        int aLicenseType)

Creates a license for specified product. In the process of the license creation it:

It's responsibility of the developer to assign all other license attributes.

Parameters:
aProduct - product to create license for aProductEditionID can initialized to null if the product has no defined editions.
aLicenseType - license type to be created; should be one of the License.TYPE_ constants
Returns:
new instance of the License

createLicense

public static LicenseImpl createLicense(Product aProduct,
                                        java.lang.String aProductEditionID,
                                        int aLicenseType)

Creates a license for specified product and product edition. In the process of the license creation it:

It's responsibility of the developer to assign all other license attributes.

Parameters:
aProduct - product to create license for
aProductEditionID - ID of the product edition to create license for. aProductEditionID can initialized to null if the product has no defined editions.
aLicenseType - license type to be created; should be one of the License.TYPE_ constants
Returns:
new instance of the License

createLicense

public LicenseImpl createLicense(LicenseBase aLicenseInfo)
Creates new license according to the specified license information

Parameters:
aLicenseInfo - license information
Returns:
new instance of the license

writeLicense

public void writeLicense(License aLicense,
                         java.io.File aFile)
                  throws java.io.IOException
Encodes license and writes it to the specified file

Parameters:
aLicense - license to encode and write
aFile - file to write license to
Throws:
java.io.IOException - in case of errors during license writing

getLicenseWriter

protected ProductLicenseWriter getLicenseWriter(Product product)

writeLicense

public void writeLicense(License aLicense,
                         java.io.OutputStream anOutputStream)
                  throws java.io.IOException
Encodes license and writes it to the specified stream

Parameters:
aLicense - license to encode and write
anOutputStream - stream to write license to
Throws:
java.io.IOException - in case of errors during license writing

isSkipEncryption

public boolean isSkipEncryption()
Checks whether license encryption should be skipped.

Returns:
true license encryption should be skipped, false otherwise.

setSkipEncryption

public void setSkipEncryption(boolean aSkipEncryption)
Specifies that license encryption should be skipped. Note: skipping can be useful for debugging purposes only.

Parameters:
aSkipEncryption - true if license encryption should be skipped, false otherwise.

isVerbose

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

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

setVerbose

public void setVerbose(boolean aVerbose)
Specifies that writer should run in verbose mode. If writer run in verbose mode all thrown exceptions and stack traces will be printed out to the stderr. Otherwise there is no output generated in order to prevent the "code flow" analysis.

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