### Calculator Example

This example demonstrates a simple Calculator application which is composed of POJO services for each Çalculator service (add, subtract, mulitple, divide). This example shows the use of associations and how association based dependency injection can be used. This document is organized as follows :

- Building the Example
- Example Source Files
- Running the Example

Building the Example
Building the example is straight forward, you must have Ant and the JDK. If these requirements are met :
$ cd <rio-home>/examples/calculator
$ ant

Example Source Files
Source code is located in <rio-home>/examples/calculator directory

File Name | Location | Description
Add.java | /src/main/java/calculator | Interface for the Add service
Calculator.java | /src/main/java/calculator | Interface for the Calculator
Divide.java | /src/main/java/calculator | Interface for the Divide service
Multiply.java | /src/main/java/calculator | Interface for the Multiply service
Subtract.java | /src/main/java/calculator | Interface for the Subtract service
CalculatorTest.java | /src/test/java/calculator | Provides a JUnit client for running the example
AddImpl.java | /src/main/java/calculator/service | The Add service implementation
CalculatorImpl.java | /src/main/java/calculator/service | The Calculator service implementation
DivideImpl.java | /src/main/java/calculator/service | The Divide service implementation
MultiplyImpl.java | /src/main/java/calculator/service | The Mulitply service implementation
SubtractImpl.java | /src/main/java/calculator/service | The Subtract service implementation
calculator.xml | /src/main/conf | The opstring for the example
build.xml | . | The ant build file
readme.html | . | This file

Running the Example

How to run the example :

1. Start Rio services :
   $ cd <rio-home>/bin
   $ startall
2. Deploy the example using of the of following methods

- Using the Rio CLI
  $ cd <rio-home>/bin
  $ rio deploy ../examples/calculator/src/main/conf/calculator.xml
- Using Ant deploy task
  $ cd <rio-home>/examples/calculator
  $ ant deploy

3. Run the client using ant
   $ cd <rio-home>/examples/calculator
   $ ant client
   Buildfile: build.xml
   client:
   [java] JUnit version 4.4
   [java] Discovering Calculator service ...
   [java] . 3 + 2 = 5.0
   [java] . 3 - 2 = 1.0
   [java] . 10 * 10 = 100.0
   [java] . 10 % 10 = 1.0
   [java]
   [java] Time: 0.805
   [java]
   [java] OK (4 tests)
   [java]
   BUILD SUCCESSFUL
   Total time: 1 second
4. Undeploy the example using of the of following methods

- Using the Rio CLI
  $ cd <rio-home>/bin
  $ rio undeploy ../examples/calculator/src/main/conf/calculator.xml
- Using Ant undeploy task
  $ cd <rio-home>/examples/calculator
  $ ant deploy