summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/tags/2.0.1-RC1/testing/itest/implementation-spring/src/main/java/spring/annotations/CalculatorServiceImpl.java
blob: 544b39ad589e0b0492def862bdd5b642a0e4a679 (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
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.    
 */
package spring.annotations;

import org.oasisopen.sca.annotation.ComponentName;
import org.oasisopen.sca.annotation.Destroy;
import org.oasisopen.sca.annotation.Init;
import org.oasisopen.sca.annotation.Property;
import org.oasisopen.sca.annotation.Reference;
import org.oasisopen.sca.annotation.Service;

import calculator.AddService;
import calculator.CalculatorService;
import calculator.DivideService;
import calculator.MultiplyService;
import calculator.SubtractService;

/**
 * An implementation of the Calculator service.
 */
@Service(CalculatorService.class)
public class CalculatorServiceImpl implements AddService, SubtractService, MultiplyService, DivideService {
    
    public AddService addService;  // setter injection
    
    @Reference
    public SubtractService subtractService;  // field injection
    
    @Reference(name="multiplyService", required=false)
    public MultiplyService multiply;  // field injection (different reference and field name)
    
    public DivideService divide;  // setter injection (different reference and field name)
    
    public String message;  // setter injection
    
    @Property(name="message", required=false)
    public String message2;  // field injection
    
    public String componentName;
    
    @Init
    public void initMethod () {
        System.out.println("Init method is sucessfully called.....");
        // Property value should be null here.
        System.out.println("Property Value message is...." + message);
    }
    
    @Destroy
    public void destroyMethod () {
        System.out.println("Component Name is...." + componentName);
        System.out.println("Property Value message is...." + message);
        System.out.println("Property Value message2 is...." + message2);
        System.out.println("Destroy method is sucessfully called.....");
    }

    @Reference
    public void setAddService(AddService addService) {
        this.addService = addService;
    }
    
    public AddService getAddService() {
        return addService;
    }

    /*public void setSubtractService(SubtractService subtractService) {
        this.subtractService = subtractService;
    }
    
    public SubtractService getSubtractService() {
        return subtractService;
    }*/    
    
    @Reference(name="divideService", required=false)
    public void setDivideService(DivideService divide) {
        this.divide = divide;
    }
    
    public DivideService getDivideService() {
        return divide;
    }
    
    /*public void setMultiplyService(MultiplyService multiplyService) {
        this.multiplyService = multiplyService;
    }
    
    public MultiplyService getMultiplyService() {
        return multiplyService;
    }*/
    
    @ComponentName
    public void setComponentName(String componentName) {
        this.componentName = componentName;
    }
    
    @Property
    public void setMessage(String message) {
        this.message = message;
    }    

    public double add(double n1, double n2) {
        return addService.add(n1, n2);
    }

    public double subtract(double n1, double n2) {
        return subtractService.subtract(n1, n2);
    }

    public double multiply(double n1, double n2) {
        return multiply.multiply(n1, n2);
    }

    public double divide(double n1, double n2) {
        return divide.divide(n1, n2);
    }
}