Vinod Kumar S
Committed by Gerrit Code Review

[ONOS-3885, ONOS-3886, ONOS-3887] Implement YANG sub-module, container and list data model

Change-Id: Id9be89054db0f4c4f84e62547d3b6851cfed3de2
/*
* Copyright 2016 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*-
* Reference 6020.
*
* The "belongs-to" statement specifies the module to which the
* submodule belongs. The argument is an identifier that is the name of
* the module.
*
* A submodule MUST only be included by the module to which it belongs,
* or by another submodule that belongs to that module.
*
* The mandatory "prefix" sub-statement assigns a prefix for the module
* to which the submodule belongs. All definitions in the local
* submodule and any included submodules can be accessed by using the
* prefix.
*
* The belongs-to's sub-statements
*
* +--------------+---------+-------------+
* | substatement | section | cardinality |
* +--------------+---------+-------------+
* | prefix | 7.1.4 | 1 |
* +--------------+---------+-------------+
*/
/**
* Maintains the belongs-to data type information.
*/
public class YangBelongsTo implements Parsable {
/**
* Reference RFC 6020.
*
* The "belongs-to" statement specifies the module to which the submodule
* belongs. The argument is an identifier that is the name of the module.
*/
private String belongsToModuleName;
/**
* Reference RFC 6020.
*
* The mandatory "prefix" substatement assigns a prefix for the module to
* which the submodule belongs. All definitions in the local submodule and
* any included submodules can be accessed by using the prefix.
*/
private String prefix;
/**
* Create a belongs to object.
*/
public YangBelongsTo() {
}
/**
* Get the belongs to module name.
*
* @return the belongs to module name
*/
public String getBelongsToModuleName() {
return belongsToModuleName;
}
/**
* Set the belongs to module name.
*
* @param belongsToModuleName the belongs to module name to set
*
*/
public void setBelongsToModuleName(String belongsToModuleName) {
this.belongsToModuleName = belongsToModuleName;
}
/**
* Get the prefix.
*
* @return the prefix.
*/
public String getPrefix() {
return prefix;
}
/**
* Set the prefix.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/**
* Returns the type of the data as belongs-to.
*
* @return ParsedDataType returns BELONGS_TO_DATA
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.BELONGS_TO_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* Copyright 2016 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.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.utils.io.CachedFileHandle;
/*-
* Reference RFC 6020.
*
* The "container" statement is used to define an interior data node in the
* schema tree. It takes one argument, which is an identifier, followed by a
* block of sub-statements that holds detailed container information.
*
* A container node does not have a value, but it has a list of child nodes in
* the data tree. The child nodes are defined in the container's sub-statements.
*
* Containers with Presence
*
* YANG supports two styles of containers, those that exist only for organizing
* the hierarchy of data nodes, and those whose presence in the configuration
* has an explicit meaning.
*
* In the first style, the container has no meaning of its own, existing only to
* contain child nodes. This is the default style.
*
* For example, the set of scrambling options for Synchronous Optical Network
* (SONET) interfaces may be placed inside a "scrambling" container to enhance
* the organization of the configuration hierarchy, and to keep these nodes
* together. The "scrambling" node itself has no meaning, so removing the node
* when it becomes empty relieves the user from performing this task.
*
* In the second style, the presence of the container itself is configuration
* data, representing a single bit of configuration data. The container acts as
* both a configuration knob and a means of organizing related configuration.
* These containers are explicitly created and deleted.
*
* YANG calls this style a "presence container" and it is indicated using the
* "presence" statement, which takes as its argument a text string indicating
* what the presence of the node means.
*
* The container's Substatements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | anyxml | 7.10 | 0..n | -not supported |
* | choice | 7.9 | 0..n | -child nodes |
* | config | 7.19.1 | 0..1 | -boolean |
* | container | 7.5 | 0..n | -child nodes |
* | description | 7.19.3 | 0..1 | -string |
* | grouping | 7.11 | 0..n | -child nodes |
* | if-feature | 7.18.2 | 0..n | -TODO |
* | leaf | 7.6 | 0..n | -YangLeaf |
* | leaf-list | 7.7 | 0..n | -YangLeafList |
* | list | 7.8 | 0..n | -child nodes |
* | must | 7.5.3 | 0..n | -TODO |
* | presence | 7.5.5 | 0..1 | -boolean |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | typedef | 7.3 | 0..n | -child nodes |
* | uses | 7.12 | 0..n | -child nodes |
* | when | 7.19.5 | 0..1 | -TODO |
* +--------------+---------+-------------+------------------+
*/
/**
* Data model node to maintain information defined in YANG container.
*/
public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
/**
* Name of the container.
*/
private String name;
/**
* If container maintains config data.
*/
private boolean isConfig;
/**
* Description of container.
*/
private String description;
/**
* List of leaves contained.
*/
@SuppressWarnings("rawtypes")
private List<YangLeaf> listOfLeaf;
/**
* List of leaf-lists contained.
*/
@SuppressWarnings("rawtypes")
private List<YangLeafList> listOfLeafList;
/**
* If it is a presence container, then the textual documentation of presence
* usage.
*/
private String presence;
/**
* Reference of the module.
*/
private String reference;
/**
* Status of the node.
*/
private YangStatusType status;
/**
* package of the generated java code.
*/
private String pkg;
/**
* Cached Java File Handle.
*/
private CachedFileHandle fileHandle;
/**
* Create a container node.
*/
public YangContainer() {
super(YangNodeType.CONTAINER_NODE);
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#getName()
*/
@Override
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* Get the config flag.
*
* @return the isConfig
*/
public boolean isConfig() {
return isConfig;
}
/**
* Set the config flag.
*
* @param isCfg the config flag.
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
}
/**
* Get the description.
*
* @return the description.
*/
public String getDescription() {
return description;
}
/**
* Set the description.
*
* @param description set the description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Get the list of leaves.
*
* @return the list of leaves.
*/
@SuppressWarnings("rawtypes")
public List<YangLeaf> getListOfLeaf() {
return listOfLeaf;
}
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
*/
@SuppressWarnings("rawtypes")
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
*/
@SuppressWarnings("rawtypes")
public void addLeaf(YangLeaf<?> leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
}
getListOfLeaf().add(leaf);
}
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
*/
@SuppressWarnings("rawtypes")
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
*/
@SuppressWarnings("rawtypes")
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
*/
@SuppressWarnings("rawtypes")
public void addLeafList(YangLeafList<?> leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
}
getListOfLeafList().add(leafList);
}
/**
* Get the presence string if present.
*
* @return the isPressence.
*/
public String getPresence() {
return presence;
}
/**
* Set the presence string.
*
* @param presence the presence flag
*/
public void setPresence(String presence) {
this.presence = presence;
}
/**
* Get the textual reference.
*
* @return the reference.
*/
public String getReference() {
return reference;
}
/**
* Set the textual reference.
*
* @param reference the reference to set.
*/
public void setReference(String reference) {
this.reference = reference;
}
/**
* Get the status.
*
* @return the status.
*/
public YangStatusType getStatus() {
return status;
}
/**
* Set the status.
*
* @param status the status to set.
*/
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Get the cached file handle.
*
* @return the fileHandle
*/
public CachedFileHandle getFileHandle() {
return fileHandle;
}
/**
* Set the cached file handle.
*
* @param handle the fileHandle to set
*/
public void setFileHandle(CachedFileHandle handle) {
fileHandle = handle;
}
/**
* Returns the type of the data.
*
* @return returns CONTAINER_DATA.
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.CONTAINER_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Get the mapped java package.
*
* @return the java package
*/
@Override
public String getPackage() {
return pkg;
}
/**
* Set the mapped java package.
*
* @param pcg the package to set
*/
@Override
public void setPackage(String pcg) {
pkg = pcg;
}
/**
* Generate the java code corresponding to YANG container.
*/
public void generateJavaCodeEntry() {
//TODO: autogenerated method stub, to be implemented
return;
}
/**
* Free resources used to generate code.
*/
public void generateJavaCodeExit() {
//TODO: autogenerated method stub, to be implemented
return;
}
}
......@@ -22,18 +22,21 @@ package org.onosproject.yangutils.datamodel;
public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* int8 represents integer values between -128 and 127, inclusively.
*/
INT8,
/**
* Reference:RFC 6020.
*
* int16 represents integer values between -32768 and 32767, inclusively.
*/
INT16,
/**
* Reference:RFC 6020.
*
* int32 represents integer values between -2147483648 and 2147483647,
* inclusively.
*/
......@@ -41,6 +44,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* int64 represents integer values between -9223372036854775808 and
* 9223372036854775807, inclusively.
*/
......@@ -48,24 +52,28 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* uint8 represents integer values between 0 and 255, inclusively.
*/
UINT8,
/**
* Reference:RFC 6020.
*
* uint16 represents integer values between 0 and 65535, inclusively.
*/
UINT16,
/**
* Reference:RFC 6020.
*
* uint32 represents integer values between 0 and 4294967295, inclusively.
*/
UINT32,
/**
* Reference:RFC 6020.
*
* uint64 represents integer values between 0 and 18446744073709551615,
* inclusively.
*/
......@@ -73,6 +81,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* 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
......@@ -83,6 +92,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The string built-in type represents human-readable strings in YANG. Legal
* characters are tab, carriage return, line feed, and the legal characters
* of Unicode and ISO/IEC 10646
......@@ -91,12 +101,14 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The boolean built-in type represents a boolean value.
*/
BOOLEAN,
/**
* Reference:RFC 6020.
*
* The enumeration built-in type represents values from a set of assigned
* names.
*/
......@@ -104,6 +116,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The bits built-in 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.
......@@ -112,6 +125,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The binary built-in type represents any binary data, i.e., a sequence of
* octets.
*/
......@@ -119,6 +133,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The leafref type is used to reference a particular leaf instance in the
* data tree. The "path" sub-statement (Section 9.9.2) selects a set of leaf
* instances, and the leafref value space is the set of values of these leaf
......@@ -139,12 +154,14 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The identityref type is used to reference an existing identity.
*/
IDENTITYREF,
/**
* Reference:RFC 6020.
*
* The empty built-in type represents a leaf that does not have any value,
* it conveys information by its presence or absence.
*
......@@ -154,6 +171,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The union built-in type represents a value that corresponds to one of its
* member types.
*
......@@ -175,6 +193,7 @@ public enum YangDataTypes {
/**
* Reference:RFC 6020.
*
* The instance-identifier built-in type is used to uniquely identify a
* particular instance node in the data tree.
*
......
/*
* Copyright 2016 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.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*-
* The "list" statement is used to define an interior data node in the
* schema tree. A list node may exist in multiple instances in the data
* tree. Each such instance is known as a list entry. The "list"
* statement takes one argument, which is an identifier, followed by a
* block of sub-statements that holds detailed list information.
*
* A list entry is uniquely identified by the values of the list's keys,
* if defined.
*
* The list's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | anyxml | 7.10 | 0..n |-not supported |
* | choice | 7.9 | 0..n |-child nodes |
* | config | 7.19.1 | 0..1 |-boolean |
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
* | grouping | 7.11 | 0..n |-child nodes |
* | if-feature | 7.18.2 | 0..n |-TODO |
* | key | 7.8.2 | 0..1 |-String list |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | max-elements | 7.7.4 | 0..1 |-int |
* | min-elements | 7.7.3 | 0..1 |-int |
* | must | 7.5.3 | 0..n |-TODO |
* | ordered-by | 7.7.5 | 0..1 |-TODO |
* | reference | 7.19.4 | 0..1 |-string |
* | status | 7.19.2 | 0..1 |-YangStatus |
* | typedef | 7.3 | 0..n |-child nodes |
* | unique | 7.8.3 | 0..n |-TODO |
* | uses | 7.12 | 0..n |-child nodes(TODO)|
* | when | 7.19.5 | 0..1 |-TODO |
* +--------------+---------+-------------+------------------+
*/
/**
* List data represented in YANG.
*/
public class YangList extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable {
/**
* name of the YANG list.
*/
private String name;
/**
* If list maintains config data.
*/
private boolean isConfig;
/**
* Description of list.
*/
private String description;
/**
* Reference RFC 6020.
*
* The "key" statement, which MUST be present if the list represents
* configuration, and MAY be present otherwise, takes as an argument a
* string that specifies a space-separated list of leaf identifiers of this
* list. A leaf identifier MUST NOT appear more than once in the key. Each
* such leaf identifier MUST refer to a child leaf of the list. The leafs
* can be defined directly in sub-statements to the list, or in groupings
* used in the list.
*
* The combined values of all the leafs specified in the key are used to
* uniquely identify a list entry. All key leafs MUST be given values when a
* list entry is created. Thus, any default values in the key leafs or their
* types are ignored. It also implies that any mandatory statement in the
* key leafs are ignored.
*
* A leaf that is part of the key can be of any built-in or derived type,
* except it MUST NOT be the built-in type "empty".
*
* All key leafs in a list MUST have the same value for their "config" as
* the list itself.
*
* List of key leaf names.
*/
private List<String> keyList;
/**
* List of leaves.
*/
@SuppressWarnings("rawtypes")
private List<YangLeaf> listOfLeaf;
/**
* List of leaf-lists.
*/
@SuppressWarnings("rawtypes")
private List<YangLeafList> listOfLeafList;
/**
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
* max-elements entries.
*
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
private int maxElelements;
/**
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
*
* If no "min-elements" statement is present, it defaults to zero.
*
* The behavior of the constraint depends on the type of the leaf-list's or
* list's closest ancestor node in the schema tree that is not a non-
* presence container:
*
* o If this ancestor is a case node, the constraint is enforced if any
* other node from the case exists.
*
* o Otherwise, it is enforced if the ancestor node exists.
*/
private int minElements;
/**
* reference.
*/
private String reference;
/**
* Status of the node.
*/
private YangStatusType status;
/**
* Constructor.
*
* @param type list node
*/
public YangList(YangNodeType type) {
super(type);
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#getName()
*/
@Override
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* Get the config flag.
*
* @return the isConfig
*/
public boolean isConfig() {
return isConfig;
}
/**
* Set the config flag.
*
* @param isCfg the config flag.
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
}
/**
* Get the description.
*
* @return the description.
*/
public String getDescription() {
return description;
}
/**
* Set the description.
*
* @param description set the description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Get the list of key field names.
*
* @return the list of key field names.
*/
public List<String> getKeyList() {
return keyList;
}
/**
* Set the list of key field names.
*
* @param keyList the list of key field names.
*/
private void setKeyList(List<String> keyList) {
this.keyList = keyList;
}
/**
* Add a key field name.
*
* @param key key field name.
*/
public void addKey(String key) {
if (getKeyList() == null) {
setKeyList(new LinkedList<String>());
}
getKeyList().add(key);
}
/**
* Get the list of leaves.
*
* @return the list of leaves.
*/
@SuppressWarnings("rawtypes")
public List<YangLeaf> getListOfLeaf() {
return listOfLeaf;
}
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
*/
@SuppressWarnings("rawtypes")
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
*/
@SuppressWarnings("rawtypes")
public void addLeaf(YangLeaf<?> leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
}
getListOfLeaf().add(leaf);
}
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
*/
@SuppressWarnings("rawtypes")
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
*/
@SuppressWarnings("rawtypes")
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
*/
@SuppressWarnings("rawtypes")
public void addLeafList(YangLeafList<?> leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
}
getListOfLeafList().add(leafList);
}
/**
* Get the max elements.
*
* @return the max elements.
*/
public int getMaxElelements() {
return maxElelements;
}
/**
* Set the max elements.
*
* @param maxElelements the max elements.
*/
public void setMaxElelements(int maxElelements) {
this.maxElelements = maxElelements;
}
/**
* Get the minimum elements.
*
* @return the minimum elements.
*/
public int getMinElements() {
return minElements;
}
/**
* Set the minimum elements.
*
* @param minElements the minimum elements.
*/
public void setMinElements(int minElements) {
this.minElements = minElements;
}
/**
* Get the textual reference.
*
* @return the reference.
*/
public String getReference() {
return reference;
}
/**
* Set the textual reference.
*
* @param reference the reference to set.
*/
public void setReference(String reference) {
this.reference = reference;
}
/**
* Get the status.
*
* @return the status.
*/
public YangStatusType getStatus() {
return status;
}
/**
* Set the status.
*
* @param status the status to set.
*/
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns the type of the parsed data.
*
* @return returns LIST_DATA.
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.LIST_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
*/
public void generateJavaCodeEntry() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
public void generateJavaCodeExit() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
*/
@Override
public String getPackage() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
*/
@Override
public void setPackage(String pkg) {
// TODO Auto-generated method stub
}
}
......@@ -17,7 +17,14 @@ package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
/*
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.translator.CodeGenerator;
import org.onosproject.yangutils.utils.io.CachedFileHandle;
/*-
* Reference:RFC 6020.
* The "module" statement defines the module's name,
* and groups all statements that belong to the module together. The "module"
......@@ -57,14 +64,11 @@ import java.util.List;
* +--------------+---------+-------------+-----------------------+
*/
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/**
* Data model node to maintain information defined in YANG module.
*/
public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, YangReference, Parsable {
public class YangModule extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
/**
* Name of the module.
......@@ -73,6 +77,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
/**
* Reference:RFC 6020.
*
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
......@@ -83,6 +88,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
/**
* Reference:RFC 6020.
*
* The "description" statement takes as an argument a string that contains a
* human-readable textual description of this definition. The text is
* provided in a language (or languages) chosen by the module developer; for
......@@ -119,6 +125,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
/**
* Reference:RFC 6020.
*
* The "organization" statement defines the party responsible for this
* module. The argument is a string that is used to specify a textual
* description of the organization(s) under whose auspices this module was
......@@ -147,26 +154,34 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
private byte version;
/**
* package of the generated java code.
*/
private String pkg;
/**
* Cached Java File Handle.
*/
private CachedFileHandle fileHandle;
/**
* Create a YANG node of module type.
*/
public YangModule() {
super(YangNodeType.MODULE_NODE);
}
/**
* Get the module name.
*
* @return the module name.
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#getName()
*/
@Override
public String getName() {
return name;
}
/**
* set the module name.
*
* @param moduleName the module name to set.
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
*/
@Override
public void setName(String moduleName) {
name = moduleName;
}
......@@ -375,7 +390,7 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
* @param org the organization to set.
*/
public void setOrganization(String org) {
this.organization = org;
organization = org;
}
/**
......@@ -451,6 +466,44 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
}
/**
* Get the mapped java package.
*
* @return the java package
*/
@Override
public String getPackage() {
return pkg;
}
/**
* Set the mapped java package.
*
* @param pcg the package to set
*/
@Override
public void setPackage(String pcg) {
pkg = pcg;
}
/**
* Get the cached file handle.
*
* @return the fileHandle
*/
public CachedFileHandle getFileHandle() {
return fileHandle;
}
/**
* Set the cached file handle.
*
* @param handle the fileHandle to set
*/
public void setFileHandle(CachedFileHandle handle) {
fileHandle = handle;
}
/**
* Returns the type of the parsed data.
*
* @return returns MODULE_DATA.
......@@ -476,4 +529,22 @@ public class YangModule extends YangNode implements YangLeavesHolder, YangDesc,
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Generates java code for module.
*/
public void generateJavaCodeEntry() {
//TODO: autogenerated method stub, to be implemented
return;
}
/**
* Free resources used to generate code.
*/
public void generateJavaCodeExit() {
//TODO: autogenerated method stub, to be implemented
return;
}
}
......
......@@ -16,25 +16,36 @@
package org.onosproject.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.CodeGenerator;
/**
* Base class of a node in data model tree.
*/
public abstract class YangNode {
public abstract class YangNode implements CodeGenerator {
/* Type of information maintained in node */
/**
* Type of node.
*/
private YangNodeType nodeType;
/* Parent reference */
/**
* Parent reference.
*/
private YangNode parent;
/* First child reference */
/**
* First child reference.
*/
private YangNode child;
/* Next sibling reference */
/**
* Next sibling reference.
*/
private YangNode nextSibling;
/* Previous sibling reference */
/**
* Previous sibling reference.
*/
private YangNode previousSibling;
/**
......@@ -213,4 +224,33 @@ public abstract class YangNode {
curNode.setNextSibling(newChild);
return;
}
/**
* Get the YANG name of the node.
*
* @return the name of node as defined in YANG file.
*/
public abstract String getName();
/**
* Set the YANG name of the node.
*
* @param name the name of node as defined in YANG file.
*/
public abstract void setName(String name);
/**
* Get the mapped java package.
*
* @return the java package
*/
public abstract String getPackage();
/**
* Set the mapped java package.
*
* @param pkg the package to set
*/
public abstract void setPackage(String pkg);
}
......
......@@ -23,27 +23,30 @@ package org.onosproject.yangutils.datamodel;
*/
/**
* ENUM to represent the status of YANG entities.
* Represents the status of YANG entities.
*/
public enum YangStatusType {
/**
* Reference:RFC 6020.
*
* "current" means that the definition is current and valid.
*/
CURRENT,
/**
* Reference:RFC 6020.
* "deprecated" indicates an obsolete definition, but it permits new/
* continued implementation in order to foster interoperability with
* older/existing implementations.
*
* "deprecated" indicates an obsolete definition, but it
* permits new/ continued implementation in order to foster interoperability
* with older/existing implementations.
*/
DEPRECATED,
/**
* Reference:RFC 6020.
* "obsolete" means the definition is obsolete and SHOULD NOT be implemented
* and/or can be removed from implementations.
*
* "obsolete" means the definition is obsolete and
* SHOULD NOT be implemented and/or can be removed from implementations.
*/
OBSOLETE
}
......
/*
* Copyright 2016 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.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
/*
* Reference RFC 6020.
*
* While the primary unit in YANG is a module, a YANG module can itself
* be constructed out of several submodules. Submodules allow a module
* designer to split a complex model into several pieces where all the
* submodules contribute to a single namespace, which is defined by the
* module that includes the submodules.
*
* The "submodule" statement defines the submodule's name, and groups
* all statements that belong to the submodule together. The
* "submodule" statement's argument is the name of the submodule,
* followed by a block of sub-statements that hold detailed submodule
* information.
*
* The submodule's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | anyxml | 7.10 | 0..n | - not supported |
* | augment | 7.15 | 0..n | - child nodes |
* | belongs-to | 7.2.2 | 1 | - YangBelongsTo |
* | choice | 7.9 | 0..n | - child nodes |
* | contact | 7.1.8 | 0..1 | - string |
* | container | 7.5 | 0..n | - child nodes |
* | description | 7.19.3 | 0..1 | - string |
* | deviation | 7.18.3 | 0..n | - TODO |
* | extension | 7.17 | 0..n | - TODO |
* | feature | 7.18.1 | 0..n | - TODO |
* | grouping | 7.11 | 0..n | - child nodes |
* | identity | 7.16 | 0..n | - TODO |
* | import | 7.1.5 | 0..n | - YangImport |
* | include | 7.1.6 | 0..n | - YangInclude |
* | leaf | 7.6 | 0..n | - YangLeaf |
* | leaf-list | 7.7 | 0..n | - YangLeafList |
* | list | 7.8 | 0..n | - child nodes |
* | notification | 7.14 | 0..n | - TODO |
* | organization | 7.1.7 | 0..1 | - string |
* | reference | 7.19.4 | 0..1 | - string |
* | revision | 7.1.9 | 0..n | - string |
* | rpc | 7.13 | 0..n | - TODO |
* | typedef | 7.3 | 0..n | - child nodes |
* | uses | 7.12 | 0..n | - child nodes |
* | YANG-version | 7.1.2 | 0..1 | - int |
* +--------------+---------+-------------+------------------+
*/
/**
* Data model node to maintain information defined in YANG sub-module.
*/
public class YangSubModule extends YangNode
implements YangLeavesHolder, YangDesc, YangReference, Parsable {
/**
* Name of sub module.
*/
private String name;
/**
* Module to which it belongs to.
*/
private YangBelongsTo belongsTo;
/**
* Reference RFC 6020.
*
* The "contact" statement provides contact information for the module. The
* argument is a string that is used to specify contact information for the
* person or persons to whom technical queries concerning this module should
* be sent, such as their name, postal address, telephone number, and
* electronic mail address.
*/
private String contact;
/**
* Description.
*/
private String description;
/**
* List of YANG modules imported.
*/
private List<YangImport> importList;
/**
* List of YANG sub-modules included.
*/
private List<YangInclude> includeList;
/**
* List of leaves at root level in the sub-module.
*/
@SuppressWarnings("rawtypes")
private List<YangLeaf> listOfLeaf;
/**
* List of leaf-lists at root level in the sub-module.
*/
@SuppressWarnings("rawtypes")
private List<YangLeafList> listOfLeafList;
/**
* organization owner of the sub-module.
*/
private String organization;
/**
* reference of the sub-module.
*/
private String reference;
/**
* revision info of the sub-module.
*/
private YangRevision revision;
/**
* YANG version.
*/
private byte version;
/**
* Create a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#getName()
*/
@Override
public String getName() {
return name;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
*/
@Override
public void setName(String subModuleName) {
name = subModuleName;
}
/**
* Get the module info.
*
* @return the belongs to info
*/
public YangBelongsTo getBelongsTo() {
return belongsTo;
}
/**
* Set the module info.
*
* @param belongsTo module info to set.
*/
public void setBelongsTo(YangBelongsTo belongsTo) {
this.belongsTo = belongsTo;
}
/**
* Get the contact.
*
* @return the contact.
*/
public String getContact() {
return contact;
}
/**
* Set the contact.
*
* @param contact the contact to set
*/
public void setContact(String contact) {
this.contact = contact;
}
/**
* Get the description.
*
* @return the description.
*/
public String getDescription() {
return description;
}
/**
* Set the description.
*
* @param description set the description.
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Get the list of imported modules.
*
* @return the list of imported modules.
*/
public List<YangImport> getImportList() {
return importList;
}
/**
* prevent setting the import list from outside.
*
* @param importList the import list to set.
*/
private void setImportList(List<YangImport> importList) {
this.importList = importList;
}
/**
* Add the imported module information to the import list.
*
* @param importedModule module being imported.
*/
public void addImportedInfo(YangImport importedModule) {
if (getImportList() == null) {
setImportList(new LinkedList<YangImport>());
}
getImportList().add(importedModule);
return;
}
/**
* Get the list of included sub modules.
*
* @return the included list of sub modules.
*/
public List<YangInclude> getIncludeList() {
return includeList;
}
/**
* Set the list of included sub modules.
*
* @param includeList the included list to set.
*/
private void setIncludeList(List<YangInclude> includeList) {
this.includeList = includeList;
}
/**
* Add the included sub module information to the include list.
*
* @param includeModule submodule being included.
*/
public void addIncludedInfo(YangInclude includeModule) {
if (getIncludeList() == null) {
setIncludeList(new LinkedList<YangInclude>());
}
getIncludeList().add(includeModule);
return;
}
/**
* Get the list of leaves.
*
* @return the list of leaves.
*/
@SuppressWarnings("rawtypes")
public List<YangLeaf> getListOfLeaf() {
return listOfLeaf;
}
/**
* Set the list of leaves.
*
* @param leafsList the list of leaf to set.
*/
@SuppressWarnings("rawtypes")
private void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Add a leaf.
*
* @param leaf the leaf to be added.
*/
@SuppressWarnings("rawtypes")
public void addLeaf(YangLeaf<?> leaf) {
if (getListOfLeaf() == null) {
setListOfLeaf(new LinkedList<YangLeaf>());
}
getListOfLeaf().add(leaf);
}
/**
* Get the list of leaf-list.
*
* @return the list of leaf-list.
*/
@SuppressWarnings("rawtypes")
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
/**
* Set the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set.
*/
@SuppressWarnings("rawtypes")
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Add a leaf-list.
*
* @param leafList the leaf-list to be added.
*/
@SuppressWarnings("rawtypes")
public void addLeafList(YangLeafList<?> leafList) {
if (getListOfLeafList() == null) {
setListOfLeafList(new LinkedList<YangLeafList>());
}
getListOfLeafList().add(leafList);
}
/**
* Get the sub-modules organization.
*
* @return the organization.
*/
public String getOrganization() {
return organization;
}
/**
* Set the sub-modules organization.
*
* @param org the organization to set.
*/
public void setOrganization(String org) {
organization = org;
}
/**
* Get the textual reference.
*
* @return the reference.
*/
public String getReference() {
return reference;
}
/**
* Set the textual reference.
*
* @param reference the reference to set.
*/
public void setReference(String reference) {
this.reference = reference;
}
/**
* Get the revision.
*
* @return the revision.
*/
public YangRevision getRevision() {
return revision;
}
/**
* Set the revision.
*
* @param revision the revision to set.
*/
public void setRevision(YangRevision revision) {
this.revision = revision;
}
/**
* Get the version.
*
* @return the version.
*/
public byte getVersion() {
return version;
}
/**
* Set the version.
*
* @param version the version to set.
*/
public void setVersion(byte version) {
this.version = version;
}
/**
* Returns the type of the parsed data.
*
* @return returns SUB_MODULE_DATA.
*/
public ParsableDataType getParsableDataType() {
return ParsableDataType.SUB_MODULE_DATA;
}
/**
* Validate the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validate the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules.
*/
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
*/
public void generateJavaCodeEntry() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
*/
public void generateJavaCodeExit() {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
*/
@Override
public String getPackage() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
*/
@Override
public void setPackage(String pkg) {
// TODO Auto-generated method stub
}
}
/*
* Copyright 2016 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.yangutils.translator;
/**
* Abstraction of an entity which provides Code generator functionalities.
*/
public interface CodeGenerator {
/**
* Traverse the schema of application and generate corresponding code.
*/
void generateJavaCodeEntry();
/**
* Traverse the schema of application and generate corresponding code.
*/
void generateJavaCodeExit();
}
/*Copyright 2016.year 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.yangutils.translator;
/**
* Type of files generated.
*/
public enum GeneratedFileType {
/**
* interface file.
*/
INTERFACE,
/**
* class file.
*/
BUILDER_CLASS,
/**
* interface and class file.
*/
BOTH
}
/*Copyright 2016.year 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.yangutils.utils.io;
import org.onosproject.yangutils.translator.GeneratedFileType;
/**
* Cached java file handle, which supports the addition of member attributes and
* methods.
*/
public interface CachedFileHandle {
/**
* Add a new attribute to the file(s).
*
* @param attrType data type of the added attribute.
* @param name name of the attribute.
* @param isListAttr if the current added attribute needs to be maintained
* in a list.
* @param fileTypes types of files in which the attribute needs to be added.
*/
void addAttributeInfo(String attrType, String name, boolean isListAttr, GeneratedFileType fileTypes);
/**
* Flushes the cached contents to the target file, frees used resources.
*/
void close();
}