1 package net.sf.mbus4j.dataframes.datablocks;
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 import net.sf.json.JSONObject;
31 import net.sf.mbus4j.dataframes.MBusMedium;
32 import net.sf.mbus4j.dataframes.datablocks.dif.DataFieldCode;
33
34
35
36
37
38
39
40 public class EnhancedIdentificationDataBlock extends DataBlock {
41
42 private int id;
43 private String man;
44 private int version;
45 private MBusMedium medium;
46
47 public EnhancedIdentificationDataBlock() {
48 super();
49 }
50
51
52
53
54 public int getId() {
55 return id;
56 }
57
58
59
60
61 public String getMan() {
62 return man;
63 }
64
65
66
67
68 public MBusMedium getMedium() {
69 return medium;
70 }
71
72 @Override
73 public String getValueAsString() {
74 throw new UnsupportedOperationException("Not supported yet.");
75 }
76
77
78
79
80 public int getVersion() {
81 return version;
82 }
83
84
85
86
87 public void setId(int id) {
88 this.id = id;
89 }
90
91
92
93
94 public void setMan(String man) {
95 this.man = man;
96 }
97
98
99
100
101 public void setMedium(MBusMedium medium) {
102 this.medium = medium;
103 }
104
105
106
107
108 public void setVersion(int version) {
109 this.version = version;
110 }
111
112 @Override
113 public void toString(StringBuilder sb, String inset) {
114 sb.append(inset).append("dataType = ").append(getDataFieldCode()).append("\n");
115 if (getVif() != null) {
116 sb.append(inset).append("description = ").append(getParamDescr()).append("\n");
117 }
118 sb.append(inset).append(String.format("id = %08d\n", id));
119 if (man != null) {
120
121 sb.append(inset).append("man = ").append(man).append("\n");
122 sb.append(inset).append("version = ").append(version).append("\n");
123 }
124 if (medium != null) {
125 sb.append(inset).append("medium = ").append(medium).append("\n");
126 }
127 }
128
129 @Override
130 protected void accumulateDatatoJSON(JSONObject json) {
131 JSONObject jsonData = new JSONObject();
132 if (getDataFieldCode().equals(DataFieldCode._64_BIT_INTEGER)) {
133 jsonData.accumulate("man", getMan());
134 jsonData.accumulate("medium", getMedium().getLabel());
135 jsonData.accumulate("version", getVersion());
136 }
137 jsonData.accumulate("id", getId());
138 json.accumulate("data", jsonData);
139 }
140
141 @Override
142 public void fromJSON(JSONObject json) {
143 super.fromJSON(json);
144 if (json.containsKey("data")) {
145 JSONObject jsonData = json.getJSONObject("data");
146 if (getDataFieldCode().equals(DataFieldCode._64_BIT_INTEGER)) {
147 setMan(jsonData.getString("man"));
148 setMedium(MBusMedium.fromLabel(jsonData.getString("medium")));
149 setVersion(jsonData.getInt("version"));
150 }
151 setId(jsonData.getInt("id"));
152 }
153 }
154
155 @Override
156 public void setValue(String text) {
157 throw new UnsupportedOperationException("Not supported yet.");
158 }
159 }