1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.grinderscript.dotnet.scriptengine;
18
19 import static java.util.Collections.emptyList;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import net.grinder.common.GrinderProperties;
28 import net.grinder.engine.common.EngineException;
29 import net.grinder.engine.common.ScriptLocation;
30 import net.grinder.scriptengine.Instrumenter;
31 import net.grinder.scriptengine.ScriptEngineService;
32 import net.grinder.util.FileExtensionMatcher;
33
34
35
36
37
38
39 public class DotNetScriptEngineService implements ScriptEngineService {
40
41 private final Logger logger = LoggerFactory
42 .getLogger(DotNetScriptEngineService.class);
43
44 private final FileExtensionMatcher dllFileMatcher = new FileExtensionMatcher(".dll");
45
46 private final GrinderProperties properties;
47 private final DotNetScriptEngineFactory factory;
48
49 DotNetScriptEngineService(GrinderProperties properties, DotNetScriptEngineFactory factory) {
50 logger.trace("ctor: Enter, properties = {}, factory = {}", properties, factory);
51 this.properties = properties;
52 this.factory = factory;
53 logger.trace("ctor: Exit");
54 }
55
56 public DotNetScriptEngineService(GrinderProperties properties) {
57 this(properties, new DotNetScriptEngineFactory.Default());
58 }
59
60
61
62
63 @Override public List<? extends Instrumenter> createInstrumenters()
64 throws EngineException {
65 return emptyList();
66 }
67
68
69
70
71 @Override public ScriptEngine createScriptEngine(ScriptLocation script)
72 throws EngineException {
73 logger.trace("createScriptEngine: Enter, script = {}", script);
74 ScriptEngine result = null;
75 if (dllFileMatcher.accept(script.getFile())) {
76 DotNetScriptEngine engine = factory.createScriptEngine(properties, script);
77 try {
78 engine.initialize();
79 } catch (IOException e) {
80 throw new EngineException("Could not initalize the CLR bridge",
81 e);
82 }
83 result = engine;
84 }
85 logger.trace("createScriptEngine: Exit, result = {}", result);
86 return result;
87 }
88
89 GrinderProperties getProperties()
90 {
91 return properties;
92 }
93
94 DotNetScriptEngineFactory getFactory() {
95 return factory;
96 }
97 }