1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.model.attributes;
19
20 import java.util.Collection;
21 import java.util.Map;
22
23 import pl.edu.agh.cast.model.ModelUtil;
24 import pl.edu.agh.cast.model.base.IDataSet;
25 import pl.edu.agh.cast.model.base.IEntity;
26 import pl.edu.agh.cast.model.base.Model;
27
28
29
30
31
32
33
34 public class NodeAttributeManager extends AttributeManager {
35
36 private static final long serialVersionUID = -3321558530249411428L;
37
38
39
40
41 public static final String PERMANENT_ID = "Id";
42
43
44
45
46 public static final String PERMANENT_ISMAIN = "IsMain";
47
48
49
50
51 public static final String PERMANENT_LABEL = "Label";
52
53
54
55
56 private transient ModelUtil modelUtil = new ModelUtil();
57
58
59
60
61 protected static NodeAttributeManager dummyManager = new NodeAttributeManager();
62
63 public static NodeAttributeManager getDummyManager() {
64 return dummyManager;
65 }
66
67
68
69
70 public NodeAttributeManager() {
71 super();
72
73
74 this.registerPermanentAttribute(PERMANENT_ID, ValueType.String, false, false);
75 getAttribute(PERMANENT_ID).setDefaultMergePolicy(AttributeMergePolicy.MERGE_POLICY_ALWAYS_FIRST);
76
77 this.registerPermanentAttribute(PERMANENT_LABEL, ValueType.String, true, true);
78 getAttribute(PERMANENT_LABEL).setDefaultMergePolicy(AttributeMergePolicy.MERGE_POLICY_ALWAYS_FIRST);
79
80 this.registerPermanentAttribute(PERMANENT_ISMAIN, ValueType.Boolean, true, false);
81 getAttribute(PERMANENT_ISMAIN).setDefaultMergePolicy(AttributeMergePolicy.MERGE_POLICY_LOGICAL_OR);
82
83 }
84
85
86
87
88
89
90 public NodeAttributeManager(Collection<IDataSet> dataSets) {
91 this();
92 Collection<IEntity> entities = Model.getEntities(dataSets);
93 Map<String, Map<String, String>> map = modelUtil.getAttributeMap(dataSets);
94 for (IEntity entityNode : entities) {
95 for (String attributeName : entityNode.getAttributeNames()) {
96 if (!this.isRegisteredId(attributeName)) {
97
98
99
100
101 String modelExtensionId = map != null ? map.get(entityNode.getType()).get(attributeName) : null;
102
103 this.registerPermanentAttribute(attributeName, ValueType.String, true, false, entityNode.getType(),
104 modelExtensionId);
105 }
106 }
107 }
108 }
109
110 }