View Javadoc
1   /**
2    * Copyright By Grandsoft Company Limited.  
3    * 2012-2-16 下午03:34:12
4    */
5   package gboat2.base.core.web;
6   
7   import gboat2.base.bridge.debug.DefaultDebugHook;
8   import gboat2.base.bridge.util.ClassHelper;
9   
10  import java.util.List;
11  
12  import net.sf.json.JSONArray;
13  import net.sf.json.JSONObject;
14  
15  /**
16   *  
17   * 拆分元数据
18   * @author zhangxj-a
19   * @since jdk1.6
20   * @date 2013-5-21
21   *  
22   */
23  public class MetadataList extends SplitMetadataStrategy {
24  
25  	private static SplitMetadataStrategy instance = new MetadataList();
26  
27  	private MetadataList() {
28  		super();
29  	}
30  
31  	public JSONObject decorateMetadata(JSONObject returned, String invokeMethod, BaseActionSupport action) {
32  		//list方法需要附加ListDomain或Domain的fields
33  		Class<?> domain;
34  		domain = action.getDomainClassAnnotationedForList();
35  		if (domain == null) {
36  			throw new RuntimeException("no Domain or ListDomain annotation exist.");
37  		}
38  		List<String> fields = ClassHelper.getFieldNames(domain);
39  
40  		JSONArray operas = (JSONArray) returned.get("operations");
41  		if (operas == null) {
42  			operas = new JSONArray();
43  		} else {
44  			fields.add("operations");
45  		}
46  		returned.accumulate("fields", fields.toArray());
47  		//增加系统级操作
48  		if (DefaultDebugHook.getInstance().devMode) {
49  			//增加设计、属性按钮
50  			operas.addAll(getSystemButtonsJSON(action, invokeMethod));
51  		}
52  
53  		//获取页面级全局操作操作(比如“添加记录”这种定义在组件上的按钮,而不是数据列表中的“编辑”和“删除”等),并进行权限过滤
54  		operas = filtMetaOperas(operas, action);
55  		returned.put("operations", operas);
56  
57  		return returned;
58  	}
59  
60  	public static SplitMetadataStrategy getInstance() {
61  		return instance;
62  	}
63  }