1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.javagen.agile.core.xml.jaxb;
17
18 import java.util.HashMap;
19 import java.util.Map;
20 import java.util.Set;
21 import javax.xml.bind.annotation.adapters.XmlAdapter;
22
23 import org.javagen.agile.core.model.Model;
24
25
26 public class ContextTypeAdapter extends XmlAdapter<ContextType, Map<?,?>> {
27
28 @Override
29 public Map<?,?> unmarshal(ContextType boundType) throws Exception {
30 if (boundType==null)
31 return null;
32 Map<String, Object> map = new HashMap<String, Object>();
33 if (boundType.getEntries()!=null)
34 for(ContextEntryType entry : boundType.getEntries()) {
35 map.put(entry.getKey(), entry.getValue());
36 }
37 if (boundType.getEntryRefs()!=null)
38 for(ContextModelEntryType entry : boundType.getEntryRefs()) {
39 map.put(entry.getKey(), entry.getModel());
40 }
41 return map;
42 }
43
44 @Override
45 public ContextType marshal(Map<?,?> valueType) throws Exception {
46 if (valueType==null)
47 return null;
48 Set<?> keys = valueType.keySet();
49 ContextType context = new ContextType();
50 for(Object key : keys) {
51 Object value = valueType.get(key);
52 if (value instanceof Model) {
53 context.addEntryRef(key.toString(), (Model)value);
54 } else {
55 context.addEntry(key.toString(), value);
56 }
57 }
58 return context;
59 }
60
61 }