Holger's Java API

## com.antelmann
Class License

    java.lang.Object
      com.antelmann.License

All Implemented Interfaces:
  Serializable

    public final class License

extends Object
implements 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.

Author:
  Holger Antelmann
See Also:
  `LicenseManager`, `LicensingException`, Serialized Form

Field Summary
`static int` `INDEFINATE`

Constructor Summary
`License(Class<?> licenseeClass, String issuedFor, Date expirationDate, int usageLimit)` only usable if properly signed
`License(Package licenseePackage, String issuedFor, Date expirationDate, int usageLimit)` only usable if properly signed
`License(Package licenseePackage, String issuedFor, Date expirationDate, int usageLimit, boolean includeSubPackages)` only usable if properly signed
`License(String classOrPackageName, String issuedFor, Date expirationDate, int usageLimit, boolean includeSubPackagesForPackage)` only usable if properly signed

Method Summary
`void` `addBoundEnvironment(String envVariable, 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(String key, String value)` allows to add a condition where this license can only be used in an environment where the given system or settings property corresponds to the given value.
`void` `checkValidation()` checks whether this license is properly singed, not expired, still has usage left and has no other boundaries that prevent its validation on this system.
`boolean` `equals(Object obj)`
`Date` `expiration()` returns the date after which this license expires.
`Map<String,String>` `getBoundEnvironment()` returns an unmodifiable view of the bound environment variables of this license
`String` `getBoundMacAddress()`
`Map<String,String>` `getBoundProperties()` returns an unmodifiable view of the bound system properties of this license
`Date` `getCreationDate()` returns the time when this license was created.
`String` `getLicensee()` returns a String representing either a Class or a Package object
`LicenseKey` `getLicenseKey()` returns the associated LicenseKey object - if any
`byte[]` `getSignature()` returns a copy of the signature that is used to verify that this license has been created by an authorized issuer
`Date` `getSigningDate()` returns the date this license was signed (if at all)
`int` `hashCode()`
`boolean` `includesSubPackages()` determines whether this license is also valid for sub-packages
`boolean` `isBound()` returns true only if this license is either bound to one or more properties or environment variables.
`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; license is not validated
`static License` `loadLicense(File file)` loads a single serialized license from a file; license is not validated
`static License` `loadLicense(InputStream stream)` loads a single serialized license from a stream; license is not validated
`static License` `loadLicense(URL url)` loads a single serialized license from a URL; license is not validated
`void` `saveTo(File file)` convenience method; overwrites the file if it exists
`void` `setBoundMacAddress(String macAddress)` bounds this license to the given macAddress (no bound if null is given)
`void` `setLicenseKey(LicenseKey key)` allows to set an individual license key for a license; must be set before signing.
`void` `setSignature(byte[] signature)` the method that signs the license and thus makes it usable.
`String` `toString()` includes only a subset of restrictions for this license
`int` `usageLeft()` returns how many times `use()` can be called.
`int` `use()` uses this license; if usage is limited, the return value of `usageLeft()` is decreased by one after a call to this method.
`byte[]` `verification()` returns the data that serves as a basis for generating the signature.

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### INDEFINATE

    public static final int INDEFINATE

See Also:
  Constant Field Values

Constructor Detail

### License

    public License(Package licenseePackage,
                   String issuedFor,
                   Date expirationDate,
                   int usageLimit)

  only usable if properly signed

### License

    public License(Package licenseePackage,
                   String issuedFor,
                   Date expirationDate,
                   int usageLimit,
                   boolean includeSubPackages)

  only usable if properly signed

### License

    public License(Class<?> licenseeClass,
                   String issuedFor,
                   Date expirationDate,
                   int usageLimit)

  only usable if properly signed

### License

    public License(String classOrPackageName,
                   String issuedFor,
                   Date expirationDate,
                   int usageLimit,
                   boolean includeSubPackagesForPackage)

  only usable if properly signed

Method Detail

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### equals

    public boolean equals(Object obj)

  Overrides:
    `equals` in class `Object`

### verification

    public byte[] verification()

  returns the data that serves as a basis for generating the signature. The return value is guaranteed to be stable after signing provided that a LicenseKey (if any) follows the requirement that its `toString()` method is stable, too.

### getLicenseKey

    public LicenseKey getLicenseKey()

  returns the associated LicenseKey object - if any

### setLicenseKey

    public void setLicenseKey(LicenseKey key)
                       throws IllegalStateException

  allows to set an individual license key for a license; must be set before signing.

  Throws:
    `IllegalStateException` - if the license has already been signed

### includesSubPackages

    public boolean includesSubPackages()

  determines whether this license is also valid for sub-packages

### addBoundEnvironment

    public void addBoundEnvironment(String envVariable,
                                    String value)
                             throws 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.

  Throws:
    `IllegalStateException` - if the license has already been signed

### addBoundProperty

    public void addBoundProperty(String key,
                                 String value)
                          throws IllegalStateException

  allows to add a condition where this license can only be used in an environment where the given system or settings property corresponds to the given value. Bound values can only be changed before a license was signed.

  Throws:
    `IllegalStateException` - if the license has already been signed
  See Also:
    `Settings.getProperties()`, `System.getProperties()`

### setBoundMacAddress

    public void setBoundMacAddress(String macAddress)
                            throws IllegalStateException

  bounds this license to the given macAddress (no bound if null is given)

  Throws:
    `IllegalStateException` - if the license has already been signed
  See Also:
    `Misc.getMacAddress()`

### getBoundMacAddress

    public String getBoundMacAddress()

### isBound

    public boolean isBound()

  returns true only if this license is either bound to one or more properties or environment variables.

  See Also:
    `getBoundProperties()`, `getBoundEnvironment()`

### getBoundProperties

    public Map<String,String> getBoundProperties()

  returns an unmodifiable view of the bound system properties of this license

### getBoundEnvironment

    public Map<String,String> getBoundEnvironment()

  returns an unmodifiable view of the bound environment variables of this license

### getCreationDate

    public Date getCreationDate()

  returns the time when this license was created.

### issuedFor

    public String issuedFor()

  a hint to whom this license was issued

### 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

### setSignature

    public void setSignature(byte[] signature)
                      throws LicensingException

  the method that signs the license and thus makes it usable. The license must not (cannot) be altered anymore after signing.

  Throws:
    `IllegalStateException` - if the license has already been signed
    `LicensingException` - if the signature is invalid

### getSigningDate

    public Date getSigningDate()

  returns the date this license was signed (if at all)

### saveTo

    public void saveTo(File file)
                throws IOException

  convenience method; overwrites the file if it exists

  Throws:
    `IOException`
  See Also:
    `loadLicense(File)`

### loadLicense

    public static License loadLicense(File file)
                               throws IOException,
                                      LicensingException

  loads a single serialized license from a file; license is not validated

  Throws:
    `IOException`
    `LicensingException`
  See Also:
    `saveTo(File)`

### loadLicense

    public static License loadLicense(URL url)
                               throws IOException,
                                      LicensingException

  loads a single serialized license from a URL; license is not validated

  Throws:
    `IOException`
    `LicensingException`

### loadLicense

    public static License loadLicense(InputStream stream)
                               throws IOException,
                                      LicensingException

  loads a single serialized license from a stream; license is not validated

  Throws:
    `IOException`
    `LicensingException`

### loadLicense

    public static License loadLicense(byte[] bytes)
                               throws IOException,
                                      LicensingException

  deserializes a license object from a byte pattern; license is not validated

  Throws:
    `IOException`
    `LicensingException`
  See Also:
    `Data.serialize(Object)`

### getLicensee

    public String getLicensee()

  returns a String representing either a Class or a Package object

### 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, still has usage left and has no other boundaries that prevent its validation on this system. The license itself is not altered through this call. Note that the license is not verified by this call (i.e. the signature is not further checked).

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

### expiration

    public Date expiration()

  returns the date after which this license expires. If the return value is null, this license doesn't expire in time.

### usageLeft

    public int usageLeft()

  returns how many times `use()` can be called. if `INDEFINATE` is returned, this license is not limited by usage. if 0 is returned, this license will throw a LicensingException on next use.

  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 String toString()

  includes only a subset of restrictions for this license

  Overrides:
    `toString` in class `Object`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads