In the javaeetutorial5\examples\ejb\converter example from Sun J2EE tutorial, the ConverterBean class is in the appClient.jar. Is the bean class real needed in the appClient.jar? I though the interface Converter should be enough for the appclient.
In the stand-alone Java client, it works fine without bean class, just need the interface.
ConvertClient.java
/*
* Copyright 2007 Sun Microsystems, Inc.
* All rights reserved. You may not modify, use,
* reproduce, or distribute this software except in
* compliance with the terms of the License at:
*
http://developer.sun.com/berkeley_license.html
*/
package converter.client;
import converter.ejb.Converter;
import java.math.BigDecimal;
import javax.ejb.EJB;
/**
*
* @author ian
*/
public class ConverterClient {
@EJB
private static Converter converter;
/** Creates a new instance of Client */
public ConverterClient(String[] args) {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ConverterClient client = new ConverterClient(args);
client.doConversion();
}
public void doConversion() {
try {
BigDecimal param = new BigDecimal("100.00");
BigDecimal yenAmount = converter.dollarToYen(param);
System.out.println("$" + param + " is " + yenAmount + " Yen.");
BigDecimal euroAmount = converter.yenToEuro(yenAmount);
System.out.println(yenAmount + " Yen is " + euroAmount + " Euro.");
System.exit(0);
} catch (Exception ex) {
System.err.println("Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
----------------------------------------------------------
Converter.java
/*
* Copyright 2007 Sun Microsystems, Inc.
* All rights reserved. You may not modify, use,
* reproduce, or distribute this software except in
* compliance with the terms of the License at:
*
http://developer.sun.com/berkeley_license.html
*/
package converter.ejb;
import java.math.BigDecimal;
import javax.ejb.Remote;
@Remote
public interface Converter {
public BigDecimal dollarToYen(BigDecimal dollars);
public BigDecimal yenToEuro(BigDecimal yen);
}
-----------------------------------------------
ConverterBean.java
/*
* Copyright 2007 Sun Microsystems, Inc.
* All rights reserved. You may not modify, use,
* reproduce, or distribute this software except in
* compliance with the terms of the License at:
*
http://developer.sun.com/berkeley_license.html
*/
package converter.ejb;
import java.math.BigDecimal;
import javax.ejb.Stateless;
/**
* This is the bean class for the ConverterBean enterprise bean.
* Created Jan 20, 2006 1:14:27 PM
* @author ian
*/
@Stateless
public class ConverterBean implements converter.ejb.Converter {
private BigDecimal euroRate = new BigDecimal("0.0070");
private BigDecimal yenRate = new BigDecimal("112.58");
public BigDecimal dollarToYen(BigDecimal dollars) {
BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}
public BigDecimal yenToEuro(BigDecimal yen) {
BigDecimal result = yen.multiply(euroRate);
return result.setScale(2, BigDecimal.ROUND_UP);
}
}