cuba.wired
Class WiredClientContext

java.lang.Object
  extended by cuba.wired.WiredClientContext
All Implemented Interfaces:
ClientContextI, ContextI

public class WiredClientContext
extends java.lang.Object
implements ClientContextI

Client interface to a wired container used to get access to components and resources provided by that container.

Author:
Jan Lessner

Nested Class Summary
 
Nested classes/interfaces inherited from interface cuba.ContextI
ContextI.Type
 
Field Summary
 
Fields inherited from interface cuba.ClientContextI
CALLER_PROPERTY
 
Constructor Summary
WiredClientContext()
          Like function above with null properties
WiredClientContext(java.util.Properties props)
          Creates a WiredClientContext for the default WiredContainer.
WiredClientContext(WiredContainer container)
          Creates a WiredClientContext for the passed WiredContainer without any particular configuration parameters.
WiredClientContext(WiredContainer container, java.util.Properties props)
          Creates a WiredClientContext for the passed WiredContainer.
 
Method Summary
 java.lang.Object getComponent(java.lang.String globalName)
          Looks up a component by its global symbolic name.
 javax.sql.DataSource getDataSource(java.lang.String globalName)
          Looks up an SQL database refered to by a global symbolic name.
 javax.transaction.UserTransaction getTransaction()
          Provide access to a user transaction
 javax.transaction.TransactionManager getTransactionManager()
          Returns the TransactionManager of the WiredContainer being accessed through this client context.
 int getType()
          Returns the type of context, i.e.
static void setDefaultContainer(WiredContainer newDefault)
          Sets the static variable defaultContainer to the given value
static void setDefaultProperties(java.util.Properties props)
          Sets the default properties to be used for new WiredClientsContexts when no specific properties are passed in the constructor.
 void shutdown()
          Shuts down the WiredContainer associated to this client context in order to release all allocated resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WiredClientContext

public WiredClientContext(WiredContainer container,
                          java.util.Properties props)
Creates a WiredClientContext for the passed WiredContainer. This constructor allows to use multiple containers in a single application which is seldom necessary. Therefore you should usually use the default constructor instead.

Parameters:
props - Configuration parameters, currently only used for optional specification of the caller name.

WiredClientContext

public WiredClientContext(WiredContainer container)
Creates a WiredClientContext for the passed WiredContainer without any particular configuration parameters.


WiredClientContext

public WiredClientContext(java.util.Properties props)
                   throws InitException
Creates a WiredClientContext for the default WiredContainer. If this is the first WiredClientContext created in the application, the call will implicitly create and configure a default container.

Parameters:
props - Configuration parameters, currently only used for optional specification of the caller name. If this parameter is null, the default properties are used instead.
Throws:
InitException - if the initialization of the default container failed.

WiredClientContext

public WiredClientContext()
                   throws InitException
Like function above with null properties

Throws:
InitException
Method Detail

getType

public int getType()
Returns the type of context, i.e. ContextI.Type.WIRED

Specified by:
getType in interface ContextI

getComponent

public java.lang.Object getComponent(java.lang.String globalName)
                              throws ConstructionException,
                                     ReferenceException
Looks up a component by its global symbolic name.

Specified by:
getComponent in interface ContextI
Parameters:
globalName - The global name of the component to look up
Returns:
A proxy object, implementing the component's interface. The return value must be casted to the required type.
Throws:
ConstructionException - if the container failed to provide the required component
ReferenceException - if the provided symbolic name cannot be resolved.

getTransaction

public javax.transaction.UserTransaction getTransaction()
                                                 throws javax.transaction.SystemException
Description copied from interface: ContextI
Provide access to a user transaction

Specified by:
getTransaction in interface ContextI
Throws:
javax.transaction.SystemException

getDataSource

public javax.sql.DataSource getDataSource(java.lang.String globalName)
                                   throws ConstructionException,
                                          ReferenceException
Looks up an SQL database refered to by a global symbolic name.

Specified by:
getDataSource in interface ContextI
Parameters:
globalName - The global name of the SQL source to look up
Returns:
A proxy object, providing access to the database.
Throws:
ConstructionException - if the container failed to provide the required SQL database
ReferenceException - if the provided symbolic name cannot be resolved.

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Returns the TransactionManager of the WiredContainer being accessed through this client context. The TransactionManager may e.g. be required to integrate sophistiacted persistence managers with the WiredContainer.


shutdown

public void shutdown()
Shuts down the WiredContainer associated to this client context in order to release all allocated resources. This function should only be called if the client context is no longer used. A servlet engine e.g. can use this function to close CUBA's connection pools on application shutdown.


setDefaultContainer

public static void setDefaultContainer(WiredContainer newDefault)
Sets the static variable defaultContainer to the given value

Parameters:
newDefault - The new Default WiredContainer-Object

setDefaultProperties

public static void setDefaultProperties(java.util.Properties props)
Sets the default properties to be used for new WiredClientsContexts when no specific properties are passed in the constructor.