1
2
3
4
5 package gboat2.base.core.web.md;
6
7 import gboat2.base.core.GBoatClassLoader;
8 import gboat2.base.core.web.BaseActionSupport;
9
10 import java.net.URL;
11 import java.util.Iterator;
12 import java.util.LinkedList;
13 import java.util.List;
14
15 import net.sf.json.JSONObject;
16
17 import org.osgi.framework.Bundle;
18
19
20
21
22
23
24
25
26
27
28 public class MetadataHandlerChain {
29
30 private static List<IFileFilter> fileFilters = new LinkedList<IFileFilter>();
31 private static List<MetadataHandler> handlers = new LinkedList<MetadataHandler>();
32 static {
33
34 fileFilters.add(new ExtendMethodHandler());
35 fileFilters.add(new MultiFileModelHandler());
36 fileFilters.add(new SingleFileModelHandler());
37 fileFilters.add(new IFrameHandler());
38
39
40 handlers.add(new DebugHandler());
41 handlers.add(new IFrameHandler());
42 handlers.add(new CacheHandler());
43 handlers.add(new DbConfigHandler());
44 handlers.add(new MultiFileModelHandler());
45 handlers.add(new SingleFileModelHandler());
46 handlers.add(new ExtendMetadataHandler());
47 }
48
49 private String filePath;
50
51 private Bundle bundle;
52
53 private BaseActionSupport action;
54
55 private String invokeMethod;
56
57 private Iterator<MetadataHandler> it = handlers.iterator();
58
59 public MetadataHandlerChain(BaseActionSupport action,String invokeMethod){
60 this.invokeMethod = invokeMethod;
61 this.action = action;
62 }
63
64 public static MetadataHandlerChain getHandlerChain(BaseActionSupport action,String invokeMethod) {
65 return new MetadataHandlerChain(action,invokeMethod);
66 }
67
68 public MetadataHandler getHandler(){
69 return (MetadataHandler)it.next();
70 }
71
72 public JSONObject doHandler(JSONObject object,URL url,Bundle bundle) {
73 if(it.hasNext()){
74 return it.next().parseMetadata(object, url, bundle, this);
75 }
76 return object;
77 }
78
79 public MetadataHandlerChain clone(MetadataHandlerChain chain){
80 return new MetadataHandlerChain(chain.getAction(),chain.getInvokeMethod());
81 }
82
83 public String getFilePath() {
84 return filePath;
85 }
86
87 public void setFilePath(String filePath) {
88 this.filePath = filePath;
89 }
90
91 public Bundle getBundle() {
92 if(bundle==null){
93 bundle = GBoatClassLoader.getInstance().getBundle(action.getClass().getPackage().getName());
94 }
95 return bundle;
96 }
97
98 public BaseActionSupport getAction() {
99 return action;
100 }
101
102 public String getInvokeMethod() {
103 return invokeMethod;
104 }
105
106 public static List<MetadataHandler> getHandlers() {
107 return handlers;
108 }
109
110 public static List<IFileFilter> getFileFilters() {
111 return fileFilters;
112 }
113 }