KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > naming > ejb > TestEjbLinkBean


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.test.naming.ejb;
23
24 import javax.ejb.CreateException JavaDoc;
25 import javax.ejb.EJBException JavaDoc;
26 import javax.ejb.SessionBean JavaDoc;
27 import javax.ejb.SessionContext JavaDoc;
28 import javax.naming.Context JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31 import javax.rmi.PortableRemoteObject JavaDoc;
32
33 import org.jboss.test.naming.interfaces.TestEjbLinkHome;
34 import org.jboss.test.naming.interfaces.TestEjbLink;
35 import org.jboss.test.naming.interfaces.TestEjbLinkLocalHome;
36 import org.jboss.test.naming.interfaces.TestEjbLinkLocal;
37 import org.jboss.test.util.Debug;
38
39 /** A bean that tests ejb-link works
40
41 @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian.Brock</a>
42 @version $Revision: 58115 $
43 */

44 public class TestEjbLinkBean implements SessionBean JavaDoc
45 {
46    org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(getClass());
47
48     public void ejbCreate() throws CreateException JavaDoc
49     {
50     }
51
52 // --- Begin SessionBean interface methods
53
public void ejbActivate()
54     {
55     }
56     
57     public void ejbPassivate()
58     {
59     }
60     
61     public void ejbRemove()
62     {
63     }
64
65     public void setSessionContext(SessionContext JavaDoc sessionContext) throws EJBException JavaDoc
66     {
67     }
68
69     public String JavaDoc testEjbLinkCaller(String JavaDoc jndiName)
70     {
71        try
72        {
73           InitialContext JavaDoc initial = new InitialContext JavaDoc();
74           Object JavaDoc object = initial.lookup(jndiName);
75           log.debug("jndiName="+jndiName);
76
77           StringBuffer JavaDoc results = new StringBuffer JavaDoc("testEjbLinkCaller Proxy info\n");
78           Debug.displayClassInfo(object.getClass(), results);
79           log.debug(results.toString());
80
81           results.setLength(0);
82           results.append("testEjbLinkCaller TestEjbLinkLocalHome.class info\n");
83           Debug.displayClassInfo(TestEjbLinkLocalHome.class, results);
84           log.debug(results.toString());
85
86           TestEjbLinkHome home =
87             (TestEjbLinkHome) PortableRemoteObject.narrow(object, TestEjbLinkHome.class);
88           TestEjbLink bean = home.create();
89           return bean.testEjbLinkCalled();
90        }
91        catch (Exception JavaDoc e)
92        {
93           log.debug("failed", e);
94           return "Failed";
95        }
96     }
97
98     public String JavaDoc testEjbLinkCallerLocal(String JavaDoc jndiName)
99     {
100        try
101        {
102           InitialContext JavaDoc initial = new InitialContext JavaDoc();
103           Object JavaDoc object = initial.lookup(jndiName);
104           log.debug("jndiName="+jndiName);
105
106           StringBuffer JavaDoc results = new StringBuffer JavaDoc("testEjbLinkCallerLocal Proxy info\n");
107           Debug.displayClassInfo(object.getClass(), results);
108           log.debug(results.toString());
109
110           results.setLength(0);
111           results.append("testEjbLinkCallerLocal TestEjbLinkLocalHome.class info\n");
112           Debug.displayClassInfo(TestEjbLinkLocalHome.class, results);
113           log.debug(results.toString());
114
115           TestEjbLinkLocalHome home =
116             (TestEjbLinkLocalHome) PortableRemoteObject.narrow(object, TestEjbLinkLocalHome.class);
117           TestEjbLinkLocal bean = home.create();
118           return bean.testEjbLinkCalled();
119        }
120        catch (Exception JavaDoc e)
121        {
122           log.debug("failed", e);
123           return "Failed";
124        }
125     }
126
127     public String JavaDoc testEjbLinkCalled()
128     {
129        return "Works";
130     }
131
132 }
133
Popular Tags