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