1 22 package org.jboss.ejb3.test.standalone; 23 24 import java.util.ArrayList ; 25 import java.util.Hashtable ; 26 import javax.ejb.EJB ; 27 import javax.annotation.Resource; 28 import javax.ejb.Remove ; 29 import javax.ejb.SessionContext ; 30 import javax.ejb.Stateful ; 31 import javax.naming.Context ; 32 import javax.naming.InitialContext ; 33 import javax.naming.NamingException ; 34 import org.jboss.ejb3.Container; 35 36 42 @Stateful 43 public class ShoppingCartBean implements ShoppingCart 44 { 45 private ArrayList <String > cart = new ArrayList <String >(); 46 47 private @EJB CalculatorLocal calculator; 48 private @EJB CalculatorRemote calculatorRemote; 49 private @Resource SessionContext ctx; 50 51 private CalculatorRemote setCalc; 52 53 @EJB 54 public void setCalculatorSetter(CalculatorRemote r) 55 { 56 setCalc = r; 57 } 58 59 public ArrayList <String > getCart() 60 { 61 return cart; 62 } 63 64 @Remove 65 public void checkout() 66 { 67 calculator.add(1, 1); 68 Hashtable props = new Hashtable (); 69 props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); 70 props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.LocalOnlyContextFactory"); 71 try 72 { 73 InitialContext initialContext = new InitialContext (props); 74 calculator = (CalculatorLocal)initialContext.lookup(Container.ENC_CTX_NAME + "/env/org.jboss.ejb3.test.standalone.ShoppingCartBean/calculator"); 75 } 76 catch (NamingException e) 77 { 78 throw new RuntimeException (e); 79 } 80 calculator.add(1, 1); 81 calculator = (CalculatorLocal)ctx.lookup("org.jboss.ejb3.test.standalone.ShoppingCartBean/calculator"); 82 calculator.add(1, 1); 83 calculatorRemote.add(2, 2); 84 85 setCalc.add(3, 3); 86 87 88 } 89 } 90 | Popular Tags |