Application encapsulates the SBT Application. In a web application SBTFilter (HTTP servlet filter) is responsible for initializing the application using servlet context. Application does the initialization like loading the managed beans and properties factories. Application can optionally have Listeners associated with it to capture the Application related events.
Following are the major classes in SDK related to Application:
- com.ibm.commons.runtime.Application - Abstract class that encapsulates SBT Application.
- com.ibm.commons.runtime.impl.AbstractApplication - This class extends com.ibm.commons.runtime.Application. It is an base abstract implementation for J2EE servers/web applications/java applications. This class loads the managed beans and properties factories.
- com.ibm.commons.runtime.impl.servlet.ApplicationServlet - This class extends from com.ibm.commons.runtime.impl.AbstractApplication. It is the SBT Application implementation for a servlet environment.
- com.ibm.commons.runtime.impl.app.ApplicationStandalone - This class extends from com.ibm.commons.runtime.impl.AbstractApplication. It is the SBT Application implementation for a non-web java application.
Context encapsulates a context which can be reused by all helpers in SDK Application. In SDK Application Context is stored on per thread level in a ThreadLocal variable. In a web application SBTFilter (HTTP servlet filter) is responsible for initializing the context by passing the application, Servlet Request and Servlet Response Objects. In a non-web application, context is initialized by passing only the application since there are no request and response objects.
Once initialized, context is used to store various things at different scopes like session, application, request scopes. Context also stores cookies in a map. Context can optionally have Listeners associated with it to capture the Context related events.
Following are the major classes in SDK related to Context:
- com.ibm.commons.runtime.Context - this is base abstract class which encapsulated context of SDK Application.
- com.ibm.commons.runtime.impl.AbstractContext - This class extends com.ibm.commons.runtime.Context and contains the abstract implementation iof Context for J2EE Services/web applications/java applications.
- com.ibm.commons.runtime.impl.servlet.ContextServlet - This class extends com.ibm.commons.runtime.impl.AbstractContext and contains SBT Context implementation for a servlet environment. It has Maps to store beans at session, application or reqiuest level. Helper classes can retrieve the stored beans using this context. It also has a Map to store cookies.
- com.ibm.commons.runtime.impl.app.ContextStandalone - This class extends com.ibm.commons.runtime.impl.AbstractContext and contains SBT Context implementation for a non-web java application. All web related methods have stubbed implementation in this. Unlike Context servlet, there are no maps to store beans at any scope.
Example usage of Context in getting endpoint bean:
Parent topic: Runtime concepts
Look for a property defining the bean associated to this server
Context context = Context.get();
String beanName = context.getProperty(SERVERPROP_PREFIX+name, null);
beanName = SERVERBEAN_PREFIX+name;
Look for a bean and/or class
Object o = context.getBean(beanName);