private static Node readNode(JsonReader reader) throws IOException {
String id = null;
Label label = null;
NodeType type = null;
String hNodeId = null;
String columnName = null;
Label rdfLiteralType = null;
Label datatype = null;
String value = null;
boolean isUri = false;
SemanticType userSelectedSemanticType = null;
List<SemanticType> suggestedSemanticTypes = null;
Set<String> modelIds = null;
reader.beginObject();
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("id") && reader.peek() != JsonToken.NULL) {
id = reader.nextString();
} else if (key.equals("label") && reader.peek() != JsonToken.NULL) {
label = readLabel(reader);
} else if (key.equals("type") && reader.peek() != JsonToken.NULL) {
type = NodeType.valueOf(reader.nextString());
} else if (key.equals("hNodeId") && reader.peek() != JsonToken.NULL) {
hNodeId = reader.nextString();
} else if (key.equals("columnName") && reader.peek() != JsonToken.NULL) {
columnName = reader.nextString();
} else if (key.equals("datatype") && reader.peek() != JsonToken.NULL) {
datatype = readLabel(reader);
} else if (key.equals("value") && reader.peek() != JsonToken.NULL) {
value = reader.nextString();
} else if (key.equals("isUri") && reader.peek() != JsonToken.NULL) {
isUri = Boolean.parseBoolean(reader.nextString());
} else if (key.equals("rdfLiteralType") && reader.peek() != JsonToken.NULL) {
rdfLiteralType = readLabel(reader);
} else if (key.equals("userSelectedSemanticType") && reader.peek() != JsonToken.NULL) {
userSelectedSemanticType = readSemanticType(reader);
} else if (key.equals("suggestedSemanticTypes") && reader.peek() != JsonToken.NULL) {
suggestedSemanticTypes = new ArrayList<SemanticType>();
reader.beginArray();
while (reader.hasNext()) {
SemanticType semanticType = readSemanticType(reader);
suggestedSemanticTypes.add(semanticType);
}
reader.endArray();
} else if (key.equals("modelIds") && reader.peek() != JsonToken.NULL) {
modelIds = readModelIds(reader);
} else {
reader.skipValue();
}
}
reader.endObject();
Node n = null;
if (type == NodeType.InternalNode) {
n = new InternalNode(id, label);
} else if (type == NodeType.ColumnNode) {
n = new ColumnNode(id, hNodeId, columnName, rdfLiteralType);
((ColumnNode)n).setUserSelectedSemanticType(userSelectedSemanticType);
((ColumnNode)n).setSuggestedSemanticTypes(suggestedSemanticTypes);
} else if (type == NodeType.LiteralNode) {
n = new LiteralNode(id, value, datatype, isUri);
} else {
logger.error("cannot instanciate a node from the type: " + type.toString());
return null;
}
n.setModelIds(modelIds);