org.modeshape.graph
Class ExecutionContext

java.lang.Object
  extended by org.modeshape.graph.ExecutionContext
All Implemented Interfaces:
Cloneable, ClassLoaderFactory
Direct Known Subclasses:
DnaExecutionContext, StreamSequencerContext

@Immutable
public class ExecutionContext
extends Object
implements ClassLoaderFactory, Cloneable

An ExecutionContext is a representation of the environment or context in which a component or operation is operating. Some components require this context to be passed into individual methods, allowing the context to vary with each method invocation. Other components require the context to be provided before it's used, and will use that context for all its operations (until it is given a different one).

ExecutionContext instances are immutable, so components may hold onto references to them without concern of those contexts changing. Contexts may be used to create other contexts that vary the environment and/or security context. For example, an ExecutionContext could be used to create another context that references the same namespace registry but which has a different security context.


Field Summary
static ExecutionContext DEFAULT_CONTEXT
           
 
Constructor Summary
  ExecutionContext()
          Create an instance of an execution context that uses the current JAAS calling context , with default implementations for all other components (including default namespaces in the namespace registry.
protected ExecutionContext(ExecutionContext original)
          Create a copy of the supplied execution context.
protected ExecutionContext(ExecutionContext original, SecurityContext securityContext)
          Create a copy of the supplied execution context, but use the supplied AccessControlContext instead.
protected ExecutionContext(SecurityContext securityContext, NamespaceRegistry namespaceRegistry, ValueFactories valueFactories, PropertyFactory propertyFactory, MimeTypeDetector mimeTypeDetector, ClassLoaderFactory classLoaderFactory)
          Create an instance of the execution context by supplying all parameters.
 
Method Summary
 ExecutionContext clone()
          
 ClassLoader getClassLoader(String... classpath)
          Get a class loader for the supplied classpath.
protected  ClassLoaderFactory getClassLoaderFactory()
          Get the class loader factory used by this context.
 String getId()
          Get the unique identifier for this context.
 Logger getLogger(Class<?> clazz)
          Return a logger associated with this context.
 Logger getLogger(String name)
          Return a logger associated with this context.
 MimeTypeDetector getMimeTypeDetector()
          Return an object that can be used to determine the MIME type of some content, such as the content of a file.
 NamespaceRegistry getNamespaceRegistry()
          Get the (mutable) namespace registry for this context.
 PropertyFactory getPropertyFactory()
          Get the factory for creating Property objects.
 SecurityContext getSecurityContext()
          Get the security context for this context.
 ValueFactories getValueFactories()
          Get the factories that should be used to create values for properties.
protected  void initializeDefaultNamespaces(NamespaceRegistry namespaceRegistry)
          Method that initializes the default namespaces for namespace registries.
 String toString()
          
 ExecutionContext with(ClassLoaderFactory classLoaderFactory)
          Create a new execution context that mirrors this context but that uses the supplied class loader factory.
 ExecutionContext with(MimeTypeDetector mimeTypeDetector)
          Create a new execution context that is the same as this context, but which uses the supplied MIME type detector.
 ExecutionContext with(NamespaceRegistry namespaceRegistry)
          Create a new execution context that mirrors this context but that uses the supplied namespace registry.
 ExecutionContext with(SecurityContext securityContext)
          Create an ExecutionContext that is the same as this context, but which uses the supplied security context.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CONTEXT

public static final ExecutionContext DEFAULT_CONTEXT
Constructor Detail

ExecutionContext

public ExecutionContext()
Create an instance of an execution context that uses the current JAAS calling context , with default implementations for all other components (including default namespaces in the namespace registry.


ExecutionContext

protected ExecutionContext(ExecutionContext original)
Create a copy of the supplied execution context.

Parameters:
original - the original
Throws:
IllegalArgumentException - if the original is null

ExecutionContext

protected ExecutionContext(ExecutionContext original,
                           SecurityContext securityContext)
Create a copy of the supplied execution context, but use the supplied AccessControlContext instead.

Parameters:
original - the original
securityContext - the security context
Throws:
IllegalArgumentException - if the original or access control context are is null

ExecutionContext

protected ExecutionContext(SecurityContext securityContext,
                           NamespaceRegistry namespaceRegistry,
                           ValueFactories valueFactories,
                           PropertyFactory propertyFactory,
                           MimeTypeDetector mimeTypeDetector,
                           ClassLoaderFactory classLoaderFactory)
Create an instance of the execution context by supplying all parameters.

Parameters:
securityContext - the security context, or null if there is no associated authenticated user
namespaceRegistry - the namespace registry implementation, or null if a thread-safe version of SimpleNamespaceRegistry instance should be used
valueFactories - the ValueFactories implementation, or null if a StandardValueFactories instance should be used
propertyFactory - the PropertyFactory implementation, or null if a BasicPropertyFactory instance should be used
mimeTypeDetector - the MimeTypeDetector implementation, or null if an ExtensionBasedMimeTypeDetector instance should be used
classLoaderFactory - the ClassLoaderFactory implementation, or null if a StandardClassLoaderFactory instance should be used
Method Detail

getClassLoaderFactory

protected ClassLoaderFactory getClassLoaderFactory()
Get the class loader factory used by this context.

Returns:
the class loader factory implementation; never null

getLogger

public Logger getLogger(Class<?> clazz)
Return a logger associated with this context. This logger records only those activities within the context and provide a way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log via this mechanism should not also obtain a system logger.

Parameters:
clazz - the class that is doing the logging
Returns:
the logger, named after clazz; never null
See Also:
getLogger(String)

getLogger

public Logger getLogger(String name)
Return a logger associated with this context. This logger records only those activities within the context and provide a way to capture the context-specific activities. All log messages are also sent to the system logger, so classes that log via this mechanism should not also obtain a system logger.

Parameters:
name - the name for the logger
Returns:
the logger, named after clazz; never null
See Also:
getLogger(Class)

getMimeTypeDetector

public MimeTypeDetector getMimeTypeDetector()
Return an object that can be used to determine the MIME type of some content, such as the content of a file.

Returns:
the detector; never null

getSecurityContext

public SecurityContext getSecurityContext()
Get the security context for this context.

Returns:
the security context; never null

getNamespaceRegistry

public NamespaceRegistry getNamespaceRegistry()
Get the (mutable) namespace registry for this context.

Returns:
the namespace registry; never null

getPropertyFactory

public final PropertyFactory getPropertyFactory()
Get the factory for creating Property objects.

Returns:
the property factory; never null

getValueFactories

public ValueFactories getValueFactories()
Get the factories that should be used to create values for properties.

Returns:
the property value factory; never null

getClassLoader

public ClassLoader getClassLoader(String... classpath)
Get a class loader for the supplied classpath.

Specified by:
getClassLoader in interface ClassLoaderFactory
Parameters:
classpath - the classpath to use
Returns:
the class loader; may not be null
See Also:
ClassLoaderFactory.getClassLoader(java.lang.String[])

getId

public String getId()
Get the unique identifier for this context.

Returns:
the unique identifier string; never null and never empty

with

public ExecutionContext with(NamespaceRegistry namespaceRegistry)
Create a new execution context that mirrors this context but that uses the supplied namespace registry. The resulting context's value factories and property factory all make use of the new namespace registry.

Parameters:
namespaceRegistry - the new namespace registry implementation, or null if the default implementation should be used
Returns:
the execution context that is identical with this execution context, but which uses the supplied registry; never null

with

public ExecutionContext with(MimeTypeDetector mimeTypeDetector)
Create a new execution context that is the same as this context, but which uses the supplied MIME type detector.

Parameters:
mimeTypeDetector - the new MIME type detector implementation, or null if the default implementation should be used
Returns:
the execution context that is identical with this execution context, but which uses the supplied detector implementation; never null

with

public ExecutionContext with(ClassLoaderFactory classLoaderFactory)
Create a new execution context that mirrors this context but that uses the supplied class loader factory.

Parameters:
classLoaderFactory - the new class loader factory implementation, or null if the default implementation should be used
Returns:
the execution context that is identical with this execution context, but which uses the supplied class loader factory implementation; never null

with

public ExecutionContext with(SecurityContext securityContext)
Create an ExecutionContext that is the same as this context, but which uses the supplied security context.

Parameters:
securityContext - the new security context to use; may be null
Returns:
the execution context that is identical with this execution context, but with a different security context; never null
Throws:
IllegalArgumentException - if the name is null

clone

public ExecutionContext clone()

Overrides:
clone in class Object
See Also:
Object.clone()

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()

initializeDefaultNamespaces

protected void initializeDefaultNamespaces(NamespaceRegistry namespaceRegistry)
Method that initializes the default namespaces for namespace registries.

Parameters:
namespaceRegistry - the namespace registry


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.