package org.opendaylight.ovsdb.lib.schema;
+import com.fasterxml.jackson.databind.JsonNode;
import org.opendaylight.ovsdb.lib.error.TyperException;
import org.opendaylight.ovsdb.lib.jsonrpc.JsonUtils;
import org.opendaylight.ovsdb.lib.notation.OvsdbMap;
import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
-import com.fasterxml.jackson.databind.JsonNode;
-
public abstract class ColumnType {
BaseType baseType;
}
/**
+ * JSON.
+ * <pre>
"type": {
"key": {
"maxInteger": 4294967295,
"refTable": "Queue"
},
"max": "unlimited"
- }
- * @param json
- * @return
+ }</pre>
*/
public static ColumnType fromJson(JsonNode json) {
for (ColumnType colType : columns) {
/**
- * Creates a ColumnType from the JsonNode if the implementation knows how to, returns null otherwise
+ * Creates a ColumnType from the JsonNode if the implementation knows how to, returns null otherwise.
*
* @param json the JSONNode object that needs to converted
- * @return a valid SubType or Null (if the JsonNode does not represent
- * the subtype)
+ * @return a valid SubType or Null (if the JsonNode does not represent the subtype)
*/
protected abstract ColumnType fromJsonNode(JsonNode json);
public AtomicColumnType() {
}
- public AtomicColumnType(BaseType baseType1) {
- super(baseType1);
+ public AtomicColumnType(BaseType baseType) {
+ super(baseType);
}
@Override
if (json.isObject() && json.has("value")) {
return null;
}
- BaseType baseType = BaseType.fromJson(json, "key");
+ BaseType jsonBaseType = BaseType.fromJson(json, "key");
- if (baseType != null) {
+ if (jsonBaseType != null) {
- AtomicColumnType atomicColumnType = new AtomicColumnType(baseType);
+ AtomicColumnType atomicColumnType = new AtomicColumnType(jsonBaseType);
JsonNode node;
if ((node = json.get("min")) != null) {
if (json.isValueNode() || !json.has("value")) {
return null;
}
- BaseType keyType = BaseType.fromJson(json, "key");
+ BaseType jsonKeyType = BaseType.fromJson(json, "key");
BaseType valueType = BaseType.fromJson(json, "value");
- KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(keyType, valueType);
+ KeyValuedColumnType keyValueColumnType = new KeyValuedColumnType(jsonKeyType, valueType);
JsonNode node;
if ((node = json.get("min")) != null) {
keyValueColumnType.setMin(node.asLong());
@Override
public Object valueFromJson(JsonNode node) {
- if (node.isArray()) {
- if (node.size() == 2) {
- if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
- OvsdbMap<Object, Object> map = new OvsdbMap<>();
- for (JsonNode pairNode : node.get(1)) {
- if (pairNode.isArray() && node.size() == 2) {
- Object key = getKeyType().toValue(pairNode.get(0));
- Object value = getBaseType().toValue(pairNode.get(1));
- map.put(key, value);
- }
+ if (node.isArray() && node.size() == 2) {
+ if (node.get(0).isTextual() && "map".equals(node.get(0).asText())) {
+ OvsdbMap<Object, Object> map = new OvsdbMap<>();
+ for (JsonNode pairNode : node.get(1)) {
+ if (pairNode.isArray() && node.size() == 2) {
+ Object key = getKeyType().toValue(pairNode.get(0));
+ Object value = getBaseType().toValue(pairNode.get(1));
+ map.put(key, value);
}
- return map;
- } else if (node.size() == 0) {
- return null;
}
+ return map;
+ } else if (node.size() == 0) {
+ return null;
}
}
return null;