Commit 418c7a22 authored by Christophe Demarey's avatar Christophe Demarey

Add a peso conversion to this example.

parent e9b0328f
......@@ -51,7 +51,7 @@ public class Client implements Runnable {
System.out.print("Updating exchange rate to "+newRate+" ...");
try {
updater.updateExchangeRate(newRate);
updater.updateDollarExchangeRate(newRate);
System.out.println(" Done!");
result = converter.dollarToEuro(100);
System.out.println("100$ are now worth about "+result+"€.");
......@@ -62,7 +62,7 @@ public class Client implements Runnable {
System.out.println("Updating exchange rate to "+newRateV2+" ...");
try {
updater.updateExchangeRateV2(newRateV2);
updater.updateDollarExchangeRateV2(newRateV2);
System.out.println("Done!");
result = converter.dollarToEuro(100);
System.out.println("100$ are now worth about "+result+"€.");
......
......@@ -47,4 +47,20 @@ public interface CurrencyConverter {
@GET
@Path("/dollar2euro")
double dollarToEuro(@FormParam("value") double value);
/**
* Converts Euros to Pesos.
*
* @param value the amount of euros to convert.
*/
@GET
@Path("/euro2peso")
double euroToPeso(@FormParam("value") double value);
/**
* Converts Pesos to Euros.
*
* @param value the amount of dollars to convert.
*/
@GET
@Path("/peso2euro")
double pesoToEuro(@FormParam("value") double value);
}
......@@ -29,7 +29,10 @@ import org.osoa.sca.annotations.Scope;
*/
@Scope(value="COMPOSITE")
public class CurrencyConverterImpl implements CurrencyConverter {
private double exchangeRate;
/** Dollar exchange rate 1€ = dollarExchangeRate$ */
private double dollarExchangeRate;
/** Mexican Peso exchange rate 1€ = pesoExchangeRate$ */
private double pesoExchangeRate;
/** Default constructor. */
public CurrencyConverterImpl() {
......@@ -37,23 +40,42 @@ public class CurrencyConverterImpl implements CurrencyConverter {
}
/**
* Set the exchangeRate property.
* Set the dollarExchangeRate property.
*
* @param rate - the new value of the exchange rate.
* @param rate - the new value of the dollar exchange rate.
*/
@Property
public void setExchangeRate(final double rate) {
System.out.println("Setting exchange rate to '" + rate + "'.");
this.exchangeRate = rate;
public void setDollarExchangeRate(final double rate) {
System.out.println("Setting Dollar exchange rate to '" + rate + "'.");
this.dollarExchangeRate = rate;
}
/**
* Set the PesoExchangeRate property.
*
* @param rate - the new value of the peso exchange rate.
*/
@Property
public void setPesoExchangeRate(final double rate) {
System.out.println("Setting Peso exchange rate to '" + rate + "'.");
this.pesoExchangeRate = rate;
}
// Implementation of the CurrencyConverter service
public double dollarToEuro(double value) {
return value * exchangeRate;
return value * dollarExchangeRate;
}
public double euroToDollar(double value) {
return value / exchangeRate;
return value / dollarExchangeRate;
}
public double euroToPeso(double value) {
return value * pesoExchangeRate;
}
public double pesoToEuro(double value) {
return value / pesoExchangeRate;
}
}
\ No newline at end of file
......@@ -30,8 +30,6 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.text.NumberFormat;
import java.util.Locale;
......@@ -41,8 +39,6 @@ import javax.swing.JOptionPane;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;
import org.objectweb.util.explorer.swing.gui.api.DialogBox;
import org.objectweb.util.explorer.swing.gui.lib.DefaultDialogBox;
import org.ow2.frascati.examples.reconfig.converter.CurrencyConverter;
import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
......
......@@ -71,7 +71,7 @@ public class UpdaterPanel extends AbstractSelectionPanel<ExchangeRateUpdater> {
if (jTextFieldValue.getText().length() > 0) {
double newValue = Double.parseDouble( jTextFieldValue.getText() );
try {
selected.updateExchangeRate(newValue);
selected.updateDollarExchangeRate(newValue);
} catch (FScriptException e1) {
System.out.println("Reconfiguration failed!");
e1.printStackTrace();
......
......@@ -34,7 +34,7 @@ public interface ExchangeRateUpdater {
*
* @param newValue The new exchange rate value.
*/
void updateExchangeRate(double newValue) throws FScriptException;
void updateDollarExchangeRate(double newValue) throws FScriptException;
/**
* Update the exchange rate of the converter with the help of fscript.
* This method does the same thing as {@link #updateExchangeRate(double)} but
......@@ -43,5 +43,5 @@ public interface ExchangeRateUpdater {
*
* @param newValue The new exchange rate value.
*/
void updateExchangeRateV2(double newValue) throws FScriptException;
void updateDollarExchangeRateV2(double newValue) throws FScriptException;
}
......@@ -39,15 +39,15 @@ public class ExchangeRateUpdaterImpl implements ExchangeRateUpdater {
@Property
protected String reconfigurationScript;
public void updateExchangeRate(double newValue) throws FScriptException {
public void updateDollarExchangeRate(double newValue) throws FScriptException {
FraSCAtiScript fscript = FraSCAtiScript.getSingleton();
fscript.execute("converter = $domain/scachild::reconfig/scachild::converter/scachild::currency-converter;");
fscript.execute("rate = $converter/scaproperty::exchangeRate;");
fscript.execute("rate = $converter/scaproperty::dollarExchangeRate;");
fscript.execute("set-value($rate,"+newValue+")");
}
public void updateExchangeRateV2(double newValue) throws FScriptException {
public void updateDollarExchangeRateV2(double newValue) throws FScriptException {
Set<String> loadedProc = new TreeSet<String>();
FraSCAtiScript fscript = FraSCAtiScript.getSingleton();
......
......@@ -39,7 +39,8 @@
<interface.java interface="org.ow2.frascati.examples.reconfig.converter.CurrencyConverter"/>
</service>
<property name="exchangeRate">0.75</property>
<property name="dollarExchangeRate">0.75</property>
<property name="pesoExchangeRate">2751.43358</property>
</component>
......
......@@ -2,6 +2,6 @@
action reconfigure-converter(newValue){
converter = $domain/scachild::reconfig/scachild::converter/scachild::currency-converter;
rate = $converter/scaproperty::exchangeRate;
rate = $converter/scaproperty::dollarExchangeRate;
set-value($rate, $newValue);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment