pt.jcodeutil.core.ejb
Class ContextUtils

java.lang.Object
  |
  +--pt.jcodeutil.core.ejb.ContextUtils

public abstract class ContextUtils
extends java.lang.Object

Title:

Description: Utilities for creating contexts and closing them.

Version:
1.0
Author:
Marco Samuel (samuelbb@sapo.pt)

Constructor Summary
ContextUtils()
           
 
Method Summary
static void close(javax.naming.Context ctx)
          Close the context given by argument, ignoring any exception.
static javax.naming.Context getContext(java.lang.String initialCtxFactory, java.lang.String providerURL)
          Get a context based in the arguments that are given.
static javax.naming.Context getContext(java.lang.String initialCtxFactory, java.lang.String providerURL, java.lang.String securityAuthentication)
          Get a context based in the arguments that are given.
static javax.naming.Context getContext(java.lang.String inicialContextFactory, java.lang.String providerURL, java.lang.String securityPrincipal, java.lang.String securityCredentials)
          Get a context based in the arguments that are given.
static javax.naming.Context getRootContext()
          Get the root context based in the called context.
static java.lang.Object lookup(javax.naming.Context ctx, java.lang.String envName, java.lang.Class classType)
          Do a lookup of an Object in the context given by argument.
static java.lang.Object narrow(java.lang.Object obj, java.lang.Class classType)
          Narrow an object to a specific Class Type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextUtils

public ContextUtils()
Method Detail

getContext

public static javax.naming.Context getContext(java.lang.String initialCtxFactory,
                                              java.lang.String providerURL)
                                       throws javax.naming.NamingException
Get a context based in the arguments that are given.
Parameters:
initialCtxFactory - the context factory
providerURL - the provider of the context
Returns:
the context that is created based in this arguments.
Throws:
javax.naming.NamingException -  

getContext

public static javax.naming.Context getContext(java.lang.String initialCtxFactory,
                                              java.lang.String providerURL,
                                              java.lang.String securityAuthentication)
                                       throws javax.naming.NamingException
Get a context based in the arguments that are given.
Parameters:
initialCtxFactory - the context factory.
providerURL - the provider of the context.
securityAuthentication - the authentication to be used.
Returns:
the context that is created based in this arguments.
Throws:
javax.naming.NamingException -  

getContext

public static javax.naming.Context getContext(java.lang.String inicialContextFactory,
                                              java.lang.String providerURL,
                                              java.lang.String securityPrincipal,
                                              java.lang.String securityCredentials)
                                       throws javax.naming.NamingException
Get a context based in the arguments that are given.
Parameters:
initialCtxFactory - the context factory.
providerURL - the provider of the context.
securityPrincipal - the principal to be used.
securityCredentials - the credentials to be used.
Returns:
the context that is created based in this arguments.
Throws:
javax.naming.NamingException -  

getRootContext

public static javax.naming.Context getRootContext()
                                           throws javax.naming.NamingException
Get the root context based in the called context.
Returns:
the root context (InitialContext).

close

public static void close(javax.naming.Context ctx)
Close the context given by argument, ignoring any exception.
Parameters:
ctx - the context to be closed.

narrow

public static final java.lang.Object narrow(java.lang.Object obj,
                                            java.lang.Class classType)
Narrow an object to a specific Class Type.
Parameters:
obj - the object to be narrowed.
classType - the class type that the object is going to be narrowed to.
Returns:
The result of narrowing the Object to the Class Type.

lookup

public static final java.lang.Object lookup(javax.naming.Context ctx,
                                            java.lang.String envName,
                                            java.lang.Class classType)
                                     throws javax.naming.NamingException
Do a lookup of an Object in the context given by argument.
Parameters:
ctx - context where to look for
envName - name to look for
classType - class type of the object in the context
Returns:
the object that we are looking in the context
Throws:
javax.naming.NamingException - if not found