1
2
3
4
5 package gboat2.base.core.web;
6
7 import java.lang.reflect.Method;
8
9 import net.sf.json.JSONObject;
10
11 import org.springframework.util.ReflectionUtils;
12
13
14
15
16
17
18
19
20
21 public class ObtainData extends MetadataSupportStrategy{
22
23 private static MetadataSupportStrategy instance = new ObtainData();
24
25 private ObtainData() {
26 super();
27 }
28
29 public Object getMetadata(String metadataType, String invokeMethod, BaseActionSupport action) {
30 logger.info("执行 [{}] 方法,数据类型 [{}],使用的策略类 [{}]", invokeMethod, metadataType, getClass().getName());
31 JSONObject metadataObj;
32
33
34 boolean calledInvokedMethod = false;
35 JSONObject returned = new JSONObject();
36
37 if (!callInitInvokedMethod(invokeMethod, action)) {
38 Method method = ReflectionUtils.findMethod(action.getClass(), invokeMethod);
39 if (method != null) {
40 try {
41 ReflectionUtils.invokeMethod(method, action);
42 calledInvokedMethod = true;
43 } catch (Exception e) {
44 e.printStackTrace();
45 }
46 }else{
47
48 calledInvokedMethod = true;
49 }
50 }
51
52 try {
53 metadataObj = getMetadataFromResource(invokeMethod, action);
54 } catch (MetadataException e) {
55 metadataObj = new JSONObject();
56 }
57 decorateWithData(calledInvokedMethod, metadataObj, invokeMethod, action, returned);
58
59 if (returned != null) {
60 logger.debug(returned.toString());
61 }
62 return returned;
63 }
64
65
66
67
68 public static MetadataSupportStrategy getInstance() {
69 return instance;
70 }
71
72 }