(mensagem de log vazia)
@@ -0,0 +1,96 @@ | ||
1 | +package org.dyndns.nuda.repserv.scripting; | |
2 | + | |
3 | +import java.io.Reader; | |
4 | +import java.io.Writer; | |
5 | +import java.util.List; | |
6 | + | |
7 | +import javax.script.Bindings; | |
8 | +import javax.script.ScriptContext; | |
9 | + | |
10 | +public class RepServScriptContext implements ScriptContext { | |
11 | + | |
12 | + @Override | |
13 | + public void setBindings(Bindings bindings, int scope) { | |
14 | + // TODO 自動生成されたメソッド・スタブ | |
15 | + | |
16 | + } | |
17 | + | |
18 | + @Override | |
19 | + public Bindings getBindings(int scope) { | |
20 | + // TODO 自動生成されたメソッド・スタブ | |
21 | + return null; | |
22 | + } | |
23 | + | |
24 | + @Override | |
25 | + public void setAttribute(String name, Object value, int scope) { | |
26 | + // TODO 自動生成されたメソッド・スタブ | |
27 | + | |
28 | + } | |
29 | + | |
30 | + @Override | |
31 | + public Object getAttribute(String name, int scope) { | |
32 | + // TODO 自動生成されたメソッド・スタブ | |
33 | + return null; | |
34 | + } | |
35 | + | |
36 | + @Override | |
37 | + public Object removeAttribute(String name, int scope) { | |
38 | + // TODO 自動生成されたメソッド・スタブ | |
39 | + return null; | |
40 | + } | |
41 | + | |
42 | + @Override | |
43 | + public Object getAttribute(String name) { | |
44 | + // TODO 自動生成されたメソッド・スタブ | |
45 | + return null; | |
46 | + } | |
47 | + | |
48 | + @Override | |
49 | + public int getAttributesScope(String name) { | |
50 | + // TODO 自動生成されたメソッド・スタブ | |
51 | + return 0; | |
52 | + } | |
53 | + | |
54 | + @Override | |
55 | + public Writer getWriter() { | |
56 | + // TODO 自動生成されたメソッド・スタブ | |
57 | + return null; | |
58 | + } | |
59 | + | |
60 | + @Override | |
61 | + public Writer getErrorWriter() { | |
62 | + // TODO 自動生成されたメソッド・スタブ | |
63 | + return null; | |
64 | + } | |
65 | + | |
66 | + @Override | |
67 | + public void setWriter(Writer writer) { | |
68 | + // TODO 自動生成されたメソッド・スタブ | |
69 | + | |
70 | + } | |
71 | + | |
72 | + @Override | |
73 | + public void setErrorWriter(Writer writer) { | |
74 | + // TODO 自動生成されたメソッド・スタブ | |
75 | + | |
76 | + } | |
77 | + | |
78 | + @Override | |
79 | + public Reader getReader() { | |
80 | + // TODO 自動生成されたメソッド・スタブ | |
81 | + return null; | |
82 | + } | |
83 | + | |
84 | + @Override | |
85 | + public void setReader(Reader reader) { | |
86 | + // TODO 自動生成されたメソッド・スタブ | |
87 | + | |
88 | + } | |
89 | + | |
90 | + @Override | |
91 | + public List<Integer> getScopes() { | |
92 | + // TODO 自動生成されたメソッド・スタブ | |
93 | + return null; | |
94 | + } | |
95 | + | |
96 | +} |
@@ -0,0 +1,16 @@ | ||
1 | +package org.dyndns.nuda.repserv.scripting; | |
2 | + | |
3 | +import javax.script.ScriptEngineFactory; | |
4 | + | |
5 | +public class EngineFactoryBuilder { | |
6 | + private static ScriptEngineFactory FACTORY = null; | |
7 | + | |
8 | + private EngineFactoryBuilder(){} | |
9 | + | |
10 | + public static ScriptEngineFactory getInstance() { | |
11 | + if(FACTORY == null) { | |
12 | + FACTORY = new EngineFactory(); | |
13 | + } | |
14 | + return FACTORY; | |
15 | + } | |
16 | +} |
@@ -1,6 +1,8 @@ | ||
1 | 1 | package org.dyndns.nuda.repserv.scripting; |
2 | 2 | |
3 | 3 | import java.io.Reader; |
4 | +import java.util.HashMap; | |
5 | +import java.util.Map; | |
4 | 6 | |
5 | 7 | import javax.script.Bindings; |
6 | 8 | import javax.script.ScriptContext; |
@@ -7,6 +9,7 @@ | ||
7 | 9 | import javax.script.ScriptEngine; |
8 | 10 | import javax.script.ScriptEngineFactory; |
9 | 11 | import javax.script.ScriptException; |
12 | +import javax.script.SimpleBindings; | |
10 | 13 | |
11 | 14 | /** |
12 | 15 | * RepServDSL用スクリプティングエンジンです |
@@ -15,6 +18,12 @@ | ||
15 | 18 | */ |
16 | 19 | public class Engine implements ScriptEngine { |
17 | 20 | |
21 | + private ScriptContext ctx = null; | |
22 | + | |
23 | + private Map<Integer, Bindings> bindingMap = new HashMap<Integer, Bindings>(); | |
24 | + | |
25 | + private Map<String, Object> bindingContextMap = new HashMap<String, Object>(); | |
26 | + | |
18 | 27 | @Override |
19 | 28 | public Object eval(String script, ScriptContext context) |
20 | 29 | throws ScriptException { |
@@ -55,50 +64,75 @@ | ||
55 | 64 | |
56 | 65 | @Override |
57 | 66 | public void put(String key, Object value) { |
58 | - // TODO 自動生成されたメソッド・スタブ | |
67 | + if(key == null) { | |
68 | + throw new NullPointerException("Parameter of [key] is null"); | |
69 | + } | |
70 | + if(key.isEmpty()) { | |
71 | + throw new IllegalArgumentException("Parameter of [key] is empty"); | |
72 | + } | |
59 | 73 | |
74 | + this.bindingContextMap.put(key, value); | |
60 | 75 | } |
61 | 76 | |
62 | 77 | @Override |
63 | 78 | public Object get(String key) { |
64 | - // TODO 自動生成されたメソッド・スタブ | |
65 | - return null; | |
79 | + if(key == null) { | |
80 | + throw new NullPointerException("Parameter of [key] is null"); | |
81 | + } | |
82 | + if(key.isEmpty()) { | |
83 | + throw new IllegalArgumentException("Parameter of [key] is empty"); | |
84 | + } | |
85 | + return this.bindingContextMap.get(key); | |
66 | 86 | } |
67 | 87 | |
68 | 88 | @Override |
69 | 89 | public Bindings getBindings(int scope) { |
70 | - // TODO 自動生成されたメソッド・スタブ | |
71 | - return null; | |
90 | + if(!checkScope(scope)) { | |
91 | + throw new IllegalArgumentException("Parameter of [scope] is invalid"); | |
92 | + } | |
93 | + return this.bindingMap.get(scope); | |
72 | 94 | } |
73 | 95 | |
74 | 96 | @Override |
75 | 97 | public void setBindings(Bindings bindings, int scope) { |
76 | - // TODO 自動生成されたメソッド・スタブ | |
77 | - | |
98 | + if(bindings == null) { | |
99 | + throw new NullPointerException("Parameter of [bindings] is null"); | |
100 | + } | |
101 | + if(!checkScope(scope)) { | |
102 | + throw new IllegalArgumentException("Parameter of [scope] is invalid"); | |
103 | + } | |
104 | + this.bindingMap.put(scope, bindings); | |
78 | 105 | } |
79 | 106 | |
80 | 107 | @Override |
81 | 108 | public Bindings createBindings() { |
82 | - // TODO 自動生成されたメソッド・スタブ | |
83 | - return null; | |
109 | + return new SimpleBindings(); | |
84 | 110 | } |
85 | 111 | |
86 | 112 | @Override |
87 | 113 | public ScriptContext getContext() { |
88 | - // TODO 自動生成されたメソッド・スタブ | |
89 | - return null; | |
114 | + return this.ctx; | |
90 | 115 | } |
91 | 116 | |
92 | 117 | @Override |
93 | 118 | public void setContext(ScriptContext context) { |
94 | - // TODO 自動生成されたメソッド・スタブ | |
95 | - | |
119 | + if(context == null) { | |
120 | + throw new NullPointerException("Parameter of [context] is null"); | |
121 | + } | |
122 | + this.ctx = context; | |
96 | 123 | } |
97 | 124 | |
98 | 125 | @Override |
99 | 126 | public ScriptEngineFactory getFactory() { |
100 | - // TODO 自動生成されたメソッド・スタブ | |
101 | - return null; | |
127 | + return EngineFactoryBuilder.getInstance(); | |
102 | 128 | } |
103 | 129 | |
130 | + private boolean checkScope(int scope) { | |
131 | + if(ScriptContext.ENGINE_SCOPE == scope) { | |
132 | + return true; | |
133 | + } else if(ScriptContext.GLOBAL_SCOPE == scope) { | |
134 | + return true; | |
135 | + } | |
136 | + return false; | |
137 | + } | |
104 | 138 | } |