[ONOS-5793] Schema context definition, this will be implemented by YANG runtime and used by serializers to obtain schema context of nodes
Change-Id: I29b6650d8bed6ddf24e4b975b6bfa4c2b5aa9686
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafRestriction.java b/model/src/main/java/org/onosproject/yang/model/LeafRestriction.java
new file mode 100644
index 0000000..ce627c7
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafRestriction.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2017-present 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.yang.model;
+
+/**
+ * Representation of leaf restriction.
+ */
+public class LeafRestriction {
+ // TODO
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java b/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
new file mode 100644
index 0000000..a1d123d
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafSchemaContext.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2017-present 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.yang.model;
+
+/**
+ * Representation of a context for obtaining leaf/leaf-list schema related
+ * extended information.
+ */
+public interface LeafSchemaContext extends SchemaContext {
+
+ /**
+ * Returns type of the leaf.
+ *
+ * @return value of leaf in object
+ */
+ LeafType getLeafType();
+
+ /**
+ * Returns the restrictions associated with leaf/leaf-list. Returns null
+ * if no restrictions are associated with leaf.
+ *
+ * @param <T> restriction type
+ * @return restriction
+ */
+ <T extends LeafRestriction> T getLeafRestrictions();
+
+ /**
+ * Returns object from string value of a leaf.
+ *
+ * @param value leaf value in string
+ * @return leaf's object
+ * @throws IllegalArgumentException when input value is not as per the
+ * schema
+ */
+ Object fromString(String value);
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafType.java b/model/src/main/java/org/onosproject/yang/model/LeafType.java
new file mode 100644
index 0000000..d60d8b1
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafType.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2016-present 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.yang.model;
+
+/**
+ * Representation of leaf's type.
+ */
+public enum LeafType {
+
+ /**
+ * Represents JAVA short.
+ */
+ SHORT,
+
+ /**
+ * Represents JAVA int.
+ */
+ INT,
+
+ /**
+ * Represents JAVA long.
+ */
+ LONG,
+
+ /**
+ * Represents JAVA float.
+ */
+ FLOAT,
+
+ /**
+ * Represents JAVA double.
+ */
+ DOUBLE,
+
+ /**
+ * Represents JAVA boolean.
+ */
+ BOOLEAN,
+
+ /**
+ * Represents JAVA char.
+ */
+ CHAR,
+
+ /**
+ * Represents JAVA byte.
+ */
+ BYTE,
+
+ /**
+ * Represents JAVA string.
+ */
+ STRING,
+
+ /**
+ * Represents JAVA big integer.
+ */
+ BIG_INTEGER,
+
+ /**
+ * Represents JAVA enum type.
+ */
+ ENUM,
+
+ /**
+ * Represents big decimal.
+ * The decimal64 type represents a subset of the real numbers, which can
+ * be represented by decimal numerals. The value space of decimal64 is
+ * the set of numbers that can be obtained by multiplying a 64-bit
+ * signed integer by a negative power of ten, i.e., expressible as
+ * "i x 10^-n" where i is an integer64 and n is an integer between 1 and
+ * 18, inclusively.
+ */
+ BIG_DECIMAL,
+
+ /**
+ * Represents binary. The binary type represents any binary data,
+ * i.e., a sequence of octets.
+ */
+ BINARY,
+
+ /**
+ * Represents bits. The bits type represents a bit set. That
+ * is, a bits value is a set of flags identified by small integer
+ * position numbers starting at 0. Each bit number has an assigned name.
+ */
+ BITS,
+
+ /**
+ * Represents union type. The union type represents a value that
+ * corresponds to one of its member types.
+ */
+ UNION,
+
+ /**
+ * The resource identifier type is used to uniquely identify a
+ * particular instance node in the data tree.
+ */
+ RESOURCE_IDENTIFIER,
+
+ /**
+ * The identityref type is used to reference an existing identity
+ */
+ IDENTITY_REF,
+
+ /**
+ * The leafref type is used to reference a particular leaf instance in
+ * the data tree.
+ */
+ LEAF_REF,
+
+ /**
+ * The empty type represents a leaf that does not have any
+ * value, it conveys information by its presence or absence.
+ */
+ EMPTY
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ListSchemaContext.java b/model/src/main/java/org/onosproject/yang/model/ListSchemaContext.java
new file mode 100644
index 0000000..4c0ffb9
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ListSchemaContext.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017-present 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.yang.model;
+
+import java.util.Set;
+
+/**
+ * Representation of multi instance node schema context.
+ */
+public interface ListSchemaContext extends SingleInstanceNodeContext {
+
+ /**
+ * Returns ordered set of key leaf name as per the YANG schema.
+ *
+ * @return set of key leaf
+ */
+ Set<String> getKeyLeaf();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/SchemaContext.java b/model/src/main/java/org/onosproject/yang/model/SchemaContext.java
new file mode 100644
index 0000000..f86eefa
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/SchemaContext.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-present 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.yang.model;
+
+import static org.onosproject.yang.model.DataNode.Type;
+
+/**
+ * Representation of a context for obtaining schema related information.
+ */
+public interface SchemaContext {
+
+ /**
+ * Returns parent context. Returns null if current context is of topmost
+ * node "/" which doesn't have any parent.
+ *
+ * @return parent context
+ */
+ SchemaContext getParentContext();
+
+ /**
+ * Returns type of the node.
+ *
+ * @return node type
+ */
+ Type getType();
+
+ /**
+ * Returns schema identifier of the node.
+ *
+ * @return schema identifier
+ */
+ SchemaId getSchemaId();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/SchemaContextProvider.java b/model/src/main/java/org/onosproject/yang/model/SchemaContextProvider.java
new file mode 100644
index 0000000..8c3e386
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/SchemaContextProvider.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017-present 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.yang.model;
+
+/**
+ * Representation of an entity that provides schema context.
+ */
+public interface SchemaContextProvider {
+
+ /**
+ * Returns schema context corresponding to a given resource identifier.
+ * It returns null if module is not registered. Resource identifier with
+ * "/" is to be provided to obtain root level resource context.
+ *
+ * @param id absolute resource identifier
+ * @return schema context
+ * @throws IllegalArgumentException when module as per resource
+ * identifier is registered, but given
+ * resource identifier is invalid
+ */
+ SchemaContext getSchemaContext(ResourceId id);
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/SingleInstanceNodeContext.java b/model/src/main/java/org/onosproject/yang/model/SingleInstanceNodeContext.java
new file mode 100644
index 0000000..c235410
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/SingleInstanceNodeContext.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2017-present 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.yang.model;
+
+/**
+ * Representation of single instance node schema context.
+ */
+public interface SingleInstanceNodeContext extends SchemaContext {
+
+ /**
+ * Returns child context.
+ *
+ * @param id schema identifier
+ * @return child schema context
+ * @throws IllegalArgumentException when schema identifier is invalid
+ */
+ SchemaContext getChildContext(SchemaId id);
+}