summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/modules/sca-api/src/main/java/org/oasisopen/sca/ComponentContext.java
blob: 09faf1b15e8ebca9f9d8c5f97389074b459d9568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
 * Copyright(C) OASIS(R) 2005,2010. All Rights Reserved.
 * OASIS trademark, IPR and other policies apply.
 */
package org.oasisopen.sca;

import java.util.Collection;

/**
 * The ComponentContext interface is used to obtain contextual information
 * about the SCA component which is executing at the time the API is
 * invoked.
 * 
 * <p>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.
 */
public interface ComponentContext {

    /**
     * Returns the absolute URI of the component within the SCA domain.
     * 
     * @return the absolute URI of the component within the SCA domain.
     */
    String getURI();

    /**
     * Returns a typed service proxy object for a reference defined by the
     * current component, where the reference has multiplicity 0..1 or 1..1.
     *
     * @param     <B> the Java type that is implemented by the returned proxy
     *            object.
     * @param     businessInterface the Class object for the Java type that
     *            is implemented by the returned proxy object.
     * @param     referenceName the name of the service reference.
     * @return    a proxy for the reference defined by the current component.
     *            Returns null if the named reference has no target service
     *            configured.
     * @exception IllegalArgumentException if the reference has multiplicity
     *            greater than one, or the component does not have the reference
     *            named by <code>referenceName</code>, or the interface of the named
     *            reference is not compatible with the interface supplied in
     *            the <code>businessInterface</code> parameter. 
     */
    <B> B getService(Class<B> businessInterface, String referenceName)
    		throws IllegalArgumentException;

    /**
     * Returns a ServiceReference object for a reference defined by the current
     * component, where the reference has multiplicity 0..1 or 1..1.
     * 
     * @param     <B> the Java type of the reference that is associated with
     *            the returned object.
     * @param     businessInterface the Class object for the Java type that
     *            is associated with the returned object.
     * @param     referenceName the name of the service reference.
     * @return    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.
     * @exception IllegalArgumentException if the reference has multiplicity
     *            greater than one, or the component does not have the reference
     *            named by <code>referenceName</code>, or the interface of the named
     *            reference is not compatible with the interface supplied in
     *            the <code>businessInterface</code> parameter.
     */
    <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, 
                                                String referenceName)
            throws 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.
     *
     * @param     <B> the Java type that is implemented by the returned proxy
     *            objects.
     * @param     businessInterface the Class object for the Java type that
     *            is implemented by the returned proxy objects.
     * @param     referenceName the name of the service reference.
     * @return    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 
     *            <code>businessInterface</code> parameter. The collection is empty if the
     *            reference is not wired to any target services.
     * @exception IllegalArgumentException if the reference has multiplicity
     *            greater other than 0..1 or 1..1, or the component does not have the reference
     *            named by <code>referenceName</code>, or the interface of the named
     *            reference is not compatible with the interface supplied in
     *            the <code>businessInterface</code> parameter.
     */
    <B> Collection<B> getServices(Class<B> businessInterface,
                                  String referenceName)
     		throws 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.
     *
     * @param     <B> the Java type that is associated with returned proxy
     *            objects.
     * @param     <B> the Java type of the reference that is associated with
     *            the returned object.
     * @param     referenceName the name of the service reference.
     * @return    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 <code>businessInterface</code> parameter.
     *            The collection is empty if the reference is not wired to any target services.
     * @exception IllegalArgumentException if the reference has multiplicity
     *            greater other than 0..1 or 1..1, or the component does not have the reference
     *            named by <code>referenceName</code>, or the interface of the named
     *            reference is not compatible with the interface supplied in
     *            the <code>businessInterface</code> parameter.
     */
    <B> Collection<ServiceReference<B>> getServiceReferences(
                       Class<B> businessInterface, String referenceName)
     		throws IllegalArgumentException; 

    /**
     * Returns a ServiceReference that can be used to invoke this component
     * over the designated service.
     *
     * @param     <B> the Java type of the reference that is associated with
     *            the returned object.
     * @param     businessInterface the Class object for the Java type that
     *            is associated with the returned object.
     * @return    a ServiceReference that can be used to invoke this
     *            component over the designated service.
     * @exception IllegalArgumentException if the component does not have a service
     *            which implements the interface identified by the <code>
     *            businessinterface</code> parameter.
     */
    <B> ServiceReference<B> createSelfReference(Class<B> businessInterface)
     		throws IllegalArgumentException;

    /**
     * Returns a ServiceReference that can be used to invoke this component
     * over the designated service. The <code>serviceName</code> parameter explicitly names
     * the service with which the returned ServiceReference is associated.
     *
     * @param     <B> the Java type of the reference that is associated with
     *            the returned object.
     * @param     businessInterface the Class object for the Java type that
     *            is associated with the returned object.
     * @param     serviceName the service name with which the returned ServiceReference
     *            is associated.
     * @return    a ServiceReference that can be used to invoke this component
     *            over the designated service.
     * @exception IllegalArgumentException if the component does not have a service
     *            with the name identified by the <code>serviceName</code> parameter, or
     *            if the named service does not implement the interface identified by the
     *            <code>businessinterface</code> parameter.
     */
    <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, 
                                                String serviceName)
     		throws IllegalArgumentException;

    /**
     * Returns the value of an SCA property defined by this component.
     *
     * @param     <B> the property type.
     * @param     type the Class object for the property type.
     * @param     propertyName the property name.
     * @return    The value of an SCA property defined by this component, or null if
     *            the property is not configured.
     * @exception IllegalArgumentException if the component does not have a property
     *            with the name identified by the <code>propertyName</code> parameter, or
     *            if the named property type is not compatible with the <code>type</code>
     *            parameter.
     */
    <B> B getProperty(Class<B> type, String propertyName)
		    throws IllegalArgumentException;

    /**
     * Casts a type-safe reference to a ServiceReference.
     *
     * @param     <B> the Java type of the reference that is associated with
     *            the returned object.
     * @param     target the type-safe reference proxy that implements interface <B>.
     * @return    a  type-safe reference to a ServiceReference.
     */
    <B> ServiceReference<B> cast(B target) 
            throws IllegalArgumentException;

    /**
     * Returns the RequestContext for the current SCA service request.
     *
     * @return    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.
     */
    RequestContext getRequestContext();
}