Project

General

Profile

1
package eu.dnetlib.msro.openaireplus.workflows.nodes.contexts;
2

    
3
import java.util.List;
4
import java.util.Map;
5
import java.util.Map.Entry;
6

    
7
import com.google.common.collect.Lists;
8
import com.google.common.collect.Maps;
9
import org.dom4j.DocumentHelper;
10
import org.dom4j.Element;
11

    
12
public class ContextDesc {
13

    
14
	private String id;
15
	private String label;
16
	private String type;
17
	private String xml;
18
	private Map<String, ContextPart> categories = Maps.newLinkedHashMap();
19
	private Map<String, String> dbEntries = Maps.newLinkedHashMap();
20
	private Map<String, String> params;
21

    
22
	public ContextDesc(final String id, final String label, final String type, final Map<String, String> params) {
23
		this.id = id;
24
		this.label = label;
25
		this.type = type;
26
		this.params = params;
27
	}
28

    
29
	public String getId() {
30
		return id;
31
	}
32

    
33
	public void setId(final String id) {
34
		this.id = id;
35
	}
36

    
37
	public String getLabel() {
38
		return label;
39
	}
40

    
41
	public void setLabel(final String label) {
42
		this.label = label;
43
	}
44

    
45
	public String getType() {
46
		return type;
47
	}
48

    
49
	public void setType(final String type) {
50
		this.type = type;
51
	}
52

    
53
	public String getXml() {
54
		return xml;
55
	}
56

    
57
	public void setXml(final String xml) {
58
		this.xml = xml;
59
	}
60

    
61
	public Map<String, ContextPart> getCategories() {
62
		return categories;
63
	}
64

    
65
	public void setCategories(final Map<String, ContextPart> categories) {
66
		this.categories = categories;
67
	}
68

    
69
	public Map<String, String> getDbEntries() {
70
		return dbEntries;
71
	}
72

    
73
	public void setDbEntries(final Map<String, String> dbEntries) {
74
		this.dbEntries = dbEntries;
75
	}
76

    
77
	public Element asDomElement() {
78
		final Element ctxElem = DocumentHelper.createElement("context");
79
		ctxElem.addAttribute("id", getId());
80
		ctxElem.addAttribute("label", getLabel());
81
		ctxElem.addAttribute("type", getType());
82
		for (Element param : getParamsAsElements()) {
83
			ctxElem.add(param);
84
		}
85
		for (ContextPart part : getCategories().values()) {
86
			ctxElem.add(part.asDomElement("category"));
87
		}
88

    
89
		return ctxElem;
90
	}
91

    
92
	public List<Element> getParamsAsElements() {
93
		List<Element> elements = Lists.newArrayList();
94
		for (Entry<String, String> e : params.entrySet()) {
95
			Element param = DocumentHelper.createElement("param");
96
			param.addAttribute("name", e.getKey());
97
			param.setText(e.getValue());
98
			elements.add(param);
99
		}
100
		return elements;
101
	}
102

    
103
	public Map<String, String> getParams() {
104
		return params;
105
	}
106

    
107
	public void setParams(final Map<String, String> params) {
108
		this.params = params;
109
	}
110
}
(2-2/8)