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(null, null);
19 static final BaseTypeFactory<UuidBaseType> FACTORY = new BaseTypeFactory<>() {
21 UuidBaseType create(final JsonNode typeDefinition) {
22 final JsonNode refTableNode = typeDefinition.get("refTable");
23 final String refTable = refTableNode != null ? refTableNode.asText() : null;
25 final JsonNode refTypeJson = typeDefinition.get("refType");
26 final RefType refType = refTypeJson != null ? RefType.valueOf(refTypeJson.asText()) : RefType.strong;
28 // FIXME: this is weird from refTable/refType perspective -- if there is no table, we should not default
29 // to strong reference and squash to singleton
30 return new UuidBaseType(refTable, refType);
34 private final String refTable;
35 private final RefType refType;
37 UuidBaseType(final String refTable, final RefType refType) {
38 this.refTable = refTable;
39 this.refType = refType;
43 public Object toValue(final JsonNode value) {
44 if (value.isArray()) {
45 if (value.size() == 2 && value.get(0).isTextual() && "uuid".equals(value.get(0).asText())) {
46 return new UUID(value.get(1).asText());
50 * UUIDBaseType used by RefTable from SouthBound will always be an Array of ["uuid", <uuid>].
51 * But there are some cases from northbound where the RefTable type can be expanded to a Row
52 * with contents. In those scenarios, just retain the content and return a ReferencedRow for
53 * the upper layer functions to process it.
55 return new ReferencedRow(refTable, value);
61 public void validate(final Object value) {
65 public String getRefTable() {
69 public UuidBaseType.RefType getRefType() {
74 public String toString() {
75 return "UuidBaseType";
79 public int hashCode() {
82 result = prime * result
83 + (refTable == null ? 0 : refTable.hashCode());
84 result = prime * result
85 + (refType == null ? 0 : refType.hashCode());
90 public boolean equals(final Object obj) {
97 if (getClass() != obj.getClass()) {
100 UuidBaseType other = (UuidBaseType) obj;
101 if (refTable == null) {
102 if (other.refTable != null) {
105 } else if (!refTable.equals(other.refTable)) {
108 if (refType != other.refType) {