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 ObtainMetadata extends MetadataSupportStrategy{
22
23 private static MetadataSupportStrategy instance = new ObtainMetadata();
24
25 private ObtainMetadata() {
26 super();
27 }
28
29 public Object getMetadata(String metadataType, String invokeMethod, BaseActionSupport action) {
30 logger.info("Current Strategy:{}",this.getClass().getName());
31 logger.info("get metadata type : " + metadataType + ", invoke : " + invokeMethod);
32 JSONObject metadataObj;
33
34
35 boolean calledInvokedMethod = false;
36 JSONObject returned = new JSONObject();
37
38 if (!callInitInvokedMethod(invokeMethod, action)) {
39 Method method = ReflectionUtils.findMethod(action.getClass(), invokeMethod);
40 if (method != null) {
41 try {
42 ReflectionUtils.invokeMethod(method, action);
43 calledInvokedMethod = true;
44 } catch (Exception e) {
45 e.printStackTrace();
46 }
47 }else{
48
49 calledInvokedMethod = true;
50 }
51 }
52
53 metadataObj = getMetadataFromResource(invokeMethod, action);
54
55
56 if (metadataObj.containsKey("success") && metadataObj.getBoolean("success") == false) {
57 returned = metadataObj;
58 } else if (metadataObj.get("component").equals("iframe")) {
59 returned.accumulate("metadata", metadataObj);
60 } else {
61 metadataObj = decorateMetadata(metadataObj, invokeMethod, action);
62 returned.accumulate("metadata", metadataObj);
63
64
65 decorateWithData(calledInvokedMethod, metadataObj, invokeMethod, action, returned);
66 }
67 return returned;
68
69 }
70
71 public static MetadataSupportStrategy getInstance() {
72 return instance;
73 }
74 }