01: // Copyright 2004, 2005 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // 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;
16:
17: import org.apache.hivemind.Registry;
18:
19: /**
20: * Runs through the methods of the {@link org.apache.examples.Calculator} with
21: * a pair of argument values parsed from the command line.
22: *
23: * @author Howard Lewis Ship
24: */
25: public class CalculatorMain {
26: public static void main(String[] args) {
27: double arg0 = Double.parseDouble(args[0]);
28: double arg1 = Double.parseDouble(args[1]);
29:
30: Registry registry = ExampleUtils.buildRegistry("examples.xml");
31:
32: // Since we know there's exactly *one* service-point implementing Calculator,
33: // we can get it this way, and never have to know its service id.
34:
35: Calculator calculator = (Calculator) registry
36: .getService(Calculator.class);
37:
38: System.out.println("Inputs: " + arg0 + " and " + arg1);
39: System.out.println("Add: " + calculator.add(arg0, arg1));
40: System.out.println("Subtract: "
41: + calculator.subtract(arg0, arg1));
42: System.out.println("Multiply: "
43: + calculator.multiply(arg0, arg1));
44: System.out
45: .println("Divide: " + calculator.divide(arg0, arg1));
46:
47: registry.shutdown();
48: }
49: }
|