KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > reference21_30 > Session30Bean


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.reference21_30;
23
24 import javax.naming.*;
25 import javax.ejb.EJB JavaDoc;
26 import javax.ejb.EJBs JavaDoc;
27 import javax.ejb.Remote JavaDoc;
28 import javax.ejb.Stateless JavaDoc;
29 import javax.ejb.Local JavaDoc;
30
31 import org.jboss.annotation.ejb.LocalBinding;
32 import org.jboss.annotation.ejb.RemoteBinding;
33 import org.jboss.ejb3.Container;
34 import org.jboss.logging.Logger;
35
36 /**
37  * @version <tt>$Revision: 46096 $</tt>
38  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
39  */

40 @Stateless JavaDoc(name="Session30")
41 @Remote JavaDoc(Session30.class)
42 @Local JavaDoc(LocalSession30.class)
43 @RemoteBinding(jndiBinding = "Session30")
44 @LocalBinding(jndiBinding = "LocalSession30")
45 @EJBs JavaDoc({@EJB JavaDoc(name="injected", beanInterface=org.jboss.ejb3.test.reference21_30.Session21.class, beanName="Session21")})
46 public class Session30Bean
47 {
48    private static final Logger log = Logger.getLogger(Session30Bean.class);
49
50    @EJB JavaDoc(mappedName="Session21") Object JavaDoc testMappedName;
51    
52    public String JavaDoc access()
53    {
54       return "Session30";
55    }
56    
57    public String JavaDoc access21()
58    {
59       try {
60          InitialContext jndiContext = new InitialContext();
61          Session21 session = (Session21)jndiContext.lookup(Container.ENC_CTX_NAME + "/env/injected");
62          return session.access();
63       } catch (Exception JavaDoc e)
64       {
65          e.printStackTrace();
66          return null;
67       }
68    }
69    
70    public String JavaDoc globalAccess21()
71    {
72       try {
73          InitialContext jndiContext = new InitialContext();
74          Session21Home home = (Session21Home)jndiContext.lookup("Session21");
75          Session21 session = (Session21)home.create();
76          return session.access();
77       } catch (Exception JavaDoc e)
78       {
79          e.printStackTrace();
80          return null;
81       }
82    }
83    
84    public String JavaDoc accessLocalStateful()
85    {
86       try {
87          InitialContext jndiContext = new InitialContext();
88          StatefulSession30LocalHome localHome = (StatefulSession30LocalHome)jndiContext.lookup("LocalStatefulSession30Home");
89          LocalStatefulSession30 localSession = localHome.create();
90          return localSession.getLocalValue();
91       } catch (Exception JavaDoc e)
92       {
93          e.printStackTrace();
94          return null;
95       }
96    }
97    
98    public String JavaDoc accessLocalStateful(String JavaDoc value)
99    {
100       try {
101          InitialContext jndiContext = new InitialContext();
102          StatefulSession30LocalHome localHome = (StatefulSession30LocalHome)jndiContext.lookup("LocalStatefulSession30Home");
103          LocalStatefulSession30 localSession = localHome.create(value);
104          return localSession.getLocalValue();
105       } catch (Exception JavaDoc e)
106       {
107          e.printStackTrace();
108          return null;
109       }
110    }
111    
112    public String JavaDoc accessLocalStateful(String JavaDoc value, Integer JavaDoc suffix)
113    {
114       try {
115          InitialContext jndiContext = new InitialContext();
116          StatefulSession30LocalHome localHome = (StatefulSession30LocalHome)jndiContext.lookup("LocalStatefulSession30Home");
117          LocalStatefulSession30 localSession = localHome.create(value, suffix);
118          return localSession.getLocalValue();
119       } catch (Exception JavaDoc e)
120       {
121          e.printStackTrace();
122          return null;
123       }
124    }
125    
126 }
127
Popular Tags