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
}
}
......@@ -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.
*
......
......@@ -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.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();
}