KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > dirbyresource > Main


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.dirbyresource;
8
9 import java.util.Hashtable JavaDoc;
10 import javax.naming.InitialContext JavaDoc;
11 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
12 import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
13
14 /**
15  * Comment
16  *
17  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
18  * @version $Revision: 1.1 $
19  */

20 public class Main
21 {
22    public static void main(String JavaDoc[] args) throws Exception JavaDoc
23    {
24       EJB3StandaloneBootstrap.boot(null);
25
26       EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer();
27       deployer.getDeployDirsByResource().add("META-INF/persistence.xml");
28
29       // need to set the InitialContext properties that deployer will use
30
// to initial EJB containers
31
deployer.setJndiProperties(getInitialContextProperties());
32
33       deployer.create();
34       deployer.start();
35
36       InitialContext JavaDoc ctx = getInitialContext();
37       CustomerDAOLocal local = (CustomerDAOLocal)ctx.lookup(CustomerDAOLocal.class.getName());
38       CustomerDAORemote remote = (CustomerDAORemote)ctx.lookup(CustomerDAORemote.class.getName());
39
40       System.out.println("----------------------------------------------------------");
41
42       int id = local.createCustomer("Gavin");
43       Customer cust = local.findCustomer(id);
44       System.out.println("Successfully created and found Gavin from @Local interface");
45
46       id = remote.createCustomer("Emmanuel");
47       cust = remote.findCustomer(id);
48       System.out.println("Successfully created and found Emmanuel from @Remote interface");
49       System.out.println("----------------------------------------------------------");
50
51       deployer.stop();
52       deployer.destroy();
53    }
54
55    public static InitialContext JavaDoc getInitialContext() throws Exception JavaDoc
56    {
57       Hashtable JavaDoc props = getInitialContextProperties();
58       return new InitialContext JavaDoc(props);
59    }
60
61    private static Hashtable JavaDoc getInitialContextProperties()
62    {
63       Hashtable JavaDoc props = new Hashtable JavaDoc();
64       props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
65       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
66       return props;
67    }
68 }
69
Popular Tags