com.bea.p13n.management
Class ApplicationHelper

java.lang.Object
  extended by com.bea.p13n.management.ApplicationHelper

public final class ApplicationHelper
extends Object

Utility methods for applications.


Method Summary
static String getApplicationName()
          Deprecated The methods getNonVersionedAppName and getVersionedAppName should be used instead of this method. This method is not descriptive enough for use with side by side deployment. This method will be removed at a future date. This method now returns the same thing as getNonVersionedAppName();
static String getContextRoot(String versionedapplicationName, String webAppName)
          Retrieve the context root for a webapp.
static String getNonVersionedAppName()
          Get name of the current application.
static InputStream getResourceAsStream(String uri)
          Read a resource (file) from the current application.
static String getVersionedAppName()
          Get name of the current application.
static String getWebAppName(javax.servlet.http.HttpServletRequest theRequest)
          Get name of the current WebApp module running the given HTTP Request.
static String getWebAppName(javax.servlet.ServletContext theContext)
          Get name of the current WebApp module for the given context.
static String getWebAppUri(javax.servlet.ServletContext theContext)
          Retrieve the URI where the webapp is deployed.
static String getWebAppUri(String versionedapplicationName, String webAppName)
          Retrieve the URI where the webapp is deployed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getApplicationName

@Deprecated
public static String getApplicationName()
                                 throws IllegalStateException
Deprecated The methods getNonVersionedAppName and getVersionedAppName should be used instead of this method. This method is not descriptive enough for use with side by side deployment. This method will be removed at a future date. This method now returns the same thing as getNonVersionedAppName();

Throws
IllegalStateException

getNonVersionedAppName

public static String getNonVersionedAppName()
                                     throws IllegalStateException
Get name of the current application. This name is unique among applications deployed to the domain, and thus can be useful for naming resources to be scoped to the application.

This method must be called from an application context. That is, some component (EJB, Servlet, etc.) deployed as part of an application (ear), or code called from such a component. The result will be specific to the application containing that component.

The Application Name is the deployed name of the application, and is often the name of the EAR jar file or directory, although this is not always the case.

This method differs from getVersionedApplicaitonName in that the name will be stay the same between versioned deployments.

Returns
The name of the application in which the calling component is deployed.
Throws
IllegalStateException - If not called from an application context.

getVersionedAppName

public static String getVersionedAppName()
                                  throws IllegalStateException
Get name of the current application. This name is unique among applications deployed to the domain, and thus can be useful for naming resources to be scoped to the application.

This method must be called from an application context. That is, some component (EJB, Servlet, etc.) deployed as part of an application (ear), or code called from such a component. The result will be specific to the application containing that component.

The Application Name is the deployed name of the application, and is often the name of the EAR jar file or directory, although this is not always the case.

This method differs from get NoVersionedApplicaitonName in that the name change from versioned deployment to versioned deployment. This name would most often be used in the case where you need to key some data by the applicaiton but do not want the data to collide between two applicaitons running in side by side mode. An example where this might be used is in a caching framework or versioned security provider.

Returns
The name of the application in which the calling component is deployed.
Throws
IllegalStateException - If not called from an application context.

getWebAppName

public static String getWebAppName(javax.servlet.ServletContext theContext)
Get name of the current WebApp module for the given context.

This method is intended to be called from a WebApp component (Servlet) that wants to know its own deployed name. The name is a unique name for the webapp, and is often the webapp's context root, although this is not guaranteed to be the case. This name is unique among webapps in the application, and thus can be useful for naming resources to be scoped to the webapp. Note, however, that the name might not be unique within a server or domain, so it is safest to qualify this name with the application name, if server-wide uniqueness is needed.

Parameters
theContext - The Servlet context for which the name is to be returned.
Returns
The WebApp name.
Throws
IllegalStateException - If not called with a WebLogic ServletContext.
See Also
getApplicationName(), getWebAppName(HttpServletRequest), getContextRoot(String, String), getWebAppUri(String, String)

getWebAppName

public static String getWebAppName(javax.servlet.http.HttpServletRequest theRequest)
Get name of the current WebApp module running the given HTTP Request.

This method is intended to be called from a WebApp component (Servlet) that wants to know its own deployed name. The name is a unique name for the webapp, and is often the webapp's context root, although this is not guaranteed to be the case. This name is unique among webapps in the application, and thus can be useful for naming resources to be scoped to the webapp. Note, however, that the name might not be unique within a server or domain, so it is safest to qualify this name with the application name, if server-wide uniqueness is needed.

Parameters
theRequest - The Request for which the name is to be returned.
Returns
The WebApp name.
Throws
IllegalStateException - If not called with a WebLogic Request.
See Also
getApplicationName(), getWebAppName(ServletContext), getContextRoot(String, String), getWebAppUri(String, String)

getWebAppUri

public static String getWebAppUri(String versionedapplicationName,
                                  String webAppName)
                           throws InstanceNotFoundException
Retrieve the URI where the webapp is deployed. The URI is the directory or war file name of the deployed webapp, relative to the application root. The returned uri might be a directory or a war file.

This uri can be used with getResourceAsStream to retrieve files from a webapp, for example, when ServletContext.getResourceAsStream() will not work. Usually this will be in the case of one webapp "managing" another webapp.

Parameters
versionedapplicationName - the name of the application containing the webapp
webAppName - the name of the webapp (context-root)
Returns
the URI for the webapp, relative to the application root
Throws
InstanceNotFoundException - if the named application or webapp does not exist
See Also
getApplicationName(), getWebAppName(ServletContext), getWebAppName(HttpServletRequest), getContextRoot(String, String)

getWebAppUri

public static String getWebAppUri(javax.servlet.ServletContext theContext)
                           throws IllegalStateException
Retrieve the URI where the webapp is deployed. The URI is the directory or war file name of the deployed webapp, relative to the application root. The returned uri might be a directory or a war file.

This uri can be used with getResourceAsStream to retrieve files from a webapp, for example, when ServletContext.getResourceAsStream() will not work. Usually this will be in the case of one webapp "managing" another webapp.

Parameters
theContext - The Servlet context for which the URI is to be returned.
Returns
the URI for the webapp, as specified in application.xml
Throws
IllegalStateException - If not called with a WebLogic ServletContext.
See Also
getApplicationName(), getWebAppName(ServletContext), getWebAppName(HttpServletRequest), getContextRoot(String, String)

getContextRoot

public static String getContextRoot(String versionedapplicationName,
                                    String webAppName)
                             throws InstanceNotFoundException
Retrieve the context root for a webapp. The context root can be used to build a URL to access that webapp. The context root is specified in either the application's or the webapp's deployment descriptors.

This can be used when a webapp needs to build an absolute URL to itself, or a URL to some other webapp.

Parameters
versionedapplicationName - the name of the application containing the webapp
webAppName - the name of the webapp
Returns
the context root for the webapp
Throws
InstanceNotFoundException - if the named application or webapp does not exist
See Also
getApplicationName(), getWebAppName(ServletContext), getWebAppName(HttpServletRequest), getWebAppUri(String, String)

getResourceAsStream

public static InputStream getResourceAsStream(String uri)
                                       throws IOException
Read a resource (file) from the current application.

This method must be called from an application context. That is, some component (EJB, Servlet, etc.) deployed as part of an application (ear), or code called from such a component. The result will be specific to the application containing that component.

This will fail (log and throw an IOException) if the file does not exist. Use resourceExists() to test existence and prevent the exception being logged.

Parameters
uri - the location of the resource (file) in the application. Path must be relative to the application (ear) and not null. The uri may optionally be of the form moduleUri#resourceUri, (for example myWebApp.war#WEB-INF/web.xml) to retrieve resources from modules within the application.
Returns
stream for the resource
Throws
FileNotFoundException - if the file or module doesn't exist
IOException - if there is trouble reading the file or problem with deployment or app or something
NullPointerException - if uri is null
See Also
resourceExists(String)


Copyright © 2011, Oracle. All rights reserved.