---
title: "GWT涂鸦(3)——Spring Roo Project"
author: "ratlsun"
date: "2010-12-27T21:22:23Z"
tags: []
categories: ["Web前端"]
slug: "gwt-3-spring-roo-project"
draft: false
lastmod: "2010-12-29T21:13:30Z"
id: 853318
url: "https://ratlsun.iteye.com/blog/853318"
---

## The module XML file

### 位置：src/main/java/包/applicationScaffold.gwt.xml

由于Roo的项目必须是maven构建的，所以有固定的src目录结构；名字也是自动生成的（@question希望在使用Roo命令时可以修改 ）；

### 内容：

模块：applicationScaffold

继承User  
继承Standard theme

继承Activity

继承Place

继承Inject ：gwt的依赖注入模块，项目名字叫[Gin](http://code.google.com/p/google-gin/) ，是基于[Guice](http://code.google.com/p/google-guice/) 的

继承RequestFactory ：可以理解为客户端entity管理

继承CellView

继承Text

继承Logging

entry-point：\*\*.client.scaffold.Scaffold

源client  
源shared

公共public

 

下面配置表示对InjectorWrapper的注入会根据客户端不同而采用Desktop或者Mobile的InjectorWapper

 

```
  <define-property name="mobile.user.agent" values="mobilesafari, none"/>
  
  <property-provider name="mobile.user.agent">
  
  <![CDATA[
  		var ua = navigator.userAgent.toLowerCase();

        if (ua.indexOf("webkit") != -1 && ua.indexOf("mobile") != -1) {
        return "mobilesafari";
        }

        var isMobile;

        // Look for the m as a url argument
        if (isMobile == null) {
        var args = location.search;
        var startMobile = args.indexOf("m");
        if (startMobile >= 0) {
          var mobile = args.substring(startMobile);
          var begin = mobile.indexOf("=") + 1;
          var end = mobile.indexOf("&");
          if (end == -1) {
            end = mobile.length;
          }
          isMobile = mobile.substring(begin, end);
        }
        }

        if (isMobile){
        return "mobilesafari";
        }

        return "none";
  ]]>
  
  </property-provider>
```

 

## The Host Page

### 位置：src\\main\\webapp\\ApplicationScaffold.html

### 内容：

meta tag  
css: **没有指定css**  
js: applicationScaffold/applicationScaffold.nocache.js

span: 显示loading...

 

 

 

 

## The Entry Point Class

### 位置：src/包.client.scaffold.Scaffold

### 内容：

实现EntryPoint.onModuleLoad()：通过DesktopInjectorWrapper得到DesktopInjector得到ScaffoldDesktopApp 对象并调用该对象的run方法。

 

 

## The Main App Class

### 位置：src/包.client.scaffold.ScaffoldDesktopApp(ScaffoldMobileApp)

### 内容：

1. 通过正常Inject注入的属性包括ScaffoldDesktopShell shell，placeHistoryFactory，applicationMasterActivities，applicationDetailsActivities。
2. 通过BindingModule注入的属性包括eventBus，ApplicationRequestFactory requestFactory，placeController；由于这些类需要通过GWT来create，所以需要用到BindingModule设置。
3. 定义run 方法作为整个app的入口。

 

## The Request Factory

### 位置：src/包.client.managed.request

### 内容：

1. RequestFactory &lt;|-- ApplicationRequestFactory 接口：Request的工厂，每个Entity都应该有对应的Request创建方法在这个工厂里，同时它还包括了UserInformationRequest（User模块），LoggingRequest（Logging模块）；。
2. RequestContext &lt;|--\*Request 接口：定义所有在客户端可以访问的entity\*的crud+finding类方法。
3. EntityProxy &lt;|--\*Proxy 接口：对entity\*在客户端的代理，类似DTO。
4. ApplicationEntityTypesProcessor&lt;T&gt; @TODO 。

 

## The IoC (Gin)

### 位置：src../包.client.scaffold.ioc

### 内容：

1. InjectWapper接口（包含2个实现类 [DesktopInjectorWrapper /]() MobileInjectorWrapper）：Inject类的工厂；
2. ScaffoldInjector接口，继承自Ginjector（包含2个子接口DesktopInjector/MobileInjector）：Inject类，使用指定的Binding Module类来生成依赖注入后的对象，由于客户端无法使用Guice的Inject的getInstance方法，所以在Gin中要定义Inject接口，并通过@GinModules定义具体的Binding Module；
3. ScaffoldModule类，继承自AbstractGinModule：Binding Module类，通过config函数定义依赖关系。