Class SmallEnvironment

java.lang.Object
com.blackrook.small.SmallEnvironment
All Implemented Interfaces:
EventListener, javax.servlet.http.HttpSessionAttributeListener, javax.servlet.http.HttpSessionListener

public class SmallEnvironment extends Object implements javax.servlet.http.HttpSessionAttributeListener, javax.servlet.http.HttpSessionListener
The component application environment.
Author:
Matthew Tropiano
  • Method Details

    • getJSONDriver

      public JSONDriver getJSONDriver()
      Gets this application's JSON converter driver.
      Returns:
      the supplied driver, or null if none found.
    • getXMLDriver

      public XMLDriver getXMLDriver()
      Gets this application's XML converter driver.
      Returns:
      the supplied driver, or null if none found.
    • getMIMETypeDriver

      public MIMETypeDriver getMIMETypeDriver()
      Gets this application's MIME-Type resolver driver.
      Returns:
      the instantiated driver.
    • getTemporaryDirectory

      public File getTemporaryDirectory()
      Returns:
      the temporary directory to use for multipart files.
    • getComponent

      public <T> T getComponent(Class<T> clazz)
      Returns a singleton component instantiated by Small of a particular type or subtype.
      Type Parameters:
      T - object type.
      Parameters:
      clazz - the class to fetch or instantiate.
      Returns:
      a singleton component annotated with Component by class, or null if not found.
      Throws:
      SmallFrameworkException - if more than one component would be returned using this method.
      Since:
      1.3.0, this does not instantiate components, only retrieves.
    • getComponentList

      public <T> Iterable<T> getComponentList(Class<T> clazz)
      Returns all singleton components instantiated by Small of a particular type or subtype.
      Type Parameters:
      T - object type.
      Parameters:
      clazz - the class type search for.
      Returns:
      all singleton component annotated with Component by class, or an empty list if not found.
      Since:
      1.3.0
    • getComponents

      public Object[] getComponents(Class<?>... types)
      Returns a new array of objects that match the provided types in the order the types are provided. If the component can't be found, null is set in that index.
      Parameters:
      types - the requested types.
      Returns:
      an array of matching singletons.
      Throws:
      SmallFrameworkException - if more than one component would be returned for any one type using this method.
      Since:
      1.3.0
      See Also:
    • handleView

      public boolean handleView(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object model, String viewName) throws ViewProcessingException
      Iterates through the list of views attempting to find a view handler suitable for rendering the provided view.
      Parameters:
      request - the HTTP request object.
      response - the HTTP response object.
      model - the model to render using the view.
      viewName - the name of the view to handle.
      Returns:
      true if the view was handled by this component, false if not.
      Throws:
      ViewProcessingException - if an error occurs on view processing of any kind.
    • handleException

      public <T extends Throwable> boolean handleException(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, T throwable)
      Attempts to find a handler for an uncaught exception.
      Type Parameters:
      T - the exception type.
      Parameters:
      request - the HTTP request object.
      response - the HTTP response object.
      throwable - the throwable to handle.
      Returns:
      true if the exception was handled by this method, false if not.
    • sessionCreated

      public void sessionCreated(javax.servlet.http.HttpSessionEvent httpse)
      Specified by:
      sessionCreated in interface javax.servlet.http.HttpSessionListener
    • sessionDestroyed

      public void sessionDestroyed(javax.servlet.http.HttpSessionEvent httpse)
      Specified by:
      sessionDestroyed in interface javax.servlet.http.HttpSessionListener
    • attributeAdded

      public void attributeAdded(javax.servlet.http.HttpSessionBindingEvent httpsbe)
      Specified by:
      attributeAdded in interface javax.servlet.http.HttpSessionAttributeListener
    • attributeRemoved

      public void attributeRemoved(javax.servlet.http.HttpSessionBindingEvent httpsbe)
      Specified by:
      attributeRemoved in interface javax.servlet.http.HttpSessionAttributeListener
    • attributeReplaced

      public void attributeReplaced(javax.servlet.http.HttpSessionBindingEvent httpsbe)
      Specified by:
      attributeReplaced in interface javax.servlet.http.HttpSessionAttributeListener