Brian O'Connor

Moving yangtools to separate repo

https://gerrit.onosproject.org/onos-yang-tools

Change-Id: I0dc994264b9b698cba2344b48e4e226b22951f55
Showing 1000 changed files with 0 additions and 5217 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

......@@ -33,7 +33,6 @@
<modules>
<module>junit</module>
<module>misc</module>
<module>yangutils</module>
<module>osgi</module>
<module>rest</module>
<module>osgiwrap</module>
......
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.onosproject</groupId>
<artifactId>onos-yangutils</artifactId>
<version>1.7.0-SNAPSHOT</version>
</parent>
<artifactId>yangutils-datamodel</artifactId>
<version>1.7.0-SNAPSHOT</version>
<name>onos-yang-utils-datamodel</name>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
/*-
* 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.yangutils.datamodel;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.DataTypeException;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt16;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt32;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt64;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangInt8;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint16;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint32;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint64;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangUint8;
/**
* Factory to create an object of required type.
*/
public final class BuiltInTypeObjectFactory implements Serializable {
private static final long serialVersionUID = 8006201671L;
/**
* Utility factory class, hence the object creation is forbidden.
*/
private BuiltInTypeObjectFactory() {
}
/**
* Given the value represented in string return the corresponding types
* object with the value initialized.
*
* @param valueInStr value represented in string
* @param builtInType built in data type
* @param <T> the data type of the target object
* @return the target data type object with the value initialized
*/
public static <T extends YangBuiltInDataTypeInfo<?>> T getDataObjectFromString(String valueInStr,
YangDataTypes builtInType) {
switch (builtInType) {
case INT8: {
return (T) new YangInt8(valueInStr);
}
case INT16: {
return (T) new YangInt16(valueInStr);
}
case INT32: {
return (T) new YangInt32(valueInStr);
}
case INT64: {
return (T) new YangInt64(valueInStr);
}
case UINT8: {
return (T) new YangUint8(valueInStr);
}
case UINT16: {
return (T) new YangUint16(valueInStr);
}
case UINT32: {
return (T) new YangUint32(valueInStr);
}
case UINT64: {
return (T) new YangUint64(valueInStr);
}
case DECIMAL64: {
return (T) new YangDecimal64(valueInStr);
}
default: {
throw new DataTypeException("YANG file error : Unsupported data type");
}
}
}
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Abstraction of YANG collision function. Abstracted to unify the collision
* detection functionality.
*/
public interface CollisionDetector {
/**
* Checks for the colliding child.
*
* @param identifierName name of identifier for which collision to be
* checked
* @param dataType type of the YANG construct for which collision to be
* checked
* @throws DataModelException if there is any collision in YANG rules in
* parsed data, corresponding exception should be thrown
*/
void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException;
/**
* Check for the self collision.
*
* @param identifierName name of identifier for which collision to be
* checked
* @param dataType type of the YANG construct for which collision to be
* checked
* @throws DataModelException if there is any collision in YANG rules in
* parsed data, corresponding exception should be thrown
*/
void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException;
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of location information, this is used during resolution is
* carried out and line/character position in line is required to point
* out the error location in YANG file.
*/
public interface LocationInfo {
/**
* Returns the line number YANG construct in file.
*
* @return the line number YANG construct in file
*/
int getLineNumber();
/**
* Returns the character position in line.
*
* @return the character position in line
*/
int getCharPosition();
/**
* Sets line number of YANG construct.
*
* @param lineNumber the line number of YANG construct in file
*/
void setLineNumber(int lineNumber);
/**
* Sets character position of YANG construct.
*
* @param charPositionInLine character position of YANG construct in file
*/
void setCharPosition(int charPositionInLine);
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
/**
* Abstraction of YANG resolvable information. Abstracted to obtain the
* information required for linking resolution.
*
* @param <T> YANG resolvable info
*/
public interface Resolvable<T> {
/**
* Returns the status of resolution. If completely resolved returns enum
* value "RESOLVED", if not returns "UNRESOLVED", in case reference of
* grouping/typedef is added to uses/type but it's not resolved
* "INTRA_FILE_RESOLVED" is returned.
*
* @return status of resolution
*/
ResolvableStatus getResolvableStatus();
/**
* Set the status of type/uses resolution. If completely resolved set enum
* value "RESOLVED", if not set it to "UNRESOLVED", in case reference of
* grouping/typedef is added to uses/type but it's not resolved
* "INTRA_FILE_RESOLVED" should be set.
*
* @param resolvableStatus status of resolution
*/
void setResolvableStatus(ResolvableStatus resolvableStatus);
/**
* Resolves the linking.
*
* @return list of entities to be added for resolution
* @throws DataModelException data model exception
*/
T resolve()
throws DataModelException;
}
/*
* 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.yangutils.datamodel;
/**
* Type of the resolvable info.
*/
public enum ResolvableType {
/**
* Identifies the derived data type.
*/
YANG_DERIVED_DATA_TYPE,
/**
* Identifies the uses.
*/
YANG_USES,
/**
* Identifies the if-feature.
*/
YANG_IF_FEATURE,
/**
* Identifies the leafref.
*/
YANG_LEAFREF,
/**
* Identifies the base.
*/
YANG_BASE,
/**
* Identifies the identityref.
*/
YANG_IDENTITYREF,
/**
* Identifies the augment.
*/
YANG_AUGMENT
}
/*
* 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.yangutils.datamodel;
/**
* Represents class having rpc and notification.
*/
public interface RpcNotificationContainer {
}
/*
* 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.yangutils.datamodel;
/**
* Represents data model tree traversal types.
*/
public enum TraversalType {
/**
* Start of traversal at the tree root.
*/
ROOT,
/**
* Child node traversal.
*/
CHILD,
/**
* Sibling node traversal.
*/
SIBILING,
/**
* Parent node traversal.
*/
PARENT
}
/*
* 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.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG app-data-structure.
*/
public class YangAppDataStructure implements Parsable {
/**
* Data structure information.
*/
private YangDataStructure dataStructure;
/**
* List of key names.
*/
private List<String> keyList;
/**
* Prefix of app-data-structure.
*/
private String prefix;
/**
* Returns the YANG data structure information.
*
* @return the YANG data structure information
*/
public YangDataStructure getDataStructure() {
return dataStructure;
}
/**
* Sets the YANG data structure information.
*
* @param dataStructure the YANG data structure to set
*/
public void setDataStructure(YangDataStructure dataStructure) {
this.dataStructure = dataStructure;
}
/**
* Returns the list of key field names.
*
* @return the list of key field names
*/
public List<String> getKeyList() {
return keyList;
}
/**
* Sets the list of key field names.
*
* @param keyList the list of key field names
*/
public void setKeyList(List<String> keyList) {
this.keyList = keyList;
}
/**
* Adds a key field name.
*
* @param key key field name
*/
public void addKey(String key) {
if (getKeyList() == null) {
setKeyList(new LinkedList<>());
}
getKeyList().add(key);
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix information.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.APP_DATA_STRUCTURE;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO : to be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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.yangutils.datamodel;
/**
* Represents data model node to maintain YANG app error message information.
*/
public interface YangAppErrorHolder {
/**
* Sets the application's error information.
*
* @param yangAppErrorInfo the application's error information
*/
void setAppErrorInfo(YangAppErrorInfo yangAppErrorInfo);
/**
* Returns application's error information.
*
* @return application's error information
*/
YangAppErrorInfo getAppErrorInfo();
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
/**
* Represents data model to maintain yang app error information.
*/
public class YangAppErrorInfo implements Serializable {
private static final long serialVersionUID = 807201693L;
/**
* Application's error message, to be used for data error.
*/
private String errorMessage;
/**
* Error tag, to be filled in data validation error response.
*/
private String errorTag;
/**
* Application's error tag, to be filled in data validation error response.
*/
private String errorAppTag;
/**
* Application's error path, to be filled in data validation error response.
*/
private String errorAppPath;
/**
* Application's error info, to be filled in data validation error response.
*/
private String errorAppInfo;
/**
* Creates a YANG app error info object.
*/
@SuppressWarnings("unused")
public YangAppErrorInfo() {
}
/**
* Returns application's error message, to be used for data error.
*
* @return Application's error message, to be used for data error
*/
public String getGetErrorMessage() {
return errorMessage;
}
/**
* Sets Application's error message, to be used for data error.
*
* @param errMsg Application's error message, to be used for data error
*/
public void setErrorMessage(String errMsg) {
errorMessage = errMsg;
}
/**
* Returns error tag, to be used for data error.
*
* @return error tag, to be used for data error
*/
public String getGetErrorTag() {
return errorTag;
}
/**
* Sets error tag, to be used for data error.
*
* @param errTag error tag, to be used for data error
*/
public void setErrorTag(String errTag) {
errorTag = errTag;
}
/**
* Returns application's error tag, to be used for data error.
*
* @return application's error tag, to be used for data error
*/
public String getGetErrorAppTag() {
return errorAppTag;
}
/**
* Sets application's error tag, to be used for data error.
*
* @param errTag application's error tag, to be used for data error
*/
public void setErrorAppTag(String errTag) {
errorAppTag = errTag;
}
/**
* Returns application's error path, to be used for data error.
*
* @return application's error path, to be used for data error
*/
public String getGetErrorAppPath() {
return errorAppPath;
}
/**
* Sets application's error path, to be used for data error.
*
* @param errPath application's error path, to be used for data error
*/
public void setErrorAppPath(String errPath) {
errorAppPath = errPath;
}
/**
* Returns application's error info, to be used for data error.
*
* @return application's error info, to be used for data error
*/
public String getGetErrorAppInfo() {
return errorAppInfo;
}
/**
* Sets application's error info, to be used for data error.
*
* @param errInfo application's error info, to be used for data error
*/
public void setErrorAppInfo(String errInfo) {
errorAppInfo = errInfo;
}
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG extended name.
*/
public class YangAppExtendedName implements Parsable {
/**
* App extended name information.
*/
private String yangAppExtendedName;
/**
* Prefix of extended name.
*/
private String prefix;
/**
* Returns the YANG app extended name information.
*
* @return the YANG app extended name information
*/
public String getYangAppExtendedName() {
return yangAppExtendedName;
}
/**
* Sets the YANG app extended name information.
*
* @param yangAppExtendedName the YANG app extended name to set
*/
public void setYangAppExtendedName(String yangAppExtendedName) {
this.yangAppExtendedName = yangAppExtendedName;
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix information.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.APP_EXTENDED_NAME_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO : to be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.List;
/**
* Representation of data model node to maintain absolute path defined in YANG path-arg.
*/
public class YangAtomicPath implements Serializable {
private static final long serialVersionUID = 806201688L;
// YANG node identifier.
private YangNodeIdentifier nodeIdentifier;
// List of path predicates expression.
private List<YangPathPredicate> pathPredicatesList;
/**
* Resolved node for the absolute path.
*/
private YangNode resolvedNode;
/**
* Returns the node identifier.
*
* @return the node identifier
*/
public YangNodeIdentifier getNodeIdentifier() {
return nodeIdentifier;
}
/**
* Sets the node identifier.
*
* @param nodeIdentifier Sets the node identifier
*/
public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
this.nodeIdentifier = nodeIdentifier;
}
/**
* Returns the path predicate expression.
*
* @return the path predicate expression
*/
public List<YangPathPredicate> getPathPredicatesList() {
return pathPredicatesList;
}
/**
* Sets the path predicate expression.
*
* @param pathPredicatesList Sets the path predicate expression
*/
public void setPathPredicatesList(List<YangPathPredicate> pathPredicatesList) {
this.pathPredicatesList = pathPredicatesList;
}
/**
* Adds predicate expression in data holder.
*
* @param predicatesExp the predicate expression to be added
*/
public void addLeavesPredicate(YangPathPredicate predicatesExp) {
getPathPredicatesList().add(predicatesExp);
}
/**
* Returns resolved node.
*
* @return resolved node
*/
public YangNode getResolvedNode() {
return resolvedNode;
}
/**
* Sets resolved node.
*
* @param resolvedNode resolved node
*/
public void setResolvedNode(YangNode resolvedNode) {
this.resolvedNode = resolvedNode;
}
}
/*
* 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.yangutils.datamodel;
import java.util.List;
/**
* Represents YANG constructs which can be augmented.
*/
public interface YangAugmentableNode {
/**
* Adds augment info to the augment info list.
*
* @param augmentInfo augment info of node
*/
void addAugmentation(YangAugmentedInfo augmentInfo);
/**
* Removes augment info from the node.
*
* @param augmentInfo augment info of node
*/
void removeAugmentation(YangAugmentedInfo augmentInfo);
/**
* Returns list of augment info.
*
* @return list of augment info
*/
List<YangAugmentedInfo> getAugmentedInfoList();
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of an entity which represents YANG augmented info.
*/
public interface YangAugmentedInfo {
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of an entity which represent operation parameter info for augmentable node.
*/
public interface YangAugmentedOpParamInfo extends YangAugmentedInfo {
/**
* Returns class object of base class.
*
* @return class object of base class
*/
Class<?> getBaseClass();
/**
* Returns if augmented info's contents matches.
*
* @param augmentedInfo augmented info
* @return true or false
*/
boolean isFilterContentMatch(Object augmentedInfo);
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import java.io.Serializable;
/**
* Reference RFC 6020.
*
* Represents data model node to maintain information defined in YANG base.
* The "base" statement, which is optional, takes as an argument a
* string that is the name of an existing identity, from which the new
* identity is derived. If no "base" statement is present, the identity
* is defined from scratch.
*
* If a prefix is present on the base name, it refers to an identity
* defined in the module that was imported with that prefix, or the
* local module if the prefix matches the local module's prefix.
* Otherwise, an identity with the matching name MUST be defined in the
* current module or an included submodule.
*/
/**
* Represents data model node to maintain information defined in YANG base.
*/
public class YangBase implements Resolvable, Serializable {
private static final long serialVersionUID = 806201693L;
// YANG node identifier.
private YangNodeIdentifier baseIdentifier;
// Referred identity parent information.
private YangIdentity referredIdentity;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef/base/identityref
* is added to uses/type/base/identityref but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
// Creates a base type of node.
public YangBase() {
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
/**
* Returns the YANG node identifier.
*
* @return the YANG node identifier
*/
public YangNodeIdentifier getBaseIdentifier() {
return baseIdentifier;
}
/**
* Sets the YANG node identifier.
*
* @param baseIdentifier the YANG node identifier to set
*/
public void setBaseIdentifier(YangNodeIdentifier baseIdentifier) {
this.baseIdentifier = baseIdentifier;
}
/**
* Returns the parent identity node.
*
* @return the parent identity node
*/
public YangIdentity getReferredIdentity() {
return referredIdentity;
}
/**
* Sets the parent identity node.
*
* @param referredIdentity the parent identity node to set
*/
public void setReferredIdentity(YangIdentity referredIdentity) {
this.referredIdentity = referredIdentity;
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public Object resolve() throws DataModelException {
return null;
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
/*-
* 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 |
* +--------------+---------+-------------+
*/
/**
* Represents the belongs-to data type information.
*/
public class YangBelongsTo implements Parsable, LocationInfo, Serializable {
private static final long serialVersionUID = 806201639L;
/**
* 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;
/**
* Module node to which sub-module belongs to.
*/
private YangNode moduleNode;
/**
* 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;
// Error Line number.
private transient int lineNumber;
// Error character position.
private transient int charPosition;
/**
* Create a belongs to object.
*/
public YangBelongsTo() {
}
/**
* Returns the belongs to module name.
*
* @return the belongs to module name
*/
public String getBelongsToModuleName() {
return belongsToModuleName;
}
/**
* Sets the belongs to module name.
*
* @param belongsToModuleName the belongs to module name to set
*/
public void setBelongsToModuleName(String belongsToModuleName) {
this.belongsToModuleName = belongsToModuleName;
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/**
* Returns the module data model node.
*
* @return the module data model node
*/
public YangNode getModuleNode() {
return moduleNode;
}
/**
* Sets the module node.
*
* @param moduleNode module data model node
*/
public void setModuleNode(YangNode moduleNode) {
this.moduleNode = moduleNode;
}
/**
* Returns the type of the data as belongs-to.
*
* @return ParsedDataType returns BELONGS_TO_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.BELONGS_TO_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public int getLineNumber() {
return lineNumber;
}
@Override
public int getCharPosition() {
return charPosition;
}
@Override
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
@Override
public void setCharPosition(int charPositionInLine) {
charPosition = charPositionInLine;
}
/**
* Links the belongs to with a module.
*
* @param yangNodeSet YANG file information set
* @throws DataModelException a violation in data model rule
*/
public void linkWithModule(Set<YangNode> yangNodeSet)
throws DataModelException {
String belongsToModuleName = getBelongsToModuleName();
YangNode moduleNode = findReferredNode(yangNodeSet, belongsToModuleName);
if (moduleNode != null) {
if (moduleNode instanceof YangModule) {
setModuleNode(moduleNode);
return;
}
}
DataModelException exception = new DataModelException("YANG file error : Module " + belongsToModuleName +
"to which sub-module belongs to is not found.");
exception.setLine(getLineNumber());
exception.setCharPosition(getCharPosition());
throw exception;
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Base64;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
/*
* Reference RFC 6020.
*
* The binary built-in type represents any binary data,
* i.e., a sequence of octets.
*/
public class YangBinary implements YangBuiltInDataTypeInfo<YangBinary>, Serializable, Comparable<YangBinary> {
private static final long serialVersionUID = 2106201608L;
// Binary data is a decoded value by base64 decoding scheme from data input (jason)
private byte[] binaryData;
/**
* Creates a binary object corresponding to the base 64 encoding value.
*
* @param strValue base64 encoded value
*/
public YangBinary(String strValue) {
setBinaryData(Base64.getDecoder().decode(strValue));
}
/**
* Retrieves decoded binary data.
*
* @return binary data
*/
public byte[] getBinaryData() {
return binaryData;
}
/**
* Sets binary data.
*
* @param binaryData binary data
*/
public void setBinaryData(byte[] binaryData) {
this.binaryData = binaryData;
}
/**
* Encodes binary data by base64 encoding scheme.
*
* @return encoded binary data
*/
public String toString() {
return Base64.getEncoder()
.encodeToString(binaryData);
}
@Override
public YangDataTypes getYangType() {
return YangDataTypes.BINARY;
}
@Override
public int compareTo(YangBinary o) {
for (int i = 0, j = 0; i < this.binaryData.length && j < o.binaryData.length; i++, j++) {
int a = (this.binaryData[i] & 0xff);
int b = (o.binaryData[j] & 0xff);
if (a != b) {
return a - b;
}
}
return this.binaryData.length - o.binaryData.length;
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*-
* The "bit" statement, which is a sub-statement to the "type" statement,
* MUST be present if the type is "bits". It is repeatedly used to
* specify each assigned named bit of a bits type. It takes as an
* argument a string that is the assigned name of the bit. It is
* followed by a block of sub-statements that holds detailed bit
* information.
* All assigned names in a bits type MUST be unique.
*
* The bit's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | - string |
* | reference | 7.19.4 | 0..1 | - string |
* | status | 7.19.2 | 0..1 | - YangStatus |
* | position | 9.7.4.2 | 0..1 | - int |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents the bit data type information.
*/
public class YangBit implements YangCommonInfo, Parsable, Serializable {
private static final long serialVersionUID = 806201640L;
/**
* Name of the bit.
*/
private String bitName;
/**
* Description of the bit field.
*/
private String description;
/**
* Reference info of the bit field.
*/
private String reference;
/**
* Status of the bit field.
*/
private YangStatusType status;
/**
* Position of the bit whose name bit is described.
*/
private int position;
/**
* Create a YANG bit type object.
*/
public YangBit() {
}
/**
* Returns bit name.
*
* @return the bit name
*/
public String getBitName() {
return bitName;
}
/**
* Sets the bit name.
*
* @param bitName the bit name to set
*/
public void setBitName(String bitName) {
this.bitName = bitName;
}
/**
* Returns description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns status.
*
* @return the status
*/
@Override
public YangStatusType getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns bit position.
*
* @return the position
*/
public int getPosition() {
return position;
}
/**
* Sets the bit position.
*
* @param position the position to set
*/
public void setPosition(int position) {
this.position = position;
}
/**
* Returns the type of the data.
*
* @return ParsedDataType returns BIT_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.BIT_DATA;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof YangBit) {
final YangBit other = (YangBit) obj;
return Objects.equals(bitName, other.bitName);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(bitName);
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* 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.
*/
/**
* Represents the bits data type information.
*/
public class YangBits implements Parsable, Serializable {
private static final long serialVersionUID = 806201641L;
private static final String SPACE = " ";
// Bits name
private String bitsName;
// Bits data contains bit-positions will be used to send to ONOS application
private BitSet bitDataSet;
/**
* Mapping bit name to YangBit. In data input (jason), only bit name will be received.
* By using the bit name corresponding (yang) bit-position will be retrieved from bitNameMap map.
*/
private Map<String, YangBit> bitNameMap;
/**
* Mapping bit position to YangBit. The bit-position received from ONOS application
* will be converted into bit-name by using bitPositionMap map to send (jason) output data as response.
*/
private Map<Integer, YangBit> bitPositionMap;
/**
* Creates a YANG bits type object.
*/
public YangBits() {
bitDataSet = new BitSet();
setBitNameMap(new HashMap<>());
setBitPositionMap(new HashMap<>());
}
/**
* Returns the bits name.
*
* @return the bits name
*/
public String getBitsName() {
return bitsName;
}
/**
* Sets the bits name.
*
* @param bitsName the bits name
*/
public void setBitsName(String bitsName) {
this.bitsName = bitsName;
}
/**
* Returns the bit data set.
*
* @return the bit data set
*/
public BitSet getBitDataSet() {
return bitDataSet;
}
/**
* Sets the bit data set.
*
* @param bitNames the set of bit names
* @throws DataModelException due to violation in data model rules
*/
public void setBitDataSet(String[] bitNames) throws DataModelException {
YangBit bit;
for (String bitName : bitNames) {
bit = bitNameMap.get(bitName);
if (bit == null) {
throw new DataModelException("YANG file error: Unable to find " +
"corresponding bit position for bit name: " + bitName);
}
bitDataSet.set(bit.getPosition());
}
}
/**
* Returns the bit name map.
*
* @return the bit name map
*/
public Map<String, YangBit> getBitNameMap() {
return bitNameMap;
}
/**
* Sets the bit name map.
*
* @param bitNameMap the bit name map
*/
public void setBitNameMap(Map<String, YangBit> bitNameMap) {
this.bitNameMap = bitNameMap;
}
/**
* Checks whether bit name already available.
*
* @param bitName bit name
* @return true if bit name already available otherwise returns false
*/
public boolean isBitNameExists(String bitName) {
return bitNameMap.containsKey(bitName);
}
/**
* Returns the bit position map.
*
* @return the bit position map
*/
public Map<Integer, YangBit> getBitPositionMap() {
return bitPositionMap;
}
/**
* Sets the bit position map.
*
* @param bitPositionMap the bit position map
*/
public void setBitPositionMap(Map<Integer, YangBit> bitPositionMap) {
this.bitPositionMap = bitPositionMap;
}
/**
* Checks whether bit position already available.
*
* @param bitPosition bit position
* @return true if bit position already available otherwise returns false
*/
public boolean isBitPositionExists(Integer bitPosition) {
return bitPositionMap.containsKey(bitPosition);
}
/**
* Adds bit info.
*
* @param bitInfo the bit information to be added
* @throws DataModelException due to violation in data model rules
*/
public void addBitInfo(YangBit bitInfo) throws DataModelException {
if (bitNameMap.put(bitInfo.getBitName(), bitInfo) != null) {
throw new DataModelException("YANG file error: Duplicate bit name detected, same as bit name \""
+ bitInfo.getBitName() + "\"");
}
if (bitPositionMap.put(bitInfo.getPosition(), bitInfo) != null) {
throw new DataModelException("YANG file error: Duplicate bit position detected, same as bit position \""
+ bitInfo.getPosition() + "\"");
}
}
/**
* Returns the type of the data.
*
* @return ParsedDataType returns BITS_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.BITS_DATA;
}
@Override
public String toString() {
YangBit bit;
String bits = new String();
for (int i = bitDataSet.nextSetBit(0); i >= 0; i = bitDataSet.nextSetBit(i + 1)) {
bit = bitPositionMap.get(i);
if (bit == null) {
return null;
}
if (bits.isEmpty()) {
bits = bit.getBitName();
} else {
bits += " " + bit.getBitName();
}
}
return bits.trim();
}
/**
* Returns the object of YANG bits based on specific set of bit names.
*
* @param bits set of bit names
* @return Object of YANG bits
*/
public YangBits fromString(String bits) {
try {
String[] bitNames = bits.trim().split(Pattern.quote(SPACE));
setBitDataSet(bitNames);
return this;
} catch (Exception e) {
}
return null;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of YANG entity's common meta data. Abstracted to unify the
* parsing and translator processing.
*/
public interface YangCommonInfo extends YangDesc, YangReference, YangStatus {
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG compiler-annotation.
*/
public class YangCompilerAnnotation implements Parsable {
/**
* App data structure information.
*/
private YangAppDataStructure yangAppDataStructure;
/**
* App extended name information.
*/
private YangAppExtendedName yangAppExtendedName;
/**
* Prefix of compiler-annotation.
*/
private String prefix;
/**
* Path of compiler-annotation.
*/
private String path;
/**
* Returns the YANG app data structure information.
*
* @return the YANG app data structure information
*/
public YangAppDataStructure getYangAppDataStructure() {
return yangAppDataStructure;
}
/**
* Sets the YANG app data structure information.
*
* @param yangAppDataStructure the YANG app data structure to set
*/
public void setYangAppDataStructure(YangAppDataStructure yangAppDataStructure) {
this.yangAppDataStructure = yangAppDataStructure;
}
/**
* Returns the prefix.
*
* @return the prefix
*/
public String getPrefix() {
return prefix;
}
/**
* Sets the prefix information.
*
* @param prefix the prefix to set
*/
public void setPrefix(String prefix) {
this.prefix = prefix;
}
/**
* Returns the path.
*
* @return the path
*/
public String getPath() {
return path;
}
/**
* Sets the path.
*
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* Returns the YANG app extended name information.
*
* @return the YANG app extended name information
*/
public YangAppExtendedName getYangAppExtendedName() {
return yangAppExtendedName;
}
/**
* Sets the YANG app extended name information.
*
* @param yangAppExtendedName the YANG app extended name to set
*/
public void setYangAppExtendedName(YangAppExtendedName yangAppExtendedName) {
this.yangAppExtendedName = yangAppExtendedName;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.COMPILER_ANNOTATION_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO : to be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of YANG data node, used by YMS to abstractly refer the data
* nodes in YANG data tree.
*/
public interface YangDataNode {
}
/*
* 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.yangutils.datamodel;
/**
* Represents ENUM to identify the YANG data type.
*/
public enum YangDataStructure {
MAP,
LIST,
SET;
/**
* Returns YANG data structure type for corresponding data structure name.
*
* @param name data structure name from YANG file.
* @return YANG data structure for corresponding data structure name.
*/
public static YangDataStructure getType(String name) {
name = name.replace("\"", "");
for (YangDataStructure dataStructure : values()) {
if (dataStructure.name().toLowerCase().equals(name)) {
return dataStructure;
}
}
return null;
}
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of textual description for a YANG entity. Abstracted to unify the
* parsing and translator processing of description.
*/
public interface YangDesc {
/**
* Returns the description of YANG entity.
*
* @return the description of YANG entity.
*/
String getDescription();
/**
* Set the description of YANG entity.
*
* @param description set the description of YANG entity.
*/
void setDescription(String description);
}
/*
* 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.yangutils.datamodel;
/**
* Abstraction of information about entity being resolved.
*
* @param <T> type of entity being resolved, uses / grouping
*/
public interface YangEntityToResolveInfo<T> {
/**
* Retrieves the entity to be resolved.
*
* @return entity to be resolved
*/
T getEntityToResolve();
/**
* Sets entity to be resolved.
*
* @param entityToResolve entity to be resolved
*/
void setEntityToResolve(T entityToResolve);
/**
* Retrieves the parent node which contains the entity to be resolved.
*
* @return parent node which contains the entity to be resolved
*/
YangNode getHolderOfEntityToResolve();
/**
* Sets parent node which contains the entity to be resolved.
*
* @param holderOfEntityToResolve parent node which contains the entity to
* be resolved
*/
void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve);
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
/**
* Represents implementation of information about entity being resolved.
*
* @param <T> type of entity being resolved, uses / grouping
*/
public class YangEntityToResolveInfoImpl<T> implements YangEntityToResolveInfo<T>, Serializable, LocationInfo {
private static final long serialVersionUID = 806201659L;
/**
* Parsable node for which resolution is to be performed.
*/
private T entityToResolve;
/**
* Holder of the YANG construct for which resolution has to be carried out.
*/
private YangNode holderOfEntityToResolve;
/**
* Error line number.
*/
private transient int lineNumber;
/**
* Error character position in number.
*/
private transient int charPositionInLine;
@Override
public T getEntityToResolve() {
return entityToResolve;
}
@Override
public void setEntityToResolve(T entityToResolve) {
this.entityToResolve = entityToResolve;
}
@Override
public YangNode getHolderOfEntityToResolve() {
return holderOfEntityToResolve;
}
@Override
public void setHolderOfEntityToResolve(YangNode holderOfEntityToResolve) {
this.holderOfEntityToResolve = holderOfEntityToResolve;
}
@Override
public int getLineNumber() {
return lineNumber;
}
@Override
public int getCharPosition() {
return charPositionInLine;
}
@Override
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
@Override
public void setCharPosition(int charPositionInLine) {
this.charPositionInLine = charPositionInLine;
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Objects;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*-
* The "ENUM" statement, which is a sub-statement to the "type"
* statement, MUST be present if the type is "enumeration". It is
* repeatedly used to specify each assigned name of an enumeration type.
* It takes as an argument a string which is the assigned name. The
* string MUST NOT be empty and MUST NOT have any leading or trailing
* whitespace characters. The use of Unicode control codes SHOULD be
* avoided.
*
* The statement is optionally followed by a block of sub-statements that
* holds detailed ENUM information.
* All assigned names in an enumeration MUST be unique.
*
* The ENUM's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | - string |
* | reference | 7.19.4 | 0..1 | - string |
* | status | 7.19.2 | 0..1 | - YangStatus |
* | value | 9.6.4.2 | 0..1 | - int |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents the ENUM data type information.
*/
public class YangEnum implements YangCommonInfo, Parsable, Comparable<YangEnum>, Serializable {
private static final long serialVersionUID = 806201643L;
/**
* Named value for the ENUM.
*/
private String namedValue;
/**
* Description of the ENUM value.
*/
private String description;
/**
* Reference info of the ENUM value.
*/
private String reference;
/**
* Status of the ENUM value.
*/
private YangStatusType status;
/**
* Value of ENUM.
*/
private int value;
/**
* Create a YANG ENUM.
*/
public YangEnum() {
}
/**
* Returns the named value.
*
* @return the named value
*/
public String getNamedValue() {
return namedValue;
}
/**
* Sets the named value.
*
* @param namedValue the named value to set
*/
public void setNamedValue(String namedValue) {
this.namedValue = namedValue;
}
/**
* Returns the description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns the status.
*
* @return the status
*/
@Override
public YangStatusType getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns the value.
*
* @return the value
*/
public int getValue() {
return value;
}
/**
* Sets the value.
*
* @param value the value to set
*/
public void setValue(int value) {
this.value = value;
}
/**
* Returns the type of the data.
*
* @return ParsedDataType returns ENUM_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.ENUM_DATA;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof YangEnum) {
final YangEnum other = (YangEnum) obj;
return Objects.equals(namedValue, other.namedValue);
}
return false;
}
@Override
public int hashCode() {
return Objects.hashCode(namedValue);
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public int compareTo(YangEnum otherEnum) {
if (namedValue.equals(otherEnum.getNamedValue())) {
return 0;
}
return new Integer(value).compareTo(otherEnum.getValue());
}
}
/*
* 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.yangutils.datamodel;
import java.util.SortedSet;
import java.util.TreeSet;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* The enumeration built-in type represents values from a set of
* assigned names.
*/
/**
* Represents the enumeration data type information.
*/
public class YangEnumeration
extends YangNode
implements Parsable, CollisionDetector {
private static final long serialVersionUID = 806201606L;
// Enumeration info set.
private SortedSet<YangEnum> enumSet;
// Enumeration name.
private String name;
/**
* Creates an enumeration object.
*/
public YangEnumeration() {
super(YangNodeType.ENUMERATION_NODE);
setEnumSet(new TreeSet<YangEnum>());
}
/**
* Returns the ENUM set.
*
* @return the ENUM set
*/
public SortedSet<YangEnum> getEnumSet() {
return enumSet;
}
/**
* Sets the ENUM set.
*
* @param enumSet the ENUM set to set
*/
private void setEnumSet(SortedSet<YangEnum> enumSet) {
this.enumSet = enumSet;
}
/**
* Adds ENUM information.
*
* @param enumInfo the ENUM information to be added
* @throws DataModelException due to violation in data model rules
*/
public void addEnumInfo(YangEnum enumInfo)
throws DataModelException {
if (!getEnumSet().add(enumInfo)) {
throw new DataModelException("YANG ENUM already exists");
}
}
/**
* Returns enumeration name.
*
* @return the enumeration name
*/
@Override
public String getName() {
return name;
}
/**
* Sets the enumeration name.
*
* @param name enumeration name
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* Returns the type of the data.
*
* @return returns ENUMERATION_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.ENUMERATION_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
/*
Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
*/
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
/*
Do nothing, since it is not part of the schema tree, it is only type of an existing node in schema tree.
*/
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*-
* Reference RFC 6020.
*
* The "extension" statement allows the definition of new statements
* within the YANG language. This new statement definition can be
* imported and used by other modules.
*
* The statement's argument is an identifier that is the new keyword for
* the extension and must be followed by a block of sub-statements that
* holds detailed extension information. The purpose of the "extension"
* statement is to define a keyword, so that it can be imported and used
* by other modules.
*
* The extension can be used like a normal YANG statement, with the
* statement name followed by an argument if one is defined by the
* extension, and an optional block of sub-statements. The statement's
* name is created by combining the prefix of the module in which the
* extension was defined, a colon (":"), and the extension's keyword,
* with no interleaving whitespace. The sub-statements of an extension
* are defined by the extension, using some mechanism outside the scope
* of this specification. Syntactically, the sub-statements MUST be YANG
* statements, or also defined using "extension" statements.
*
* The extension's Sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* | argument | 7.17.2 | 0..1 | -string |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG extension.
*/
public class YangExtension
implements YangCommonInfo, Serializable, Parsable {
private static final long serialVersionUID = 806201605L;
/**
* Name of the extension.
*/
private String name;
/**
* Name of the argument.
*/
private String argumentName;
/**
* Description of extension.
*/
private String description;
/**
* Reference of the extension.
*/
private String reference;
/**
* Status of the extension.
*/
private YangStatusType status = YangStatusType.CURRENT;
/**
* Returns the YANG name of extension.
*
* @return the name of extension as defined in YANG file
*/
public String getName() {
return name;
}
/**
* Sets the YANG name of extension.
*
* @param name the name of extension as defined in YANG file
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the YANG argument name of extension.
*
* @return the name of argument as defined in YANG file
*/
public String getArgumentName() {
return argumentName;
}
/**
* Sets the YANG argument name of extension.
*
* @param argumentName the name of argument as defined in YANG file
*/
public void setArgumentName(String argumentName) {
this.argumentName = argumentName;
}
/**
* Returns the description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns the status.
*
* @return the status
*/
@Override
public YangStatusType getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns the type of the data.
*
* @return returns EXTENSION_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.EXTENSION_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
// TODO : to be implemented
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* Reference RFC 6020.
*
* The "feature" statement is used to define a mechanism by which
* portions of the schema are marked as conditional. A feature name is
* defined that can later be referenced using the "if-feature" statement.
* Schema nodes tagged with a feature are ignored by the device unless
* the device supports the given feature. This allows portions of the
* YANG module to be conditional based on conditions on the device.
* The model can represent the abilities of the device within the model,
* giving a richer model that allows for differing device abilities and roles.
*
* The argument to the "feature" statement is the name of the new
* feature, and follows the rules for identifiers. This name is used by the
* "if-feature" statement to tie the schema nodes to the feature.
*
* The feature's Substatements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | description | 7.19.3 | 0..1 | -string |
* | if-feature | 7.18.2 | 0..n | -YangIfFeature |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG feature.
*/
public class YangFeature implements YangCommonInfo, Parsable, YangIfFeatureHolder, Serializable {
private static final long serialVersionUID = 806201635L;
/**
* Name of the feature.
*/
private String name;
/**
* Description of feature.
*/
private String description;
/**
* Reference of the feature.
*/
private String reference;
/**
* Status of feature.
*/
private YangStatusType statusType;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getReference() {
return reference;
}
@Override
public void setReference(String reference) {
this.reference = reference;
}
@Override
public YangStatusType getStatus() {
return statusType;
}
@Override
public void setStatus(YangStatusType status) {
this.statusType = status;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.FEATURE_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
//TODO : To be implemented
}
@Override
public void validateDataOnExit() throws DataModelException {
//TODO : To be implemented
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
/*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.datamodel;
import java.util.List;
/**
* Abstraction of feature entity. It is used to abstract the data holders of feature.
*/
public interface YangFeatureHolder {
/**
* Returns the list of feature from data holder like container / list.
*
* @return the list of feature
*/
List<YangFeature> getFeatureList();
/**
* Adds feature in feature list.
*
* @param feature the feature to be added
*/
void addFeatureList(YangFeature feature);
/**
* Sets the list of feature.
*
* @param listOfFeature the list of feature to set
*/
void setListOfFeature(List<YangFeature> listOfFeature);
}
/*
* 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.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
/*-
* Reference RFC 6020.
*
* The "grouping" statement is used to define a reusable block of nodes,
* which may be used locally in the module, in modules that include it,
* and by other modules that import from it. It takes one argument,
* which is an identifier, followed by a block of sub-statements that
* holds detailed grouping information.
*
* The "grouping" statement is not a data definition statement and, as
* such, does not define any nodes in the schema tree.
*
* A grouping is like a "structure" or a "record" in conventional
* programming languages.
* Once a grouping is defined, it can be referenced in a "uses"
* statement. A grouping MUST NOT reference itself,
* neither directly nor indirectly through a chain of other groupings.
*
* If the grouping is defined at the top level of a YANG module or
* submodule, the grouping's identifier MUST be unique within the
* module.
*
* A grouping is more than just a mechanism for textual substitution,
* but defines a collection of nodes. Identifiers appearing inside the
* grouping are resolved relative to the scope in which the grouping is
* defined, not where it is used. Prefix mappings, type names, grouping
* names, and extension usage are evaluated in the hierarchy where the
* "grouping" statement appears. For extensions, this means that
* extensions are applied to the grouping node, not the uses node.
*
* The grouping's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | anyxml | 7.10 | 0..n |-not supported |
* | choice | 7.9 | 0..n |-child nodes |
* | container | 7.5 | 0..n |-child nodes |
* | description | 7.19.3 | 0..1 |-string |
* | grouping | 7.11 | 0..n |-child nodes |
* | leaf | 7.6 | 0..n |-YangLeaf |
* | leaf-list | 7.7 | 0..n |-YangLeafList |
* | list | 7.8 | 0..n |-child nodes |
* | 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 |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG grouping.
*/
public class YangGrouping
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201607L;
/**
* Name of the grouping.
*/
private String name;
/**
* Description.
*/
private String description;
/**
* List of leaves.
*/
private List<YangLeaf> listOfLeaf;
/**
* List of leaf lists.
*/
private List<YangLeafList> listOfLeafList;
/**
* Reference of the module.
*/
private String reference;
/**
* Status of the node.
*/
private YangStatusType status;
/**
* Creates the grouping node.
*/
public YangGrouping() {
super(YangNodeType.GROUPING_NODE);
listOfLeaf = new LinkedList<YangLeaf>();
listOfLeafList = new LinkedList<YangLeafList>();
}
/**
* Returns YANG grouping name.
*
* @return YANG grouping name
*/
@Override
public String getName() {
return name;
}
/**
* Sets YANG grouping name.
*
* @param name YANG grouping name
*/
@Override
public void setName(String name) {
this.name = name;
}
/**
* Returns the description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the list of leaves.
*
* @return the list of leaves
*/
@Override
public List<YangLeaf> getListOfLeaf() {
return listOfLeaf;
}
/**
* Sets the list of leaves.
*
* @param leafsList the list of leaf to set
*/
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
/**
* Adds a leaf.
*
* @param leaf the leaf to be added
*/
@Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
}
/**
* Returns the list of leaf-list.
*
* @return the list of leaf-list
*/
@Override
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
/**
* Sets the list of leaf-list.
*
* @param listOfLeafList the list of leaf-list to set
*/
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
/**
* Adds a leaf-list.
*
* @param leafList the leaf-list to be added
*/
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
/**
* Returns the textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns the status.
*
* @return the status
*/
@Override
public YangStatusType getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns the type of the data.
*
* @return returns GROUPING_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.GROUPING_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/*
* Reference RFC6020
*
* Once a grouping is defined, it can be referenced in a "uses"
* statement (see Section 7.12). A grouping MUST NOT reference itself,
* neither directly nor indirectly through a chain of other groupings.
*
* If the grouping is defined at the top level of a YANG module or
* submodule, the grouping's identifier MUST be unique within the
* module.
*/
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
// Asks helper to detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as grouping \"" +
getName() + "\"");
}
}
// TODO A grouping MUST NOT reference itself, neither directly nor indirectly through a chain of other groupings.
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import java.io.Serializable;
/*-
* Reference RFC 6020.
*
* The "identity" statement is used to define a new globally unique,
* abstract, and untyped identity. Its only purpose is to denote its
* name, semantics, and existence. An identity can either be defined
* from scratch or derived from a base identity. The identity's
* argument is an identifier that is the name of the identity. It is
* followed by a block of substatements that holds detailed identity
* information.
*
* The identity's Substatements
*
* +--------------+---------+-------------+-----------------------+
* | substatement | section | cardinality | data model mapping |
* +--------------+---------+-------------+-----------------------+
* | base | 7.16.2 | 0..1 | -YangNodeIdentifier |
* | description | 7.19.3 | 0..1 | -string |
* | reference | 7.19.4 | 0..1 | -string |
* | status | 7.19.2 | 0..1 | -YangStatus |
* +--------------+---------+-------------+-----------------------+
*/
/**
* Represents data model node to maintain information defined in YANG identity.
*/
public class YangIdentity extends YangNode implements YangCommonInfo, Parsable, Serializable {
private static final long serialVersionUID = 806201691L;
//Name of the identity.
private String name;
//Base node of identity.
private YangBase baseNode;
//Status of YANG identity.
private YangStatusType status;
//Description of YANG identity.
private String description;
//YANG reference of the identity.
private String reference;
//Creates a identity type of node.
public YangIdentity() {
super(YangNodeType.IDENTITY_NODE);
}
/**
* Returns the name of identity.
*
* @return the identity name
*/
public String getName() {
return name;
}
/**
* Sets the name of identity.
*
* @param name the identity name to set
*/
public void setName(String name) {
this.name = name;
}
@Override
public YangStatusType getStatus() {
return status;
}
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
@Override
public String getDescription() {
return description;
}
@Override
public void setDescription(String description) {
this.description = description;
}
@Override
public String getReference() {
return reference;
}
@Override
public void setReference(String reference) {
this.reference = reference;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IDENTITY_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
}
@Override
public void validateDataOnExit() throws DataModelException {
}
/**
* Returns base node of identity.
*
* @return the base node of identity
*/
public YangBase getBaseNode() {
return baseNode;
}
/**
* Sets the base node.
*
* @param baseNode the base node to set
*/
public void setBaseNode(YangBase baseNode) {
this.baseNode = baseNode;
}
}
/*
* 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.yangutils.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import java.io.Serializable;
/*-
* Reference RFC 6020.
*
* The identityref type is used to reference an existing identity.
*
* The identityref's base Statement :
* The "base" statement, which is a substatement to the "type"
* statement, MUST be present if the type is "identityref". The
* argument is the name of an identity, as defined by an "identity"
* statement. If a prefix is present on the identity name, it refers to
* an identity defined in the module that was imported with that prefix.
* Otherwise, an identity with the matching name MUST be defined in the
* current module or an included submodule.
* Valid values for an identityref are any identities derived from the
* identityref's base identity. On a particular server, the valid
* values are further restricted to the set of identities defined in the
* modules supported by the server.
*/
/**
* Represents data model node to maintain information defined in YANG identityref.
*/
public class YangIdentityRef extends YangNode implements Parsable, Resolvable, Serializable {
private static final long serialVersionUID = 806201692L;
// Get referred identity parent information.
private YangIdentity referredIdentity;
// YANG node identifier.
private YangNodeIdentifier baseIdentity;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef/identityref/base
* is added to uses/type/identityref/base but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
// Creates a specific identityref of node.
public YangIdentityRef() {
super(YangNodeType.IDENTITYREF_NODE);
baseIdentity = new YangNodeIdentifier();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public Object resolve() throws DataModelException {
// Check if the derived info is present.
YangIdentity identity = getReferredIdentity();
if (identity == null) {
throw new DataModelException("Linker Error: Identity information is missing.");
}
while (identity.getBaseNode() != null) {
if (identity.getBaseNode().getResolvableStatus() != ResolvableStatus.RESOLVED) {
setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
return null;
}
identity = identity.getBaseNode().getReferredIdentity();
}
return null;
}
/**
* Returns the YANG base node identifier.
*
* @return the YANG base node identifier
*/
public YangNodeIdentifier getBaseIdentity() {
return baseIdentity;
}
/**
* Sets the YANG node identifier.
*
* @param baseIdentity the YANG node identifier to set
*/
public void setBaseIdentity(YangNodeIdentifier baseIdentity) {
this.baseIdentity = baseIdentity;
}
/**
* Returns the name of identity.
*
* @return the identity name
*/
@Override
public String getName() {
return baseIdentity.getName();
}
/**
* Sets the name of identity.
*
* @param name the identity name to set
*/
@Override
public void setName(String name) {
baseIdentity.setName(name);
}
/**
* Sets node identifier.
*
* @param nodeIdentifier the node identifier
*/
public void setNodeIdentifier(YangNodeIdentifier nodeIdentifier) {
this.baseIdentity = nodeIdentifier;
}
/**
* Returns prefix associated with base.
*
* @return prefix associated with base
*/
public String getPrefix() {
return baseIdentity.getPrefix();
}
/**
* Sets prefix associated with base.
*
* @param prefix prefix associated with base
*/
public void setPrefix(String prefix) {
baseIdentity.setPrefix(prefix);
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IDENTITYREF_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
}
@Override
public void validateDataOnExit() throws DataModelException {
}
/**
* Returns the parent identity node.
*
* @return the parent identity node
*/
public YangIdentity getReferredIdentity() {
return referredIdentity;
}
/**
* Sets the parent identity node.
*
* @param referredIdentity the parent identity node to set
*/
public void setReferredIdentity(YangIdentity referredIdentity) {
this.referredIdentity = referredIdentity;
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* Reference RFC 6020.
*
* The "if-feature" statement makes its parent statement conditional.
* The argument is the name of a feature, as defined by a "feature"
* statement. The parent statement is implemented by servers that
* support this feature. If a prefix is present on the feature name, it
* refers to a feature defined in the module that was imported with that
* prefix, or the local module if the prefix matches the local module's
* prefix. Otherwise, a feature with the matching name MUST be defined
* in the current module or an included submodule.
*
* Since submodules cannot include the parent module, any features in
* the module that need to be exposed to submodules MUST be defined in a
* submodule. Submodules can then include this submodule to find the
* definition of the feature.
*/
/**
* Represents data model node to maintain information defined in YANG if-feature.
*/
public class YangIfFeature implements Parsable, Resolvable, Serializable {
private static final long serialVersionUID = 806201635L;
/**
* if-feature argument.
*/
YangNodeIdentifier name;
/**
* Referred feature information.
*/
YangFeature referredFeature;
/**
* Referred feature parent information.
*/
YangNode referredFeatureHolder;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED",
* if not enum value is "UNRESOLVED", in case reference of grouping/typedef
* is added to uses/type but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
*/
private ResolvableStatus resolvableStatus;
/**
* Returns referred feature holder.
*
* @return referred feature holder
*/
public YangNode getReferredFeatureHolder() {
return referredFeatureHolder;
}
/**
* Sets the referred feature holder.
*
* @param referredFeatureHolder referred feature holder
*/
public void setReferredFeatureHolder(YangNode referredFeatureHolder) {
this.referredFeatureHolder = referredFeatureHolder;
}
/**
* Returns prefix associated with identifier.
*
* @return prefix associated with identifier
*/
public String getPrefix() {
return name.getPrefix();
}
/**
* Sets prefix associated with identifier.
*
* @param prefix prefix associated with identifier
*/
public void setPrefix(String prefix) {
name.setPrefix(prefix);
}
/**
* Returns referred feature associated with if-feature.
*
* @return referred feature associated with if-feature
*/
public YangFeature getReferredFeature() {
return referredFeature;
}
/**
* Sets referred feature associated with if-feature.
*
* @param referredFeature referred feature associated with if-feature
*/
public void setReferredFeature(YangFeature referredFeature) {
this.referredFeature = referredFeature;
}
/**
* Returns the YANG name of if-feature.
*
* @return the name of if-feature as defined in YANG file
*/
public YangNodeIdentifier getName() {
return name;
}
/**
* Sets the YANG name of if-feature.
*
* @param name the name of if-feature as defined in YANG file
*/
public void setName(YangNodeIdentifier name) {
this.name = name;
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IF_FEATURE_DATA;
}
@Override
public void validateDataOnEntry() throws DataModelException {
// do nothing, no validation required for if-feature
}
@Override
public void validateDataOnExit() throws DataModelException {
// do nothing, no validation required for if-feature
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public Object resolve() throws DataModelException {
YangFeature feature = getReferredFeature();
// check whether feature has if-feature
List<YangIfFeature> ifFeatureList = feature.getIfFeatureList();
if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
while (ifFeatureIterator.hasNext()) {
YangIfFeature ifFeature = ifFeatureIterator.next();
if (ifFeature.getResolvableStatus() != ResolvableStatus.RESOLVED) {
setResolvableStatus(ResolvableStatus.INTRA_FILE_RESOLVED);
return null;
}
}
}
return null;
}
}
/*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.datamodel;
import java.util.List;
/**
* Abstraction of if-feature entity. It is used to abstract the data holders of if-feature.
*/
public interface YangIfFeatureHolder {
/**
* Returns the list of if-feature from data holder like container / list.
*
* @return the list of if-feature
*/
List<YangIfFeature> getIfFeatureList();
/**
* Adds if-feature in if-feature list.
*
* @param ifFeature the if-feature to be added
*/
void addIfFeatureList(YangIfFeature ifFeature);
/**
* Sets the list of if-feature.
*
* @param ifFeatureList the list of if-feature to set
*/
void setIfFeatureList(List<YangIfFeature> ifFeatureList);
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
/*
* Reference:RFC 6020.
* The "import" statement makes definitions from one module available
* inside another module or submodule. The argument is the name of the
* module to import, and the statement is followed by a block of
* sub statements that holds detailed import information.
* When a module is imported, the importing module may:
* o use any grouping and typedef defined at the top level in the
* imported module or its submodules.
*
* o use any extension, feature, and identity defined in the imported
* module or its submodules.
*
* o use any node in the imported module's schema tree in "must",
* "path", and "when" statements, or as the target node in "augment"
* and "deviation" statements.
*
* The mandatory "prefix" sub statement assigns a prefix for the imported
* module that is scoped to the importing module or submodule. Multiple
* "import" statements may be specified to import from different
* modules.
* When the optional "revision-date" sub-statement is present, any
* typedef, grouping, extension, feature, and identity referenced by
* definitions in the local module are taken from the specified revision
* of the imported module. It is an error if the specified revision of
* the imported module does not exist. If no "revision-date"
* sub-statement is present, it is undefined from which revision of the
* module they are taken.
*
* Multiple revisions of the same module MUST NOT be imported.
*
* The import's Substatements
*
* +---------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | prefix | 7.1.4 | 1 | string |
* | revision-date | 7.1.5.1 | 0..1 | Date |
* +---------------+---------+-------------+------------------+
*/
/**
* Represents the information about the imported modules.
*/
public class YangImport
implements Parsable, LocationInfo, Serializable {
private static final long serialVersionUID = 806201642L;
/**
* Name of the module that is being imported.
*/
private String name;
/**
* Prefix used to identify the entities from the imported module.
*/
private String prefixId;
/**
* Reference:RFC 6020.
* <p>
* The import's "revision-date" statement is used to specify the exact
* version of the module to import. The "revision-date" statement MUST match
* the most recent "revision" statement in the imported module. organization
* which defined the YANG module.
*/
private Date revision;
/**
* Reference to node which is imported.
*/
private YangNode importedNode;
// Error Line number.
private transient int lineNumber;
// Error character position.
private transient int charPosition;
/**
* Creates a YANG import.
*/
public YangImport() {
}
/**
* Returns the imported module name.
*
* @return the module name
*/
public String getModuleName() {
return name;
}
/**
* Sets module name.
*
* @param moduleName the module name to set
*/
public void setModuleName(String moduleName) {
name = moduleName;
}
/**
* Returns the prefix used to identify the entities from the imported module.
*
* @return the prefix used to identify the entities from the imported
* module
*/
public String getPrefixId() {
return prefixId;
}
/**
* Sets prefix identifier.
*
* @param prefixId set the prefix identifier of the imported module
*/
public void setPrefixId(String prefixId) {
this.prefixId = prefixId;
}
/**
* Returns the revision of the imported module.
*
* @return the revision of the imported module
*/
public Date getRevision() {
return revision;
}
/**
* Sets the revision of the imported module.
*
* @param rev set the revision of the imported module
*/
public void setRevision(Date rev) {
revision = rev;
}
/**
* Returns the type of the parsed data.
*
* @return returns IMPORT_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.IMPORT_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Returns imported node.
*
* @return imported node
*/
public YangNode getImportedNode() {
return importedNode;
}
/**
* Sets imported node.
*
* @param importedNode imported node
*/
public void setImportedNode(YangNode importedNode) {
this.importedNode = importedNode;
}
@Override
public int getLineNumber() {
return lineNumber;
}
@Override
public int getCharPosition() {
return charPosition;
}
@Override
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
@Override
public void setCharPosition(int charPositionInLine) {
charPosition = charPositionInLine;
}
/**
* Adds reference to an import.
*
* @param yangNodeSet YANG file info set
* @throws DataModelException a violation of data model rules
*/
public void addReferenceToImport(Set<YangNode> yangNodeSet) throws DataModelException {
String importedModuleName = getModuleName();
Date importedModuleRevision = getRevision();
YangNode moduleNode = null;
/*
* Find the imported module node for a given module name with a
* specified revision if revision is not null.
*/
if (importedModuleRevision != null) {
String importedModuleNameWithRevision = importedModuleName + "@" + importedModuleRevision;
moduleNode = findReferredNode(yangNodeSet, importedModuleNameWithRevision);
}
/*
* Find the imported module node for a given module name without
* revision if can't find with revision.
*/
if (moduleNode == null) {
moduleNode = findReferredNode(yangNodeSet, importedModuleName);
}
if (moduleNode != null) {
if (moduleNode instanceof YangModule) {
if (getRevision() == null) {
setImportedNode(moduleNode);
return;
}
// Match revision if import is with revision.
if (((YangModule) moduleNode).getRevision().getRevDate().equals(importedModuleRevision)) {
setImportedNode(moduleNode);
return;
}
}
}
// Exception if there is no match.
DataModelException exception = new DataModelException("YANG file error : Imported module "
+ importedModuleName + " with revision " + importedModuleRevision + " is not found.");
exception.setLine(getLineNumber());
exception.setCharPosition(getCharPosition());
throw exception;
}
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.findReferredNode;
/*
* Reference:RFC 6020.
* The "include" statement is used to make content from a submodule
* available to that submodule's parent module, or to another submodule
* of that parent module. The argument is an identifier that is the
* name of the submodule to include.
* The includes's Substatements
*
* +---------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +---------------+---------+-------------+------------------+
* | revision-date | 7.1.5.1 | 0..1 | string |
* +---------------+---------+-------------+------------------+
*/
/**
* Represents the information about the included sub-modules.
*/
public class YangInclude
implements Parsable, LocationInfo, Serializable {
private static final long serialVersionUID = 806201644L;
/**
* Name of the sub-module that is being included.
*/
private String subModuleName;
/**
* The include's "revision-date" statement is used to specify the exact
* version of the submodule to import.
*/
private Date revision;
/**
* Reference to node which is included.
*/
private YangNode includedNode;
// Error Line number.
private transient int lineNumber;
// Error character position.
private transient int charPosition;
/**
* Creates a YANG include.
*/
public YangInclude() {
}
/**
* Returns the name of included sub-module.
*
* @return the sub-module name
*/
public String getSubModuleName() {
return subModuleName;
}
/**
* Sets the name of included sub-modules.
*
* @param subModuleName the sub-module name to set
*/
public void setSubModuleName(String subModuleName) {
this.subModuleName = subModuleName;
}
/**
* Returns the revision.
*
* @return the revision
*/
public Date getRevision() {
return revision;
}
/**
* Sets the revision.
*
* @param revision the revision to set
*/
public void setRevision(Date revision) {
this.revision = revision;
}
/**
* Returns the type of parsed data.
*
* @return returns INCLUDE_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.INCLUDE_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
public YangNode getIncludedNode() {
return includedNode;
}
public void setIncludedNode(YangNode includedNode) {
this.includedNode = includedNode;
}
@Override
public int getLineNumber() {
return lineNumber;
}
@Override
public int getCharPosition() {
return charPosition;
}
@Override
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
@Override
public void setCharPosition(int charPositionInLine) {
charPosition = charPositionInLine;
}
/**
* Adds reference to an include.
*
* @param yangNodeSet YANG node set
* @return YANG sub module node
* @throws DataModelException a violation of data model rules
*/
public YangSubModule addReferenceToInclude(Set<YangNode> yangNodeSet) throws DataModelException {
String includedSubModuleName = getSubModuleName();
Date includedSubModuleRevision = getRevision();
YangNode subModuleNode = null;
/*
* Find the included sub-module node for a given module name with a
* specified revision if revision is not null.
*/
if (includedSubModuleRevision != null) {
String includedSubModuleNameWithRevision = includedSubModuleName + "@" + includedSubModuleRevision;
subModuleNode = findReferredNode(yangNodeSet, includedSubModuleNameWithRevision);
}
/*
* Find the imported sub module node for a given module name without
* revision if can't find with revision.
*/
if (subModuleNode == null) {
subModuleNode = findReferredNode(yangNodeSet, includedSubModuleName);
}
if (subModuleNode != null) {
if (subModuleNode instanceof YangSubModule) {
if (getRevision() == null) {
setIncludedNode(subModuleNode);
return (YangSubModule) subModuleNode;
}
// Match revision if inclusion is with revision.
if (((YangSubModule) subModuleNode).getRevision().getRevDate().equals(includedSubModuleRevision)) {
setIncludedNode(subModuleNode);
return (YangSubModule) subModuleNode;
}
}
}
// Exception if there is no match.
DataModelException exception = new DataModelException("YANG file error : Included sub module " +
includedSubModuleName + "with a given revision is not found.");
exception.setLine(getLineNumber());
exception.setCharPosition(getCharPosition());
throw exception;
}
/**
* Reports an error when included sub-module doesn't meet condition that
* "included sub-modules should belong module, as defined by the
* "belongs-to" statement or sub-modules are only allowed to include other
* sub-modules belonging to the same module.
*
* @throws DataModelException a violation in data model rule
*/
public void reportIncludeError() throws DataModelException {
DataModelException exception = new DataModelException("YANG file error : Included sub-module " +
getSubModuleName() + "doesn't belongs to parent module also it doesn't belongs" +
"to sub-module belonging to the same parent module.");
exception.setLine(getLineNumber());
exception.setCharPosition(getCharPosition());
throw exception;
}
}
/*
* 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.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
/*
* Reference RFC 6020.
*
* The "input" statement, which is optional, is used to define input
* parameters to the RPC operation. It does not take an argument. The
* substatements to "input" define nodes under the RPC's input node.
*
* If a leaf in the input tree has a "mandatory" statement with the
* value "true", the leaf MUST be present in a NETCONF RPC invocation.
* Otherwise, the server MUST return a "missing-element" error.
*
* If a leaf in the input tree has a default value, the NETCONF server
* MUST use this value in the same cases as described in Section 7.6.1.
* In these cases, the server MUST operationally behave as if the leaf
* was present in the NETCONF RPC invocation with the default value as
* its value.
*
* If a "config" statement is present for any node in the input tree,
* the "config" statement is ignored.
*
* If any node has a "when" statement that would evaluate to false, then
* this node MUST NOT be present in the input tree.
*
* The input substatements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | anyxml | 7.10 | 0..n | -not supported |
* | choice | 7.9 | 0..n | -child nodes |
* | container | 7.5 | 0..n | -child nodes |
* | grouping | 7.11 | 0..n | -child nodes |
* | leaf | 7.6 | 0..n | -YangLeaf |
* | leaf-list | 7.7 | 0..n | -YangLeafList |
* | list | 7.8 | 0..n | -child nodes |
* | typedef | 7.3 | 0..n | -child nodes |
* | uses | 7.12 | 0..n | -child nodes |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents data model node to maintain information defined in YANG input.
*/
public class YangInput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode, YangIsFilterContentNodes {
private static final long serialVersionUID = 806201608L;
/**
* Name of the input.
*/
private String name;
/**
* List of leaves contained.
*/
private List<YangLeaf> listOfLeaf;
/**
* List of leaf-lists contained.
*/
private List<YangLeafList> listOfLeafList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Create a rpc input node.
*/
public YangInput() {
super(YangNodeType.INPUT_NODE);
listOfLeaf = new LinkedList<>();
listOfLeafList = new LinkedList<>();
}
@Override
public void detectCollidingChild(String identifierName, YangConstructType dataType)
throws DataModelException {
// Detect colliding child.
detectCollidingChildUtil(identifierName, dataType, this);
}
@Override
public void detectSelfCollision(String identifierName, YangConstructType dataType)
throws DataModelException {
if (getName().equals(identifierName)) {
throw new DataModelException("YANG file error: Duplicate input identifier detected, same as input \""
+ getName() + "\"");
}
}
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.INPUT_DATA;
}
@Override
public void validateDataOnEntry()
throws DataModelException {
//TODO: implement the method.
}
@Override
public void validateDataOnExit()
throws DataModelException {
//TODO: implement the method.
}
@Override
public List<YangLeaf> getListOfLeaf() {
return listOfLeaf;
}
@Override
public void setListOfLeaf(List<YangLeaf> leafsList) {
listOfLeaf = leafsList;
}
@Override
public void addLeaf(YangLeaf leaf) {
getListOfLeaf().add(leaf);
}
@Override
public List<YangLeafList> getListOfLeafList() {
return listOfLeafList;
}
@Override
public void setListOfLeafList(List<YangLeafList> listOfLeafList) {
this.listOfLeafList = listOfLeafList;
}
@Override
public void addLeafList(YangLeafList leafList) {
getListOfLeafList().add(leafList);
}
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public void addAugmentation(YangAugmentedInfo augmentInfo) {
yangAugmentedInfo.add(augmentInfo);
}
@Override
public void removeAugmentation(YangAugmentedInfo augmentInfo) {
yangAugmentedInfo.remove(augmentInfo);
}
@Override
public List<YangAugmentedInfo> getAugmentedInfoList() {
return yangAugmentedInfo;
}
}
/*
* 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.yangutils.datamodel;
/**
* Represent the YANG nodes which can contain is filter content match.
*/
public interface YangIsFilterContentNodes {
}
/*
* 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.yangutils.datamodel;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
/*
* Reference:RFC 6020.
* The "leaf" statement is used to define a leaf node in the schema
* tree. It takes one argument, which is an identifier, followed by a
* block of sub-statements that holds detailed leaf information.
*
* A leaf node has a value, but no child nodes in the data tree.
* Conceptually, the value in the data tree is always in the canonical
* form.
*
* A leaf node exists in zero or one instances in the data tree.
*
* The "leaf" statement is used to define a scalar variable of a
* particular built-in or derived type.
*
* The leaf's sub-statements
*
* +--------------+---------+-------------+------------------+
* | substatement | section | cardinality |data model mapping|
* +--------------+---------+-------------+------------------+
* | config | 7.19.1 | 0..1 | - boolean |
* | default | 7.6.4 | 0..1 | - string |
* | description | 7.19.3 | 0..1 | - string |
* | if-feature | 7.18.2 | 0..n | - YangIfFeature |
* | mandatory | 7.6.5 | 0..1 | - boolean |
* | must | 7.5.3 | 0..n | - YangMust |
* | reference | 7.19.4 | 0..1 | - string |
* | status | 7.19.2 | 0..1 | - YangStatus |
* | type | 7.6.3 | 1 | - YangType |
* | units | 7.3.3 | 0..1 | - String |
* | when | 7.19.5 | 0..1 | - YangWhen |
* +--------------+---------+-------------+------------------+
*/
/**
* Represents leaf data represented in YANG.
*/
public class YangLeaf
implements YangCommonInfo, Parsable, Cloneable, Serializable,
YangMustHolder, YangIfFeatureHolder, YangWhenHolder, YangDataNode {
private static final long serialVersionUID = 806201635L;
/**
* Name of leaf.
*/
private String name;
/**
* If the leaf is a config parameter.
*/
private Boolean isConfig;
/**
* description of leaf.
*/
private String description;
/**
* If mandatory leaf.
*/
private boolean isMandatory;
/**
* The textual reference to this leaf.
*/
private String reference;
/**
* Status of leaf in YANG definition.
*/
private YangStatusType status = YangStatusType.CURRENT;
/**
* Textual units info.
*/
private String units;
/**
* Data type of the leaf.
*/
private YangType<?> dataType;
/**
* Default value in string, needs to be converted to the target object,
* based on the type.
*/
private String defaultValueInString;
/**
* When data of the leaf.
*/
private YangWhen when;
/**
* YANG Node in which the leaf is contained.
*/
private transient YangLeavesHolder containedIn;
/**
* List of must statement constraints.
*/
private List<YangMust> mustConstraintList;
/**
* List of if-feature.
*/
private List<YangIfFeature> ifFeatureList;
/**
* Creates a YANG leaf.
*/
public YangLeaf() {
}
/**
* Returns the name of leaf.
*
* @return the leaf name
*/
public String getName() {
return name;
}
/**
* Sets the name of leaf.
*
* @param leafName the leaf name to set
*/
public void setLeafName(String leafName) {
name = leafName;
}
/**
* Returns the config flag.
*
* @return if config flag
*/
public Boolean isConfig() {
return isConfig;
}
/**
* Sets the config flag.
*
* @param isCfg the flag value to set
*/
public void setConfig(boolean isCfg) {
isConfig = isCfg;
}
/**
* Returns the when.
*
* @return the when
*/
@Override
public YangWhen getWhen() {
return when;
}
/**
* Sets the when.
*
* @param when the when to set
*/
@Override
public void setWhen(YangWhen when) {
this.when = when;
}
/**
* Returns the description.
*
* @return the description
*/
@Override
public String getDescription() {
return description;
}
/**
* Sets the description.
*
* @param description set the description
*/
@Override
public void setDescription(String description) {
this.description = description;
}
/**
* Returns if the leaf is mandatory.
*
* @return if leaf is mandatory
*/
public boolean isMandatory() {
return isMandatory;
}
/**
* Sets if the leaf is mandatory.
*
* @param isReq if the leaf is mandatory
*/
public void setMandatory(boolean isReq) {
isMandatory = isReq;
}
/**
* Returns the textual reference.
*
* @return the reference
*/
@Override
public String getReference() {
return reference;
}
/**
* Sets the textual reference.
*
* @param reference the reference to set
*/
@Override
public void setReference(String reference) {
this.reference = reference;
}
/**
* Returns the status.
*
* @return the status
*/
@Override
public YangStatusType getStatus() {
return status;
}
/**
* Sets the status.
*
* @param status the status to set
*/
@Override
public void setStatus(YangStatusType status) {
this.status = status;
}
/**
* Returns the units.
*
* @return the units
*/
public String getUnits() {
return units;
}
/**
* Sets the units.
*
* @param units the units to set
*/
public void setUnits(String units) {
this.units = units;
}
/**
* Returns the default value.
*
* @return the default value
*/
public String getDefaultValueInString() {
return defaultValueInString;
}
/**
* Sets the default value.
*
* @param defaultValueInString the default value
*/
public void setDefaultValueInString(String defaultValueInString) {
this.defaultValueInString = defaultValueInString;
}
/**
* Returns the data type.
*
* @return the data type
*/
public YangType<?> getDataType() {
return dataType;
}
/**
* Sets the data type.
*
* @param dataType the data type to set
*/
public void setDataType(YangType<?> dataType) {
this.dataType = dataType;
}
/**
* Retrieves the YANG node in which the leaf is defined.
*
* @return the YANG node in which the leaf is defined
*/
public YangLeavesHolder getContainedIn() {
return containedIn;
}
/**
* Assigns the YANG node in which the leaf is defined.
*
* @param containedIn the YANG node in which the leaf is defined
*/
public void setContainedIn(YangLeavesHolder containedIn) {
this.containedIn = containedIn;
}
@Override
public YangLeaf clone()
throws CloneNotSupportedException {
return (YangLeaf) super.clone();
}
/**
* Returns the type of the parsed data.
*
* @return returns LEAF_DATA
*/
@Override
public YangConstructType getYangConstructType() {
return YangConstructType.LEAF_DATA;
}
/**
* Validates the data on entering the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnEntry()
throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
/**
* Validates the data on exiting the corresponding parse tree node.
*
* @throws DataModelException a violation of data model rules
*/
@Override
public void validateDataOnExit()
throws DataModelException {
if (defaultValueInString != null && !defaultValueInString.isEmpty() && dataType != null) {
dataType.isValidValue(defaultValueInString);
}
}
@Override
public List<YangMust> getListOfMust() {
return mustConstraintList;
}
@Override
public void setListOfMust(List<YangMust> mustConstraintList) {
this.mustConstraintList = mustConstraintList;
}
@Override
public void addMust(YangMust must) {
if (getListOfMust() == null) {
setListOfMust(new LinkedList<>());
}
getListOfMust().add(must);
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
}
@Override
public void addIfFeatureList(YangIfFeature ifFeature) {
if (getIfFeatureList() == null) {
setIfFeatureList(new LinkedList<>());
}
getIfFeatureList().add(ifFeature);
}
@Override
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.