2 * Copyright © 2014, 2017 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.ReferencedRow;
12 import org.opendaylight.ovsdb.lib.notation.UUID;
14 final class UuidBaseType extends BaseType<UuidBaseType> {
15 // These enum types correspond to JSON values and need to be in lower-case currently
16 public enum RefType { strong, weak }
18 static final UuidBaseType SINGLETON = new UuidBaseType();
20 private String refTable;
21 private UuidBaseType.RefType refType;
24 void fillConstraints(final JsonNode node) {
25 JsonNode refTableNode = node.get("refTable");
26 refTable = refTableNode != null ? refTableNode.asText() : null;
28 JsonNode refTypeJson = node.get("refType");
29 refType = refTypeJson != null ? RefType.valueOf(refTypeJson.asText()) : RefType.strong;
33 public Object toValue(final JsonNode value) {
34 if (value.isArray()) {
35 if (value.size() == 2 && value.get(0).isTextual() && "uuid".equals(value.get(0).asText())) {
36 return new UUID(value.get(1).asText());
40 * UUIDBaseType used by RefTable from SouthBound will always be an Array of ["uuid", <uuid>].
41 * But there are some cases from northbound where the RefTable type can be expanded to a Row
42 * with contents. In those scenarios, just retain the content and return a ReferencedRow for
43 * the upper layer functions to process it.
45 return new ReferencedRow(refTable, value);
51 public void validate(final Object value) {
55 public String getRefTable() {
59 public UuidBaseType.RefType getRefType() {
64 public String toString() {
65 return "UuidBaseType";
69 public int hashCode() {
72 result = prime * result
73 + (refTable == null ? 0 : refTable.hashCode());
74 result = prime * result
75 + (refType == null ? 0 : refType.hashCode());
80 public boolean equals(final Object obj) {
87 if (getClass() != obj.getClass()) {
90 UuidBaseType other = (UuidBaseType) obj;
91 if (refTable == null) {
92 if (other.refTable != null) {
95 } else if (!refTable.equals(other.refTable)) {
98 if (refType != other.refType) {