|
© 2004 BEA Systems, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bea.p13n.management.ApplicationHelper
Utility methods for applications.
Constructor Summary | |
ApplicationHelper()
|
Method Summary | |
static String |
getApplicationName()
Get name of the current application. |
static String |
getContextRoot(String applicationName,
String webAppName)
Retrieve the context root for a webapp. |
static InputStream |
getResourceAsStream(String uri)
Read a resource (file) from the current application. |
static String |
getWebAppName(HttpServletRequest theRequest)
Get name of the current WebApp module running the given HTTP Request. |
static String |
getWebAppName(ServletContext theContext)
Get name of the current WebApp module for the given context. |
static String |
getWebAppUri(String applicationName,
String webAppName)
Retrieve the URI where the webapp is deployed. |
static boolean |
resourceExists(String uri)
Test if a resource (file) exists in the app. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ApplicationHelper()
Method Detail |
public static String getApplicationName() throws IllegalStateException
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.
IllegalStateException
- If not called from an application context.public static String getContextRoot(String applicationName, String webAppName) throws javax.management.InstanceNotFoundException
This can be used when a webapp needs to build an absolute URL to itself, or a URL to some other webapp.
applicationName
- the name of the application containing the webappwebAppName
- the name of the webapp
javax.management.InstanceNotFoundException
- if the named application or webapp does not existgetApplicationName()
,
getWebAppName(ServletContext)
,
getWebAppName(HttpServletRequest)
,
getWebAppUri(String, String)
public static InputStream getResourceAsStream(String uri) throws IOException
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.
uri
- the location of the resource (file) in the application.
Path must be relative to the application (ear) and not null.
IOException
- if the file doesn't exist or
there is trouble reading the file or problem
with deployment or app or something
NullPointerException
- if uri is nullresourceExists(String)
public static String getWebAppName(HttpServletRequest theRequest)
This method is intended to be called from a WebApp component (Servlet) that wants to know its own deployed name. The name is the deployed name of the webapp, and is often (by convention) given the name of the war file or directory, or the webapp's context root, although this is not always 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 is not unique within a server or domain, as webapps with the same name may be deployed in other applications.
IllegalStateException
- If not called with a WebLogic Request.getApplicationName()
,
getWebAppName(ServletContext)
,
getContextRoot(String, String)
,
getWebAppUri(String, String)
public static String getWebAppName(ServletContext theContext)
This method is intended to be called from a WebApp component (Servlet) that wants to know its own deployed name. The name is the deployed name of the webapp, and is often (by convention) given the name of the war file or directory, or the webapp's context root, although this is not always 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 is not unique within a server or domain, as webapps with the same name may be deployed in other applications.
theContext
- The Servlet context for which the name is to be returned.
IllegalStateException
- If not called with a WebLogic ServletContext.getApplicationName()
,
getWebAppName(HttpServletRequest)
,
getContextRoot(String, String)
,
getWebAppUri(String, String)
public static String getWebAppUri(String applicationName, String webAppName) throws javax.management.InstanceNotFoundException
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.
applicationName
- the name of the application containing the webappwebAppName
- the name of the webapp
javax.management.InstanceNotFoundException
- if the named application or webapp does not existgetApplicationName()
,
getWebAppName(ServletContext)
,
getWebAppName(HttpServletRequest)
,
getContextRoot(String, String)
public static boolean resourceExists(String uri) throws IOException
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 parent directory does not exist.
If you are intending to test for a directory, the uri must end with a "/", or it won't match.
uri
- the location of the resource (file) in the application.
Path must be relative to the application (ear) and not null.
IOException
- if the parent directory of the uri resource does not
exist.
|
© 2004 BEA Systems, Inc. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |