01: package org.mvel.integration.impl;
02:
03: import org.mvel.ParserContext;
04: import org.mvel.integration.VariableResolver;
05: import org.mvel.util.MethodStub;
06:
07: import java.lang.reflect.Method;
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: /**
12: * @author Christopher Brock
13: */
14: public class StaticMethodImportResolverFactory extends
15: BaseVariableResolverFactory {
16:
17: public StaticMethodImportResolverFactory(ParserContext ctx) {
18: this ();
19:
20: Map<String, Object> imports = ctx.getImports();
21: for (String name : imports.keySet()) {
22: if (imports.get(name) instanceof Method) {
23: createVariable(name, imports.get(name));
24: }
25: }
26: }
27:
28: public StaticMethodImportResolverFactory() {
29: this .variableResolvers = new HashMap<String, VariableResolver>();
30: }
31:
32: public VariableResolver createVariable(String name, Object value) {
33: if (value instanceof Method)
34: value = new MethodStub((Method) value);
35:
36: StaticMethodImportResolver methodResolver = new StaticMethodImportResolver(
37: name, (MethodStub) value);
38: this .variableResolvers.put(name, methodResolver);
39: return methodResolver;
40: }
41:
42: public VariableResolver createVariable(String name, Object value,
43: Class<?> type) {
44: return null;
45: }
46:
47: public boolean isTarget(String name) {
48: return this .variableResolvers.containsKey(name);
49: }
50:
51: public boolean isResolveable(String name) {
52: return isTarget(name) || isNextResolveable(name);
53: }
54:
55: public Map<String, Method> getImportedMethods() {
56: Map<String, Method> im = new HashMap<String, Method>();
57: for (String name : this .variableResolvers.keySet()) {
58: im.put(name, (Method) (this.variableResolvers.get(name))
59: .getValue());
60: }
61: return im;
62: }
63:
64: }
|