KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > examples > annotations > calculator > CalculatorModule


1 // Copyright 2007 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.examples.annotations.calculator;
16
17 import org.apache.examples.Adder;
18 import org.apache.examples.Calculator;
19 import org.apache.examples.Divider;
20 import org.apache.examples.Multiplier;
21 import org.apache.examples.Subtracter;
22 import org.apache.examples.impl.AdderImpl;
23 import org.apache.examples.impl.CalculatorImpl;
24 import org.apache.examples.impl.DividerImpl;
25 import org.apache.examples.impl.MultiplierImpl;
26 import org.apache.examples.impl.SubtracterImpl;
27 import org.apache.hivemind.annotations.AbstractAnnotatedModule;
28 import org.apache.hivemind.annotations.definition.Module;
29 import org.apache.hivemind.annotations.definition.Service;
30
31 /**
32  * Example of an annotated module that creates a calculator.
33  *
34  * @author Huegen
35  */

36 @Module( id="calculator" )
37 public class CalculatorModule extends AbstractAnnotatedModule
38 {
39
40     @Service( id="Adder" )
41     public Adder getAdderService()
42     {
43         return new AdderImpl();
44     }
45     
46     @Service( id="Subtracter" )
47     public Subtracter getSubtractorService()
48     {
49         return new SubtracterImpl();
50     }
51     
52     @Service( id="Multiplier" )
53     public Multiplier getMultiplierService()
54     {
55         return new MultiplierImpl();
56     }
57
58     @Service( id="Divider" )
59     public Divider getDividerService()
60     {
61         return new DividerImpl();
62     }
63
64     @Service( id="Calculator" )
65     public Calculator getCalculatorService()
66     {
67         CalculatorImpl result = new CalculatorImpl();
68         return autowireProperties(result);
69     }
70
71 }
72
Popular Tags