Tuscany Core

org.apache.tuscany.core.context.impl
Class AbstractCompositeContext

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.context.impl.AbstractCompositeContext
All Implemented Interfaces:
ContextFactoryBuilder, WireBuilder, AutowireContext, CompositeContext, ConfigurationContext, Context, EventPublisher, Lifecycle, ScopeAwareContext
Direct Known Subclasses:
CompositeContextImpl, SystemCompositeContextImpl

public abstract class AbstractCompositeContext
extends AbstractContext
implements AutowireContext, ScopeAwareContext, ConfigurationContext

The base implementation of a composite context

Version:
$Rev: 406160 $ $Date: 2006-05-13 19:05:09 -0400 (Sat, 13 May 2006) $

Nested Class Summary
protected static class AbstractCompositeContext.NameToScope
           
 
Field Summary
protected  org.apache.tuscany.model.assembly.AssemblyContext assemblyContext
           
protected  ConfigurationContext configurationContext
           
protected  java.util.Map<java.lang.String,ContextFactory<Context>> configurations
           
static int DEFAULT_WAIT
           
protected  EventContext eventContext
           
protected  java.util.Map<org.apache.tuscany.model.assembly.Scope,ScopeContext> immutableScopeContexts
           
protected  boolean initialized
           
protected  java.util.concurrent.CountDownLatch initializeLatch
           
protected  java.lang.Object lock
           
protected  org.apache.tuscany.model.assembly.Module module
           
protected  CompositeContext parentContext
           
protected  java.util.Map<org.apache.tuscany.model.assembly.Scope,ScopeContext> scopeContexts
           
protected  java.util.Map<java.lang.String,ScopeContext> scopeIndex
           
protected  ScopeStrategy scopeStrategy
           
 
Fields inherited from class org.apache.tuscany.core.context.impl.AbstractLifecycle
lifecycleState, name
 
Fields inherited from interface org.apache.tuscany.core.context.Lifecycle
CONFIG_ERROR, ERROR, INITIALIZED, INITIALIZING, RUNNING, STARTED, STOPPED, STOPPING, UNINITIALIZED
 
Fields inherited from interface org.apache.tuscany.core.context.Lifecycle
CONFIG_ERROR, ERROR, INITIALIZED, INITIALIZING, RUNNING, STARTED, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
AbstractCompositeContext()
           
AbstractCompositeContext(java.lang.String name, CompositeContext parent, ScopeStrategy strategy, EventContext ctx, ConfigurationContext configCtx)
           
 
Method Summary
 void build(org.apache.tuscany.model.assembly.AssemblyObject model)
          Creates or updates a context factory based on configuration contained in the given model object.
protected  void buildTarget(ContextFactory<?> target)
          Signals to target side of reference configurations to initialize
protected  void checkInit()
          Blocks until the module context has been initialized
 void completeTargetChain(TargetWireFactory targetFactory, java.lang.Class targetType, ScopeContext targetScopeContext)
          Finishes processing the target side wire chain.
 void connect(SourceWireFactory sourceFactory, TargetWireFactory targetFactory, java.lang.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 eventType, java.lang.Object message)
           
 org.apache.tuscany.model.assembly.Composite getComposite()
          Returns the composite managed by this composite context
 Context getContext(java.lang.String componentName)
          Returns the child context associated with a given name
 java.lang.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
 java.util.Map<org.apache.tuscany.model.assembly.Scope,ScopeContext> getScopeContexts()
          Returns an immutable collection of scopes keyed by type for the composite context
 java.lang.String getURI()
           
protected  void initializeScopes()
           
protected  void initializeWireFactories()
           
 void publish(Event event)
           
protected  void registerAutowireExternal(java.lang.Class<?> interfaze, java.lang.String name, ScopeContext scopeContext)
           
protected  void registerAutowireInternal(java.lang.Class<?> interfaze, java.lang.String name, ScopeContext scopeContext)
           
protected  void registerConfiguration(ContextFactory<Context> factory)
           
 void registerModelObject(org.apache.tuscany.model.assembly.Extensible model)
          Adds a runtime artifact represented by the model object to the composite context by merging it with existing artifacts.
 void registerModelObjects(java.util.List<? extends org.apache.tuscany.model.assembly.Extensible> models)
          Adds runtime artifacts represented by the set of model objects to the composite context by merging them with existing artifacts.
 void removeContext(java.lang.String name)
           
<T> T
resolveExternalInstance(java.lang.Class<T> instanceInterface)
          Invoked by a parent context to return an autowire target in a child.
<T> T
resolveInstance(java.lang.Class<T> instanceInterface)
          Invoked by child contexts to return an an autowire target.
 void setAssemblyContext(org.apache.tuscany.model.assembly.AssemblyContext assemblyContext)
          TODO remove this method
 void setAutowireContext(AutowireContext context)
           
 void setConfigurationContext(ConfigurationContext context)
           
 void setEventContext(EventContext eventContext)
           
 void setModule(org.apache.tuscany.model.assembly.Module module)
           
 void setParent(CompositeContext parent)
          Sets the parent context
 void setURI(java.lang.String uri)
           
 void start()
          Starts the Lifecycle.
 void stop()
          Stops the Lifecycle.
protected  void wireSource(ContextFactory<Context> source)
          Iterates through references and delegates to the configuration context to wire them to their targets
 
Methods inherited from class org.apache.tuscany.core.context.impl.AbstractLifecycle
addListener, addListener, getLifecycleState, getListeners, getName, 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, removeListener
 
Methods inherited from interface org.apache.tuscany.core.context.Lifecycle
getLifecycleState, getName, setName
 
Methods inherited from interface org.apache.tuscany.core.context.EventPublisher
addListener, addListener, removeListener
 
Methods inherited from interface org.apache.tuscany.core.context.Lifecycle
getLifecycleState, getName, setName
 

Field Detail

DEFAULT_WAIT

public static final int DEFAULT_WAIT
See Also:
Constant Field Values

assemblyContext

protected org.apache.tuscany.model.assembly.AssemblyContext assemblyContext

parentContext

protected CompositeContext parentContext

configurationContext

protected ConfigurationContext configurationContext

module

protected org.apache.tuscany.model.assembly.Module module

configurations

protected java.util.Map<java.lang.String,ContextFactory<Context>> configurations

scopeStrategy

protected ScopeStrategy scopeStrategy

eventContext

protected EventContext eventContext

scopeContexts

protected java.util.Map<org.apache.tuscany.model.assembly.Scope,ScopeContext> scopeContexts

immutableScopeContexts

protected java.util.Map<org.apache.tuscany.model.assembly.Scope,ScopeContext> immutableScopeContexts

scopeIndex

protected java.util.Map<java.lang.String,ScopeContext> scopeIndex

initializeLatch

protected java.util.concurrent.CountDownLatch initializeLatch

lock

protected final java.lang.Object lock

initialized

protected boolean initialized
Constructor Detail

AbstractCompositeContext

public AbstractCompositeContext()

AbstractCompositeContext

public AbstractCompositeContext(java.lang.String name,
                                CompositeContext parent,
                                ScopeStrategy strategy,
                                EventContext ctx,
                                ConfigurationContext configCtx)
Method Detail

setAssemblyContext

public void setAssemblyContext(org.apache.tuscany.model.assembly.AssemblyContext assemblyContext)
Description copied from interface: CompositeContext
TODO remove this method

Specified by:
setAssemblyContext in interface CompositeContext

getURI

public java.lang.String getURI()
Specified by:
getURI in interface CompositeContext

setURI

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

start

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

Specified by:
start in interface Lifecycle

stop

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

Specified by:
stop in interface Lifecycle

setModule

public void setModule(org.apache.tuscany.model.assembly.Module module)

setEventContext

public void setEventContext(EventContext eventContext)

setConfigurationContext

public void setConfigurationContext(ConfigurationContext context)

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

registerModelObjects

public void registerModelObjects(java.util.List<? extends org.apache.tuscany.model.assembly.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

registerModelObject

public void registerModelObject(org.apache.tuscany.model.assembly.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

registerConfiguration

protected void registerConfiguration(ContextFactory<Context> factory)
                              throws ConfigurationException
Throws:
ConfigurationException

fireEvent

public void fireEvent(int eventType,
                      java.lang.Object message)
               throws EventException
Throws:
EventException

publish

public void publish(Event event)
Specified by:
publish in interface EventPublisher
Overrides:
publish in class AbstractLifecycle

getContext

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

Specified by:
getContext in interface CompositeContext

getInstance

public java.lang.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

getScopeContexts

public java.util.Map<org.apache.tuscany.model.assembly.Scope,ScopeContext> getScopeContexts()
Description copied from interface: ScopeAwareContext
Returns an immutable collection of scopes keyed by type for the composite context

Specified by:
getScopeContexts in interface ScopeAwareContext

checkInit

protected void checkInit()
Blocks until the module context has been initialized


initializeScopes

protected void initializeScopes()

wireSource

protected void wireSource(ContextFactory<Context> source)
Iterates through references and delegates to the configuration context to wire them to their targets


buildTarget

protected void buildTarget(ContextFactory<?> target)
Signals to target side of reference configurations to initialize


initializeWireFactories

protected void initializeWireFactories()
                                throws WireFactoryInitException
Throws:
WireFactoryInitException

getComposite

public org.apache.tuscany.model.assembly.Composite getComposite()
Description copied from interface: CompositeContext
Returns the composite managed by this composite context

Specified by:
getComposite in interface CompositeContext

setAutowireContext

public void setAutowireContext(AutowireContext context)

resolveInstance

public <T> T resolveInstance(java.lang.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(java.lang.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

registerAutowireInternal

protected void registerAutowireInternal(java.lang.Class<?> interfaze,
                                        java.lang.String name,
                                        ScopeContext scopeContext)

registerAutowireExternal

protected void registerAutowireExternal(java.lang.Class<?> interfaze,
                                        java.lang.String name,
                                        ScopeContext scopeContext)

build

public void build(org.apache.tuscany.model.assembly.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,
                    java.lang.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,
                                java.lang.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

removeContext

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

Tuscany Core

-