Tuscany Core

org.apache.tuscany.core.runtime
Class RuntimeContextImpl

java.lang.Object
  extended by org.apache.tuscany.core.context.impl.AbstractLifecycle
      extended by org.apache.tuscany.core.context.impl.AbstractContext
          extended by org.apache.tuscany.core.runtime.RuntimeContextImpl
All Implemented Interfaces:
ContextFactoryBuilder, WireBuilder, AutowireContext, CompositeContext, ConfigurationContext, Context, EventPublisher, Lifecycle, RuntimeContext

public class RuntimeContextImpl
extends AbstractContext
implements RuntimeContext

Implementation of a RuntimeContext that forms the foundation for a Tuscany environment.

Version:
$Rev: 408581 $ $Date: 2006-05-21 23:34:24 -0700 (Sun, 21 May 2006) $

Field Summary
 
Fields inherited from class org.apache.tuscany.core.context.impl.AbstractLifecycle
lifecycleState, name
 
Fields inherited from interface org.apache.tuscany.core.runtime.RuntimeContext
ROOT, RUNTIME, SYSTEM
 
Fields inherited from interface org.apache.tuscany.core.context.Lifecycle
CONFIG_ERROR, ERROR, INITIALIZED, INITIALIZING, RUNNING, STARTED, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
RuntimeContextImpl(MonitorFactory monitorFactory, ContextFactoryBuilderRegistry builderRegistry, HierarchicalWireBuilder wireBuilder)
           
 
Method Summary
 void addBuilder(WireBuilder builder)
          Adds a wire builder to the runtime
 void build(AssemblyObject model)
          Creates or updates a context factory based on configuration contained in the given model object.
 void completeTargetChain(TargetWireFactory targetFactory, Class targetType, ScopeContext targetScopeContext)
          Finishes processing the target side wire chain.
 void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, Class targetType, boolean downScope, ScopeContext targetScopeContext)
          Connects wire configurations of the source proxy factory to corresponding ones in the target proxy to factory
 void fireEvent(int pEventType, Object pMessage)
           
 Composite getComposite()
          Returns the composite managed by this composite context
 Context getContext(String ctxName)
          Returns the child context associated with a given name
 Object getInstance(QualifiedName qName)
          Returns the instance associated with the requested name, which may be in a atomic or composite form.
 CompositeContext getParent()
          Returns the parent context, or null if the context does not have one
 CompositeContext getRootContext()
          Returns the context that forms the root of the user component tree.
 SystemCompositeContext getSystemContext()
          Returns the context that forms the root of the system component tree.
 String getURI()
           
 Object locateInstance(QualifiedName serviceName)
           
 Object locateService(QualifiedName serviceName)
           
 void registerModelObject(Extensible model)
          Adds a runtime artifact represented by the model object to the composite context by merging it with existing artifacts.
 void registerModelObjects(List<? extends Extensible> models)
          Adds runtime artifacts represented by the set of model objects to the composite context by merging them with existing artifacts.
 void removeContext(String name)
           
<T> T
resolveExternalInstance(Class<T> instanceInterface)
          Invoked by a parent context to return an autowire target in a child.
<T> T
resolveInstance(Class<T> instanceInterface)
          Invoked by child contexts to return an an autowire target.
 void setAssemblyContext(AssemblyContext context)
          TODO remove this method
 void setParent(CompositeContext parent)
          Sets the parent context
 void setURI(String uri)
           
 void start()
          Starts the Lifecycle.
 void stop()
          Stops the Lifecycle.
 
Methods inherited from class org.apache.tuscany.core.context.impl.AbstractLifecycle
addListener, addListener, getLifecycleState, getListeners, getName, publish, removeListener, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.tuscany.core.context.EventPublisher
addListener, addListener, publish, removeListener
 
Methods inherited from interface org.apache.tuscany.core.context.Lifecycle
getLifecycleState, getName, setName
 

Constructor Detail

RuntimeContextImpl

public RuntimeContextImpl(MonitorFactory monitorFactory,
                          ContextFactoryBuilderRegistry builderRegistry,
                          HierarchicalWireBuilder wireBuilder)
Method Detail

start

public void start()
           throws CoreRuntimeException
Description copied from interface: Lifecycle
Starts the Lifecycle.

Specified by:
start in interface Lifecycle
Throws:
CoreRuntimeException

stop

public void stop()
          throws CoreRuntimeException
Description copied from interface: Lifecycle
Stops the Lifecycle.

Specified by:
stop in interface Lifecycle
Throws:
CoreRuntimeException

addBuilder

public void addBuilder(WireBuilder builder)
Description copied from interface: RuntimeContext
Adds a wire builder to the runtime

Specified by:
addBuilder in interface RuntimeContext

getContext

public Context getContext(String ctxName)
Description copied from interface: CompositeContext
Returns the child context associated with a given name

Specified by:
getContext in interface CompositeContext

getRootContext

public CompositeContext getRootContext()
Description copied from interface: RuntimeContext
Returns the context that forms the root of the user component tree. All user components will managed by contexts that are children of this root.

Specified by:
getRootContext in interface RuntimeContext
Returns:
the root of the user component tree

getSystemContext

public SystemCompositeContext getSystemContext()
Description copied from interface: RuntimeContext
Returns the context that forms the root of the system component tree. All system components, components that provide system services needed by the Tuscany runtime itself, will be managed by contexts that are children of this root.

Specified by:
getSystemContext in interface RuntimeContext
Returns:
the root of the system component tree

registerModelObject

public void registerModelObject(Extensible model)
                         throws ConfigurationException
Description copied from interface: CompositeContext
Adds a runtime artifact represented by the model object to the composite context by merging it with existing artifacts. Implementing classes may support only a subset of Part types.

Specified by:
registerModelObject in interface CompositeContext
Throws:
ConfigurationException
See Also:
Component, ModuleComponent, AtomicComponent, EntryPoint, ExternalService

registerModelObjects

public void registerModelObjects(List<? extends Extensible> models)
                          throws ConfigurationException
Description copied from interface: CompositeContext
Adds runtime artifacts represented by the set of model objects to the composite context by merging them with existing artifacts. Implementing classes may support only a subset of Part types.

Specified by:
registerModelObjects in interface CompositeContext
Throws:
ConfigurationException
See Also:
Component, ModuleComponent, AtomicComponent, EntryPoint, ExternalService

getParent

public CompositeContext getParent()
Description copied from interface: CompositeContext
Returns the parent context, or null if the context does not have one

Specified by:
getParent in interface CompositeContext

setParent

public void setParent(CompositeContext parent)
Description copied from interface: CompositeContext
Sets the parent context

Specified by:
setParent in interface CompositeContext

getURI

public String getURI()
Specified by:
getURI in interface CompositeContext

setURI

public void setURI(String uri)
Specified by:
setURI in interface CompositeContext

setAssemblyContext

public void setAssemblyContext(AssemblyContext context)
Description copied from interface: CompositeContext
TODO remove this method

Specified by:
setAssemblyContext in interface CompositeContext

fireEvent

public void fireEvent(int pEventType,
                      Object pMessage)
               throws EventException
Throws:
EventException

locateService

public Object locateService(QualifiedName serviceName)

locateInstance

public Object locateInstance(QualifiedName serviceName)

getInstance

public Object getInstance(QualifiedName qName)
                   throws TargetException
Description copied from interface: Context
Returns the instance associated with the requested name, which may be in a atomic or composite form. Atomic (i.e. leaf) contexts will return an instance associated with the service name part of the compound name, which may be null.

Composite contexts will return an instance (likely a proxy) of a contained entry point context. In this case, the port name on the qualified name will correspond to the composite context name and the part name will be used to retrieve the contained entry point context. The latter may be null. If the contained context is not an entry point context, an exception will be thrown.

Specified by:
getInstance in interface Context
Parameters:
qName - a qualified name of the requested instance
Returns:
the implementation instance or a proxy to it
Throws:
TargetException - if an error occurs retrieving the instance or the requested component is not an entry point.
See Also:
CompositeContext, EntryPoint

build

public void build(AssemblyObject model)
           throws BuilderConfigException
Description copied from interface: ContextFactoryBuilder
Creates or updates a context factory based on configuration contained in the given model object. The model object is decorated with the factory.

Specified by:
build in interface ContextFactoryBuilder
Parameters:
model - the logical configuration model node
Throws:
BuilderConfigException

connect

public void connect(SourceWireFactory sourceFactory,
                    TargetWireFactory targetFactory,
                    Class targetType,
                    boolean downScope,
                    ScopeContext targetScopeContext)
             throws BuilderConfigException
Description copied from interface: WireBuilder
Connects wire configurations of the source proxy factory to corresponding ones in the target proxy to factory

Specified by:
connect in interface WireBuilder
Parameters:
sourceFactory - the proxy factory used in constructing the source side of the wire chain
targetFactory - the proxy factory used in constructing the target side of the wire chain
targetType - the context type of the target. Used to determine if a paricular wire builder should construct the wire
downScope - true if the component containing the reference (source side) is of a lesser scope than the target service
targetScopeContext - the scope context responsible for managing intance contexts of the target component type
Throws:
BuilderConfigException - if an error occurs during the wire buildSource process

completeTargetChain

public void completeTargetChain(TargetWireFactory targetFactory,
                                Class targetType,
                                ScopeContext targetScopeContext)
                         throws BuilderConfigException
Description copied from interface: WireBuilder
Finishes processing the target side wire chain. For example, a TargetInvoker used by target-side proxies is usually set during this phase.

Specified by:
completeTargetChain in interface WireBuilder
Parameters:
targetFactory - the target-side proxy factory
targetType - the target context type
targetScopeContext - the target scope
Throws:
BuilderConfigException - if an error occurs during the wire buildSource process

resolveInstance

public <T> T resolveInstance(Class<T> instanceInterface)
                  throws AutowireResolutionException
Description copied from interface: AutowireContext
Invoked by child contexts to return an an autowire target. Resolved targets may be entry points or components in the parent or its ancestors, or entry points in a sibling context

Specified by:
resolveInstance in interface AutowireContext
Parameters:
instanceInterface - the type of service being requested
Returns:
a reference to the requested service or null if none can be found
Throws:
AutowireResolutionException - if an error occurs attempting to resolve an autowire

resolveExternalInstance

public <T> T resolveExternalInstance(Class<T> instanceInterface)
                          throws AutowireResolutionException
Description copied from interface: AutowireContext
Invoked by a parent context to return an autowire target in a child. Resolved targets must be entry points. For example, given a parent P and two siblings, A and B, A would request an autowire by invoking #resolveInstance(Class) on P, which in turn could invoke the present method on B in order to resolve a target.

Specified by:
resolveExternalInstance in interface AutowireContext
Parameters:
instanceInterface - the type of service being requested
Returns:
a reference to the requested service or null if none can be found
Throws:
AutowireResolutionException - if an error occurs attempting to resolve an autowire

getComposite

public Composite getComposite()
Description copied from interface: CompositeContext
Returns the composite managed by this composite context

Specified by:
getComposite in interface CompositeContext

removeContext

public void removeContext(String name)
Specified by:
removeContext in interface CompositeContext

Tuscany Core

-