|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ow2.bonita.pvm.env.Environment
public abstract class Environment
maintains contextual information for a thread in a set of Context
s.
Objects have different lifecycles and different context's (aka scopes). An environment provides the structure to easily manage objects with different contexts.
Examples of contexts are:
EnvironmentFactory
. So if the
EnvironmentFactory
is maintained in a static member field, the
environment-factory context lives for the duration of the application. The
same environment-factory context is shared for all the Environments produced
by one EnvironmentFactory.An environment is typically installed like this
static EnvironmentFactory environmentFactory = new DefaultEnvironmentFactory(); ... Environment environment = environmentFactory.openEnvironment(); try { ... everything available in this block ... } finally { environment.close(); }
The first purpose of the environment is to separate the application from the environment. Standard Java and Enterprise Java are quite different and an environment abstraction like this allows for the development of applications that can run in both Standard and Enterprise environments. Also test environments are easier to tweak this way.
A second purpose of the environment is to enable specific to global searching of resources. E.g. you could search for an 'adminEmailAddress' in the contexts 'processDefinition-execution', 'processDefinition-definition' and 'environment-factory' in the given order. That way, a global adminEmailAddress can be specified in the environment-factory context and it can be refined in more specific contexts processDefinition-definition or processDefinition-execution.
To find an object in the environment, a searchOrder can be specified. A search order is an sequence that specifies the order in which the contexts should be searched.
The default search order is the inverse sequence of how the contexts are added to the environment. This is because in general, we can assume that the more recent a context was added, the more specific it is.
Three objects are used so frequently in an environment that they get special treatment:
For these special properties, setters are also available. That is to support programmatic injection into the environment. Alternatively, they can be configured in one of the contexts.
EnvironmentFactory
,
Serialized FormConstructor Summary | |
---|---|
Environment()
|
Method Summary | ||
---|---|---|
abstract void |
addContext(Context context)
|
|
abstract void |
close()
closes the Environment by removing all its contexts. |
|
abstract
|
get(java.lang.Class<T> type)
searches an object based on type. |
|
abstract
|
get(java.lang.Class<T> type,
java.lang.String[] searchOrder)
searches an object based on type. |
|
abstract java.lang.Object |
get(java.lang.String name)
searches a named object in all the contexts in the default search order. |
|
abstract java.lang.Object |
get(java.lang.String name,
java.lang.String[] searchOrder)
searches a named object in all the contexts in the given search order. |
|
abstract java.lang.ClassLoader |
getClassLoader()
|
|
abstract Context |
getContext(java.lang.String contextName)
|
|
static Environment |
getCurrent()
gets the most inner open environment. |
|
static
|
getFromCurrent(java.lang.Class<T> type)
|
|
static
|
getFromCurrent(java.lang.Class<T> type,
boolean required)
|
|
static java.lang.Object |
getFromCurrent(java.lang.String name)
|
|
static java.lang.Object |
getFromCurrent(java.lang.String name,
boolean required)
|
|
abstract java.lang.String |
getUserId()
get the authenticated user id |
|
protected static Environment |
popEnvironment()
pops the closing context from the stack of current contexts. |
|
protected static void |
pushEnvironment(Environment environment)
after opening of a new environment succeeded, the environment must be pushed in the stack of current environments. |
|
abstract void |
removeContext(Context context)
|
|
abstract void |
setClassLoader(java.lang.ClassLoader classLoader)
|
|
abstract void |
setUserId(java.lang.String userId)
set the authenticated user id |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Environment()
Method Detail |
---|
public abstract java.lang.Object get(java.lang.String name)
null
if
there is no object with the given name in the environment.public abstract java.lang.Object get(java.lang.String name, java.lang.String[] searchOrder)
searchOrder
- list of contexts names. The object will be searched in these
contexts, in the given order.
null
if
there is no object with the given name in the specified searchOrder
contexts.public abstract <T> T get(java.lang.Class<T> type)
public abstract <T> T get(java.lang.Class<T> type, java.lang.String[] searchOrder)
public abstract java.lang.String getUserId()
public abstract void setUserId(java.lang.String userId)
public abstract void close()
public abstract Context getContext(java.lang.String contextName)
public abstract void addContext(Context context)
public abstract void removeContext(Context context)
public abstract java.lang.ClassLoader getClassLoader()
public abstract void setClassLoader(java.lang.ClassLoader classLoader)
public static Environment getCurrent()
public static <T> T getFromCurrent(java.lang.Class<T> type)
public static <T> T getFromCurrent(java.lang.Class<T> type, boolean required)
public static java.lang.Object getFromCurrent(java.lang.String name)
public static java.lang.Object getFromCurrent(java.lang.String name, boolean required)
protected static Environment popEnvironment()
EnvironmentFactory#push(Environment)
protected static void pushEnvironment(Environment environment)
Environment#pop()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |