org.licas.module

## Class FrameworkModule

- java.lang.Object
- - java.lang.Thread
  - - org.licas.module.LicasModule
    - - org.licas.module.FrameworkModule

- All Implemented Interfaces:
    java.lang.Runnable, ServiceDef
  Direct Known Subclasses:
    BehaviourModule, ControlModule, DataModule, ServiceModule, SM_Service

      public class FrameworkModule
      extends LicasModule
      implements ServiceDef

  This class stores the minimal set of variables for a service reference, for behaviours and module plug-ins. The full service extends this module with the `Service` class, so this is an integrated info object in a full service. If specific variables are not set in this class and the `service` variable is used, then where variables overlap, its values are returned instead.

  This module is not typically added to another `Service` as a child service, unless it also extends the `ServiceModule` class. These modules are more specifically framework components in the service itself.

  Author:
    Kieran Greer

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class java.lang.Thread

      `java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected PasswordHandler` | `passwordHandler` This stores and compares all passwords used by this module.
    `protected Service` | `service` Reference to a `Service` object.
    `protected java.lang.String` | `serviceType` The functional service type

    - ### Fields inherited from class org.licas.module.LicasModule

      `jarFile, syncOn, uuid`

    - ### Fields inherited from class java.lang.Thread

      `MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FrameworkModule()` Creates a new instance of FrameworkModule.
    `FrameworkModule(java.lang.String password, java.lang.String adminKey)` Creates a new instance of FrameworkModule.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `canAccess(java.lang.String thePassword)` Return true if the password allows the calling component to access this component.
    `boolean` | `canAccessTemp(java.lang.String thePassword)` Return true if the password allows the calling component to access this component by a temporary password.
    `protected PasswordHandler` | `getPasswordHandler()` Get the password handler.
    `PasswordHandler` | `getPasswordHandler(java.lang.String adminKey)` Get the password handler.
    `protected java.lang.String` | `getServerPassword()` Get the local server password if it is stored.
    `java.lang.String` | `getServicePassword(java.lang.String serviceUUID, java.lang.String serverUrl)` Get or ask for the service password, making a remote call if necessary.
    `java.lang.String` | `getServiceType()` Get the functional type for this service.
    `boolean` | `isAdminKey(java.lang.String theAdminKey)` Return true if the key passed in is this service's admin key.
    `void` | `setServiceDetails(Service service, PasswordHandler passwordHandler)` Set the service reference for an external service, if not already set.
    `void` | `setServiceType(java.lang.String thisServiceType)` Set the functional service type, but only if it is currently `null`, otherwise it is not changed.

    - ### Methods inherited from class org.licas.module.LicasModule

      `getJarFile, getUUID, loadObject, setJarFile, setUUID, threadAliveState`

    - ### Methods inherited from class java.lang.Thread

      `activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.licas.def.ServiceDef

      `getUUID, setJarFile, setUUID`

- - ### Field Detail

    - #### serviceType

          protected java.lang.String serviceType

      The functional service type

    - #### passwordHandler

          protected PasswordHandler passwordHandler

      This stores and compares all passwords used by this module. Probably better to set passwords at source, because password handler can be this or service.

    - #### service

          protected Service service

      Reference to a `Service` object. This can be the service that the module uses, or a parent service if the module is a derived `Service` class.

  - ### Constructor Detail

    - #### FrameworkModule

          public FrameworkModule()
                          throws java.lang.Exception

      Creates a new instance of FrameworkModule. For an external service, you can set the service details later using `setServiceDetails`.
      Throws:
        `java.lang.Exception` - any error.

    - #### FrameworkModule

          public FrameworkModule(java.lang.String password,
                                 java.lang.String adminKey)
                          throws java.lang.Exception

      Creates a new instance of FrameworkModule. For an external service, you can set the service details later using `setServiceDetails`.
      Parameters:
        `password` - password to initialise the password handler with.
        `adminKey` - admin key to initialise the password handler with.
      Throws:
        `java.lang.Exception` - any error.

  - ### Method Detail

    - #### setServiceDetails

          public void setServiceDetails(Service service,
                                        PasswordHandler passwordHandler)
                                 throws java.lang.Exception

      Set the service reference for an external service, if not already set.
      Parameters:
        `service` - the external (not derived) service.
        `passwordHandler` - the service's psssword handler.
      Throws:
        `java.lang.Exception` - any error.

    - #### canAccess

          public boolean canAccess(java.lang.String thePassword)

      Return true if the password allows the calling component to access this component.
      Specified by:
        `canAccess` in interface `ServiceDef`
      Parameters:
        `thePassword` - the password to use.
      Returns:
        true if the entered password is the correct password or there is no password.

    - #### canAccessTemp

          public boolean canAccessTemp(java.lang.String thePassword)

      Return true if the password allows the calling component to access this component by a temporary password.
      Specified by:
        `canAccessTemp` in interface `ServiceDef`
      Parameters:
        `thePassword` - the password to use.
      Returns:
        true if the entered password is the valid.

    - #### isAdminKey

          public boolean isAdminKey(java.lang.String theAdminKey)

      Return true if the key passed in is this service's admin key.
      Specified by:
        `isAdminKey` in interface `ServiceDef`
      Parameters:
        `theAdminKey` - the key to check.
      Returns:
        true if this is the service key

    - #### getServicePassword

          public java.lang.String getServicePassword(java.lang.String serviceUUID,
                                                     java.lang.String serverUrl)

      Get or ask for the service password, making a remote call if necessary. This method only makes a single call to the other service to ask for the password, with a default yes contract. If the other service does not have to return its password, or requires a different contract, this method will fail.
      Parameters:
        `serviceUUID` - the uuid of the service. This should only be the uuid and not the whole serviceUri path.
        `serverUrl` - URL address of a remote server if it needs to be called. Can be null for local server.
      Returns:
        the password for the service to call, or null if there is an error.

    - #### getServerPassword

          protected java.lang.String getServerPassword()
                                                throws java.lang.Exception

      Get the local server password if it is stored.
      Returns:
        the local server password.
      Throws:
        `java.lang.Exception` - any error.

    - #### setServiceType

          public void setServiceType(java.lang.String thisServiceType)

      Set the functional service type, but only if it is currently `null`, otherwise it is not changed. This method should probably not be called manually as the service type is automatically set when the service is loaded as the service name.
      Specified by:
        `setServiceType` in interface `ServiceDef`
      Parameters:
        `thisServiceType` - the service type.

    - #### getServiceType

          public java.lang.String getServiceType()

      Get the functional type for this service.
      Specified by:
        `getServiceType` in interface `ServiceDef`
      Returns:
        the value of serviceType.

    - #### getPasswordHandler

          public PasswordHandler getPasswordHandler(java.lang.String adminKey)

      Get the password handler.
      Parameters:
        `adminKey` - the admin key for the service.
      Returns:
        the value of passwordHandler if the correct admin key, `null` otherwise.

    - #### getPasswordHandler

          protected PasswordHandler getPasswordHandler()

      Get the password handler.
      Returns:
        the value of passwordHandler.