My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 19 attachment: dot_attribute_lookup.patch (1.6 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
diff --git a/jsontemplate/ScopedContext.java b/jsontemplate/ScopedContext.java
index ba2484c..afa8fc0 100644
--- a/jsontemplate/ScopedContext.java
+++ b/jsontemplate/ScopedContext.java
@@ -3,8 +3,10 @@ package jsontemplate;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.SignedObject;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import java.util.Map;

class ScopedContext {
@@ -85,7 +87,7 @@ class ScopedContext {

private static Object lookup(Object context, String name) {
if (context instanceof Map) {
- return ((Map) context).get(name);
+ return lookupMap((Map) context, name);
}
else {
// bean?
@@ -129,6 +131,29 @@ class ScopedContext {
}
}

+ private static Object lookupMap(Map map, String name) {
+ Object value = map.get(name);
+
+ if (value == null) {
+ int dotIndex = name.indexOf('.');
+ if (dotIndex < 0) {
+ return null;
+ }
+
+ String parentName = name.substring(0, dotIndex);
+ Object parentMap = map.get(parentName);
+ if (!(parentMap instanceof Map)) {
+ return null;
+ }
+
+ String childName = name.substring(dotIndex + 1);
+ return lookupMap((Map) parentMap, childName);
+
+ } else {
+ return value;
+ }
+ }
+
private static boolean isNonLookupable(Object context) {
if (context == null) return true;
Class<? extends Object> contextClass = context.getClass();
Powered by Google Project Hosting