Package com.blackrook.small
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 Summary
Modifier and TypeMethodDescriptionvoid
attributeAdded
(javax.servlet.http.HttpSessionBindingEvent httpsbe) void
attributeRemoved
(javax.servlet.http.HttpSessionBindingEvent httpsbe) void
attributeReplaced
(javax.servlet.http.HttpSessionBindingEvent httpsbe) <T> T
getComponent
(Class<T> clazz) Returns a singleton component instantiated by Small of a particular type or subtype.<T> Iterable<T>
getComponentList
(Class<T> clazz) Returns all singleton components instantiated by Small of a particular type or subtype.Object[]
getComponents
(Class<?>... types) Returns a new array of objects that match the provided types in the order the types are provided.Gets this application's JSON converter driver.Gets this application's MIME-Type resolver driver.Gets this application's XML converter driver.<T extends Throwable>
booleanhandleException
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, T throwable) Attempts to find a handler for an uncaught exception.boolean
handleView
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object model, String viewName) Iterates through the list of views attempting to find a view handler suitable for rendering the provided view.void
sessionCreated
(javax.servlet.http.HttpSessionEvent httpse) void
sessionDestroyed
(javax.servlet.http.HttpSessionEvent httpse)
-
Method Details
-
getJSONDriver
Gets this application's JSON converter driver.- Returns:
- the supplied driver, or null if none found.
-
getXMLDriver
Gets this application's XML converter driver.- Returns:
- the supplied driver, or null if none found.
-
getMIMETypeDriver
Gets this application's MIME-Type resolver driver.- Returns:
- the instantiated driver.
-
getTemporaryDirectory
- Returns:
- the temporary directory to use for multipart files.
-
getComponent
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
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
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 interfacejavax.servlet.http.HttpSessionListener
-
sessionDestroyed
public void sessionDestroyed(javax.servlet.http.HttpSessionEvent httpse) - Specified by:
sessionDestroyed
in interfacejavax.servlet.http.HttpSessionListener
-
attributeAdded
public void attributeAdded(javax.servlet.http.HttpSessionBindingEvent httpsbe) - Specified by:
attributeAdded
in interfacejavax.servlet.http.HttpSessionAttributeListener
-
attributeRemoved
public void attributeRemoved(javax.servlet.http.HttpSessionBindingEvent httpsbe) - Specified by:
attributeRemoved
in interfacejavax.servlet.http.HttpSessionAttributeListener
-
attributeReplaced
public void attributeReplaced(javax.servlet.http.HttpSessionBindingEvent httpsbe) - Specified by:
attributeReplaced
in interfacejavax.servlet.http.HttpSessionAttributeListener
-