com.jp.protection.priv.products
Class ProductsStorage

java.lang.Object
  extended by com.jp.protection.priv.products.ProductsStorage
All Implemented Interfaces:
dev.util.collections.ContainerListener

public class ProductsStorage
extends java.lang.Object
implements dev.util.collections.ContainerListener

Container class for holding and maintaining products


Nested Class Summary
(package private) static class ProductsStorage.LicenseAliasHashedListStrategy
           
static interface ProductsStorage.PasswordResolver
           
static class ProductsStorage.ProductIDHashedListStrategy
           
 
Field Summary
protected  dev.util.collections.HashedBoundList fLicenseAliases
           
protected  LicensingFacadeConfig fLicensingFacadeConfig
           
protected  boolean fModified
           
protected  ProductsStorage.PasswordResolver fPasswordResolver
           
protected  dev.util.collections.HashedBoundList fProducts
           
protected  java.io.File fProductsFile
           
protected  java.lang.String fReadPassword
           
protected  char[] fSerialNumberKeyChars
           
protected  int fSerialNumberSequence
           
protected  int fSerialNumberVersion
           
protected  java.util.HashMap fShortIDProductMap
           
protected  int fVersion
           
protected  boolean fWriteEnabled
           
protected  byte[] fWritePasswordDigest
           
static int SERIAL_NUMBER_VERSION
           
static java.lang.String SIGNATURE_ENCRYPTED
           
static int VERSION
           
 
Constructor Summary
ProductsStorage()
          Creates a new instance of the ProductsStorage
 
Method Summary
 void addProductsStorageListener(ProductsStorageListener l)
          Adds products storage listener to the list of listeners
protected  void assignProductShortIDs()
           
 boolean canLoad()
          Returns whether is possible to load products storage from the file specified by the setProductsFile() call
protected  void convertProducts()
           
 boolean convertSecurityKeys()
           
protected  byte[] decrypt(byte[] aBytes)
           
 boolean doNew()
          Initialize products storage to an empty storage state
 void elementAdded(java.lang.Object anElement, java.lang.Object aSource)
           
 void elementRemoved(java.lang.Object anElement, java.lang.Object aSource)
           
 void elementsAdded(java.util.Collection anElements, java.lang.Object aSource)
           
 void elementsRemoved(java.util.Collection anElements, java.lang.Object aSource)
           
protected  byte[] encrypt(byte[] aBytes)
           
protected  void fireBeforeProductsStorageSave()
           
protected  void fireProductAdded(Product aProduct)
           
protected  void fireProductDeleted(Product aProduct)
           
protected  void fireProductsStorageLoaded()
           
protected  void fireProductsStorageSaved()
           
 void fireProductUpdated(Product aProduct)
          Notifies all registered listeners that particular project is updated
protected  int generateProductShortID()
           
 void generateSerialNumberKeyChars()
          Generates random key characters
protected  javax.crypto.Cipher getCipher(boolean isEncrypt)
           
 java.util.List<Product> getClonedProducts()
          Returns the list of clones of products contained in the storage
 java.util.List getEnabledProducts()
          Returns the list of enabled products contained in the storage.
protected  java.io.InputStream getInputStream()
           
 LicenseBase getLicense(SerialNumber aSerialNumber)
          Returns license by its Serial Number
 LicenseBase getLicense(java.lang.String aSerialNumber)
          Returns license by its Serial Number
 LicenseAlias getLicenseAlias(java.lang.String anAlias)
           
 dev.util.collections.HashedBoundList getLicenseAliases()
           
 LicensingFacadeConfig getLicensingFacadeConfig()
          Returns licensing facade configuration associated with the product's storage
protected  java.io.OutputStream getOutputStream()
           
 ProductsStorage.PasswordResolver getPasswordResolver()
           
 Product getProduct(int anIndex)
          Returns a product by its index
 Product getProduct(java.lang.String anID)
          Returns a product by its identifier
 Product getProductByShortID(int aShortID)
          Returns a product by its aShortID identifier
 java.util.List<Product> getProducts()
          Returns the list of products contained in the storage
 java.io.File getProductsFile()
          Returns products storage file
 java.lang.String getReadPassword()
           
 SerialNumber getSerialNumber()
          Creates and returns a new Serial Number
 SerialNumber getSerialNumber(LicenseBase aLicense)
          Creates Serial Number for specified license
 SerialNumber2 getSerialNumber2()
          Creates and returns a new Serial Number
 char[] getSerialNumberKeyChars()
          Returns serial number key characters
 int getSerialNumberVersion()
           
 int getVersion()
           
 byte[] getWritePasswordDigest()
           
 boolean isModified()
          Returns whether this products storage is modified
 boolean isReadOnly()
          Returns whether this products storage has a read-only attribute by checking the file specified by the setProductsFile() call
 boolean isWriteEnabled()
           
 boolean load()
          Loads products storage from the file specified by the setProductsFile() call
 boolean load(java.io.InputStream anInputStream)
          Loads products storage from the specified stream
protected  void loadData(java.io.InputStream anInputStream)
           
protected  boolean loadEncryptionSignature(java.io.InputStream anInputStream)
           
protected  void loadImpl(java.io.ObjectInputStream objectInputStream)
           
 boolean needConvertSecurityKeys()
           
 void removeProductsStorageListener(ProductsStorageListener l)
          Removes products storage listener from the list of listeners
 boolean save()
          Save products storage to the file specified by the setProductsFile() call
 boolean save(java.io.OutputStream anOutputStream)
          Saves products storage to the specified stream
protected  void saveData(java.io.OutputStream anOutputStream)
           
protected  void saveEncryptionSignature(java.io.OutputStream anOutputStream)
           
protected  void saveImpl(java.io.ObjectOutputStream objectOutputStream)
           
 void setModified(boolean aModified)
          Marks this storage as modifed
 void setPasswordResolver(ProductsStorage.PasswordResolver aPasswordResolver)
           
 void setProductsFile(java.io.File aProductsFile)
          Specifies products storage file
 void setReadPassword(java.lang.String aReadPassword)
           
 void setSerialNumberVersion(int aSerialNumberVersion)
           
 void setVersion(int aVersion)
           
 void setWriteEnabled(boolean aWriteEnabled)
           
 void setWritePasswordDigest(byte[] aWritePasswordDigest)
           
 void toLicense(SerialNumber aSerialNumber, LicenseBaseImpl aLicense)
          Updates specified license by provided Serial Number's attributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fShortIDProductMap

protected transient java.util.HashMap fShortIDProductMap

fProducts

protected dev.util.collections.HashedBoundList fProducts

fLicenseAliases

protected dev.util.collections.HashedBoundList fLicenseAliases

fWritePasswordDigest

protected byte[] fWritePasswordDigest

fWriteEnabled

protected transient boolean fWriteEnabled

fSerialNumberKeyChars

protected char[] fSerialNumberKeyChars

fSerialNumberSequence

protected int fSerialNumberSequence

SIGNATURE_ENCRYPTED

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

fReadPassword

protected transient java.lang.String fReadPassword

fPasswordResolver

protected ProductsStorage.PasswordResolver fPasswordResolver

fProductsFile

protected java.io.File fProductsFile

fModified

protected boolean fModified

fLicensingFacadeConfig

protected LicensingFacadeConfig fLicensingFacadeConfig

SERIAL_NUMBER_VERSION

public static final int SERIAL_NUMBER_VERSION
See Also:
Constant Field Values

VERSION

public static final int VERSION
See Also:
Constant Field Values

fSerialNumberVersion

protected int fSerialNumberVersion

fVersion

protected int fVersion
Constructor Detail

ProductsStorage

public ProductsStorage()
Creates a new instance of the ProductsStorage

Method Detail

getLicenseAliases

public dev.util.collections.HashedBoundList getLicenseAliases()

getLicenseAlias

public LicenseAlias getLicenseAlias(java.lang.String anAlias)

getProducts

public java.util.List<Product> getProducts()
Returns the list of products contained in the storage

Returns:
products list

getEnabledProducts

public java.util.List getEnabledProducts()
Returns the list of enabled products contained in the storage.

Returns:
products list

getClonedProducts

public java.util.List<Product> getClonedProducts()
Returns the list of clones of products contained in the storage

Returns:
products list

getProduct

public Product getProduct(java.lang.String anID)
Returns a product by its identifier

Parameters:
anID - product's identifier
Returns:
a product or null if product with such identifier is not found within the storage

getProduct

public Product getProduct(int anIndex)
Returns a product by its index

Parameters:
anIndex - product's index
Returns:
a product

doNew

public boolean doNew()
Initialize products storage to an empty storage state

Returns:
true on success; false otherwise

isWriteEnabled

public boolean isWriteEnabled()

setWriteEnabled

public void setWriteEnabled(boolean aWriteEnabled)

getWritePasswordDigest

public byte[] getWritePasswordDigest()

setWritePasswordDigest

public void setWritePasswordDigest(byte[] aWritePasswordDigest)

load

public boolean load(java.io.InputStream anInputStream)
             throws java.io.IOException
Loads products storage from the specified stream

Parameters:
anInputStream - input stream to load products storage from
Returns:
true on success; false otherwise
Throws:
java.io.IOException - in case of any error during the products storage reading process

loadData

protected void loadData(java.io.InputStream anInputStream)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

loadImpl

protected void loadImpl(java.io.ObjectInputStream objectInputStream)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

convertProducts

protected void convertProducts()

load

public boolean load()
             throws java.io.IOException
Loads products storage from the file specified by the setProductsFile() call

Returns:
true on success; false otherwise
Throws:
java.io.IOException - in case of any error during the products storage reading process

generateSerialNumberKeyChars

public void generateSerialNumberKeyChars()
Generates random key characters


getSerialNumberKeyChars

public char[] getSerialNumberKeyChars()
Returns serial number key characters

Returns:
serial number key characters

getSerialNumber

public SerialNumber getSerialNumber()
Creates and returns a new Serial Number

Returns:
an instance of SerialNumber

getSerialNumber2

public SerialNumber2 getSerialNumber2()
Creates and returns a new Serial Number

Returns:
an instance of SerialNumber

save

public boolean save(java.io.OutputStream anOutputStream)
             throws java.io.IOException
Saves products storage to the specified stream

Parameters:
anOutputStream - outpit stream to save products storage to
Returns:
true on success; false otherwise
Throws:
java.io.IOException - in case of any error during the products storage reading process

saveEncryptionSignature

protected void saveEncryptionSignature(java.io.OutputStream anOutputStream)
                                throws java.io.IOException
Throws:
java.io.IOException

loadEncryptionSignature

protected boolean loadEncryptionSignature(java.io.InputStream anInputStream)
                                   throws java.io.IOException
Throws:
java.io.IOException

saveData

protected void saveData(java.io.OutputStream anOutputStream)
                 throws java.io.IOException
Throws:
java.io.IOException

getReadPassword

public java.lang.String getReadPassword()

setReadPassword

public void setReadPassword(java.lang.String aReadPassword)

encrypt

protected byte[] encrypt(byte[] aBytes)

getPasswordResolver

public ProductsStorage.PasswordResolver getPasswordResolver()

setPasswordResolver

public void setPasswordResolver(ProductsStorage.PasswordResolver aPasswordResolver)

decrypt

protected byte[] decrypt(byte[] aBytes)
                  throws java.io.IOException
Throws:
java.io.IOException

saveImpl

protected void saveImpl(java.io.ObjectOutputStream objectOutputStream)
                 throws java.io.IOException
Throws:
java.io.IOException

save

public boolean save()
             throws java.io.IOException
Save products storage to the file specified by the setProductsFile() call

Returns:
true on success; false otherwise
Throws:
java.io.IOException - in case of any error during the products storage saving process

getOutputStream

protected java.io.OutputStream getOutputStream()
                                        throws java.io.IOException
Throws:
java.io.IOException

getInputStream

protected java.io.InputStream getInputStream()
                                      throws java.io.IOException
Throws:
java.io.IOException

canLoad

public boolean canLoad()
Returns whether is possible to load products storage from the file specified by the setProductsFile() call

Returns:
true if it is possible to load products storage; false otherwise

getProductsFile

public java.io.File getProductsFile()
Returns products storage file

Returns:
products storage file

setProductsFile

public void setProductsFile(java.io.File aProductsFile)
Specifies products storage file

Parameters:
aProductsFile - products storage file

removeProductsStorageListener

public void removeProductsStorageListener(ProductsStorageListener l)
Removes products storage listener from the list of listeners

Parameters:
l - products storage listener to remove

addProductsStorageListener

public void addProductsStorageListener(ProductsStorageListener l)
Adds products storage listener to the list of listeners

Parameters:
l - products storage listener to add

isReadOnly

public boolean isReadOnly()
Returns whether this products storage has a read-only attribute by checking the file specified by the setProductsFile() call

Returns:
true if products storage is read-only; false otherwise

isModified

public boolean isModified()
Returns whether this products storage is modified

Returns:
true if this products storage is modified; false otherwise

setModified

public void setModified(boolean aModified)
Marks this storage as modifed

Parameters:
aModified - modified value

fireProductsStorageLoaded

protected void fireProductsStorageLoaded()

fireBeforeProductsStorageSave

protected void fireBeforeProductsStorageSave()

fireProductsStorageSaved

protected void fireProductsStorageSaved()

fireProductAdded

protected void fireProductAdded(Product aProduct)

fireProductDeleted

protected void fireProductDeleted(Product aProduct)

fireProductUpdated

public void fireProductUpdated(Product aProduct)
Notifies all registered listeners that particular project is updated

Parameters:
aProduct - updated product

getProductByShortID

public Product getProductByShortID(int aShortID)
Returns a product by its aShortID identifier

Parameters:
aShortID - product's short identifier
Returns:
a product or null if product with such identifier is not found within the storage

generateProductShortID

protected int generateProductShortID()

assignProductShortIDs

protected void assignProductShortIDs()

elementAdded

public void elementAdded(java.lang.Object anElement,
                         java.lang.Object aSource)
Specified by:
elementAdded in interface dev.util.collections.ContainerListener

elementRemoved

public void elementRemoved(java.lang.Object anElement,
                           java.lang.Object aSource)
Specified by:
elementRemoved in interface dev.util.collections.ContainerListener

elementsAdded

public void elementsAdded(java.util.Collection anElements,
                          java.lang.Object aSource)
Specified by:
elementsAdded in interface dev.util.collections.ContainerListener

elementsRemoved

public void elementsRemoved(java.util.Collection anElements,
                            java.lang.Object aSource)
Specified by:
elementsRemoved in interface dev.util.collections.ContainerListener

getLicensingFacadeConfig

public LicensingFacadeConfig getLicensingFacadeConfig()
Returns licensing facade configuration associated with the product's storage

Returns:
an instance of the LicensingFacadeConfig

getLicense

public LicenseBase getLicense(java.lang.String aSerialNumber)
                       throws SerialNumberException
Returns license by its Serial Number

Parameters:
aSerialNumber - Serial Number to get the license for
Returns:
license
Throws:
SerialNumberException - if Serial Number is invalid

getLicense

public LicenseBase getLicense(SerialNumber aSerialNumber)
                       throws SerialNumberException
Returns license by its Serial Number

Parameters:
aSerialNumber - Serial Number to get the license for
Returns:
license
Throws:
SerialNumberException - if Serial Number is invalid

toLicense

public void toLicense(SerialNumber aSerialNumber,
                      LicenseBaseImpl aLicense)
               throws SerialNumberException
Updates specified license by provided Serial Number's attributes

Parameters:
aSerialNumber - Serial Number to get attributes from
aLicense - license to update
Throws:
SerialNumberException

getSerialNumber

public SerialNumber getSerialNumber(LicenseBase aLicense)
                             throws SerialNumberException
Creates Serial Number for specified license

Parameters:
aLicense - license to get Serial Number for
Returns:
an instance of the SerialNumber
Throws:
SerialNumberException - if itis impossible to get Serial Number for some reason

getSerialNumberVersion

public int getSerialNumberVersion()

setSerialNumberVersion

public void setSerialNumberVersion(int aSerialNumberVersion)

getVersion

public int getVersion()

setVersion

public void setVersion(int aVersion)

getCipher

protected javax.crypto.Cipher getCipher(boolean isEncrypt)

needConvertSecurityKeys

public boolean needConvertSecurityKeys()

convertSecurityKeys

public boolean convertSecurityKeys()