Class Application

  extended by net.rim.pushsdk.commons.Application
All Implemented Interfaces:

public class Application
extends Object
implements org.springframework.context.ApplicationContextAware

Class that maintains a static reference to the ApplicationContext.

The ApplicationContext is used to get references to the beans managed by Spring for this SDK. It is recommend you use one of the *BeanLocator classes instead of using Application directly.

This class implements the org.springframework.context.ApplicationContextAware interface; therefore, if an ApplicationContext is available, it will be automatically injected into this class and used to serve bean lookups. If no ApplicationContext is set, then this class will by default attempt to load an ApplicationContext from the context XML files in the classpath using this pattern:


In case of multiple context config locations, later bean definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain bean definitions via an extra XML file that appears later in the classpath.

Important design note: It is mandatory that an application have one, and only one, ApplicationContext set to prevent memory leaks. If your application using the SDK is a Spring enabled application, use your own method of getting the SDK beans from your own ApplicationContext (i.e. inject the SDK beans into your own application's beans using dependency injection provided by Spring) rather than using this class; similarly do not use the *BeanLocators either for the same reason.

This class is useful for standalone applications that themselves do not use the Spring framework. This class will statically instantiate an application context in order to provide an entry point to any of the beans used by the SDK, taking the context definition files from the class path.

If your application is running in a servlet container, it is highly recommend you initialize your ApplicationContext using org.springframework.web.context.ContextLoaderListener via your web.xml. To enable this add the following to your web.xml:



Example usage:

 PushService pushService = (PushService) Application.getContext().getBean("pushService");


Field Summary
          Look up path for context XML files if not ApplicationContext was injected into this class: classpath*:pushsdk-*-context.xml.
Constructor Summary
Method Summary
static org.springframework.context.ApplicationContext getContext()
          Returns the application context.
static org.springframework.context.ApplicationContext getContext(boolean createFromClasspathIfNotExist)
          Returns the ApplicationContext.
 void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
          ApplicationContextAware interface implementation; e.g.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


Look up path for context XML files if not ApplicationContext was injected into this class: classpath*:pushsdk-*-context.xml.

Constructor Detail


public Application()
Method Detail


public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
                           throws org.springframework.beans.BeansException
ApplicationContextAware interface implementation; e.g. called by the servlet container to set the context if org.springframework.web.context.ContextLoaderListener is used.

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware


public static org.springframework.context.ApplicationContext getContext()
Returns the application context. See getContext(boolean) javadoc for details. This method will delegate to that method passing 'true' as a parameter.

the application context. May be null.


public static org.springframework.context.ApplicationContext getContext(boolean createFromClasspathIfNotExist)
Returns the ApplicationContext. The ApplicationContext is typically injected by Spring since this class implements ApplicationContextAware (e.g. running in a J2EE web server you can use org.springframework.web.context.ContextLoaderListener via your web.xml). If the ApplicationContext is not injected, then this method may attempt to construct an ApplicationContext by loading the context XML file(s) from the classpath using the pattern as defined by DEFAULT_CONFIG_LOCATIONS depending on the value of the createFromClasspathIfNotExist parameter.

createFromClasspathIfNotExist - true if this class should create the ApplicationContext if it has not been injected by Spring by trying to load the context XML files by looking in the classpath; false if this class should not attempt to create an ApplicationContext if one was not automatically injected by Spring from implementing the ApplicationContextAware interface
the application context. May be null.

Copyright © 2011 Research In Motion. All Rights Reserved.