diff options
author | Ashlee Young <ashlee@wildernessvoice.com> | 2015-12-01 05:49:27 -0800 |
---|---|---|
committer | Ashlee Young <ashlee@wildernessvoice.com> | 2015-12-01 05:49:27 -0800 |
commit | e63291850fd0795c5700e25e67e5dee89ba54c5f (patch) | |
tree | 9707289536ad95bb739c9856761ad43275e07d8c /framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type | |
parent | 671823e12bc13be9a8b87a5d7de33da1bb7a44e8 (diff) |
onos commit hash c2999f30c69e50df905a9d175ef80b3f23a98514
Change-Id: I2bb8562c4942b6d6a6d60b663db2e17540477b81
Signed-off-by: Ashlee Young <ashlee@wildernessvoice.com>
Diffstat (limited to 'framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type')
12 files changed, 1069 insertions, 0 deletions
diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/AtomicColumnType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/AtomicColumnType.java new file mode 100644 index 00000000..881755ae --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/AtomicColumnType.java @@ -0,0 +1,104 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * The "atomic-type" specifies the type of data stored in this column. Refer + * to RFC 7047 Section 3.2. + */ +public final class AtomicColumnType implements ColumnType { + private final BaseType baseType; + private final int min; + private final int max; + + /** + * Constructs a AtomicColumnType object. + * @param baseType BaseType entity + */ + public AtomicColumnType(BaseType baseType) { + checkNotNull(baseType, "BaseType cannot be null"); + this.baseType = baseType; + this.min = 1; + this.max = 1; + } + + /** + * Constructs a AtomicColumnType object. + * @param baseType BaseType entity + * @param min min constraint + * @param max max constraint + */ + public AtomicColumnType(BaseType baseType, int min, int max) { + checkNotNull(baseType, "BaseType cannot be null"); + this.baseType = baseType; + this.min = min; + this.max = max; + } + + /** + * Get baseType. + * @return baseType + */ + public BaseType baseType() { + return baseType; + } + + /** + * Get min. + * @return min + */ + public int min() { + return min; + } + + /** + * Get max. + * @return max + */ + public int max() { + return max; + } + + @Override + public int hashCode() { + return Objects.hash(baseType, min, max); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof AtomicColumnType) { + final AtomicColumnType other = (AtomicColumnType) obj; + return Objects.equals(this.baseType, other.baseType) + && Objects.equals(this.min, other.min) + && Objects.equals(this.max, other.max); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("baseType", baseType).add("min", min) + .add("max", max).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BaseType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BaseType.java new file mode 100644 index 00000000..d2614c12 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BaseType.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +/** + * One of the strings "integer", "real", "boolean", "string", or "uuid", + * representing the specified scalar type. Refer to RFC 7047 Section 3.2. + */ +public interface BaseType { + +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BaseTypeFactory.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BaseTypeFactory.java new file mode 100644 index 00000000..86dbb2e6 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BaseTypeFactory.java @@ -0,0 +1,214 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import java.util.Set; + +import org.onosproject.ovsdb.rfc.exception.AbnormalJsonNodeException; +import org.onosproject.ovsdb.rfc.schema.type.UuidBaseType.RefType; +import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil; + +import com.fasterxml.jackson.databind.JsonNode; +import com.google.common.collect.Sets; + +/** + * BaseType Factory class. + */ +public final class BaseTypeFactory { + + /** + * Constructs a BaseTypeFactory object. This class should not be + * instantiated. + */ + private BaseTypeFactory() { + } + + /** + * Create a BaseType from the JsonNode. + * @param baseTypeJson the BaseType JsonNode + * @param keyorval the key node or value node + * @return BaseType + */ + public static BaseType getBaseTypeFromJson(JsonNode baseTypeJson, String keyorval) { + if (baseTypeJson.isValueNode()) { + String type = baseTypeJson.asText().trim(); + return fromTypeStr(type); + } else { + if (!baseTypeJson.has(keyorval)) { + String message = "Abnormal BaseType JsonNode, it should contain 'key' or 'value' node but was not found" + + ObjectMapperUtil.convertToString(baseTypeJson); + throw new AbnormalJsonNodeException(message); + } + return fromJsonNode(baseTypeJson.get(keyorval)); + } + } + + /** + * Get BaseType by the type value of JsonNode. + * @param type the type value of JsonNode + * @return BaseType + */ + private static BaseType fromTypeStr(String type) { + switch (type) { + case "boolean": + return new BooleanBaseType(); + case "integer": + return new IntegerBaseType(); + case "real": + return new RealBaseType(); + case "string": + return new StringBaseType(); + case "uuid": + return new UuidBaseType(); + default: + return null; + } + } + + /** + * json like "string" or json like {"type" : "string", "enum": ["set", + * ["access", "native-tagged"]]}" for key or value. + * @param type JsonNode + */ + private static BaseType fromJsonNode(JsonNode type) { + if (type.isTextual()) { + return fromTypeStr(type.asText()); + } else if (type.isObject() && type.has("type")) { + String typeStr = type.get("type").asText(); + switch (typeStr) { + case "boolean": + return new BooleanBaseType(); + case "integer": + return getIntegerBaseType(type); + case "real": + return getRealBaseType(type); + case "string": + return getStringBaseType(type); + case "uuid": + return getUuidBaseType(type); + default: + return null; + } + } + return null; + } + + /** + * Get IntegerBaseType by the type value of JsonNode which contains the + * constraints. + * @param type the type value of JsonNode + * @return IntegerBaseType + */ + private static IntegerBaseType getIntegerBaseType(JsonNode type) { + int min = Integer.MIN_VALUE; + int max = Integer.MAX_VALUE; + Set<Integer> enums = Sets.newHashSet(); + JsonNode node = type.get("minInteger"); + if (node != null) { + min = node.asInt(); + } + node = type.get("maxInteger"); + if (node != null) { + max = node.asInt(); + } + if (type.has("enum")) { + JsonNode anEnum = type.get("enum").get(1); + for (JsonNode n : anEnum) { + enums.add(n.asInt()); + } + } + return new IntegerBaseType(min, max, enums); + } + + /** + * Get RealBaseType by the type value of JsonNode which contains the + * constraints. + * @param type the type value of JsonNode + * @return RealBaseType + */ + private static RealBaseType getRealBaseType(JsonNode type) { + double min = Double.MIN_VALUE; + double max = Double.MAX_VALUE; + Set<Double> enums = Sets.newHashSet(); + JsonNode node = type.get("minReal"); + if (node != null) { + min = node.asDouble(); + } + node = type.get("maxReal"); + if (node != null) { + max = node.asDouble(); + } + if (type.has("enum")) { + JsonNode anEnum = type.get("enum").get(1); + for (JsonNode n : anEnum) { + enums.add(n.asDouble()); + } + } + return new RealBaseType(min, max, enums); + } + + /** + * Get StringBaseType by the type value of JsonNode which contains the + * constraints. + * @param type the type value of JsonNode + * @return StringBaseType + */ + private static StringBaseType getStringBaseType(JsonNode type) { + int minLength = Integer.MIN_VALUE; + int maxLength = Integer.MAX_VALUE; + Set<String> enums = Sets.newHashSet(); + JsonNode node = type.get("minLength"); + if (node != null) { + minLength = node.asInt(); + } + node = type.get("maxLength"); + if (node != null) { + maxLength = node.asInt(); + } + if (type.has("enum")) { + JsonNode enumVal = type.get("enum"); + if (enumVal.isArray()) { + JsonNode anEnum = enumVal.get(1); + for (JsonNode n : anEnum) { + enums.add(n.asText()); + } + } else if (enumVal.isTextual()) { + enums.add(enumVal.asText()); + } + } + return new StringBaseType(minLength, maxLength, enums); + } + + /** + * Get UuidBaseType by the type value of JsonNode which contains the + * constraints. + * @param type the type value of JsonNode + * @return UuidBaseType + */ + private static UuidBaseType getUuidBaseType(JsonNode type) { + String refTable = null; + String refType = RefType.STRONG.refType(); + JsonNode node = type.get("refTable"); + if (node != null) { + refTable = node.asText(); + } + node = type.get("refType"); + if (node != null) { + refType = node.asText(); + } + return new UuidBaseType(refTable, refType); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BooleanBaseType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BooleanBaseType.java new file mode 100644 index 00000000..d42337a5 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/BooleanBaseType.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; + +/** + * One of the strings "integer", "real", "boolean", "string", or "uuid", + * representing the specified scalar type. Refer to RFC 7047 Section 3.2. + * Because BooleanBaseType has no constraint conditions, and in order to be + * consistent with other BaseType, so this class is empty except for the + * toString method. + */ +public final class BooleanBaseType implements BaseType { + + @Override + public String toString() { + return toStringHelper(this).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/ColumnType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/ColumnType.java new file mode 100644 index 00000000..20f1bbac --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/ColumnType.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +/** + * The "type" specifies the type of data stored in this column. Refer to RFC + * 7047 Section 3.2. + */ +public interface ColumnType { + +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/ColumnTypeFactory.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/ColumnTypeFactory.java new file mode 100644 index 00000000..47b34a6b --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/ColumnTypeFactory.java @@ -0,0 +1,123 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import org.onosproject.ovsdb.rfc.exception.AbnormalJsonNodeException; +import org.onosproject.ovsdb.rfc.utils.ObjectMapperUtil; + +import com.fasterxml.jackson.databind.JsonNode; + +/** + * ColumnType Factory class. + */ +public final class ColumnTypeFactory { + + /** + * Constructs a ColumnTypeFactory object. This class should not be + * instantiated. + */ + private ColumnTypeFactory() { + } + + /** + * Those Json's key/value pairs. + */ + public enum Type { + KEY("key"), VALUE("value"); + + private final String type; + + private Type(String type) { + this.type = type; + } + + /** + * Returns the type for Type. + * @return the type + */ + public String type() { + return type; + } + } + + /** + * JsonNode like + * "flow_tables":{"type":{"key":{"maxInteger":254,"minInteger":0,"type": + * "integer"},"min":0,"value":{"type":"uuid","refTable":"Flow_Table"},"max": + * "unlimited"}}. + * @param columnTypeJson the ColumnType JsonNode + * @return ColumnType + */ + public static ColumnType getColumnTypeFromJson(JsonNode columnTypeJson) { + if (!columnTypeJson.isObject() || !columnTypeJson.has(Type.VALUE.type())) { + return createAtomicColumnType(columnTypeJson); + } else if (!columnTypeJson.isValueNode() && columnTypeJson.has(Type.VALUE.type())) { + return createKeyValuedColumnType(columnTypeJson); + } + String message = "Abnormal ColumnType JsonNode, it should be AtomicColumnType or KeyValuedColumnType" + + ObjectMapperUtil.convertToString(columnTypeJson); + throw new AbnormalJsonNodeException(message); + } + + /** + * Create AtomicColumnType entity. + * @param json JsonNode + * @return AtomicColumnType entity + */ + private static AtomicColumnType createAtomicColumnType(JsonNode json) { + BaseType baseType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type()); + int min = 1; + int max = 1; + JsonNode node = json.get("min"); + if (node != null && node.isNumber()) { + min = node.asInt(); + } + node = json.get("max"); + if (node != null) { + if (node.isNumber()) { + max = node.asInt(); + } else if (node.isTextual() && "unlimited".equals(node.asText())) { + max = Integer.MAX_VALUE; + } + } + return new AtomicColumnType(baseType, min, max); + } + + /** + * Create KeyValuedColumnType entity. + * @param json JsonNode + * @return KeyValuedColumnType entity + */ + private static KeyValuedColumnType createKeyValuedColumnType(JsonNode json) { + BaseType keyType = BaseTypeFactory.getBaseTypeFromJson(json, Type.KEY.type()); + BaseType valueType = BaseTypeFactory.getBaseTypeFromJson(json, Type.VALUE.type()); + int min = 1; + int max = 1; + JsonNode node = json.get("min"); + if (node != null && node.isNumber()) { + min = node.asInt(); + } + node = json.get("max"); + if (node != null) { + if (node.isNumber()) { + max = node.asInt(); + } else if (node.isTextual() && "unlimited".equals(node.asText())) { + max = Integer.MAX_VALUE; + } + } + return new KeyValuedColumnType(keyType, valueType, min, max); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/IntegerBaseType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/IntegerBaseType.java new file mode 100644 index 00000000..91939515 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/IntegerBaseType.java @@ -0,0 +1,103 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Objects; +import java.util.Set; + +import com.google.common.collect.Sets; + +/** + * One of the strings "integer", "real", "boolean", "string", or "uuid", + * representing the specified scalar type. Refer to RFC 7047 Section 3.2. + */ +public final class IntegerBaseType implements BaseType { + private final int min; + private final int max; + private final Set<Integer> enums; + + /** + * Constructs a IntegerBaseType object. + */ + public IntegerBaseType() { + this.min = Integer.MIN_VALUE; + this.max = Integer.MAX_VALUE; + this.enums = Sets.newHashSet(); + } + + /** + * Constructs a IntegerBaseType object. + * @param min min constraint + * @param max max constraint + * @param enums enums constraint + */ + public IntegerBaseType(int min, int max, Set<Integer> enums) { + this.min = min; + this.max = max; + this.enums = enums; + } + + /** + * Get min. + * @return min + */ + public int min() { + return min; + } + + /** + * Get max. + * @return max + */ + public int max() { + return max; + } + + /** + * Get enums. + * @return enums + */ + public Set<Integer> enums() { + return enums; + } + + @Override + public int hashCode() { + return Objects.hash(min, max, enums); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof IntegerBaseType) { + final IntegerBaseType other = (IntegerBaseType) obj; + return Objects.equals(this.enums, other.enums) + && Objects.equals(this.min, other.min) + && Objects.equals(this.max, other.max); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("min", min).add("max", max) + .add("enums", enums).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/KeyValuedColumnType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/KeyValuedColumnType.java new file mode 100644 index 00000000..8407457a --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/KeyValuedColumnType.java @@ -0,0 +1,108 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * a JSON object that describes the type of a database column, with key and + * value. Refer to RFC 7047 Section 3.2. + */ +public final class KeyValuedColumnType implements ColumnType { + private final BaseType keyType; + private final BaseType valueType; + private final int min; + private final int max; + + /** + * Constructs a KeyValuedColumnType object. + * @param keyType BaseType entity + * @param valueType BaseType entity + * @param min min constraint + * @param max max constraint + */ + public KeyValuedColumnType(BaseType keyType, BaseType valueType, int min, + int max) { + checkNotNull(keyType, "keyType cannot be null"); + checkNotNull(valueType, "valueType cannot be null"); + this.keyType = keyType; + this.valueType = valueType; + this.min = min; + this.max = max; + } + + /** + * Get keyType. + * @return keyType + */ + public BaseType keyType() { + return keyType; + } + + /** + * Get valueType. + * @return valueType + */ + public BaseType valueType() { + return valueType; + } + + /** + * Get min. + * @return min + */ + public int min() { + return min; + } + + /** + * Get max. + * @return max + */ + public int max() { + return max; + } + + @Override + public int hashCode() { + return Objects.hash(keyType, valueType, min, max); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof KeyValuedColumnType) { + final KeyValuedColumnType other = (KeyValuedColumnType) obj; + return Objects.equals(this.keyType, other.keyType) + && Objects.equals(this.valueType, other.valueType) + && Objects.equals(this.min, other.min) + && Objects.equals(this.max, other.max); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("keyType", keyType) + .add("valueType", valueType).add("min", min).add("max", max) + .toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/RealBaseType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/RealBaseType.java new file mode 100644 index 00000000..6704e30a --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/RealBaseType.java @@ -0,0 +1,103 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Objects; +import java.util.Set; + +import com.google.common.collect.Sets; + +/** + * One of the strings "integer", "real", "boolean", "string", or "uuid", + * representing the specified scalar type. Refer to RFC 7047 Section 3.2. + */ +public final class RealBaseType implements BaseType { + private final double min; + private final double max; + private final Set<Double> enums; + + /** + * Constructs a RealBaseType object. + */ + public RealBaseType() { + this.min = Double.MIN_VALUE; + this.max = Double.MAX_VALUE; + this.enums = Sets.newHashSet(); + } + + /** + * Constructs a RealBaseType object. + * @param min min constraint + * @param max max constraint + * @param enums enums constraint + */ + public RealBaseType(double min, double max, Set<Double> enums) { + this.min = min; + this.max = max; + this.enums = enums; + } + + /** + * Get min. + * @return min + */ + public double getMin() { + return min; + } + + /** + * Get max. + * @return max + */ + public double getMax() { + return max; + } + + /** + * Get enums. + * @return enums + */ + public Set<Double> getEnums() { + return enums; + } + + @Override + public int hashCode() { + return Objects.hash(min, max, enums); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof RealBaseType) { + final RealBaseType other = (RealBaseType) obj; + return Objects.equals(this.enums, other.enums) + && Objects.equals(this.min, other.min) + && Objects.equals(this.max, other.max); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("min", min).add("max", max) + .add("enums", enums).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/StringBaseType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/StringBaseType.java new file mode 100644 index 00000000..96d2f739 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/StringBaseType.java @@ -0,0 +1,103 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; + +import java.util.Objects; +import java.util.Set; + +import com.google.common.collect.Sets; + +/** + * One of the strings "integer", "real", "boolean", "string", or "uuid", + * representing the specified scalar type. Refer to RFC 7047 Section 3.2. + */ +public final class StringBaseType implements BaseType { + private final int minLength; + private final int maxLength; + private final Set<String> enums; + + /** + * Constructs a StringBaseType object. + */ + public StringBaseType() { + this.minLength = Integer.MIN_VALUE; + this.maxLength = Integer.MAX_VALUE; + this.enums = Sets.newHashSet(); + } + + /** + * Constructs a StringBaseType object. + * @param minLength minLength constraint + * @param maxLength maxLength constraint + * @param enums enums constraint + */ + public StringBaseType(int minLength, int maxLength, Set<String> enums) { + this.minLength = minLength; + this.maxLength = maxLength; + this.enums = enums; + } + + /** + * Get minLength. + * @return minLength + */ + public int getMinLength() { + return minLength; + } + + /** + * Get maxLength. + * @return maxLength + */ + public int getMaxLength() { + return maxLength; + } + + /** + * Get enums. + * @return enums + */ + public Set<String> getEnums() { + return enums; + } + + @Override + public int hashCode() { + return Objects.hash(minLength, maxLength, enums); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof StringBaseType) { + final StringBaseType other = (StringBaseType) obj; + return Objects.equals(this.enums, other.enums) + && Objects.equals(this.minLength, other.minLength) + && Objects.equals(this.maxLength, other.maxLength); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("minLength", minLength) + .add("maxLength", maxLength).add("enums", enums).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/UuidBaseType.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/UuidBaseType.java new file mode 100644 index 00000000..46e0d9fa --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/UuidBaseType.java @@ -0,0 +1,110 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onosproject.ovsdb.rfc.schema.type; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * One of the strings "integer", "real", "boolean", "string", or "uuid", + * representing the specified scalar type. Refer to RFC 7047 Section 3.2. + */ +public final class UuidBaseType implements BaseType { + /** + * RefType is strong or weak. refer to base-type of RFC 7047 Section 3.2. + */ + public enum RefType { + STRONG("strong"), WEAK("weak"); + + private String refType; + + private RefType(String refType) { + this.refType = refType; + } + + /** + * Returns the refType for RefType. + * @return the refType + */ + public String refType() { + return refType; + } + } + + private final String refTable; + private final String refType; + + /** + * Constructs a UuidBaseType object. + */ + public UuidBaseType() { + this.refTable = null; + this.refType = RefType.STRONG.refType(); + } + + /** + * Constructs a UuidBaseType object. + * @param refTable refTable constraint + * @param refType refType constraint + */ + public UuidBaseType(String refTable, String refType) { + checkNotNull(refType, "refType cannot be null"); + this.refTable = refTable; + this.refType = refType; + } + + /** + * Get refTable. + * @return refTable + */ + public String getRefTable() { + return refTable; + } + + /** + * Get refType. + * @return refType + */ + public String getRefType() { + return refType; + } + + @Override + public int hashCode() { + return Objects.hash(refTable, refType); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof UuidBaseType) { + final UuidBaseType other = (UuidBaseType) obj; + return Objects.equals(this.refTable, other.refTable) + && Objects.equals(this.refType, other.refType); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("refTable", refTable) + .add("refType", refType).toString(); + } +} diff --git a/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/package-info.java b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/package-info.java new file mode 100644 index 00000000..eade2e28 --- /dev/null +++ b/framework/src/onos/protocols/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/schema/type/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2015 Open Networking Laboratory + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * OVSDB schema types. + */ +package org.onosproject.ovsdb.rfc.schema.type; |