ejbcommandtarget.java

来自「100多M的J2EE培训内容」· Java 代码 · 共 43 行

JAVA
43
字号

package examples.command;

import javax.rmi.PortableRemoteObject;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.rmi.RemoteException;

public class EJBCommandTarget implements CommandTarget {

    private CommandServerHome serverHome;

        public EJBCommandTarget()
        {
            try {
                Context ctx = new InitialContext(System.getProperties());
                Object obj = ctx.lookup("CommandServer");
                System.out.println(obj);
                this.serverHome = (CommandServerHome) PortableRemoteObject.narrow(obj, CommandServerHome.class );
            } catch (NamingException e) {
                e.printStackTrace();
            } catch (ClassCastException e) {
                e.printStackTrace();
            }
        }

    public Command executeCommand(Command aCommand) throws CommandException
    {

        try {
            CommandServer aCommandServer = serverHome.create();
            aCommand = aCommandServer.executeCommand(aCommand);
            return aCommand;

        } catch (Exception e)
        {
            throw new CommandException(e);
        }
      }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?