1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package tools.gsf.facade.assetapi.asset;
18
19 import com.fatwire.assetapi.def.AttributeDef;
20
21 import java.util.AbstractMap;
22 import java.util.HashSet;
23 import java.util.Iterator;
24 import java.util.Map;
25 import java.util.Set;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class AssetMapAdapter extends AbstractMap<String, Object> implements Map<String, Object> {
41
42 private final TemplateAsset delegate;
43 private final Set<String> metaAttributes = new HashSet<String>();
44
45 public AssetMapAdapter(TemplateAsset delegate) {
46 super();
47 this.delegate = delegate;
48
49 for (AttributeDef d : delegate.getAssetTypeDef().getAttributeDefs()) {
50 if (d.isMetaDataAttribute()) {
51 metaAttributes.add(d.getName());
52 }
53 }
54
55 }
56
57 @Override
58 public Set<java.util.Map.Entry<String, Object>> entrySet() {
59 return entries;
60 }
61
62 private Set<java.util.Map.Entry<String, Object>> entries = new java.util.AbstractSet<java.util.Map.Entry<String, Object>>() {
63
64 @Override
65 public Iterator<java.util.Map.Entry<String, Object>> iterator() {
66 final Iterator<String> names = delegate.getAttributeNames().iterator();
67 return new Iterator<java.util.Map.Entry<String, Object>>() {
68
69 public boolean hasNext() {
70 return names.hasNext();
71 }
72
73 public java.util.Map.Entry<String, Object> next() {
74 final String name = names.next();
75 final Object value = delegate.getAttribute(name);
76 return new Entry<String, Object>() {
77
78 public String getKey() {
79 return name;
80 }
81
82 public Object getValue() {
83 return value;
84 }
85
86 public Object setValue(Object value) {
87 throw new UnsupportedOperationException(
88 "Not allowed to set an asset attribute value, asset is immutable");
89 }
90
91 };
92 }
93
94 public void remove() {
95 throw new UnsupportedOperationException(
96 "Not allowed to remove an asset attribute, asset is immutable");
97
98 }
99
100 };
101 }
102
103 @Override
104 public int size() {
105 return delegate.getAttributeNames().size();
106 }
107 };
108 }