org.oasisopen.sca
Interface ComponentContext


public interface ComponentContext

The ComponentContext interface is used to obtain contextual information about the SCA component which is executing at the time the API is invoked.

Note: An SCA component can obtain a service reference either through injection or programmatically through the ComponentContext API. Using reference injection is the recommended way to access a service, since it results in code with minimal use of middleware APIs. The ComponentContext API is provided for use in cases where reference injection is not possible.


Method Summary
<B> ServiceReference<B>
cast(B target)
          Casts a type-safe reference to a ServiceReference.
<B> ServiceReference<B>
createSelfReference(java.lang.Class<B> businessInterface)
          Returns a ServiceReference that can be used to invoke this component over the designated service.
<B> 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> B
getProperty(java.lang.Class<B> type, java.lang.String propertyName)
          Returns the value of an SCA property defined by this component.
 RequestContext getRequestContext()
          Returns the RequestContext for the current SCA service request.
<B> B
getService(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a typed service proxy object for a reference defined by the current component, where the reference has multiplicity 0..1 or 1..1.
<B> ServiceReference<B>
getServiceReference(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a ServiceReference object for a reference defined by the current component, where the reference has multiplicity 0..1 or 1..1.
<B> java.util.Collection<ServiceReference<B>>
getServiceReferences(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a list of typed ServiceReference objects for a reference defined by the current component, where the reference has multiplicity 0..n or 1..n.
<B> java.util.Collection<B>
getServices(java.lang.Class<B> businessInterface, java.lang.String referenceName)
          Returns a list of typed service proxies for a reference defined by the current component, where the reference has multiplicity 0..n or 1..n.
 java.lang.String getURI()
          Returns the absolute URI of the component within the SCA domain.
 

Method Detail

getURI

java.lang.String getURI()
Returns the absolute URI of the component within the SCA domain.

Returns:
the absolute URI of the component within the SCA domain.

getService

<B> B getService(java.lang.Class<B> businessInterface,
                 java.lang.String referenceName)
             throws java.lang.IllegalArgumentException
Returns a typed service proxy object for a reference defined by the current component, where the reference has multiplicity 0..1 or 1..1.

Type Parameters:
B - the Java type that is implemented by the returned proxy object.
Parameters:
businessInterface - the Class object for the Java type that is implemented by the returned proxy object.
referenceName - the name of the service reference.
Returns:
a proxy for the reference defined by the current component. Returns null if the named reference has no target service configured.
Throws:
java.lang.IllegalArgumentException - if the reference has multiplicity greater than one, or the component does not have the reference named by referenceName, or the interface of the named reference is not compatible with the interface supplied in the businessInterface parameter.

getServiceReference

<B> ServiceReference<B> getServiceReference(java.lang.Class<B> businessInterface,
                                            java.lang.String referenceName)
                                        throws java.lang.IllegalArgumentException
Returns a ServiceReference object for a reference defined by the current component, where the reference has multiplicity 0..1 or 1..1.

Type Parameters:
B - the Java type of the reference that is associated with the returned object.
Parameters:
businessInterface - the Class object for the Java type that is associated with the returned object.
referenceName - the name of the service reference.
Returns:
a ServiceReference object for a reference defined by the current component, where the reference has multiplicity 0..1 or 1..1. Returns null if the named reference has no target service configured.
Throws:
java.lang.IllegalArgumentException - if the reference has multiplicity greater than one, or the component does not have the reference named by referenceName, or the interface of the named reference is not compatible with the interface supplied in the businessInterface parameter.

getServices

<B> java.util.Collection<B> getServices(java.lang.Class<B> businessInterface,
                                        java.lang.String referenceName)
                                    throws java.lang.IllegalArgumentException
Returns a list of typed service proxies for a reference defined by the current component, where the reference has multiplicity 0..n or 1..n.

Type Parameters:
B - the Java type that is implemented by the returned proxy objects.
Parameters:
businessInterface - the Class object for the Java type that is implemented by the returned proxy objects.
referenceName - the name of the service reference.
Returns:
a collection of proxy objects for the reference, one for each target service to which the reference is wired, where each proxy object implements the interface B contained in the businessInterface parameter. The collection is empty if the reference is not wired to any target services.
Throws:
java.lang.IllegalArgumentException - if the reference has multiplicity greater other than 0..1 or 1..1, or the component does not have the reference named by referenceName, or the interface of the named reference is not compatible with the interface supplied in the businessInterface parameter.

getServiceReferences

<B> java.util.Collection<ServiceReference<B>> getServiceReferences(java.lang.Class<B> businessInterface,
                                                                   java.lang.String referenceName)
                                                               throws java.lang.IllegalArgumentException
Returns a list of typed ServiceReference objects for a reference defined by the current component, where the reference has multiplicity 0..n or 1..n.

Type Parameters:
B - the Java type that is associated with returned proxy objects.
B - the Java type of the reference that is associated with the returned object.
Parameters:
referenceName - the name of the service reference.
Returns:
a collection of ServiceReference objects for the reference, one for each target service to which the reference is wired, where each proxy object implements the interface B contained in the businessInterface parameter. The collection is empty if the reference is not wired to any target services.
Throws:
java.lang.IllegalArgumentException - if the reference has multiplicity greater other than 0..1 or 1..1, or the component does not have the reference named by referenceName, or the interface of the named reference is not compatible with the interface supplied in the businessInterface parameter.

createSelfReference

<B> ServiceReference<B> createSelfReference(java.lang.Class<B> businessInterface)
                                        throws java.lang.IllegalArgumentException
Returns a ServiceReference that can be used to invoke this component over the designated service.

Type Parameters:
B - the Java type of the reference that is associated with the returned object.
Parameters:
businessInterface - the Class object for the Java type that is associated with the returned object.
Returns:
a ServiceReference that can be used to invoke this component over the designated service.
Throws:
java.lang.IllegalArgumentException - if the component does not have a service which implements the interface identified by the businessinterface parameter.

createSelfReference

<B> ServiceReference<B> createSelfReference(java.lang.Class<B> businessInterface,
                                            java.lang.String serviceName)
                                        throws java.lang.IllegalArgumentException
Returns a ServiceReference that can be used to invoke this component over the designated service. The serviceName parameter explicitly names the service with which the returned ServiceReference is associated.

Type Parameters:
B - the Java type of the reference that is associated with the returned object.
Parameters:
businessInterface - the Class object for the Java type that is associated with the returned object.
serviceName - the service name with which the returned ServiceReference is associated.
Returns:
a ServiceReference that can be used to invoke this component over the designated service.
Throws:
java.lang.IllegalArgumentException - if the component does not have a service with the name identified by the serviceName parameter, or if the named service does not implement the interface identified by the businessinterface parameter.

getProperty

<B> B getProperty(java.lang.Class<B> type,
                  java.lang.String propertyName)
              throws java.lang.IllegalArgumentException
Returns the value of an SCA property defined by this component.

Type Parameters:
B - the property type.
Parameters:
type - the Class object for the property type.
propertyName - the property name.
Returns:
The value of an SCA property defined by this component, or null if the property is not configured.
Throws:
java.lang.IllegalArgumentException - if the component does not have a property with the name identified by the propertyName parameter, or if the named property type is not compatible with the type parameter.

cast

<B> ServiceReference<B> cast(B target)
                         throws java.lang.IllegalArgumentException
Casts a type-safe reference to a ServiceReference.

Type Parameters:
B - the Java type of the reference that is associated with the returned object.
Parameters:
target - the type-safe reference proxy that implements interface .
Returns:
a type-safe reference to a ServiceReference.
Throws:
java.lang.IllegalArgumentException

getRequestContext

RequestContext getRequestContext()
Returns the RequestContext for the current SCA service request.

Returns:
the RequestContext for the current SCA service request when invoked during the execution of a component service method or callback method. Returns null in all other cases.