4
4
import java .util .HashMap ;
5
5
6
6
import org .scijava .Priority ;
7
+ import org .scijava .batch .input .BatchInput ;
8
+ import org .scijava .batch .input .BatchInputProvider ;
7
9
import org .scijava .command .CommandService ;
8
10
import org .scijava .log .LogService ;
11
+ import org .scijava .module .Module ;
9
12
import org .scijava .module .ModuleInfo ;
13
+ import org .scijava .module .ModuleItem ;
14
+ import org .scijava .plugin .AbstractHandlerService ;
10
15
import org .scijava .plugin .Parameter ;
11
16
import org .scijava .plugin .Plugin ;
12
- import org .scijava .service .AbstractService ;
13
17
import org .scijava .service .Service ;
14
18
15
19
@ Plugin (type = Service .class , priority = Priority .LOW )
16
- public final class FileBatchService extends AbstractService implements
17
- BatchService {
20
+ public final class FileBatchService extends AbstractHandlerService <BatchInput , BatchInputProvider <?>> implements BatchService {
18
21
19
22
@ Parameter
20
23
private LogService log ;
21
-
24
+
22
25
@ Parameter
23
26
private CommandService commandService ;
24
27
25
28
/**
26
29
* Returns true if {@code type} is a {@link File}.
27
30
*/
28
31
@ Override
29
- public boolean supports (Class <?> type ) {
30
- return type .isAssignableFrom (File .class );
32
+ public boolean supportsItem (ModuleItem <?> moduleItem ) {
33
+ BatchInputProvider <?> handler = getHandler (new BatchInput (File .class , moduleItem ));
34
+ if (handler == null ) {
35
+ return false ;
36
+ }
37
+ return handler .canProvide (moduleItem );
38
+ }
39
+
40
+ @ SuppressWarnings ("unchecked" )
41
+ @ Override
42
+ public <I > void fillInput (Module module , ModuleItem <?> moduleItem , I inputObject ) {
43
+ BatchInputProvider <File > handler = (BatchInputProvider <File >) getHandler (new BatchInput (File .class , moduleItem ));
44
+ if (handler == null ) {
45
+ log .error ("No handler found for input: " + moduleItem .getName ());
46
+ return ;
47
+ }
48
+ handler .populateInput (module , moduleItem , (File ) inputObject );
31
49
}
32
50
33
51
@ Override
@@ -37,10 +55,30 @@ public void run(ModuleInfo moduleInfo) {
37
55
log .error ("No compatible inputs (of type File) found." );
38
56
return ;
39
57
}
58
+
59
+ // 1) get input ModuleItems
60
+ // 2) choose ModuleItem
61
+ // 3) get suitable BatchInputProvider
62
+ // 4) get Iterator for ModuleItem
63
+
64
+ //for (getHandler(new BatchInput(File.class, moduleItem)).iterate(fileList)) {
65
+ //}
66
+
40
67
// Call ModuleBatchProcessor with input moduleInfo
41
68
HashMap <String , Object > inputMap = new HashMap <>();
42
69
inputMap .put ("moduleInfo" , moduleInfo );
43
70
commandService .run (ModuleBatchProcessor .class , true , inputMap );
44
71
}
45
72
73
+ @ SuppressWarnings ({ "unchecked" , "rawtypes" })
74
+ @ Override
75
+ public Class <BatchInputProvider <?>> getPluginType () {
76
+ return (Class ) BatchInputProvider .class ;
77
+ }
78
+
79
+ @ Override
80
+ public Class <BatchInput > getType () {
81
+ return BatchInput .class ;
82
+ }
83
+
46
84
}
0 commit comments