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 private String refTable;
19 private UuidBaseType.RefType refType;
22 void fillConstraints(final JsonNode node) {
23 JsonNode refTableNode = node.get("refTable");
24 setRefTable(refTableNode != null ? refTableNode.asText() : null);
26 JsonNode refTypeJson = node.get("refType");
27 setRefType(refTypeJson != null ? RefType.valueOf(refTypeJson.asText()) : RefType.strong);
31 public Object toValue(final JsonNode value) {
32 if (value.isArray()) {
33 if (value.size() == 2 && value.get(0).isTextual() && "uuid".equals(value.get(0).asText())) {
34 return new UUID(value.get(1).asText());
38 * UUIDBaseType used by RefTable from SouthBound will always be an Array of ["uuid", <uuid>].
39 * But there are some cases from northbound where the RefTable type can be expanded to a Row
40 * with contents. In those scenarios, just retain the content and return a ReferencedRow for
41 * the upper layer functions to process it.
43 return new ReferencedRow(refTable, value);
49 public void validate(final Object value) {
53 public String getRefTable() {
57 public void setRefTable(final String refTable) {
58 this.refTable = refTable;
61 public UuidBaseType.RefType getRefType() {
65 public void setRefType(final UuidBaseType.RefType refType) {
66 this.refType = refType;
70 public String toString() {
71 return "UuidBaseType";
75 public int hashCode() {
78 result = prime * result
79 + (refTable == null ? 0 : refTable.hashCode());
80 result = prime * result
81 + (refType == null ? 0 : refType.hashCode());
86 public boolean equals(final Object obj) {
93 if (getClass() != obj.getClass()) {
96 UuidBaseType other = (UuidBaseType) obj;
97 if (refTable == null) {
98 if (other.refTable != null) {
101 } else if (!refTable.equals(other.refTable)) {
104 if (refType != other.refType) {