EJBCommandTarget.java
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:1k
源码类别:

Java编程

开发平台:

Java

  1. package examples.command;
  2. import javax.rmi.PortableRemoteObject;
  3. import javax.ejb.CreateException;
  4. import javax.naming.Context;
  5. import javax.naming.InitialContext;
  6. import javax.naming.NamingException;
  7. import java.rmi.RemoteException;
  8. public class EJBCommandTarget implements CommandTarget {
  9.     private CommandServerHome serverHome;
  10.         public EJBCommandTarget()
  11.         {
  12.             try {
  13.                 Context ctx = new InitialContext(System.getProperties());
  14.                 Object obj = ctx.lookup("CommandServer");
  15.                 System.out.println(obj);
  16.                 this.serverHome = (CommandServerHome) PortableRemoteObject.narrow(obj, CommandServerHome.class );
  17.             } catch (NamingException e) {
  18.                 e.printStackTrace();
  19.             } catch (ClassCastException e) {
  20.                 e.printStackTrace();
  21.             }
  22.         }
  23.     public Command executeCommand(Command aCommand) throws CommandException
  24.     {
  25.         try {
  26.             CommandServer aCommandServer = serverHome.create();
  27.             aCommand = aCommandServer.executeCommand(aCommand);
  28.             return aCommand;
  29.         } catch (Exception e)
  30.         {
  31.             throw new CommandException(e);
  32.         }
  33.       }
  34. }