Holger's
Java API

com.antelmann
Class LicenseManager

java.lang.Object
  extended by com.antelmann.LicenseManager
All Implemented Interfaces:
Iterable<License>

public final class LicenseManager
extends Object
implements Iterable<License>

LicenseManager provides the ability to use limited licenses based on classes and package names. Note that the LicenseManager only accepts Licenses that are properly signed, i.e. they will have to be created by an authorized issuer.

Once the LicenseManager is initialized, a set of licenses is installed from the licenses.dat file in the resource directory from the distribution; if any licenses therein are invalid or the file is non-existent, the resulting errors are ignored and the LicenseManager contains no licenses to begin with.

Generally, an application can go without using the LicenseManager explicitly. The class com.antelmann.util.Settings provides a few convenience methods that may suffice for a standard application.

Since:
12/31/2003
Author:
Holger Antelmann
See Also:
Settings, License, Licensed, LicenseHandler, LicensingException, Settings.checkLicense(Object), Settings.installLicense(com.antelmann.License)

Method Summary
 void check(Object licensee)
          checks for a valid license for the given object and only returns gracefully if a valid license was found.
 JTable createTable()
          creates a table containing all licenses of this manager.
 License getLicense(Object licensee)
          returns the license used for the given licensee.
static LicenseManager getLicenseManager()
          returns the global LicenseManager object (there is only one)
 Collection<License> getLicenses()
          returns an unmodifiable view of the embedded licenses
 License install(License l)
          installs the given license into this LicenseManager, so that it can be found if a check on the licensee is made.
 Iterator<License> iterator()
           
 void loadFrom(File file)
          a convenience method that installs serialized licenses from a file
 void loadFrom(InputStream stream)
          a convenience method that installs serialized licenses from a stream.
 void loadFrom(URL url)
          a convenience method that installs serialized licenses from a URL
 void removeAllLicenses()
           
 License removeLicense(License l)
           
 License signLicense(License l)
          requires a certain developer class as well as a developer private key to be present - not shipped with the distribution.
 void store(OutputStream stream)
          every license contained within is written as a serialized byte array
 void verifyLicense(License l)
          checks the signature against the certificate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createTable

public JTable createTable()
creates a table containing all licenses of this manager.

See Also:
LicenseTableModel

getLicenseManager

public static LicenseManager getLicenseManager()
                                        throws SecurityException
returns the global LicenseManager object (there is only one)

Throws:
SecurityException - if the correct certificate cannot be found

signLicense

public License signLicense(License l)
                    throws Exception
requires a certain developer class as well as a developer private key to be present - not shipped with the distribution. A license must not be altered anymore after calling this method successfully. This method uses reflection to access the required private class.

Returns:
the signed license (same object as the one passed in)
Throws:
Exception - whenever the special developer class is not present (which is usually the case).

loadFrom

public void loadFrom(File file)
              throws IOException
a convenience method that installs serialized licenses from a file

Throws:
IOException

loadFrom

public void loadFrom(URL url)
              throws IOException
a convenience method that installs serialized licenses from a URL

Throws:
IOException

loadFrom

public void loadFrom(InputStream stream)
              throws IOException
a convenience method that installs serialized licenses from a stream. Possible LicensingExceptions are ignored.

Throws:
IOException - if a license to be imported is not valid

store

public void store(OutputStream stream)
           throws IOException
every license contained within is written as a serialized byte array

Throws:
IOException

getLicenses

public Collection<License> getLicenses()
returns an unmodifiable view of the embedded licenses


iterator

public Iterator<License> iterator()
Specified by:
iterator in interface Iterable<License>

check

public void check(Object licensee)
           throws LicensingException
checks for a valid license for the given object and only returns gracefully if a valid license was found. The use() method of the license object will be called if a valid license was found.

Throws:
LicensingException - if either no license was found or the found license was invalid
See Also:
License.use(), getLicense(Object)

install

public License install(License l)
                throws LicensingException
installs the given license into this LicenseManager, so that it can be found if a check on the licensee is made. Only properly signed licenses can be installed.

Returns:
the previously installed license for the licensee embedded within the given license - if any
Throws:
LicensingException - if the license cannot be verified (i.e. if it is not properly signed)
See Also:
check(Object), verifyLicense(License)

removeLicense

public License removeLicense(License l)

removeAllLicenses

public void removeAllLicenses()

getLicense

public License getLicense(Object licensee)
returns the license used for the given licensee. If no license is found, null is returned. Note that there may be multiple licenses that may apply to a licensee; this method always returns the license that is most specific to the given licensee, even if that license turns out to be invalid. If an alternative installed license should be used instead (one that belongs to a super package and includes sub-packages), the invalid specific license must be removed from the LicenseManager.


verifyLicense

public void verifyLicense(License l)
                   throws LicensingException
checks the signature against the certificate. Note: a license passing this verification may still be invalid due to expiration or other constrains.

Throws:
LicensingException


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