net.kalio.empweb.engine
Class TransactionContext

java.lang.Object
  extended by net.kalio.empweb.engine.TransactionContext

public class TransactionContext
extends java.lang.Object

Title: TransactionContext

Description: The transaction context is an object that carries environment and "session" information for a transaction Process. Each Process receives a TransactionContext with information passed by the TransactionEngine and the previous Process'es.

Values are stored similarly to a Map, where a key object is mapped to a value object using the put method. When the value object is a DOM Node, we use Apache's JXPath library to work with JXPathContext objects and register namespaces to aid in traversing the DOM tree.

Values are retrieved through the get(Object key) method, and values within the DOM of a stored Node can be retrieved by using getXPathValue(Object key, String xpath)

There are static variables for the keys of many of the well-known objects in the TransactionContext, including userId, userDb, copyId, recordId, objectDb.

There are convenience methods for working with Object/User DOM's, and others.

Copyright: Copyright (c) 2004, 2005

Company: Kalio

Version:
1.0
Author:
Barzilai Spinak, Sebastian Filippini, Ciro Mondueri

Field Summary
static java.lang.String BUNDLE
           
static java.lang.String COPY_ID
           
static java.lang.String DAYS_SUSPENDED
           
static java.lang.String DEFAULT_LIMITS
           
static java.lang.String FINE_AMOUNT
           
static java.lang.String FINE_ID
           
static java.lang.String GLOBAL_ENV
           
static java.lang.String LOCAL_ENV
           
static java.lang.String OBJECT_CATEGORY
           
static java.lang.String OBJECT_DB
           
static java.lang.String OBJECT_DOM
           
static java.lang.String OBJECT_LOCATION
           
static java.lang.String OBJECT_STATUS
           
static java.lang.String OBJECT_STATUS_LOCK
           
static java.lang.String OBS
           
static java.lang.String OPERATOR_ID
           
static java.lang.String PAID_AMOUNT
           
static java.lang.String PARAMETERS
           
static java.lang.String PROC_NAME
           
static java.lang.String PROFILE
           
static java.lang.String RECORD_ID
           
static java.lang.String RESERVATION_ID
           
static java.lang.String RESERVATION_START_DATE
           
static java.lang.String SUSPENSION_ID
           
static java.lang.String TRANSACTION
           
static java.lang.String TRANSACTION_EXTRAS
           
static java.lang.String TRANSACTION_MODE
           
static java.lang.String USER_CLASS
           
static java.lang.String USER_DB
           
static java.lang.String USER_DOM
           
static java.lang.String USER_ID
           
static java.lang.String USER_STATUS
           
static java.lang.String USER_STATUS_LIST
           
static java.lang.String USER_STATUS_LOCK
           
static java.lang.String VOLUME_ID
           
static java.lang.String WAIT_ID
           
 
Constructor Summary
TransactionContext()
           
TransactionContext(java.util.Map map)
           
 
Method Summary
 java.lang.Object get(java.lang.Object key)
           
 java.lang.String getDefaultLimit(java.lang.String name)
          Returns the value of a given default limit from the Map returned by getDefaultLimits().
 java.lang.String getDefaultLimit(java.lang.String name, java.lang.String defValue)
          Returns the value of parameter name, or defValue if the mapping for name is null o empty.
 java.util.Map getDefaultLimits()
          When a Transaction Pipeline Process calls this method on its TransactionContext, it gets a Map of the default limits and their values that were passed to the Process from the Transaction Pipeline.
 java.lang.String getEnvironmentValue(java.lang.String name)
          Return an environment value.
 java.lang.String getEnvironmentValue(java.lang.String name, java.lang.String defValue)
          Return an environment value, or a given default value.
 org.apache.commons.jxpath.JXPathContext getJXPathContext(java.lang.Object key)
          If the key is associated to a DOM Node object, this method returns the associated JXPathContext that was created by the previous put(Object, org.w3c.dom.Node).
 java.lang.Object[] getKeys()
           
 java.util.Set getKeySet()
           
 org.w3c.dom.Element getObjectDOM()
           
 org.apache.commons.jxpath.JXPathContext getObjectJXPathContext()
           
 java.lang.Object getObjectValue(java.lang.String xpath)
           
 java.lang.String getParameter(java.lang.String name)
          Returns the value of parameter name from the Map returned by getParameters().
 java.lang.String getParameter(java.lang.String name, java.lang.String defValue)
          Returns the value of parameter name, or defValue if the mapping for name is null o empty.
 java.util.Map getParameters()
          Returns the Map of parameters passed to the instance of the Process from the Transaction Pipeline.
 org.w3c.dom.Element getUserDOM()
           
 org.apache.commons.jxpath.JXPathContext getUserJXPathContext()
           
 java.lang.Object getUserValue(java.lang.String xpath)
           
 org.w3c.dom.Node getXPathNode(java.lang.Object key, java.lang.String xpath)
          Similar to getXPathValue() but it returns the Node corresponding to the XPath expression.
 java.lang.Object getXPathValue(java.lang.Object key, java.lang.String xpath)
          Returns the value within a stored DOM object, using an XPath expression.
 org.apache.commons.jxpath.JXPathContext put(java.lang.Object key, org.w3c.dom.Node nvalue)
          Maps a key to a DOM Node object and it stores the pair into the internal Map.
 void put(java.lang.Object key, java.lang.Object value)
          Stores a generic key/value pair into the internal Map.
 org.apache.commons.jxpath.JXPathContext setObjectDOM(org.w3c.dom.Element odom)
          Convenience method.
 org.apache.commons.jxpath.JXPathContext setUserDOM(org.w3c.dom.Element udom)
          Convenience method.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TRANSACTION

public static final java.lang.String TRANSACTION
See Also:
Constant Field Values

TRANSACTION_MODE

public static final java.lang.String TRANSACTION_MODE
See Also:
Constant Field Values

TRANSACTION_EXTRAS

public static final java.lang.String TRANSACTION_EXTRAS
See Also:
Constant Field Values

PROC_NAME

public static final java.lang.String PROC_NAME
See Also:
Constant Field Values

BUNDLE

public static final java.lang.String BUNDLE
See Also:
Constant Field Values

LOCAL_ENV

public static final java.lang.String LOCAL_ENV
See Also:
Constant Field Values

GLOBAL_ENV

public static final java.lang.String GLOBAL_ENV
See Also:
Constant Field Values

PARAMETERS

public static final java.lang.String PARAMETERS
See Also:
Constant Field Values

DEFAULT_LIMITS

public static final java.lang.String DEFAULT_LIMITS
See Also:
Constant Field Values

USER_DOM

public static final java.lang.String USER_DOM
See Also:
Constant Field Values

OBJECT_DOM

public static final java.lang.String OBJECT_DOM
See Also:
Constant Field Values

USER_ID

public static final java.lang.String USER_ID
See Also:
Constant Field Values

USER_DB

public static final java.lang.String USER_DB
See Also:
Constant Field Values

COPY_ID

public static final java.lang.String COPY_ID
See Also:
Constant Field Values

VOLUME_ID

public static final java.lang.String VOLUME_ID
See Also:
Constant Field Values

RECORD_ID

public static final java.lang.String RECORD_ID
See Also:
Constant Field Values

OBJECT_DB

public static final java.lang.String OBJECT_DB
See Also:
Constant Field Values

RESERVATION_ID

public static final java.lang.String RESERVATION_ID
See Also:
Constant Field Values

WAIT_ID

public static final java.lang.String WAIT_ID
See Also:
Constant Field Values

SUSPENSION_ID

public static final java.lang.String SUSPENSION_ID
See Also:
Constant Field Values

FINE_ID

public static final java.lang.String FINE_ID
See Also:
Constant Field Values

OPERATOR_ID

public static final java.lang.String OPERATOR_ID
See Also:
Constant Field Values

FINE_AMOUNT

public static final java.lang.String FINE_AMOUNT
See Also:
Constant Field Values

PAID_AMOUNT

public static final java.lang.String PAID_AMOUNT
See Also:
Constant Field Values

OBS

public static final java.lang.String OBS
See Also:
Constant Field Values

OBJECT_LOCATION

public static final java.lang.String OBJECT_LOCATION
See Also:
Constant Field Values

DAYS_SUSPENDED

public static final java.lang.String DAYS_SUSPENDED
See Also:
Constant Field Values

USER_CLASS

public static final java.lang.String USER_CLASS
See Also:
Constant Field Values

OBJECT_CATEGORY

public static final java.lang.String OBJECT_CATEGORY
See Also:
Constant Field Values

RESERVATION_START_DATE

public static final java.lang.String RESERVATION_START_DATE
See Also:
Constant Field Values

USER_STATUS

public static final java.lang.String USER_STATUS
See Also:
Constant Field Values

OBJECT_STATUS

public static final java.lang.String OBJECT_STATUS
See Also:
Constant Field Values

USER_STATUS_LOCK

public static final java.lang.String USER_STATUS_LOCK
See Also:
Constant Field Values

OBJECT_STATUS_LOCK

public static final java.lang.String OBJECT_STATUS_LOCK
See Also:
Constant Field Values

PROFILE

public static final java.lang.String PROFILE
See Also:
Constant Field Values

USER_STATUS_LIST

public static final java.lang.String USER_STATUS_LIST
See Also:
Constant Field Values
Constructor Detail

TransactionContext

public TransactionContext()

TransactionContext

public TransactionContext(java.util.Map map)
Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object value)
Stores a generic key/value pair into the internal Map. If the value is a DOM Node, it's better to use the overloaded version of the method. The keys are usually well-known String's that other processes down the pipeline will use to retrieve the value.


get

public java.lang.Object get(java.lang.Object key)

getKeySet

public java.util.Set getKeySet()

getKeys

public java.lang.Object[] getKeys()

put

public org.apache.commons.jxpath.JXPathContext put(java.lang.Object key,
                                                   org.w3c.dom.Node nvalue)
Maps a key to a DOM Node object and it stores the pair into the internal Map. The keys are usually well-known String's that other processes down the pipeline will use to retrieve the value. For convenience, it also creates an Apache JXPathContext for the Node, which can be used with the getXPathValue() method.

Returns:
The JXPathContext for the Node

getJXPathContext

public org.apache.commons.jxpath.JXPathContext getJXPathContext(java.lang.Object key)
If the key is associated to a DOM Node object, this method returns the associated JXPathContext that was created by the previous put(Object, org.w3c.dom.Node). If there's no mapping for the key, it returns null. If there's a mapping but it doesn't correspond to an org.w3c.dom.Node then q JXPathContext was not created and a ClassCastException will be thrown.


getXPathValue

public java.lang.Object getXPathValue(java.lang.Object key,
                                      java.lang.String xpath)
Returns the value within a stored DOM object, using an XPath expression. A null may be returned or a ClassCastException may be thrown, according to the explanation in the getJXPathContext method.


getXPathNode

public org.w3c.dom.Node getXPathNode(java.lang.Object key,
                                     java.lang.String xpath)
Similar to getXPathValue() but it returns the Node corresponding to the XPath expression.


setUserDOM

public org.apache.commons.jxpath.JXPathContext setUserDOM(org.w3c.dom.Element udom)

Convenience method. It stores a mapping under the well-known key "userDOM". The udom parameter must be a DOM Element representing a userCollection XML as per the "http://kalio.net/empweb/schema/users/v1" namespace. This userCollection SHOULD normally have just one user element.

It also creates and returns a JXPathContext for udom and it automatically registers the prefix "u" as the namespace "http://kalio.net/empweb/schema/users/v1"


getUserDOM

public org.w3c.dom.Element getUserDOM()

getUserJXPathContext

public org.apache.commons.jxpath.JXPathContext getUserJXPathContext()

getUserValue

public java.lang.Object getUserValue(java.lang.String xpath)

setObjectDOM

public org.apache.commons.jxpath.JXPathContext setObjectDOM(org.w3c.dom.Element odom)

Convenience method. It stores a mapping under the well-known key "objectDOM". The odom parameter must be a DOM Element representing a modsCollection according to the Library of Congress MODS schema. This modsCollection MAY contain more than one mods element, but usually just the first one will be needed/used by transactions such as "loan".

It also creates and returns a JXPathContext for odom and it automatically registers the prefix "mods" as the namespace "http://www.loc.gov/mods/v3", and the prefix "hold" as the Empweb holdings info extension to MODS "http://kalio.net/empweb/schema/holdingsinfo/v1"


getObjectDOM

public org.w3c.dom.Element getObjectDOM()

getObjectJXPathContext

public org.apache.commons.jxpath.JXPathContext getObjectJXPathContext()

getObjectValue

public java.lang.Object getObjectValue(java.lang.String xpath)

getParameters

public java.util.Map getParameters()
Returns the Map of parameters passed to the instance of the Process from the Transaction Pipeline.


getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of parameter name from the Map returned by getParameters(). If the value exists, it will be trimmed (String.trim()); if it doesn't exist, null will be returned. If the raw, untrimmed value is wanted, use getParameters() and retrieve the raw value from the Map.


getParameter

public java.lang.String getParameter(java.lang.String name,
                                     java.lang.String defValue)
Returns the value of parameter name, or defValue if the mapping for name is null o empty.

This method calls getParameter(String), so the returned String value will be already trimmed. However, if the return value from getParameter(String) is null or the empty String, this method returns the String given by defValue.


getDefaultLimits

public java.util.Map getDefaultLimits()
When a Transaction Pipeline Process calls this method on its TransactionContext, it gets a Map of the default limits and their values that were passed to the Process from the Transaction Pipeline.


getDefaultLimit

public java.lang.String getDefaultLimit(java.lang.String name)
Returns the value of a given default limit from the Map returned by getDefaultLimits(). If the value exists, it will be trimmed (String.trim()); if it doesn't exist, null will be returned. If the raw, untrimmed value is wanted, use getDefaultLimits() and retrieve the raw value from the Map.


getDefaultLimit

public java.lang.String getDefaultLimit(java.lang.String name,
                                        java.lang.String defValue)
Returns the value of parameter name, or defValue if the mapping for name is null o empty.

This method calls getDefaultLimit(String), so the returned String value will be already trimmed. However, if the return value from getDefaultLimit(String) is null or the empty String, this method returns the String given by defValue.


getEnvironmentValue

public java.lang.String getEnvironmentValue(java.lang.String name)
Return an environment value.
It first looks in this pipeline's local environment, then in the "globalenvironment" pipeline's environment. This method returns trimmed Strings.


getEnvironmentValue

public java.lang.String getEnvironmentValue(java.lang.String name,
                                            java.lang.String defValue)
Return an environment value, or a given default value.
It calls getEnvironmentValue(String), and if the returned value is null or empty this method returns defValue.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object