summaryrefslogtreecommitdiffstats
path: root/sandbox/jboynes/sca-client/src/test/java/sample/client/BasicClient.java
blob: 6565a6a5f7bc66d2b6e2e731d1c447264cd25a77 (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
package sample.client;

import org.osoa.sca.ComponentContext;
import org.osoa.sca.ServiceReference;
import sample.HelloService;

/**
 * @version $Rev$ $Date$
 */
public class BasicClient {
    private ComponentContext context;

    public void useComponentDirectly() {
        HelloService helloService = context.getService(HelloService.class, "helloService");
        helloService.hello("World");
    }

    public void useComponentViaReference() {
        ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class, "helloService");
        HelloService helloService = ref.getService();
        helloService.hello("World");

        ServiceReference<HelloService> ref2 = context.cast(helloService);
    }

    public void useReferenceDirectly() {
        HelloService helloService = context.getService(HelloService.class, "helloReference");
        helloService.hello("World");
    }

    public void useReferenceViaReference() {
        ServiceReference<HelloService> ref = context.getServiceReference(HelloService.class, "helloReference");
        HelloService helloService = ref.getService();
        helloService.hello("World");

        ServiceReference<HelloService> ref2 = context.cast(helloService);
    }
}