4
4
import java .lang .reflect .Method ;
5
5
import java .lang .reflect .Modifier ;
6
6
import java .util .ArrayList ;
7
+ import java .util .Collections ;
7
8
import java .util .List ;
8
9
import java .util .Map ;
9
10
@@ -49,7 +50,7 @@ public static ActionInfo createInfo(Class<?> type) {
49
50
ActionInfo ai = new ActionInfo ();
50
51
evalEncoding (ai , Mirror .getAnnotationDeep (type , Encoding .class ));
51
52
evalHttpAdaptor (ai , Mirror .getAnnotationDeep (type , AdaptBy .class ));
52
- evalActionFilters (ai , Mirror .getAnnotationDeep (type , Filters .class ));
53
+ evalActionFilters (ai , Mirror .getAnnotationDeep (type , Filters .class ), null );
53
54
evalPathMap (ai , Mirror .getAnnotationDeep (type , PathMap .class ));
54
55
evalOk (ai , Mirror .getAnnotationDeep (type , Ok .class ));
55
56
evalFail (ai , Mirror .getAnnotationDeep (type , Fail .class ));
@@ -73,128 +74,13 @@ public static ActionInfo createInfo(Method method) {
73
74
ActionInfo ai = new ActionInfo ();
74
75
evalEncoding (ai , Mirror .getAnnotationDeep (method , Encoding .class ));
75
76
evalHttpAdaptor (ai , Mirror .getAnnotationDeep (method , AdaptBy .class ));
76
- evalActionFilters (ai , Mirror .getAnnotationDeep (method , Filters .class ));
77
+ evalActionFilters (ai , Mirror .getAnnotationDeep (ai . getModuleType (), Filters . class ), Mirror . getAnnotationDeep ( method , Filters .class ));
77
78
evalActionChainMaker (ai , Mirror .getAnnotationDeep (method , Chain .class ));
78
79
evalHttpMethod (ai , method , Mirror .getAnnotationDeep (method , Execute .class ), Mirror .getAnnotationDeep (method , DefaultExecute .class ));
79
80
ai .setMethod (method );
80
81
return ai ;
81
82
}
82
83
83
- // public static Set<Class<?>> scanModules(Ioc ioc, Class<?> mainModule) {
84
- // Modules ann = mainModule.getAnnotation(Modules.class);
85
- // boolean scan = null == ann ? true : ann.scanPackage();
86
- // // 准备扫描列表
87
- // Set<Class<?>> forScans = new HashSet<Class<?>>();
88
- //
89
- // // 准备存放模块类的集合
90
- // Set<Class<?>> modules = new HashSet<Class<?>>();
91
- //
92
- // // 添加主模块,简直是一定的
93
- // forScans.add(mainModule);
94
- //
95
- // // 根据配置,扩展扫描列表
96
- // if (null != ann) {
97
- // // 指定的类,这些类可以作为种子类,如果 ann.scanPackage 为 true 还要递归搜索所有子包
98
- // for (Class<?> module : ann.value()) {
99
- // forScans.add(module);
100
- // }
101
- //
102
- // // 如果定义了扩展扫描接口 ...
103
- // for (String str : ann.by()) {
104
- // ModuleScanner ms;
105
- // // 扫描器来自 Ioc 容器
106
- // if (str.startsWith("ioc:")) {
107
- // String nm = str.substring("ioc:".length());
108
- // ms = ioc.get(ModuleScanner.class, nm);
109
- // }
110
- // // 扫描器直接无参创建
111
- // else {
112
- // try {
113
- // Class<?> klass = Lang.loadClass(str);
114
- // Mirror<?> mi = Mirror.me(klass);
115
- // ms = (ModuleScanner) mi.born();
116
- // }
117
- // catch (ClassNotFoundException e) {
118
- // throw Lang.wrapThrow(e);
119
- // }
120
- // }
121
- // // 执行扫描,并将结果计入搜索结果
122
- // Collection<Class<?>> col = ms.scan();
123
- // if (null != col)
124
- // for (Class<?> type : col) {
125
- // if (isModule(type)) {
126
- // modules.add(type);
127
- // }
128
- // }
129
- // }
130
- //
131
- // // 扫描包,扫描出的类直接计入结果
132
- // if (ann.packages() != null && ann.packages().length > 0) {
133
- // for (String packageName : ann.packages()) {
134
- // scanModuleInPackage(modules, packageName);
135
- // }
136
- // }
137
- // }
138
- //
139
- // for (Class<?> type : forScans) {
140
- // // mawm 为了兼容maven,根据这个type来加载该type所在jar的加载
141
- // try {
142
- // URL location = type.getProtectionDomain().getCodeSource().getLocation();
143
- // if (log.isDebugEnabled())
144
- // log.debugf("module class location '%s'", location);
145
- // }
146
- // catch (NullPointerException e) {
147
- // // Android上无法拿到getProtectionDomain,just pass
148
- // }
149
- // Scans.me().registerLocation(type);
150
- // }
151
- //
152
- // // 执行扫描
153
- // for (Class<?> type : forScans) {
154
- // // 扫描子包
155
- // if (scan) {
156
- // scanModuleInPackage(modules, type.getPackage().getName());
157
- // }
158
- // // 仅仅加载自己
159
- // else {
160
- // if (isModule(type)) {
161
- // if (log.isDebugEnabled())
162
- // log.debugf(" > add '%s'", type.getName());
163
- // modules.add(type);
164
- // } else if (log.isTraceEnabled()) {
165
- // log.tracef(" > ignore '%s'", type.getName());
166
- // }
167
- // }
168
- // }
169
- // return modules;
170
- // }
171
-
172
- // protected static void scanModuleInPackage(Set<Class<?>> modules, String
173
- // packageName) {
174
- // if (log.isDebugEnabled())
175
- // log.debugf(" > scan '%s'", packageName);
176
- //
177
- // List<Class<?>> subs = Scans.me().scanPackage(packageName);
178
- // checkModule(modules, subs);
179
- // }
180
-
181
- // /**
182
- // * @param modules
183
- // * @param subs
184
- // */
185
- // private static void checkModule(Set<Class<?>> modules, List<Class<?>>
186
- // subs) {
187
- // for (Class<?> sub : subs) {
188
- // if (isModule(sub)) {
189
- // if (log.isDebugEnabled())
190
- // log.debugf(" >> add '%s'", sub.getName());
191
- // modules.add(sub);
192
- // } else if (log.isTraceEnabled()) {
193
- // log.tracef(" >> ignore '%s'", sub.getName());
194
- // }
195
- // }
196
- // }
197
-
198
84
public static void evalHttpMethod (ActionInfo ai , Method method , Execute execute , DefaultExecute de ) {
199
85
if (Mirror .getAnnotationDeep (method , GET .class ) != null )
200
86
ai .getHttpMethods ().add ("GET" );
@@ -205,12 +91,12 @@ public static void evalHttpMethod(ActionInfo ai, Method method, Execute execute,
205
91
if (Mirror .getAnnotationDeep (method , DELETE .class ) != null )
206
92
ai .getHttpMethods ().add ("DELETE" );
207
93
208
- if (execute != null ){
94
+ if (execute != null ) {
209
95
for (String m : execute .methods ()) {
210
96
ai .getHttpMethods ().add (m .toUpperCase ());
211
97
}
212
98
}
213
- if (de != null ){
99
+ if (de != null ) {
214
100
for (String m : de .methods ()) {
215
101
ai .getHttpMethods ().add (m .toUpperCase ());
216
102
}
@@ -279,14 +165,20 @@ public static void evalModule(ActionInfo ai, Class<?> type) {
279
165
}
280
166
281
167
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
282
- public static void evalActionFilters (ActionInfo ai , Filters filters ) {
168
+ public static void evalActionFilters (ActionInfo ai , Filters classFilters , Filters filters ) {
169
+ List <ObjectInfo <? extends ActionFilter >> list = new ArrayList <ObjectInfo <? extends ActionFilter >>();
170
+ if (null != classFilters ) {
171
+ for (By by : classFilters .value ()) {
172
+ list .add (new ObjectInfo (by .type (), by .args ()));
173
+ }
174
+ }
283
175
if (null != filters ) {
284
- List <ObjectInfo <? extends ActionFilter >> list = new ArrayList <ObjectInfo <? extends ActionFilter >>(filters .value ().length );
285
176
for (By by : filters .value ()) {
286
177
list .add (new ObjectInfo (by .type (), by .args ()));
287
178
}
288
- ai .setFilterInfos (list .toArray (new ObjectInfo [list .size ()]));
289
179
}
180
+ ai .setFilterInfos (list .toArray (new ObjectInfo [list .size ()]));
181
+
290
182
}
291
183
292
184
@ SuppressWarnings ({ "unchecked" , "rawtypes" })
0 commit comments