1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.settings4j.util;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.apache.commons.collections4.Transformer;
24 import org.apache.commons.collections4.map.LazyMap;
25 import org.settings4j.Connector;
26
27
28
29
30
31
32
33
34
35
36
37 public class ELConnectorWrapper {
38
39 private final Connector[] connectors;
40
41
42
43
44
45
46 public ELConnectorWrapper(final Connector[] connectors) {
47 super();
48 this.connectors = connectors;
49 }
50
51
52
53
54
55
56
57 public Map<String, String> getString() {
58 final Transformer<String, String> transformer = new Transformer<String, String>() {
59
60 public String transform(final String input) {
61 if (input != null) {
62 final String key = input.toString();
63 for (Connector connector : ELConnectorWrapper.this.connectors) {
64 final String result = connector.getString(key);
65 if (result != null) {
66 return result;
67 }
68 }
69 }
70 return null;
71 }
72 };
73 return LazyMap.lazyMap(new HashMap<String, String>(), transformer);
74 }
75
76
77
78
79
80
81
82 public Map<String, byte[]> getContent() {
83 final Transformer<String, byte[]> transformer = new Transformer<String, byte[]>() {
84
85 public byte[] transform(final String input) {
86 if (input != null) {
87 final String key = input.toString();
88 for (Connector connector : ELConnectorWrapper.this.connectors) {
89 final byte[] result = connector.getContent(key);
90 if (result != null) {
91 return result;
92 }
93 }
94 }
95 return null;
96 }
97 };
98 return LazyMap.lazyMap(new HashMap<String, byte[]>(), transformer);
99 }
100
101
102
103
104
105
106
107 public Map<String, Object> getObject() {
108 final Transformer<String, Object> transformer = new Transformer<String, Object>() {
109
110 public Object transform(final String input) {
111 if (input != null) {
112 final String key = input.toString();
113 for (Connector connector : ELConnectorWrapper.this.connectors) {
114 final Object result = connector.getObject(key);
115 if (result != null) {
116 return result;
117 }
118 }
119 }
120 return null;
121 }
122 };
123 return LazyMap.lazyMap(new HashMap<String, Object>(), transformer);
124 }
125 }