KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > archivebyresource > 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.archivebyresource;
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.getArchivesByResource().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       System.out.println("We will search for all archives with META-INF/persistence.xml to deploy them.");
42       System.out.println(" ");
43
44       int id = local.createCustomer("Gavin");
45       Customer cust = local.findCustomer(id);
46       System.out.println("Successfully created and found Gavin from @Local interface");
47
48       id = remote.createCustomer("Emmanuel");
49       cust = remote.findCustomer(id);
50       System.out.println("Successfully created and found Emmanuel from @Remote interface");
51       System.out.println("----------------------------------------------------------");
52
53       deployer.stop();
54       deployer.destroy();
55    }
56
57    public static InitialContext JavaDoc getInitialContext() throws Exception JavaDoc
58    {
59       Hashtable JavaDoc props = getInitialContextProperties();
60       return new InitialContext JavaDoc(props);
61    }
62
63    private static Hashtable JavaDoc getInitialContextProperties()
64    {
65       Hashtable JavaDoc props = new Hashtable JavaDoc();
66       props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
67       props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
68       return props;
69    }
70 }
71
Popular Tags