KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > slsb


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 import java.rmi.*;
23 import java.awt.*;
24 import java.util.*;
25 import javax.ejb.*;
26 import javax.naming.*;
27 import java.awt.event.*;
28 import java.util.*;
29 import java.lang.*;
30 import java.io.*;
31 import org.jboss.test.testbean.interfaces.StatelessSessionHome;
32 import org.jboss.test.testbean.interfaces.StatelessSession;
33 import org.jboss.test.testbean.interfaces.EnterpriseEntityHome;
34 import org.jboss.test.testbean.interfaces.EnterpriseEntity;
35 import javax.ejb.DuplicateKeyException JavaDoc;
36 import javax.ejb.Handle JavaDoc;
37 import javax.ejb.EJBMetaData JavaDoc;
38 import javax.ejb.EJBHome JavaDoc;
39 import javax.ejb.HomeHandle JavaDoc;
40
41 public class slsb
42 {
43     public static void main(String JavaDoc[] args)
44     {
45         try
46         {
47             Properties p = new Properties();
48             
49             p.put(Context.INITIAL_CONTEXT_FACTORY,
50                   "org.jnp.interfaces.NamingContextFactory");
51             p.put(Context.PROVIDER_URL, "10.10.10.13:1100,10.10.10.14:1100");
52             // p.put(Context.PROVIDER_URL, "localhost:1100");
53
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
54             InitialContext ctx = new InitialContext(p);
55             
56             StatelessSessionHome statelessSessionHome = (StatelessSessionHome) ctx.lookup("nextgen.StatelessSession");
57             EnterpriseEntityHome cmpHome = (EnterpriseEntityHome)ctx.lookup("nextgen.EnterpriseEntity");
58             StatelessSession statelessSession = statelessSessionHome.create();
59             EnterpriseEntity cmp = null;
60             try
61             {
62                cmp = cmpHome.findByPrimaryKey("bill");
63             }
64             catch (Exception JavaDoc ex)
65             {
66                cmp = cmpHome.create("bill");
67             }
68             int count = 0;
69             while (true)
70             {
71                System.out.println(statelessSession.callBusinessMethodB());
72                try
73                {
74                   cmp.setOtherField(count++);
75                }
76                catch (Exception JavaDoc ex)
77                {
78                   System.out.println("exception, trying to create it: " + ex);
79                   cmp = cmpHome.create("bill");
80                   cmp.setOtherField(count++);
81                }
82                System.out.println("Entity: " + cmp.getOtherField());
83                Thread.sleep(2000);
84             }
85         }
86         catch (NamingException nex)
87         {
88            if (nex.getRootCause() != null)
89            {
90               nex.getRootCause().printStackTrace();
91            }
92         }
93         catch (Exception JavaDoc ex)
94         {
95             ex.printStackTrace();
96         }
97     }
98 }
99
Popular Tags