1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.fatwire.gst.foundation.taglib;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.Collections;
22 import java.util.Enumeration;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27
28 import COM.FutureTense.Interfaces.FTVAL;
29 import COM.FutureTense.Interfaces.ICS;
30 import COM.FutureTense.Interfaces.IList;
31
32
33
34
35
36
37
38
39
40 public class ICSAsMap implements Map<String, Object> {
41
42 private final ICS ics;
43
44
45
46
47 public ICSAsMap(final ICS ics) {
48 super();
49 this.ics = ics;
50 }
51
52 public void clear() {
53
54 }
55
56 public boolean containsKey(final Object key) {
57 return ics.GetVar((String) key) != null;
58
59 }
60
61 public boolean containsValue(final Object value) {
62 return false;
63 }
64
65 @SuppressWarnings("unchecked")
66 public Set<java.util.Map.Entry<String, Object>> entrySet() {
67 final Map<String, Object> tmp = new HashMap<String, Object>();
68 for (final Enumeration<String> enumeration = ics.GetVars(); enumeration.hasMoreElements();) {
69 final String name = enumeration.nextElement();
70 tmp.put(name, get(name));
71 }
72
73 return tmp.entrySet();
74 }
75
76 @SuppressWarnings("deprecation")
77 public Object get(final Object key) {
78 if (!(key instanceof String)) {
79 throw new IllegalArgumentException("key must be a String");
80 }
81
82 final Object o = ics.GetObj((String) key);
83 if (o != null) {
84 return o;
85 }
86
87
88
89 final IList i = ics.GetList((String) key, true);
90 if (i != null) {
91
92 return i;
93 }
94 ics.ClearErrno();
95
96 final FTVAL val = ics.GetCgi((String) key);
97 if (val != null) {
98 switch (val.GetType()) {
99 case FTVAL.BLOB:
100 return val.getBlob();
101 case FTVAL.I4:
102 return val.GetInt();
103 case FTVAL.DATE:
104 case FTVAL.DOUBLE:
105 case FTVAL.LONG:
106 case FTVAL.LPSTR:
107 return val.getString();
108 case FTVAL.UNKNOWN:
109 return val.GetObj();
110
111 }
112 }
113 ics.ClearErrno();
114 return null;
115 }
116
117 public boolean isEmpty() {
118 return ics.GetVars().hasMoreElements();
119 }
120
121 @SuppressWarnings("unchecked")
122 public Set<String> keySet() {
123 return new HashSet<String>(Collections.list(ics.GetVars()));
124 }
125
126 public Object put(final String key, final Object value) {
127
128
129
130 throw new UnsupportedOperationException();
131 }
132
133 public void putAll(final Map<? extends String, ? extends Object> t) {
134 throw new UnsupportedOperationException();
135 }
136
137 public String remove(final Object key) {
138 throw new UnsupportedOperationException();
139 }
140
141 @SuppressWarnings("unchecked")
142 public int size() {
143 return Collections.list(ics.GetVars()).size();
144 }
145
146 public Collection<Object> values() {
147 final Collection<Object> tmp = new ArrayList<Object>();
148 for (@SuppressWarnings("unchecked")
149 final Enumeration<String> enumeration = ics.GetVars(); enumeration.hasMoreElements();) {
150 final String name = enumeration.nextElement();
151 tmp.add(get(name));
152 }
153
154 return tmp;
155 }
156
157 }