KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > embeddedwar > 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.embeddedwar;
8
9 import java.net.URL JavaDoc;
10 import java.util.Hashtable JavaDoc;
11 import javax.naming.InitialContext JavaDoc;
12 import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
13 import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
14
15 /**
16  * Comment
17  *
18  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
19  * @version $Revision: 1.1 $
20  */

21 public class Main
22 {
23    public static void main(String JavaDoc[] args) throws Exception JavaDoc
24    {
25       EJB3StandaloneBootstrap.boot(null);
26
27       EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer();
28       URL JavaDoc archive = getArchiveURL();
29       deployer.getArchives().add(archive);
30
31       // need to set the InitialContext properties that deployer will use
32
// to initial EJB containers
33
deployer.setJndiProperties(getInitialContextProperties());
34
35       deployer.create();
36       deployer.start();
37
38       InitialContext JavaDoc ctx = getInitialContext();
39       CustomerDAOLocal local = (CustomerDAOLocal)ctx.lookup(CustomerDAOLocal.class.getName());
40       CustomerDAORemote remote = (CustomerDAORemote)ctx.lookup(CustomerDAORemote.class.getName());
41
42       System.out.println("----------------------------------------------------------");
43       System.out.println("This is the archive deployed from: ");
44       System.out.print(" ");
45       System.out.println(archive);
46
47       int id = local.createCustomer("Gavin");
48       Customer cust = local.findCustomer(id);
49       System.out.println("Successfully created and found Gavin from @Local interface");
50
51       id = remote.createCustomer("Emmanuel");
52       cust = remote.findCustomer(id);
53       System.out.println("Successfully created and found Emmanuel from @Remote interface");
54       System.out.println("----------------------------------------------------------");
55
56       deployer.stop();
57       deployer.destroy();
58    }
59
60    public static URL JavaDoc getArchiveURL() throws Exception JavaDoc
61    {
62       // Usually you would hardcode your URL. This is just a way to make it easier for the tutorial
63
// code to configure where the resource is.
64
URL JavaDoc res = Thread.currentThread().getContextClassLoader().getResource("META-INF/persistence.xml");
65       return EJB3StandaloneDeployer.getContainingUrlFromResource(res, "META-INF/persistence.xml");
66    }
67
68    public static InitialContext JavaDoc getInitialContext() throws Exception JavaDoc
69    {
70       Hashtable JavaDoc props = getInitialContextProperties();
71       return new InitialContext JavaDoc(props);
72    }
73
74    private static Hashtable JavaDoc getInitialContextProperties()
75    {
76       Hashtable JavaDoc props = new Hashtable JavaDoc();
77       props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
78       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
79       return props;
80    }
81 }
82
Popular Tags