KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > standalone > ShoppingCartBean


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.standalone;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Hashtable JavaDoc;
26 import javax.ejb.EJB JavaDoc;
27 import javax.annotation.Resource;
28 import javax.ejb.Remove JavaDoc;
29 import javax.ejb.SessionContext JavaDoc;
30 import javax.ejb.Stateful JavaDoc;
31 import javax.naming.Context JavaDoc;
32 import javax.naming.InitialContext JavaDoc;
33 import javax.naming.NamingException JavaDoc;
34 import org.jboss.ejb3.Container;
35
36 /**
37  * Comment
38  *
39  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
40  * @version $Revision: 45473 $
41  */

42 @Stateful JavaDoc
43 public class ShoppingCartBean implements ShoppingCart
44 {
45    private ArrayList JavaDoc<String JavaDoc> cart = new ArrayList JavaDoc<String JavaDoc>();
46
47    private @EJB JavaDoc CalculatorLocal calculator;
48    private @EJB JavaDoc CalculatorRemote calculatorRemote;
49    private @Resource SessionContext JavaDoc ctx;
50
51    private CalculatorRemote setCalc;
52
53    @EJB JavaDoc
54    public void setCalculatorSetter(CalculatorRemote r)
55    {
56       setCalc = r;
57    }
58
59    public ArrayList JavaDoc<String JavaDoc> getCart()
60    {
61       return cart;
62    }
63
64    @Remove JavaDoc
65    public void checkout()
66    {
67       calculator.add(1, 1);
68       Hashtable JavaDoc props = new Hashtable JavaDoc();
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 JavaDoc initialContext = new InitialContext JavaDoc(props);
74          calculator = (CalculatorLocal)initialContext.lookup(Container.ENC_CTX_NAME + "/env/org.jboss.ejb3.test.standalone.ShoppingCartBean/calculator");
75       }
76       catch (NamingException JavaDoc e)
77       {
78          throw new RuntimeException JavaDoc(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