ShoppingCartBean.java
import java.io.Serializable;
import java.util.HashMap;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.ejb.Remote;
@Stateful
@Remote(ShoppingCart.class)
public class ShoppingCartBean implements ShoppingCart, Serializable {
    private HashMap<String, Integer> cart = new HashMap<String, Integer>();
    public void buy(String product, int quantity) {
        if(cart.containsKey(product)) {
            int currq = cart.get(product);
            currq += quantity;
            cart.put(product, currq);
        }
        else {
            cart.put(product, quantity);
        }
    }
    public HashMap<String, Integer> getCartContents() {
        return cart;
    }
    @Remove
    public void checkout() {
        System.out.println("To be implemented");
    }
}
ShoppingCart.java
import java.util.HashMap;
import javax.ejb.Remove;
public interface ShoppingCart {
    void buy(String product, int quantity);
    HashMap<String, Integer> getCartContents();
    @Remove void checkout();
}

axiez wrote:
> 
> I went through <geronimo_home>\var\log\geronimo.log file. It has the
> following entries:
> [startup] Assembling app: d:\dir1\dir2\dir3\yourDirectory
> [startup] Deployed Application(path=d:\dir1\dir2\dir3\yourDirectory). No
> entries matching [startup] Jndi for this application. Is it because I
> don't have ejb-jar.xml? I thought it no longer would be required.
> 
> axiez wrote:
>> 
>> I want to run sample code to understand ejb 3.0 basics. I am new to ejb.
>> I have the following java files: ShoppingCartBean.java, ShoppingCart.java
>> and Client.java. The Client.java file has the following code:
>> import javax.naming.InitialContext;
>> public class Client {
>>     public static void main(String[] args) throws Exception {
>>         InitialContext ctx = new InitialContext();
>>         ShoppingCart cart = (ShoppingCart)
>> ctx.lookup("ShoppingCartBean/remote");
>>         ...
>>     }
>>     My plan is to have client on a different JVM than ejb container. I
>> wonder how the client can execute bean method without even knowing IP
>> address etc of the JVM that has the other code on ejb container.
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/ejb-client-tp21193112s134p21213824.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.

Reply via email to