Class AbstractGuiseContainer

java.lang.Object
io.guise.framework.AbstractGuiseContainer
All Implemented Interfaces:
GuiseContainer
Direct Known Subclasses:
HTTPServletGuiseContainer

public abstract class AbstractGuiseContainer extends Object implements GuiseContainer
An abstract base class for a Guise instance. This implementation only works with Guise applications that descend from AbstractGuiseApplication.
Author:
Garret Wilson
  • Constructor Details

    • AbstractGuiseContainer

      public AbstractGuiseContainer(URI baseURI)
      Container base URI constructor.
      Parameters:
      baseURI - The base URI of the container, an absolute URI that ends with the base path, which ends with a slash ('/'), indicating the base path of the application base paths.
      Throws:
      NullPointerException - if the base URI is null.
      IllegalArgumentException - if the base URI is not absolute or does not end with a slash ('/') character.
  • Method Details

    • getBaseURI

      public URI getBaseURI()
      Description copied from interface: GuiseContainer
      Reports the base URI of the container. The base URI is an absolute URI that ends with the base path, which ends with a slash ('/').
      Specified by:
      getBaseURI in interface GuiseContainer
      Returns:
      The base URI representing the Guise container.
    • getBasePath

      public com.globalmentor.net.URIPath getBasePath()
      Description copied from interface: GuiseContainer
      Reports the base path of the container. The base path is an absolute path that ends with a slash ('/'), indicating the base path of the application base paths.
      Specified by:
      getBasePath in interface GuiseContainer
      Returns:
      The base path representing the Guise container.
    • getApplications

      public Collection<GuiseApplication> getApplications()
      Specified by:
      getApplications in interface GuiseContainer
      Returns:
      The applications currently installed in this container.
    • addGuiseSession

      protected void addGuiseSession(GuiseSession guiseSession)
      Adds and initializes a Guise session. This version creates a thread group for the session. The Guise session will be registered with the Guise application before it is initialized. Initialization will occur inside the appropriate session thread group.
      Parameters:
      guiseSession - The Guise session to add.
      See Also:
    • removeGuiseSession

      protected void removeGuiseSession(GuiseSession guiseSession)
      Removes and destroys a Guise session. The Guise session will be unregistered from the Guise application after it is uninitialized. Destruction will occur inside the appropriate session thread group.
      Parameters:
      guiseSession - The Guise session to remove.
      See Also:
    • installApplication

      protected void installApplication(AbstractGuiseApplication application, URI baseURI, File homeDirectory, File logDirectory, File tempDirectory) throws IOException
      Installs the given application at the given base path. If no theme is specified, the default theme will be loaded. This version ensures the home, log, and temp directories exist.
      Parameters:
      application - The application to install.
      baseURI - The base URI at which the application is being installed.
      homeDirectory - The home directory of the application.
      logDirectory - The log directory of the application.
      tempDirectory - The temporary directory of the application.
      Throws:
      NullPointerException - if the application, base URI, home directory, log directory, and/or temporary directory is null.
      IllegalArgumentException - if the given base URI is not absolute or the path of which is not absolute or not a collection.
      IllegalStateException - if the application is already installed in some container.
      IllegalStateException - if there is already an application installed in this container at the given base path.
      IOException - if there is an I/O error when installing the application.
    • uninstallApplication

      protected void uninstallApplication(AbstractGuiseApplication application)
      Uninstalls the given application.
      Parameters:
      application - The application to uninstall.
      Throws:
      NullPointerException - if the application is null.
      IllegalStateException - if the application is not installed in this container.
    • resolvePath

      public com.globalmentor.net.URIPath resolvePath(com.globalmentor.net.URIPath path)
      Description copied from interface: GuiseContainer
      Resolves a relative or absolute path against the container base path. Relative paths will be resolved relative to the container base path. Absolute paths will be be considered already resolved. For a container base path "/path/to/container/", resolving "relative/path" will yield "/path/to/container/relative/path", while resolving "/absolute/path" will yield "/absolute/path".
      Specified by:
      resolvePath in interface GuiseContainer
      Parameters:
      path - The path to be resolved.
      Returns:
      The path resolved against the container base path.
      See Also:
    • resolveURI

      public URI resolveURI(URI uri)
      Description copied from interface: GuiseContainer
      Resolves URI against the container base path. Relative paths will be resolved relative to the container base path. Absolute paths will be considered already resolved, as will absolute URIs. For a container base path "/path/to/container/", resolving "relative/path" will yield "/path/to/container/relative/path", while resolving "/absolute/path" will yield "/absolute/path". Resolving "http://example.com/path" will yield "http://example.com/path".
      Specified by:
      resolveURI in interface GuiseContainer
      Parameters:
      uri - The URI to be resolved.
      Returns:
      The URI resolved against the container base path.
      See Also:
    • hasResource

      protected abstract boolean hasResource(String resourcePath)
      Determines if the application has a resource available stored at the given resource path. The provided path is first normalized.
      Parameters:
      resourcePath - A container-relative path to a resource in the resource storage area.
      Returns:
      true if a resource exists at the given resource path.
      Throws:
      IllegalArgumentException - if the given resource path is absolute.
      IllegalArgumentException - if the given path is not a valid path.
    • getResourceInputStream

      protected abstract InputStream getResourceInputStream(String resourcePath)
      Retrieves an input stream to the resource at the given path. The provided path is first normalized.
      Parameters:
      resourcePath - A container-relative path to a resource in the resource storage area.
      Returns:
      An input stream to the resource at the given resource path, or null if no resource exists at the given resource path.
      Throws:
      IllegalArgumentException - if the given resource path is absolute.
      IllegalArgumentException - if the given path is not a valid path.
    • getInputStream

      public InputStream getInputStream(URI uri) throws IOException
      Retrieves an input stream to the entity at the given URI. The URI is first resolved to the container base URI.
      Specified by:
      getInputStream in interface GuiseContainer
      Parameters:
      uri - A URI to the entity; either absolute or relative to the container.
      Returns:
      An input stream to the entity at the given resource URI, or null if no entity exists at the given resource path.
      Throws:
      NullPointerException - if the given URI is null.
      IOException - if there was an error connecting to the entity at the given URI.
      See Also:
    • getPrincipal

      protected Principal getPrincipal(AbstractGuiseApplication application, String id)
      Looks up an application principal from the given ID. This version delegates to the given Guise application.
      Parameters:
      application - The application for which a principal should be returned for the given ID.
      id - The ID of the principal.
      Returns:
      The principal corresponding to the given ID, or null if no principal could be determined.
    • getPassword

      protected char[] getPassword(AbstractGuiseApplication application, Principal principal)
      Looks up the corresponding password for the given principal. This version delegates to the given Guise application.
      Parameters:
      application - The application for which a password should e retrieved for the given principal.
      principal - The principal for which a password should be returned.
      Returns:
      The password associated with the given principal, or null if no password is associated with the given principal.
    • getRealm

      protected String getRealm(AbstractGuiseApplication application, URI resourceURI)
      Determines the realm applicable for the resource indicated by the given URI. This version delegates to the given Guise application.
      Parameters:
      application - The application for which a realm should be returned for the given resource URI.
      resourceURI - The URI of the resource requested.
      Returns:
      The realm appropriate for the resource, or null if the given resource is not in a known realm.
      See Also:
    • isAuthorized

      protected boolean isAuthorized(AbstractGuiseApplication application, URI resourceURI, Principal principal, String realm)
      Checks whether the given principal is authorized to access the resource at the given application path. This version delegates to the given Guise application.
      Parameters:
      application - The application for which a principal should be authorized for a given resource URI.
      resourceURI - The URI of the resource requested.
      principal - The principal requesting authentication, or null if the principal is not known.
      realm - The realm with which the resource is associated, or null if the realm is not known.
      Returns:
      true if the given principal is authorized to access the resource represented by the given resource URI.