2 * Copyright (c) 2014, 2015 EBay Software Foundation and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.ovsdb.lib.schema;
10 import com.fasterxml.jackson.databind.JsonNode;
11 import org.opendaylight.ovsdb.lib.notation.OvsdbSet;
13 final class AtomicColumnType extends ColumnType {
14 AtomicColumnType(final BaseType baseType) {
15 super(baseType, 1, 1);
18 AtomicColumnType(final BaseType baseType, final long min, final long max) {
19 super(baseType, min, max);
23 * Creates a ColumnType from the JsonNode if the implementation knows how to, returns null otherwise.
25 * @param json the JSONNode object that needs to converted
26 * @return a valid SubType or Null (if the JsonNode does not represent the subtype)
28 static AtomicColumnType fromJsonNode(final JsonNode json) {
29 if (json.isObject() && json.has("value")) {
32 BaseType jsonBaseType = BaseType.fromJson(json, "key");
33 return jsonBaseType == null ? null : new AtomicColumnType(jsonBaseType, minFromJson(json), maxFromJson(json));
37 public Object valueFromJson(final JsonNode value) {
38 if (isMultiValued()) {
39 OvsdbSet<Object> result = new OvsdbSet<>();
40 if (value.isArray()) {
41 if (value.size() == 2) {
42 if (value.get(0).isTextual() && "set".equals(value.get(0).asText())) {
43 for (JsonNode node: value.get(1)) {
44 result.add(getBaseType().toValue(node));
47 result.add(getBaseType().toValue(value));
51 result.add(getBaseType().toValue(value));
55 return getBaseType().toValue(value);