KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > hello > ejb > HelloBean


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.hello.ejb;
23
24 import java.io.Serializable JavaDoc;
25 import javax.ejb.EJBException JavaDoc;
26 import javax.ejb.DuplicateKeyException JavaDoc;
27 import javax.ejb.FinderException JavaDoc;
28 import javax.naming.InitialContext JavaDoc;
29
30 import org.jboss.test.util.ejb.SessionSupport;
31 import org.jboss.test.hello.interfaces.Hello;
32 import org.jboss.test.hello.interfaces.HelloData;
33 import org.jboss.test.hello.interfaces.HelloException;
34 import org.jboss.test.hello.interfaces.LocalHelloLogHome;
35 import org.jboss.test.hello.interfaces.LocalHelloLog;
36 import org.jboss.test.hello.interfaces.NotSerializable;
37
38 /**
39  *
40  * @author Scott.Stark@jboss.org
41  * @version $Revision: 37406 $
42  */

43 public class HelloBean
44    extends SessionSupport
45 {
46    public String JavaDoc hello(String JavaDoc name)
47    {
48       return "Hello "+name+"!";
49    }
50
51    public String JavaDoc loggedHello(String JavaDoc name)
52    {
53       long begin = System.currentTimeMillis();
54       LocalHelloLog bean = null;
55       LocalHelloLogHome home = null;
56       try
57       {
58          InitialContext JavaDoc ctx = new InitialContext JavaDoc();
59          home = (LocalHelloLogHome) ctx.lookup("java:comp/env/ejb/LocalHelloLogHome");
60          bean = home.create(name);
61          log.info("Created LocalHelloLog with key="+name);
62          if( bean != null )
63             bean.setStartTime(begin);
64       }
65       catch(DuplicateKeyException JavaDoc e)
66       {
67          try
68          {
69             bean = home.findByPrimaryKey(name);
70             log.info("Found LocalHelloLog with key="+name);
71             if( bean != null )
72                bean.setStartTime(begin);
73          }
74          catch(FinderException JavaDoc fe)
75          {
76             log.debug("LocalHelloLog find failed", fe);
77          }
78       }
79       catch(Exception JavaDoc e)
80       {
81          log.debug("LocalHelloLog create failed", e);
82       }
83       String JavaDoc reply = "Hello "+name+"!";
84       long end = System.currentTimeMillis();
85       if( bean != null )
86          bean.setEndTime(end);
87
88       return reply;
89    }
90
91    public String JavaDoc helloException(String JavaDoc name)
92       throws HelloException
93    {
94       throw new HelloException("Catch me");
95    }
96
97    public Hello helloHello(Hello hello)
98    {
99       return hello;
100    }
101
102    public String JavaDoc howdy(HelloData name)
103    {
104       return "Howdy "+name.getName()+"!";
105    }
106
107    public String JavaDoc sleepingHello(String JavaDoc name, long sleepTimeMS)
108    {
109       if( sleepTimeMS <= 0 )
110          sleepTimeMS = 1;
111       try
112       {
113          Thread.sleep(sleepTimeMS);
114       }
115       catch(InterruptedException JavaDoc ignore)
116       {
117       }
118       return "Hello "+name+"!";
119    }
120
121    public Object JavaDoc getCNFEObject()
122    {
123       return new ServerData();
124    }
125    public void throwException()
126    {
127       throw new EJBException JavaDoc("Something went wrong");
128    }
129
130    public void setNotSerializable(NotSerializable ignored)
131    {
132       throw new RuntimeException JavaDoc("Should not get here");
133    }
134    public NotSerializable getNotSerializable()
135    {
136       return new NotSerializable();
137    }
138
139    static class ServerData implements Serializable JavaDoc
140    {
141    }
142 }
143
Popular Tags