org.jscience.util.license
Class License

java.lang.Object
  extended by org.jscience.util.license.License
All Implemented Interfaces:
java.io.Serializable

public final class License
extends java.lang.Object
implements java.io.Serializable

a License provides and limits access to certain functionality based on individual classes or packages. Note that for a License to be accepted by the LicenseManager, the License must be properly signed. A method for properly signing a License is not available under GPL, but there are License objects freely available on request.

See Also:
LicenseManager, LicensingException, Serialized Form

Field Summary
static int INDEFINATE
          DOCUMENT ME!
 
Constructor Summary
License(java.lang.Class licenseeClass, java.lang.String issuedFor, java.util.Date expirationDate, int usageLimit)
          only usable if properly signed
License(java.lang.Package licenseePackage, java.lang.String issuedFor, java.util.Date expirationDate, int usageLimit)
          only usable if properly signed
License(java.lang.String classOrPackageName, java.lang.String issuedFor, java.util.Date expirationDate, int usageLimit)
          only usable if properly signed
 
Method Summary
 void addBoundEnvironment(java.lang.String envVariable, java.lang.String value)
          allows to add a condition where this license can only be used if the given environment variable corresponds to the given value.
 void addBoundProperty(java.lang.String key, java.lang.String value)
          allows to add a condition where this license can only be used in an environment where the given system property corresponds to the given value.
 void checkValidation()
          checks whether this license is properly singed, not expired and still has usage left.
 java.util.Map<java.lang.String,java.lang.String> getBoundEnvironment()
          returns an unmodifiable view of the bound environment variables of this license
 java.util.Map<java.lang.String,java.lang.String> getBoundProperties()
          returns an unmodifiable view of the bound system properties of this license
 java.util.Date getCreationDate()
          returns the time when this license was created.
 java.lang.Object getLicensee()
          returns either a Class or a String representing the Package
 byte[] getSignature()
          returns a copy of the signature that is used to verify that this license has been created by an authorized issuer
 java.lang.String issuedFor()
          a hint to whom this license was issued
 boolean isValid()
          returns true only if this license passes checkValidation().
static License loadLicense(byte[] bytes)
          deserializes a license object from a byte pattern
static License loadLicense(java.io.File file)
          loads a serialized license from a file
static License loadLicense(java.io.InputStream stream)
          loads a serialized license from a stream
 void saveTo(java.io.File file)
          convenience method; overwrites the file if it exists
 void setSignature(byte[] signature)
          the method that signes the license and thus makes it usable
 java.lang.String toString()
          includes only a subset of restrictions for this license
 int usageLeft()
          returns how many times use() can be called. if INDEFINATE is returned, this license is not limited by usage.
 int use()
          uses this license; if usage is limited, the return value of usageLeft() is decreased by one after a call to this method.
 java.util.Date validUntil()
          returns the date after which this license expires.
 byte[] verification()
          returns the data that serves as a basis for generating the signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEFINATE

public static final int INDEFINATE
DOCUMENT ME!

See Also:
Constant Field Values
Constructor Detail

License

public License(java.lang.Package licenseePackage,
               java.lang.String issuedFor,
               java.util.Date expirationDate,
               int usageLimit)
only usable if properly signed


License

public License(java.lang.Class licenseeClass,
               java.lang.String issuedFor,
               java.util.Date expirationDate,
               int usageLimit)
only usable if properly signed


License

public License(java.lang.String classOrPackageName,
               java.lang.String issuedFor,
               java.util.Date expirationDate,
               int usageLimit)
only usable if properly signed

Method Detail

verification

public byte[] verification()
returns the data that serves as a basis for generating the signature.

Returns:
DOCUMENT ME!
Throws:
java.lang.RuntimeException - DOCUMENT ME!

addBoundEnvironment

public void addBoundEnvironment(java.lang.String envVariable,
                                java.lang.String value)
                         throws java.lang.IllegalStateException
allows to add a condition where this license can only be used if the given environment variable corresponds to the given value. Bound values can only be changed before a license was signed.

Parameters:
envVariable - DOCUMENT ME!
value - DOCUMENT ME!
Throws:
java.lang.IllegalStateException - if the license has already been signed
java.lang.NullPointerException - DOCUMENT ME!

addBoundProperty

public void addBoundProperty(java.lang.String key,
                             java.lang.String value)
                      throws java.lang.IllegalStateException
allows to add a condition where this license can only be used in an environment where the given system property corresponds to the given value. Bound values can only be changed before a license was signed.

Parameters:
key - DOCUMENT ME!
value - DOCUMENT ME!
Throws:
java.lang.IllegalStateException - if the license has already been signed
java.lang.NullPointerException - DOCUMENT ME!

getBoundProperties

public java.util.Map<java.lang.String,java.lang.String> getBoundProperties()
returns an unmodifiable view of the bound system properties of this license

Returns:
DOCUMENT ME!

getBoundEnvironment

public java.util.Map<java.lang.String,java.lang.String> getBoundEnvironment()
returns an unmodifiable view of the bound environment variables of this license

Returns:
DOCUMENT ME!

getCreationDate

public java.util.Date getCreationDate()
returns the time when this license was created.

Returns:
DOCUMENT ME!

issuedFor

public java.lang.String issuedFor()
a hint to whom this license was issued

Returns:
DOCUMENT ME!

getSignature

public byte[] getSignature()
returns a copy of the signature that is used to verify that this license has been created by an authorized issuer

Returns:
DOCUMENT ME!

setSignature

public void setSignature(byte[] signature)
                  throws LicensingException
the method that signes the license and thus makes it usable

Parameters:
signature - DOCUMENT ME!
Throws:
LicensingException - if the signature is invalid
java.lang.IllegalStateException - if the license has already been signed

saveTo

public void saveTo(java.io.File file)
            throws java.io.IOException
convenience method; overwrites the file if it exists

Throws:
java.io.IOException
See Also:
loadLicense(File)

loadLicense

public static License loadLicense(java.io.File file)
                           throws java.io.IOException,
                                  LicensingException
loads a serialized license from a file

Throws:
java.io.IOException
LicensingException
See Also:
saveTo(File)

loadLicense

public static License loadLicense(java.io.InputStream stream)
                           throws java.io.IOException,
                                  LicensingException
loads a serialized license from a stream

Throws:
java.io.IOException
LicensingException
See Also:
saveTo(File)

loadLicense

public static License loadLicense(byte[] bytes)
                           throws java.io.IOException,
                                  LicensingException
deserializes a license object from a byte pattern

Throws:
java.io.IOException
LicensingException
See Also:
IOUtils.serialize(Object)

getLicensee

public java.lang.Object getLicensee()
returns either a Class or a String representing the Package

Returns:
DOCUMENT ME!

isValid

public boolean isValid()
returns true only if this license passes checkValidation(). If you require more detail, call checkValidation() directly.

See Also:
checkValidation()

checkValidation

public void checkValidation()
                     throws LicensingException
checks whether this license is properly singed, not expired and still has usage left. The license itself is not altered through this call.

Throws:
LicensingException
See Also:
use(), LicenseManager.verifyLicense(License)

validUntil

public java.util.Date validUntil()
returns the date after which this license expires. If the return value is null, this license doesn't expire in time.

Returns:
DOCUMENT ME!

usageLeft

public int usageLeft()
returns how many times use() can be called. if INDEFINATE is returned, this license is not limited by usage.

See Also:
use()

use

public int use()
        throws LicensingException
uses this license; if usage is limited, the return value of usageLeft() is decreased by one after a call to this method.

Throws:
LicensingException
See Also:
isValid()

toString

public java.lang.String toString()
includes only a subset of restrictions for this license

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!