SimpleMap.java
2.19 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
55
56
57
58
59
60
61
62
63
64
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.jmx.annotation.OpenTypeUtils
* com.adobe.granite.jmx.annotation.TabularTypeInfo
*/
package com.day.crx.sling.server.jmx;
import com.adobe.granite.jmx.annotation.OpenTypeUtils;
import com.adobe.granite.jmx.annotation.TabularTypeInfo;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenDataException;
import javax.management.openmbean.TabularData;
import javax.management.openmbean.TabularDataSupport;
import javax.management.openmbean.TabularType;
@TabularTypeInfo(rowType=Entry.class, indexNames={"key"})
public class SimpleMap
extends TreeMap<String, String> {
public SimpleMap() {
}
public SimpleMap(TabularData tabular) {
if (!Entry.class.getName().equals(tabular.getTabularType().getRowType().getTypeName())) {
throw new IllegalArgumentException("Incompatible tabular data. Accepting " + Entry.class.getName());
}
for (Object entry : tabular.values()) {
CompositeData e = (CompositeData)entry;
this.put(e.get("key").toString(), e.get("value").toString());
}
}
public TabularData toTabularData() {
try {
TabularType type = OpenTypeUtils.createTabularType(this.getClass());
TabularDataSupport tabular = new TabularDataSupport(type);
CompositeType itemType = OpenTypeUtils.createCompositeType(Entry.class);
String[] itemNames = new String[]{"key", "value"};
for (Map.Entry e : this.entrySet()) {
Object[] itemValues = new Object[]{e.getKey(), e.getValue()};
tabular.put(new CompositeDataSupport(itemType, itemNames, itemValues));
}
return tabular;
}
catch (OpenDataException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
public static interface Entry {
public String getKey();
public String getValue();
}
}