基于Spring和EJB的JCF通用调用框架的研究与实现(4)

 
由上面的代码看到, EjbDelegate 只是命令的传递者而已,真是执行这个操作的地方是 SLSBexecute 方法。现在看看在 SLSBexecute 方法中到底做了些什么,如下面的代码所示:
public Response execute(Request request) throws Exception { <o:p></o:p>
       logger .debug( "SessionFacade execute" ); <o:p></o:p>
       Response resp = new Response(); <o:p></o:p>
       if (request == null ) { <o:p></o:p>
           resp.setReturnCode(Response. APPLICATION_LEVEL_ERROR ); <o:p></o:p>
           resp.getState().setErrCode( "request is Null" ); <o:p></o:p>
           return resp; <o:p></o:p>
       } <o:p></o:p>
       String serviceName = request.getServiceName(); <o:p></o:p>
       if (serviceName == null ) { <o:p></o:p>
           resp.setReturnCode(Response. APPLICATION_LEVEL_ERROR ); <o:p></o:p>
           resp.getState().setErrCode( "serviceName is Null" ); <o:p></o:p>
           return resp; <o:p></o:p>
       } <o:p></o:p>
       BaseProcessor processor = (BaseProcessor) getBeanFactory().getBean(serviceName); <o:p></o:p>
       try { <o:p></o:p>
           processor.doActivities(request, resp); <o:p></o:p>
       } catch (GoOnException e) { <o:p></o:p>
           e.printStackTrace(); <o:p></o:p>
       } catch (Exception e) { <o:p></o:p>
          e.printStackTrace(); <o:p></o:p>
          // 抛出特定的异常。 <o:p></o:p>
          try { <o:p></o:p>
              super .getSessionContext().setRollbackOnly(); <o:p></o:p>
          } catch (Exception e1) { <o:p></o:p>
             e1.printStackTrace(); <o:p></o:p>
           throw new EJBException( " 事务回滚错误 , 抛出 EJBException." ); <o:p></o:p>
           } <o:p></o:p>
        } <o:p></o:p>
       if (resp.getState().isOK()) { <o:p></o:p>
           resp.setReturnCode(Response. SUCCESS ); <o:p></o:p>
       } <o:p></o:p>
       return resp; <o:p></o:p>
    }
        SLSBexecute 方法
<o:p> </o:p>
可见 SLSB 也不是最终调用 Command 的地方,它只是获得了 Spring 的上下文,在 Spring 的上下文中查找名字叫 serviceNameProcessor ,在 SLSB 中如何获得 Spring 的上下文在 SpringEJB 的支持一节中再做介绍。 BaseProcessorProcessor 的基类,它实现了 InitializingBean, BeanNameAware, BeanFactoryAware, Processor 接口,在 Processor 接口中有个方法 doActivities ,在这里调用 Commandexecute 方法。如果在调用 Processor 的过程中发生了异常,则要调用 SLSBsetRollbackOnly 方法进行回滚。
Command 实现了 Component 接口, Component 代表了 Spring 管理的所有的组件。 Init 方法是在执行 execute 之前做一些相关的初始化工作, fini 方法在 execute 方法执行后做相关的收尾工作。
public interface Component extends Serializable,BeanNameAware { <o:p></o:p>
    // 初始化接口 <o:p></o:p>
    public abstract void init(String parameter) throws Exception; <o:p></o:p>
    public abstract void execute(Map params, Map response) throws Exception; <o:p></o:p>
    // 析构接口 <o:p></o:p>
    public abstract void fini() throws Exception; <o:p></o:p>
    public ErrorHandler getErrorHandler(); <o:p></o:p>
     public String getBeanName(); <o:p></o:p>
    }
Component 接口
<o:p> </o:p>
POJODelegate 中,由 BizDelegate 传过来的请求就在 POJODelegate 内完成。
    public Response execute(Request request) throws Exception { <o:p></o:p>
       logger .debug( "POJODelegate execute" ); <o:p></o:p>
       Response resp = new Response(); <o:p></o:p>
       if (request == null ) { <o:p></o:p>
           resp.setReturnCode(Response. APPLICATION_LEVEL_ERROR ); <o:p></o:p>
           resp.getState().setErrCode( "POJODelegate REQUEST IS NULL" ); <o:p></o:p>
           return resp; <o:p></o:p>
       } <o:p></o:p>
       String serviceName = request.getServiceName(); <o:p></o:p>
       if (serviceName == null ) { <o:p></o:p>
           resp.setReturnCode(Response. APPLICATION_LEVEL_ERROR ); <o:p></o:p>
           resp.getState().setErrCode( "POJODelegate SERVICENAME IS NULL" ); <o:p></o:p>
           return resp; <o:p></o:p>
       } <o:p></o:p>
           BaseProcessor processor = (BaseProcessor) ContextServiceLocator <o:p></o:p>
                  .getInstance().getBean(serviceName); <o:p></o:p>
           processor.doActivities(request, resp); <o:p></o:p>
       if (resp.getState().isOK()) { <o:p></o:p>
           resp.setReturnCode(Response. SUCCESS ); <o:p></o:p>
       } <o:p></o:p>
       return resp; <o:p></o:p>
    }
POJODelegateexecute 方法
  
   POJODelegateSpring 的上下文中得到相应的 Processor ,然后交给 Processor 去执行。采用 POJODelegate 的方式,在系统启动的时候,要对 Spring 做初始化设置,如在得到 Spring 的配置文件的地址中,可以用 ClassPathXmlApplicationContextFileSystemXmlApplicationContext 等进行初始化。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值