1
|
package deserialize;
|
2
|
|
3
|
import java.util.Arrays;
|
4
|
|
5
|
import org.codehaus.jackson.node.ObjectNode;
|
6
|
|
7
|
public class Variable {
|
8
|
|
9
|
private char type;
|
10
|
private String variable;
|
11
|
private String typeName;
|
12
|
private Object value = null;
|
13
|
private Object array[] = null;
|
14
|
|
15
|
public Variable(char type, String variable, String typeName) {
|
16
|
this.type = type;
|
17
|
this.variable = variable;
|
18
|
this.typeName = typeName;
|
19
|
|
20
|
if (!DataType.primTypeCodes.containsKey(type)) {
|
21
|
if (typeName.contains("/")) {
|
22
|
typeName = typeName.substring(typeName.lastIndexOf("/") + 1, typeName.length() - 1);
|
23
|
} else {
|
24
|
System.out.println(typeName);
|
25
|
typeName = typeName.substring(1);
|
26
|
}
|
27
|
|
28
|
if (typeName.length() == 1 && DataType.primTypeCodes.containsKey(typeName.charAt(0)))
|
29
|
typeName = DataType.primTypeCodes.get(typeName.charAt(0)); // remove type
|
30
|
|
31
|
this.typeName = typeName;
|
32
|
}
|
33
|
}
|
34
|
|
35
|
public char getType() {
|
36
|
return type;
|
37
|
}
|
38
|
|
39
|
public boolean isValueSet() {
|
40
|
return value != null || array != null;
|
41
|
}
|
42
|
|
43
|
public void setValue(Object value) {
|
44
|
this.value = value;
|
45
|
}
|
46
|
|
47
|
public void setValue(Object array[]) {
|
48
|
this.array = array;
|
49
|
}
|
50
|
|
51
|
public void putToJson(ObjectNode node) {
|
52
|
if (value != null || array != null) {
|
53
|
if (value != null && value.getClass().toString().equals(ClassDescription.class.toString())) {
|
54
|
ClassDescription desc = (ClassDescription) value;
|
55
|
node.put(variable, desc.getJsonNode());
|
56
|
} else if (value != null) {
|
57
|
node.put(variable, value.toString());
|
58
|
} else if (array != null) {
|
59
|
node.put(variable, Arrays.toString(array));
|
60
|
}
|
61
|
} else {
|
62
|
node.put(variable, "NOT_IMPLEMENTED");
|
63
|
}
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public String toString() {
|
68
|
String result;
|
69
|
|
70
|
if (DataType.primTypeCodes.containsKey(type)) {
|
71
|
result = DataType.primTypeCodes.get(type) + " " + variable;
|
72
|
} else {
|
73
|
result = typeName + " " + variable;
|
74
|
if (DataType.objTypeCodes.get(type) == "array")
|
75
|
result += "[]";
|
76
|
}
|
77
|
|
78
|
if (value != null) {
|
79
|
result += " = ";
|
80
|
if (value.getClass().toString().equals(ClassDescription.class.toString())) {
|
81
|
ClassDescription desc = (ClassDescription) value;
|
82
|
result += desc.toString();
|
83
|
} else if (value != null) {
|
84
|
result += value;
|
85
|
} else if (array != null) {
|
86
|
result += Arrays.toString(array);
|
87
|
}
|
88
|
}
|
89
|
|
90
|
return result;
|
91
|
}
|
92
|
|
93
|
}
|