FileDocCategorySizeDatePackage
Main.javaAPI DocJBoss 4.2.13738Fri Jul 13 20:55:28 BST 2007org.jboss.tutorial.embeddedwar

Main

public class Main extends Object
Comment
author
Bill Burke
version
$Revision: 60233 $

Fields Summary
Constructors Summary
Methods Summary
public static java.net.URLgetArchiveURL()

      // Usually you would hardcode your URL.  This is just a way to make it easier for the tutorial
      // code to configure where the resource is.
      URL res = Thread.currentThread().getContextClassLoader().getResource("META-INF/persistence.xml");
      return EJB3StandaloneDeployer.getContainingUrlFromResource(res, "META-INF/persistence.xml");
   
public static javax.naming.InitialContextgetInitialContext()

      Hashtable props = getInitialContextProperties();
      return new InitialContext(props);
   
private static java.util.HashtablegetInitialContextProperties()

      Hashtable props = new Hashtable();
      props.put("java.naming.factory.initial", "org.jnp.interfaces.LocalOnlyContextFactory");
      props.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
      return props;
   
public static voidmain(java.lang.String[] args)

      EJB3StandaloneBootstrap.boot(null);

      EJB3StandaloneDeployer deployer = new EJB3StandaloneDeployer();
      URL archive = getArchiveURL();
      deployer.getArchives().add(archive);

      // need to set the InitialContext properties that deployer will use
      // to initial EJB containers
      deployer.setJndiProperties(getInitialContextProperties());

      deployer.create();
      deployer.start();

      InitialContext ctx = getInitialContext();
      CustomerDAOLocal local = (CustomerDAOLocal)ctx.lookup("CustomerDAOBean/local");
      CustomerDAORemote remote = (CustomerDAORemote)ctx.lookup("CustomerDAOBean/remote");

      System.out.println("----------------------------------------------------------");
      System.out.println("This is the archive deployed from: ");
      System.out.print("    ");
      System.out.println(archive);

      int id = local.createCustomer("Gavin");
      Customer cust = local.findCustomer(id);
      System.out.println("Successfully created and found Gavin from @Local interface");

      id = remote.createCustomer("Emmanuel");
      cust = remote.findCustomer(id);
      System.out.println("Successfully created and found Emmanuel from @Remote interface");
      System.out.println("----------------------------------------------------------");

      deployer.stop();
      deployer.destroy();