org.apache.tuscany.sca.core.context
Class ComponentContextImpl

java.lang.Object
  extended by org.apache.tuscany.sca.core.context.ComponentContextImpl
All Implemented Interfaces:
ComponentContextExtension, RuntimeComponentContext, org.osoa.sca.ComponentContext

public class ComponentContextImpl
extends java.lang.Object
implements RuntimeComponentContext

Implementation of ComponentContext that delegates to a ComponentContextProvider.


Constructor Summary
ComponentContextImpl(CompositeActivator compositeActivator, AssemblyFactory assemblyFactory, ProxyFactory proxyFactory, InterfaceContractMapper interfaceContractMapper, RequestContextFactory requestContextFactory, JavaInterfaceFactory javaInterfaceFactory, RuntimeComponent component)
           
 
Method Summary
<B,R extends org.osoa.sca.CallableReference<B>>
R
cast(B target)
          Cast a type-safe reference to a CallableReference.
<B> org.osoa.sca.ServiceReference<B>
createSelfReference(java.lang.Class<B> businessInterface)
          Returns a ServiceReference that can be used to invoke this component over the default service.
<B> org.osoa.sca.ServiceReference<B>
createSelfReference(java.lang.Class<B> businessInterface, ComponentService service)
           
<B> org.osoa.sca.ServiceReference<B>
createSelfReference(java.lang.Class<B> businessInterface, java.lang.String serviceName)
          Returns a ServiceReference that can be used to invoke this component over the designated service.
<B> org.osoa.sca.CallableReference<B>
getCallableReference(java.lang.Class<B> businessInterface, RuntimeComponent component, RuntimeComponentService service)
          Create a CallableReference for the given component service
 CompositeActivator getCompositeActivator()
           
<B> B
getProperty(java.lang.Class<B> type, java.lang.String propertyName)
          Gets the value for the specified property with the specified type.
 org.osoa.sca.RequestContext getRequestContext()
          Returns the context for the current SCA service request, or null if there is no current request or if the context is unavailable.
<B> B
getService(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a proxy for a reference defined by this component.
<B> org.osoa.sca.ServiceReference<B>
getServiceReference(java.lang.Class<B> businessInterface, RuntimeComponentReference reference, Binding binding)
          Get the CallableReference for a given component reference
<B> org.osoa.sca.ServiceReference<B>
getServiceReference(java.lang.Class<B> businessInterface, RuntimeComponentReference reference, RuntimeComponent component, RuntimeComponentService service)
          Bind a component reference to a component service
<B> org.osoa.sca.ServiceReference<B>
getServiceReference(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a ServiceReference for a reference defined by this component.
<B> java.util.Collection<org.osoa.sca.ServiceReference<B>>
getServiceReferences(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a Collection of typed service reference for a business interface type and a reference name.
<B> java.util.Collection<B>
getServices(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a Collection of typed service proxies for a business interface type and a reference name.
 java.lang.String getURI()
          Returns the absolute URI of the component within the SCA Domain.
 RuntimeComponent read(java.io.Reader reader)
          Deserialize the component reference
 void setPropertyValueFactory(PropertyValueFactory factory)
          The Implementation is responsible for calling this method to set the PropertyValueFactory that is used to get the Property Value from a Tuscany Property object.
 void start(RuntimeComponentReference reference)
          Activate the reference (creating runtime wires)
 void write(RuntimeComponentReference reference, java.io.Writer writer)
          Serialize the component reference
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComponentContextImpl

public ComponentContextImpl(CompositeActivator compositeActivator,
                            AssemblyFactory assemblyFactory,
                            ProxyFactory proxyFactory,
                            InterfaceContractMapper interfaceContractMapper,
                            RequestContextFactory requestContextFactory,
                            JavaInterfaceFactory javaInterfaceFactory,
                            RuntimeComponent component)
Method Detail

getURI

public java.lang.String getURI()
Description copied from interface: org.osoa.sca.ComponentContext
Returns the absolute URI of the component within the SCA Domain.

Specified by:
getURI in interface org.osoa.sca.ComponentContext
Returns:
the absolute URI of the component

cast

public <B,R extends org.osoa.sca.CallableReference<B>> R cast(B target)
                                                 throws java.lang.IllegalArgumentException
Description copied from interface: org.osoa.sca.ComponentContext
Cast a type-safe reference to a CallableReference. Converts a type-safe reference to an equivalent CallableReference; if the target refers to a service then a ServiceReference will be returned, if the target refers to a callback then a CallableReference will be returned.

Specified by:
cast in interface org.osoa.sca.ComponentContext
Type Parameters:
B - the Java type of the business interface for the reference
R - the type of reference to be returned
Parameters:
target - a reference proxy provided by the SCA runtime
Returns:
a CallableReference equivalent for the proxy
Throws:
java.lang.IllegalArgumentException - if the supplied instance is not a reference supplied by the SCA runtime

getService

public <B> B getService(java.lang.Class<B> businessInterface,
                        java.lang.String referenceName)
Description copied from interface: org.osoa.sca.ComponentContext
Returns a proxy for a reference defined by this component.

Specified by:
getService in interface org.osoa.sca.ComponentContext
Type Parameters:
B - the Java type of the business interface for the reference
Parameters:
businessInterface - the interface that will be used to invoke the service
referenceName - the name of the reference
Returns:
an object that implements the business interface

getServiceReference

public <B> org.osoa.sca.ServiceReference<B> getServiceReference(java.lang.Class<B> businessInterface,
                                                                java.lang.String referenceName)
Description copied from interface: org.osoa.sca.ComponentContext
Returns a ServiceReference for a reference defined by this component.

Specified by:
getServiceReference in interface org.osoa.sca.ComponentContext
Type Parameters:
B - the Java type of the business interface for the reference
Parameters:
businessInterface - the interface that will be used to invoke the service
referenceName - the name of the reference
Returns:
a ServiceReference for the designated reference

setPropertyValueFactory

public void setPropertyValueFactory(PropertyValueFactory factory)
The Implementation is responsible for calling this method to set the PropertyValueFactory that is used to get the Property Value from a Tuscany Property object.

Parameters:
factory - The PropertyValueFactory to use
See Also:
getProperty(Class, String)

getProperty

public <B> B getProperty(java.lang.Class<B> type,
                         java.lang.String propertyName)
Gets the value for the specified property with the specified type.

Specified by:
getProperty in interface org.osoa.sca.ComponentContext
Type Parameters:
B - the Java type of the property
Parameters:
type - The type of the property value we are getting
propertyName - The name of the property we are getting
B - The class of the property value we are getting
Returns:
the property value
Throws:
org.osoa.sca.ServiceRuntimeException - If a Property for the specified propertyName is not found
See Also:
setPropertyValueFactory(PropertyValueFactory)

createSelfReference

public <B> org.osoa.sca.ServiceReference<B> createSelfReference(java.lang.Class<B> businessInterface)
Description copied from interface: org.osoa.sca.ComponentContext
Returns a ServiceReference that can be used to invoke this component over the default service.

Specified by:
createSelfReference in interface org.osoa.sca.ComponentContext
Type Parameters:
B - the Java type of the business interface for the reference
Parameters:
businessInterface - the interface that will be used to invoke the service
Returns:
a ServiceReference that will invoke this component

createSelfReference

public <B> org.osoa.sca.ServiceReference<B> createSelfReference(java.lang.Class<B> businessInterface,
                                                                java.lang.String serviceName)
Description copied from interface: org.osoa.sca.ComponentContext
Returns a ServiceReference that can be used to invoke this component over the designated service.

Specified by:
createSelfReference in interface org.osoa.sca.ComponentContext
Type Parameters:
B - the Java type of the business interface for the reference
Parameters:
businessInterface - the interface that will be used to invoke the service
serviceName - the name of the service to invoke
Returns:
a ServiceReference that will invoke this component

createSelfReference

public <B> org.osoa.sca.ServiceReference<B> createSelfReference(java.lang.Class<B> businessInterface,
                                                                ComponentService service)
Specified by:
createSelfReference in interface RuntimeComponentContext
Type Parameters:
B -
Parameters:
businessInterface -
service -
Returns:

getRequestContext

public org.osoa.sca.RequestContext getRequestContext()
Description copied from interface: org.osoa.sca.ComponentContext
Returns the context for the current SCA service request, or null if there is no current request or if the context is unavailable.

Specified by:
getRequestContext in interface org.osoa.sca.ComponentContext
Returns:
the SCA request context; may be null

getServiceReference

public <B> org.osoa.sca.ServiceReference<B> getServiceReference(java.lang.Class<B> businessInterface,
                                                                RuntimeComponentReference reference,
                                                                Binding binding)
Description copied from interface: RuntimeComponentContext
Get the CallableReference for a given component reference

Specified by:
getServiceReference in interface RuntimeComponentContext
Parameters:
businessInterface -
reference -
binding - The binding to be used, if it's null, either binding.sca or the 1st binding will be selected
Returns:
Throws:
java.lang.CloneNotSupportedException
InvalidInterfaceException

getServiceReference

public <B> org.osoa.sca.ServiceReference<B> getServiceReference(java.lang.Class<B> businessInterface,
                                                                RuntimeComponentReference reference,
                                                                RuntimeComponent component,
                                                                RuntimeComponentService service)
Bind a component reference to a component service

Specified by:
getServiceReference in interface RuntimeComponentContext
Type Parameters:
B -
Parameters:
businessInterface -
reference -
service -
component - The target component
Returns:
Throws:
java.lang.CloneNotSupportedException
InvalidInterfaceException

getCallableReference

public <B> org.osoa.sca.CallableReference<B> getCallableReference(java.lang.Class<B> businessInterface,
                                                                  RuntimeComponent component,
                                                                  RuntimeComponentService service)
Description copied from interface: RuntimeComponentContext
Create a CallableReference for the given component service

Specified by:
getCallableReference in interface RuntimeComponentContext
Returns:

getCompositeActivator

public CompositeActivator getCompositeActivator()
Returns:
the compositeActivator

start

public void start(RuntimeComponentReference reference)
Description copied from interface: RuntimeComponentContext
Activate the reference (creating runtime wires)

Specified by:
start in interface RuntimeComponentContext
See Also:
RuntimeComponentContext.start(org.apache.tuscany.sca.runtime.RuntimeComponentReference)

read

public RuntimeComponent read(java.io.Reader reader)
                      throws java.io.IOException
Description copied from interface: RuntimeComponentContext
Deserialize the component reference

Specified by:
read in interface RuntimeComponentContext
Returns:
A component that contains the reference
Throws:
java.io.IOException
See Also:
RuntimeComponentContext.read(java.io.Reader)

write

public void write(RuntimeComponentReference reference,
                  java.io.Writer writer)
           throws java.io.IOException
Description copied from interface: RuntimeComponentContext
Serialize the component reference

Specified by:
write in interface RuntimeComponentContext
Throws:
java.io.IOException
See Also:
RuntimeComponentContext.write(org.apache.tuscany.sca.runtime.RuntimeComponentReference, java.io.Writer)

getServices

public <B> java.util.Collection<B> getServices(java.lang.Class<B> businessInterface,
                                               java.lang.String referenceName)
Description copied from interface: ComponentContextExtension
Returns a Collection of typed service proxies for a business interface type and a reference name.

Specified by:
getServices in interface ComponentContextExtension
Type Parameters:
B - the Java type of the business interface for the reference
Parameters:
businessInterface - the interface that will be used to invoke the service
referenceName - the name of the reference
Returns:
a Collection of objects that implements the business interface
See Also:
ComponentContext#getServices(Class, String)

getServiceReferences

public <B> java.util.Collection<org.osoa.sca.ServiceReference<B>> getServiceReferences(java.lang.Class<B> businessInterface,
                                                                                       java.lang.String referenceName)
Description copied from interface: ComponentContextExtension
Returns a Collection of typed service reference for a business interface type and a reference name.

Specified by:
getServiceReferences in interface ComponentContextExtension
Type Parameters:
B - the Java type of the business interface for the reference
Parameters:
businessInterface - the interface that will be used to invoke the service
referenceName - the name of the reference
Returns:
a Collection of objects that implements the business interface
See Also:
ComponentContext#getServiceReferences(Class, String)