端到端J2ME应用开发实例——介绍Smart Ticket

来源: 作者: 2006-10-12 出处:pcdog.com

access  j2me  java  xml  解决方案  
上一页 1 2 3 4 5 6 下一页 

下图展示了整体 MVC 和界面的体系结构:

端到端J2ME应用开发实例——介绍Smart Ticket(图五)

实现模式

MVC 和界面模式定义了应用程序的整体结构。另外,Smart Ticket 也列出了一些重要的行为模式,这些模式能帮助开发人员提高效率。

处理程序链

The RemoteModelProxy 类把每一个请求动作都委托给 handler 类链,以便透明地解决 RMS 串行化和 HTTP 连接的异常管道。 链接的处理程序体系结构基于实现它的 RequestHandler接口和 RemoteModelRequestHandler 抽象类:

public interface RequestHandler {
    RequestHandler getNextHandler();
    void init() throws ApplicationException;
    void destroy() throws ApplicationException;
}
abstract public class RemoteModelRequestHandler 
  implements RequestHandler, RemoteModel {
  private RemoteModelRequestHandler nextHandler;
  private Preferences preferences;
  protected static ProgressObserver progressObserver;
  public RemoteModelRequestHandler(
      RemoteModelRequestHandler nextHandler) {
    this.nextHandler = nextHandler;
  }
  public RequestHandler getNextHandler() {
    return nextHandler;
  }
  public void init() throws ApplicationException {
    if (nextHandler != null) {
      nextHandler.init();
    }
    return;
  }
  public void destroy() throws ApplicationException {
    if (nextHandler != null) {
      nextHandler.destroy();
    }
    return;
  }
  public void login(String userName, String password) 
      throws ModelException, ApplicationException {
    getRemoteModelRequestHandler().login(userName, password);
    return;
  } 
  public void createAccount(AccountInfo accountInfo) 
                            throws ModelException, 
                            ApplicationException {
    getRemoteModelRequestHandler().createAccount(accountInfo);
    return;
  }
  // Other action methods declared in RemoteModel
  // ...
}
            

具体的 handler 类扩展了 RemoteModelRequestHandler 类。嵌套的构造函数建立一个处理程序链。Smart Ticket 启用了两个处理程序类:RMSCacheHandlerHTTPCommunicationHandler。因此链接装配方法如下:

public class RemoteModelProxy extends ModelObjectLoader 
                              implements RemoteModel {
  private RemoteModelRequestHandler requestHandlerChain;
  private Preferences preferences = null;
  private Hashtable movies = new Hashtable();
  public RemoteModelProxy(String serviceURL) 
                          throws ApplicationException {
    requestHandlerChain =
      new RMSCacheHandler(
        new HTTPCommunicationHandler(null, serviceURL));
    return;
  }
  // ...
  public Movie getMovie(String movieKey) 
                        throws ModelException, 
                        ApplicationException {
    Movie movie = (Movie) movies.get(movieKey);
    if (movie == null) {
      movie = requestHandlerChain.getMovie(movieKey);
      movies.put(movieKey, movie);
    } 
    return movie;
  } 
  // Other methods ...
}
            

更多内容请看PCdog.com--J2ME安装配置  j2me开发  J2ME开发基础专题
上一页 1 2 3 4 5 6 下一页 
上一篇:如何组建J2EE开发团队
下一篇:minij2ee常见问题(FAQ)