Bharat saraswal
Committed by Patrick Liu

[ONOS-4799],[ONOS-4351] Augment inter file linker and Generated Code refactored.

Change-Id: Id1f3ac9c90a632373f51cc75d499c3110216be17
Showing 110 changed files with 2020 additions and 640 deletions
......@@ -49,5 +49,10 @@ public enum ResolvableType {
/**
* Identifies the identityref.
*/
YANG_IDENTITYREF
YANG_IDENTITYREF,
/**
* Identifies the augment.
*/
YANG_AUGMENT
}
......
......@@ -20,6 +20,7 @@ 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;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCollidingChildUtil;
......@@ -81,7 +82,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangAugment
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangWhenHolder, YangIfFeatureHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentedInfo, Resolvable,
YangXPathResolver, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201602L;
......@@ -108,7 +110,7 @@ public class YangAugment
/**
* List of node identifiers.
*/
private List<YangNodeIdentifier> targetNode;
private List<YangAtomicPath> targetNode;
/**
* Reference of the YANG augment.
......@@ -121,6 +123,19 @@ public class YangAugment
private YangStatusType status;
/**
* Resolved augmented node.
*/
private YangNode augmentedNode;
/**
* 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;
/**
* When data of the node.
*/
private YangWhen when;
......@@ -135,6 +150,7 @@ public class YangAugment
*/
public YangAugment() {
super(YangNodeType.AUGMENT_NODE);
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
/**
......@@ -142,7 +158,7 @@ public class YangAugment
*
* @return the augmented node
*/
public List<YangNodeIdentifier> getTargetNode() {
public List<YangAtomicPath> getTargetNode() {
return targetNode;
}
......@@ -151,7 +167,7 @@ public class YangAugment
*
* @param nodeIdentifiers the augmented node
*/
public void setTargetNode(List<YangNodeIdentifier> nodeIdentifiers) {
public void setTargetNode(List<YangAtomicPath> nodeIdentifiers) {
targetNode = nodeIdentifiers;
}
......@@ -371,6 +387,24 @@ public class YangAugment
this.name = name;
}
/**
* Returns augmented node.
*
* @return augmented node
*/
public YangNode getAugmentedNode() {
return augmentedNode;
}
/**
* Sets augmented node.
*
* @param augmentedNode augmented node
*/
public void setAugmentedNode(YangNode augmentedNode) {
this.augmentedNode = augmentedNode;
}
@Override
public List<YangIfFeature> getIfFeatureList() {
return ifFeatureList;
......@@ -388,4 +422,20 @@ public class YangAugment
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@Override
public ResolvableStatus getResolvableStatus() {
return resolvableStatus;
}
@Override
public void setResolvableStatus(ResolvableStatus resolvableStatus) {
this.resolvableStatus = resolvableStatus;
}
@Override
public void resolve() throws DataModelException {
// Resolving of target node is being done in XPathLinker.
}
}
......
......@@ -14,31 +14,33 @@
* limitations under the License.
*/
package org.onosproject.yangutils.utils;
package org.onosproject.yangutils.datamodel;
import java.util.List;
/**
* Abstraction of an entity which represents augmentation of a YANG node.
* Represents YANG constructs which can be augmented.
*/
public interface AugmentationHolder {
public interface YangAugmentableNode {
/**
* Adds augment info to the augment info list.
*
* @param augmentInfo augment info of node
*/
void addAugmentation(AugmentedInfo augmentInfo);
void addAugmentation(YangAugmentedInfo augmentInfo);
/**
* Removes augment info from the node.
*
* @param augmentInfo augment info of node
*/
void removeAugmentation();
void removeAugmentation(YangAugmentedInfo augmentInfo);
/**
* Returns list of augment info.
*
* @return list of augment info
*/
List<AugmentedInfo> getAugmentedInfoList();
List<YangAugmentedInfo> getAugmentedInfoList();
}
......
......@@ -17,7 +17,7 @@
package org.onosproject.yangutils.datamodel;
/**
* Represents YANG constructs which can be augmented.
* Abstraction of an entity which represents YANG augmented info.
*/
public interface YangAugmentationHolder {
public interface YangAugmentedInfo {
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
......@@ -94,7 +95,7 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_D
*/
public class YangCase
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode,
YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201603L;
......@@ -141,6 +142,8 @@ public class YangCase
*/
private List<YangIfFeature> ifFeatureList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Creates a choice node.
*/
......@@ -392,4 +395,19 @@ public class YangCase
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@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;
}
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
......@@ -63,8 +64,8 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE
* Represents data model node to maintain information defined in YANG choice.
*/
public class YangChoice extends YangNode
implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder, YangWhenHolder,
YangIfFeatureHolder {
implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentableNode,
YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201604L;
......@@ -156,6 +157,8 @@ public class YangChoice extends YangNode
*/
private List<YangIfFeature> ifFeatureList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Create a choice node.
*/
......@@ -418,4 +421,18 @@ public class YangChoice extends YangNode
this.ifFeatureList = ifFeatureList;
}
@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;
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
......@@ -89,8 +90,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangContainer
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangWhenHolder, YangIfFeatureHolder {
private static final long serialVersionUID = 806201605L;
......@@ -130,6 +131,8 @@ public class YangContainer
*/
private String reference;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Status of the node.
*/
......@@ -518,4 +521,18 @@ public class YangContainer
getListOfMust().add(must);
}
@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;
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
......@@ -70,7 +71,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangInput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode {
private static final long serialVersionUID = 806201608L;
......@@ -89,6 +90,8 @@ public class YangInput
*/
private List<YangLeafList> listOfLeafList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Create a rpc input node.
*/
......@@ -171,4 +174,19 @@ public class YangInput
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;
}
}
......
......@@ -43,7 +43,8 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVE
*
* @param <T> YANG leafref info
*/
public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder {
public class YangLeafRef<T> implements Parsable, Resolvable, Serializable, YangIfFeatureHolder,
YangXPathResolver {
private static final long serialVersionUID = 286201644L;
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
......@@ -70,8 +71,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangList
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangMustHolder, YangIfFeatureHolder, YangDataNode {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangMustHolder, YangIfFeatureHolder, YangDataNode {
private static final long serialVersionUID = 806201609L;
......@@ -127,6 +128,8 @@ public class YangList
*/
private List<YangLeafList> listOfLeafList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Reference RFC 6020.
*
......@@ -570,8 +573,7 @@ public class YangList
* @throws DataModelException a violation of data model rules
*/
private void validateKey(List<YangLeaf> leaves, List<YangLeafList> leafLists, List<String> keys)
throws
DataModelException {
throws DataModelException {
boolean leafFound = false;
List<YangLeaf> keyLeaves = new LinkedList<>();
List<YangLeafList> keyLeafLists = new LinkedList<>();
......@@ -713,4 +715,19 @@ public class YangList
}
getListOfMust().add(must);
}
@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;
}
}
......
......@@ -201,30 +201,34 @@ public class YangModule
private List<YangResolutionInfo> derivedTypeResolutionList;
/**
* uses resolution list.
* Uses resolution list.
*/
private List<YangResolutionInfo> usesResolutionList;
/**
* if-feature resolution list.
* If-feature resolution list.
*/
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* leafref resolution list.
* Leafref resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
/**
* base resolution list.
* Base resolution list.
*/
private List<YangResolutionInfo> baseResolutionList;
/**
* identityref resolution list.
* Identityref resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
/**
* Augment resolution list.
*/
private List<YangResolutionInfo> augmentResolutionList;
/**
* Creates a YANG node of module type.
......@@ -233,6 +237,7 @@ public class YangModule
super(YangNodeType.MODULE_NODE);
derivedTypeResolutionList = new LinkedList<>();
augmentResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
......@@ -608,6 +613,8 @@ public class YangModule
return derivedTypeResolutionList;
} else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
return augmentResolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else if (type == ResolvableType.YANG_LEAFREF) {
......@@ -632,6 +639,8 @@ public class YangModule
leafrefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
}
......@@ -650,6 +659,8 @@ public class YangModule
leafrefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
......@@ -76,8 +77,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangNotification
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder,
YangIfFeatureHolder {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector,
YangAugmentableNode, YangIfFeatureHolder {
private static final long serialVersionUID = 806201611L;
......@@ -116,6 +117,8 @@ public class YangNotification
*/
private List<YangIfFeature> ifFeatureList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Create a notification node.
*/
......@@ -245,4 +248,19 @@ public class YangNotification
public void setIfFeatureList(List<YangIfFeature> ifFeatureList) {
this.ifFeatureList = ifFeatureList;
}
@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;
}
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.yangutils.datamodel;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
......@@ -69,7 +70,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangOutput
extends YangNode
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentableNode {
private static final long serialVersionUID = 806201612L;
......@@ -88,6 +89,8 @@ public class YangOutput
*/
private List<YangLeafList> listOfLeafList;
private List<YangAugmentedInfo> yangAugmentedInfo = new ArrayList<>();
/**
* Create a rpc output node.
*/
......@@ -170,4 +173,19 @@ public class YangOutput
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;
}
}
......
......@@ -20,10 +20,13 @@ package org.onosproject.yangutils.datamodel;
*/
public enum YangPathArgType {
// Absolute path.
/**
* Absolute path.
*/
ABSOLUTE_PATH,
// Relative path.
/**
* Relative path.
*/
RELATIVE_PATH
}
......
......@@ -20,6 +20,8 @@ package org.onosproject.yangutils.datamodel;
*/
public enum YangPathOperator {
// Path expression contains equal to.
/**
* Path expression contains equal-to.
*/
EQUALTO
}
......
......@@ -199,36 +199,42 @@ public class YangSubModule
private List<YangResolutionInfo> derivedTypeResolutionList;
/**
* uses resolution list.
* Uses resolution list.
*/
private List<YangResolutionInfo> usesResolutionList;
/**
* if-feature resolution list.
* If-feature resolution list.
*/
private List<YangResolutionInfo> ifFeatureResolutionList;
/**
* leafref resolution list.
* Leafref resolution list.
*/
private List<YangResolutionInfo> leafrefResolutionList;
/**
* base resolution list.
* Base resolution list.
*/
private List<YangResolutionInfo> baseResolutionList;
/**
* identityref resolution list.
* Identityref resolution list.
*/
private List<YangResolutionInfo> identityrefResolutionList;
/**
* Augment resolution list.
*/
private List<YangResolutionInfo> augmentResolutionList;
/**
* Creates a sub module node.
*/
public YangSubModule() {
super(YangNodeType.SUB_MODULE_NODE);
derivedTypeResolutionList = new LinkedList<>();
augmentResolutionList = new LinkedList<>();
usesResolutionList = new LinkedList<>();
ifFeatureResolutionList = new LinkedList<>();
leafrefResolutionList = new LinkedList<>();
......@@ -569,6 +575,8 @@ public class YangSubModule
return derivedTypeResolutionList;
} else if (type == ResolvableType.YANG_USES) {
return usesResolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
return augmentResolutionList;
} else if (type == ResolvableType.YANG_IF_FEATURE) {
return ifFeatureResolutionList;
} else if (type == ResolvableType.YANG_LEAFREF) {
......@@ -593,6 +601,8 @@ public class YangSubModule
leafrefResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList.add(resolutionInfo);
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList.add(resolutionInfo);
}
......@@ -611,6 +621,8 @@ public class YangSubModule
leafrefResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_BASE) {
baseResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_AUGMENT) {
augmentResolutionList = resolutionList;
} else if (type == ResolvableType.YANG_IDENTITYREF) {
identityrefResolutionList = resolutionList;
}
......
......@@ -14,10 +14,10 @@
* limitations under the License.
*/
package org.onosproject.yangutils.utils;
package org.onosproject.yangutils.datamodel;
/**
* Abstraction of an entity which represents augmented info.
* Abstraction of an entity which can be resolved with x-path linker.
*/
public interface AugmentedInfo {
public interface YangXPathResolver {
}
......
......@@ -16,12 +16,17 @@
package org.onosproject.yangutils.datamodel.utils;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangIfFeature;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangIdentityRef;
import org.onosproject.yangutils.datamodel.YangLeaf;
......@@ -171,6 +176,10 @@ public final class DataModelUtils {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_USES);
} else if (resolutionInfo.getEntityToResolveInfo()
.getEntityToResolve() instanceof YangAugment) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_AUGMENT);
} else if (resolutionInfo.getEntityToResolveInfo()
.getEntityToResolve() instanceof YangIfFeature) {
resolutionNode.addToResolutionList(resolutionInfo,
ResolvableType.YANG_IF_FEATURE);
......@@ -272,4 +281,30 @@ public final class DataModelUtils {
*/
return currentNode.getParent();
}
/**
* Returns de-serializes YANG data-model nodes.
*
* @param serializableInfoSet YANG file info set
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
*/
public static List<YangNode> deSerializeDataModel(List<String> serializableInfoSet) throws IOException {
List<YangNode> nodes = new ArrayList<>();
for (String fileInfo : serializableInfoSet) {
YangNode node = null;
try {
FileInputStream fileInputStream = new FileInputStream(fileInfo);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
node = (YangNode) objectInputStream.readObject();
nodes.add(node);
objectInputStream.close();
fileInputStream.close();
} catch (IOException | ClassNotFoundException e) {
throw new IOException(fileInfo + " not found.");
}
}
return nodes;
}
}
......
......@@ -161,6 +161,8 @@ public class YangLinkerManager
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_USES);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
((YangReferenceResolver) yangNode)
.resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
......
/*
* 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.linker.impl;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
/**
* Represent utilities for YANG linker.
*/
public final class YangLinkerUtils {
private YangLinkerUtils() {
}
/**
* Detects collision between target nodes leaf/leaf-list or child node with
* augmented leaf/leaf-list or child node.
*
* @param targetNode target node
* @param augment augment node
*/
private static void detectCollision(YangNode targetNode, YangAugment augment) {
YangNode targetNodesChild = targetNode.getChild();
YangNode augmentsChild = augment.getChild();
YangLeavesHolder augmentsLeavesHolder = augment;
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
if (targetNode instanceof YangAugment) {
parent = targetNode.getParent();
} else {
while (parent.getParent() != null) {
parent = parent.getParent();
}
}
if (augmentsLeavesHolder.getListOfLeaf() != null && augmentsLeavesHolder.getListOfLeaf().size() != 0
&& targetNodesLeavesHolder.getListOfLeaf() != null) {
for (YangLeaf leaf : augmentsLeavesHolder.getListOfLeaf()) {
for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
if (targetLeaf.getName().equals(leaf.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented leaf " + leaf.getName() + " in module "
+ parent.getName());
}
}
}
} else if (augmentsLeavesHolder.getListOfLeafList() != null
&& augmentsLeavesHolder.getListOfLeafList().size() != 0
&& targetNodesLeavesHolder.getListOfLeafList() != null) {
for (YangLeafList leafList : augmentsLeavesHolder.getListOfLeafList()) {
for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
if (targetLeafList.getName().equals(leafList.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented leaf-list" + leafList.getName() + " in module "
+ parent.getName());
}
}
}
} else {
while (augmentsChild != null) {
while (targetNodesChild != null) {
if (targetNodesChild.getName().equals(augmentsChild.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented child node" + augmentsChild.getName() + " in module "
+ parent.getName());
}
targetNodesChild = targetNodesChild.getNextSibling();
}
augmentsChild = augmentsChild.getNextSibling();
}
}
}
/**
* Detects collision between target nodes and its all leaf/leaf-list or child node with
* augmented leaf/leaf-list or child node.
*
* @param targetNode target node
* @param augment augment node
*/
public static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
// Detect collision for target node and augment node.
detectCollision(targetNode, augment);
List<YangAugmentedInfo> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
// Detect collision for target augment node and current augment node.
for (YangAugmentedInfo info : yangAugmentedInfo) {
detectCollision((YangAugment) info, augment);
}
}
}
......@@ -24,6 +24,8 @@ import java.util.Stack;
import org.onosproject.yangutils.datamodel.Resolvable;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangBase;
import org.onosproject.yangutils.datamodel.YangDerivedInfo;
import org.onosproject.yangutils.datamodel.YangEntityToResolveInfo;
......@@ -55,10 +57,12 @@ import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.YangXPathResolver;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.YangLinkingPhase;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
......@@ -68,6 +72,7 @@ import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNDEFIN
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTER_FILE;
import static org.onosproject.yangutils.linker.YangLinkingPhase.INTRA_FILE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
......@@ -1438,15 +1443,74 @@ public class YangResolutionInfoImpl<T>
throw new DataModelException("Data Model Exception: Entity to resolved is not Resolvable");
}
if (entityToResolve instanceof YangXPathResolver) {
//Process x-path linking.
processXPathLinking(getEntityToResolveInfo(), dataModelRootNode);
} else {
// Push the initial entity to resolve in stack.
addInPartialResolvedStack(getEntityToResolveInfo());
// Inter file linking and resolution.
linkInterFileAndResolve();
// Resolve the derived types having leafref.
addDerivedRefTypeToRefTypeResolutionList();
}
}
/**
* Process x-path linking for augment and leaf-ref.
*
* @param entityToResolveInfo entity to resolve
* @param root root node
*/
private void processXPathLinking(YangEntityToResolveInfoImpl<T> entityToResolveInfo,
YangReferenceResolver root) {
YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
T entityToResolve = entityToResolveInfo.getEntityToResolve();
if (entityToResolve instanceof YangAugment) {
YangNode targetNode = null;
YangAugment augment = (YangAugment) entityToResolve;
targetNode = xPathLinker.processAugmentXpathLinking(augment.getTargetNode(),
(YangNode) root);
if (targetNode != null) {
if (targetNode instanceof YangAugmentableNode) {
detectCollisionForAugmentedNode(targetNode, augment);
((YangAugmentableNode) targetNode).addAugmentation(augment);
augment.setAugmentedNode(targetNode);
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
} else {
throw new LinkerException("Invalid target node type " + targetNode.getNodeType() + " for "
+ augment.getName());
}
} else {
throw new LinkerException("Failed to link " + augment.getName());
}
} else if (entityToResolve instanceof YangLeafRef) {
YangLeafRef leafRef = (YangLeafRef) entityToResolve;
Object target = xPathLinker.processLeafRefXpathLinking(leafRef.getAtomicPath(),
(YangNode) root);
if (target != null) {
YangLeaf leaf = null;
YangLeafList leafList = null;
leafRef.setReferredLeafOrLeafList(target);
if (target instanceof YangLeaf) {
leaf = (YangLeaf) target;
leafRef.setEffectiveDataType(leaf.getDataType());
} else {
leafList = (YangLeafList) target;
leafRef.setEffectiveDataType(leafList.getDataType());
}
leafRef.setResolvableStatus(RESOLVED);
//TODO: add logic for leaf-ref for path predicates.
} else {
throw new LinkerException("YANG file error: Unable to find base leaf/leaf-list for given leafref "
+ leafRef.getPath());
}
}
}
/**
* Returns the referenced prefix of entity under resolution.
......
......@@ -18,18 +18,20 @@ package org.onosproject.yangutils.parser.impl.listeners;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.AUGMENT_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
......@@ -38,22 +40,17 @@ import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRI
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.generateNameForAugmentNode;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getParentsPrefix;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.parserException;
import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.validateNodeInTargetPath;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction
.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
......@@ -106,7 +103,7 @@ public final class AugmentListener {
checkStackIsNotEmpty(listener, MISSING_HOLDER, AUGMENT_DATA, ctx.augment().getText(), ENTRY);
// Validate augment argument string
List<YangNodeIdentifier> targetNodes = getValidAbsoluteSchemaNodeId(ctx.augment().getText(),
List<YangAtomicPath> targetNodes = getValidAbsoluteSchemaNodeId(ctx.augment().getText(),
AUGMENT_DATA, ctx);
// Validate sub statement cardinality.
......@@ -126,7 +123,7 @@ public final class AugmentListener {
// TODO: handle in linker.
yangAugment.setTargetNode(targetNodes);
yangAugment.setName(generateNameForAugmentNode(curData, targetNodes, listener));
yangAugment.setName(removeQuotesAndHandleConcat(ctx.augment().getText()));
try {
curNode.addChild(yangAugment);
......@@ -135,6 +132,13 @@ public final class AugmentListener {
AUGMENT_DATA, ctx.augment().getText(), ENTRY, e.getMessage()));
}
listener.getParsedDataStack().push(yangAugment);
// Add resolution information to the list
YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangAugment>(yangAugment,
curNode, line,
charPositionInLine);
addToResolutionList(resolutionInfo, ctx);
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, AUGMENT_DATA,
ctx.augment().getText(), ENTRY));
......@@ -177,35 +181,19 @@ public final class AugmentListener {
}
/**
* Validates whether the current target node path is correct or not.
* Add to resolution list.
*
* @param targetNodes list of target nodes
* @param curNode current Node
* @param ctx augment context
* @param curNode current YANG node
* @param resolutionInfo resolution information.
* @param ctx context object of the grammar rule
*/
private static void validateTargetNodePath(List<YangNodeIdentifier> targetNodes, YangNode curNode,
private static void addToResolutionList(YangResolutionInfoImpl<YangAugment> resolutionInfo,
GeneratedYangParser.AugmentStatementContext ctx) {
YangNodeIdentifier moduleId = targetNodes.get(0);
if (moduleId.getPrefix() == null) {
if (!moduleId.getName().equals(curNode.getName())) {
throw parserException(ctx);
} else {
//validateNodeInTargetPath(curNode, targetNodes, ctx);
// TODO: handle in linker.
}
} else {
String parentPrefix = getParentsPrefix(curNode);
if (parentPrefix != null) {
if (!parentPrefix.equals(moduleId.getPrefix())) {
// TODO: handle in linker.
} else {
validateNodeInTargetPath(curNode, targetNodes, ctx);
}
} else {
// TODO: handle in linker.
}
try {
addResolutionInfo(resolutionInfo);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
AUGMENT_DATA, ctx.augment().getText(), EXIT, e.getMessage()));
}
}
}
......
......@@ -709,10 +709,10 @@ public final class ListenerUtil {
* @param ctx yang construct's context to get the line number and character position
* @return target nodes list of absolute schema node id
*/
public static List<YangNodeIdentifier> getValidAbsoluteSchemaNodeId(String argumentString,
public static List<YangAtomicPath> getValidAbsoluteSchemaNodeId(String argumentString,
YangConstructType yangConstructType, ParserRuleContext ctx) {
List<YangNodeIdentifier> targetNodes = new LinkedList<>();
List<YangAtomicPath> targetNodes = new ArrayList<>();
YangNodeIdentifier yangNodeIdentifier;
String tmpSchemaNodeId = removeQuotesAndHandleConcat(argumentString);
......@@ -728,7 +728,9 @@ public final class ListenerUtil {
String[] tmpData = tmpSchemaNodeId.replaceFirst(CARET + SLASH, EMPTY_STRING).split(SLASH);
for (String nodeIdentifiers : tmpData) {
yangNodeIdentifier = getValidNodeIdentifier(nodeIdentifiers, yangConstructType, ctx);
targetNodes.add(yangNodeIdentifier);
YangAtomicPath yangAbsPath = new YangAtomicPath();
yangAbsPath.setNodeIdentifier(yangNodeIdentifier);
targetNodes.add(yangAbsPath);
}
return targetNodes;
}
......
......@@ -17,11 +17,9 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
......@@ -41,6 +39,7 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
import static org.onosproject.yangutils.utils.UtilConstants.JAR;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -155,32 +154,6 @@ public final class YangPluginUtils {
}
/**
* Returns de-serializes YANG data-model nodes.
*
* @param serailizedfileInfoSet YANG file info set
* @return de-serializes YANG data-model nodes
* @throws IOException when fails do IO operations
*/
public static List<YangNode> deSerializeDataModel(List<String> serailizedfileInfoSet) throws IOException {
List<YangNode> nodes = new ArrayList<>();
for (String fileInfo : serailizedfileInfoSet) {
YangNode node = null;
try {
FileInputStream fileInputStream = new FileInputStream(fileInfo);
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
node = (YangNode) objectInputStream.readObject();
nodes.add(node);
objectInputStream.close();
fileInputStream.close();
} catch (IOException | ClassNotFoundException e) {
throw new IOException(fileInfo + " not found.");
}
}
return nodes;
}
/**
* Returns list of jar path.
*
* @param project maven project
......@@ -188,7 +161,7 @@ public final class YangPluginUtils {
* @param remoteRepos remote repository
* @return list of jar paths
*/
private static List<String> resolveDependecyJarPath(MavenProject project, ArtifactRepository localRepository,
private static List<String> resolveDependencyJarPath(MavenProject project, ArtifactRepository localRepository,
List<ArtifactRepository> remoteRepos) {
StringBuilder path = new StringBuilder();
......@@ -232,7 +205,7 @@ public final class YangPluginUtils {
List<ArtifactRepository> remoteRepos, String directory)
throws IOException {
List<String> dependeciesJarPaths = resolveDependecyJarPath(project, localRepository, remoteRepos);
List<String> dependeciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
List<YangNode> resolvedDataModelNodes = new ArrayList<>();
for (String dependecy : dependeciesJarPaths) {
resolvedDataModelNodes.addAll(deSerializeDataModel(parseJarFile(dependecy, directory)));
......
......@@ -87,8 +87,14 @@ public class YangUtilManager
/**
* Source directory for generated files.
*/
@Parameter(property = "genFilesDir", defaultValue = "src/main/java")
private String genFilesDir;
@Parameter(property = "classFileDir", defaultValue = "target/generated-sources")
private String classFileDir;
/**
* Source directory for manager's generated files.
*/
@Parameter(property = "managerFileDir", defaultValue = "src/main/java")
private String managerFileDir;
/**
* Base directory for project.
......@@ -153,11 +159,12 @@ public class YangUtilManager
/*
* For deleting the generated code in previous build.
*/
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, outputDirectory));
String searchDir = getDirectory(baseDir, yangFilesDir);
String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
String codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
String managerCodeGenDir = getDirectory(baseDir, managerFileDir) + SLASH;
// Creates conflict resolver and set values to it.
YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
......@@ -167,6 +174,7 @@ public class YangUtilManager
conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
YangPluginConfig yangPlugin = new YangPluginConfig();
yangPlugin.setCodeGenDir(codeGenDir);
yangPlugin.setManagerCodeGenDir(managerCodeGenDir);
yangPlugin.setConflictResolver(conflictResolver);
/*
......@@ -195,18 +203,18 @@ public class YangUtilManager
// Serialize data model.
serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
addToCompilationRoot(getDirectory(baseDir, genFilesDir), project, context);
addToCompilationRoot(codeGenDir, project, context);
addToCompilationRoot(managerCodeGenDir, project, context);
copyYangFilesToTarget(getYangFileInfoSet(), getDirectory(baseDir, outputDirectory), project);
} catch (IOException | ParserException e) {
getLog().info(e);
String fileName = "";
if (getCurYangFileInfo() != null) {
fileName = getCurYangFileInfo().getYangFileName();
}
try {
translatorErrorHandler(getRootNode());
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, classFileDir) + DEFAULT_PKG);
} catch (IOException ex) {
throw new MojoExecutionException(
"Error handler failed to delete files for data model node.");
......@@ -255,14 +263,12 @@ public class YangUtilManager
public void resolveDependenciesUsingLinker()
throws MojoExecutionException {
createYangNodeSet();
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
setCurYangFileInfo(yangFileInfo);
try {
yangLinker.resolveDependencies(getYangNodeSet());
} catch (LinkerException e) {
throw new MojoExecutionException(e.getMessage());
}
}
}
/**
......
......@@ -122,6 +122,11 @@ public final class GeneratedTempFileType {
public static final int EVENT_SUBJECT_SETTER_MASK = 524288;
/**
* Event subject setter implementation of class.
*/
public static final int AUGMENTE_CLASS_CONSTRUCTOR_MASK = 1048576;
/**
* Creates an instance of generated temp file type.
*/
private GeneratedTempFileType() {
......
......@@ -21,10 +21,6 @@ import java.util.SortedSet;
import java.util.TreeSet;
import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
......@@ -40,9 +36,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static java.util.Collections.sort;
/**
......@@ -220,33 +214,6 @@ public class JavaImportData {
}
/**
* Returns import for array list attribute.
*
* @return import for array list attribute
*/
public String getImportForArrayList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
}
/**
* Returns import string for AugmentationHolder class.
*
* @return import string for AugmentationHolder class
*/
public String getAugmentationHolderImport() {
return IMPORT + PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for AugmentedInfo class.
*
* @return import string for AugmentedInfo class
*/
public String getAugmentedInfoImport() {
return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for ListenerService class.
*
* @return import string for ListenerService class
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
/**
* Represents implementation of java bean code fragments temporary implementations.
......@@ -88,7 +88,7 @@ public class TempJavaBeanFragmentFiles
*/
private void addConstructor(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
appendToFile(getConstructorImplTempFileHandle(), getConstructor(attr,
getGeneratedJavaFiles(), pluginConfig));
}
......
......@@ -36,7 +36,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetG
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
......
......@@ -27,7 +27,6 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
......@@ -54,9 +53,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAnnotationsImports;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAnnotationsImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
......@@ -390,7 +389,7 @@ public class TempJavaServiceFragmentFiles
}
if (isNotification) {
addListnersImport(curNode, imports, true, LISTENER_SERVICE);
addListenersImport(curNode, imports, true, LISTENER_SERVICE);
}
/**
* Creates rpc interface file.
......@@ -399,8 +398,8 @@ public class TempJavaServiceFragmentFiles
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
if (isNotification) {
addListnersImport(curNode, imports, false, LISTENER_SERVICE);
addListnersImport(curNode, imports, true, LISTENER_REG);
addListenersImport(curNode, imports, false, LISTENER_SERVICE);
addListenersImport(curNode, imports, true, LISTENER_REG);
}
addAnnotationsImports(imports, true);
/**
......@@ -411,14 +410,14 @@ public class TempJavaServiceFragmentFiles
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
if (isNotification) {
addListnersImport(curNode, imports, false, LISTENER_REG);
addListenersImport(curNode, imports, false, LISTENER_REG);
}
addAnnotationsImports(imports, false);
if (isNotification) {
generateEventJavaFile(GENERATE_EVENT_CLASS, curNode);
generateEventJavaFile(curNode);
generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode);
generateEventSubjectJavaFile(GENERATE_EVENT_SUBJECT_CLASS, curNode);
generateEventSubjectJavaFile(curNode);
}
/**
......@@ -478,11 +477,10 @@ public class TempJavaServiceFragmentFiles
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventJavaFile(int fileType, YangNode curNode)
public void generateEventJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
......@@ -536,11 +534,10 @@ public class TempJavaServiceFragmentFiles
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventSubjectJavaFile(int fileType, YangNode curNode)
public void generateEventSubjectJavaFile(YangNode curNode)
throws IOException {
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
......@@ -778,7 +775,7 @@ public class TempJavaServiceFragmentFiles
/**
* Returns a temporary file handle for the event's file type.
*
* @param fileName file name
* @param name file name
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
......@@ -786,9 +783,10 @@ public class TempJavaServiceFragmentFiles
throws IOException {
JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
JavaFileInfo childInfo = ((JavaFileInfoContainer) curNode.getChild()).getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
parentInfo);
childInfo);
}
/**
......
......@@ -39,7 +39,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
......
......@@ -16,17 +16,22 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represents augment information extended to support java code generation.
......@@ -38,11 +43,21 @@ public class YangJavaAugment
private static final long serialVersionUID = 806201632L;
/**
* Prefix to be added to generated java file for augment node.
*/
private static final String AUGMENTED = "Augmented";
/**
* Contains the information of the java file being generated.
*/
private JavaFileInfo javaFileInfo;
/**
* TargetNodes java qualified info.
*/
private List<JavaQualifiedTypeInfo> extendedClassInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
*/
......@@ -54,6 +69,7 @@ public class YangJavaAugment
public YangJavaAugment() {
super();
setJavaFileInfo(new JavaFileInfo());
setExtendedClassInfo(new ArrayList<>());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
......@@ -130,4 +146,46 @@ public class YangJavaAugment
throw new TranslatorException("Failed to generate code for augmentable node " + getName());
}
}
/**
* Returns augment class name.
*
* @return augment class name
*/
public String getAugmentClassName() {
YangNodeIdentifier nodeId = getTargetNode().get(getTargetNode().size() - 1).getNodeIdentifier();
if (nodeId.getPrefix() != null) {
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
} else {
return AUGMENTED + getCapitalCase(nodeId.getName());
}
}
/**
* Returns extended class info.
*
* @return extended class info
*/
public List<JavaQualifiedTypeInfo> getExtendedClassInfo() {
return extendedClassInfo;
}
/**
* Sets extended class info.
*
* @param augmentedInfo extended class info
*/
private void setExtendedClassInfo(List<JavaQualifiedTypeInfo> augmentedInfo) {
extendedClassInfo = augmentedInfo;
}
/**
* Adds to extended class info list.
*
* @param augmentedInfo extended class info
*/
public void addToExtendedClassInfo(JavaQualifiedTypeInfo augmentedInfo) {
getExtendedClassInfo().add(augmentedInfo);
}
}
......
......@@ -35,7 +35,7 @@ import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaMode
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
......
......@@ -33,8 +33,10 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -60,7 +62,7 @@ public class YangJavaModule
/**
* List of notifications nodes.
*/
private List<YangNode> notificationNodes;
private transient List<YangNode> notificationNodes;
/**
* Creates a YANG node of module type.
......@@ -153,10 +155,15 @@ public class YangJavaModule
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for module node " + getName());
}
......
......@@ -35,8 +35,10 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
......@@ -62,7 +64,7 @@ public class YangJavaSubModule
/**
* List of notifications nodes.
*/
private List<YangNode> notificationNodes = new ArrayList<>();
private transient List<YangNode> notificationNodes = new ArrayList<>();
/**
* Creates YANG java sub module object.
......@@ -167,9 +169,13 @@ public class YangJavaSubModule
* The manager class needs to extend the "ListenerRegistry".
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
getJavaFileInfo().getPackageFilePath());
} catch (IOException e) {
throw new TranslatorException("Failed to generate code for submodule node " + getName());
}
......
......@@ -16,31 +16,51 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.IMMEDIATE;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static java.util.Collections.sort;
/**
* Represents utility class to generate the java snippet.
......@@ -121,17 +141,6 @@ public final class JavaCodeSnippetGen {
}
/**
* Returns attribute of augmented info for generated impl file.
*
* @return attribute of augmented info for generated impl file
*/
public static String getAugmentedInfoAttribute() {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
+ getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST
+ DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
* Returns based on the file type and the YANG name of the file, generate the class
* / interface definition close.
*
......@@ -155,4 +164,128 @@ public final class JavaCodeSnippetGen {
+ value + CLOSE_PARENTHESIS + COMMA + NEW_LINE;
}
/**
* Adds annotations imports.
*
* @param imports list if imports
* @param operation to add or to delete
*/
public static void addAnnotationsImports(List<String> imports, boolean operation) {
if (operation) {
imports.add(ACTIVATE_ANNOTATION_IMPORT);
imports.add(DEACTIVATE_ANNOTATION_IMPORT);
imports.add(COMPONENT_ANNOTATION_IMPORT);
imports.add(SERVICE_ANNOTATION_IMPORT);
imports.add(LOGGER_FACTORY_IMPORT);
imports.add(LOGGER_IMPORT);
} else {
imports.remove(ACTIVATE_ANNOTATION_IMPORT);
imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
imports.remove(COMPONENT_ANNOTATION_IMPORT);
imports.remove(SERVICE_ANNOTATION_IMPORT);
imports.remove(LOGGER_FACTORY_IMPORT);
imports.remove(LOGGER_IMPORT);
}
sortImports(imports);
}
/**
* Returns sorted import list.
*
* @param imports import list
* @return sorted import list
*/
public static List<String> sortImports(List<String> imports) {
sort(imports);
return imports;
}
/**
* Returns event enum start.
*
* @return event enum start
*/
public static String getEventEnumTypeStart() {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
/**
* Adds listener's imports.
*
* @param curNode currentYangNode.
* @param imports import list
* @param operation add or remove
* @param classInfo class info to be added to import list
*/
public static void addListenersImport(YangNode curNode, List<String> imports, boolean operation,
String classInfo) {
String thisImport = "";
if (classInfo.equals(LISTENER_SERVICE)) {
thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerServiceImport();
performOperationOnImports(imports, thisImport, operation);
} else {
thisImport = getTempJavaFragment(curNode).getJavaImportData().getListenerRegistryImport();
performOperationOnImports(imports, thisImport, operation);
}
}
/**
* Performs given operations on import list.
*
* @param imports list of imports
* @param curImport current import
* @param operation add or remove
* @return import list
*/
private static List<String> performOperationOnImports(List<String> imports, String curImport,
boolean operation) {
if (operation) {
imports.add(curImport);
} else {
imports.remove(curImport);
}
sortImports(imports);
return imports;
}
/**
* Returns temp java fragment.
*
* @param curNode current YANG node
* @return temp java fragments
*/
public static TempJavaFragmentFiles getTempJavaFragment(YangNode curNode) {
TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles();
if (container.getBeanTempFiles() != null) {
return container.getBeanTempFiles();
}
if (container.getServiceTempFiles() != null) {
return container.getServiceTempFiles();
}
return null;
}
/**
* Returns integer attribute for enum's class to get the values.
*
* @param className enum's class name
* @return enum's attribute
*/
public static String getEnumsValueAttribute(String className) {
return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
+ SEMI_COLAN + NEW_LINE;
}
/**
* Returns component string.
*
* @return component string
*/
public static String addComponentString() {
return NEW_LINE + COMPONENT_ANNOTATION + SPACE + OPEN_PARENTHESIS + IMMEDIATE + SPACE
+ EQUAL + SPACE + TRUE + CLOSE_PARENTHESIS + NEW_LINE + SERVICE_ANNOTATION;
}
}
......
......@@ -28,7 +28,7 @@ import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getTempJavaFragment;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
......@@ -62,7 +62,7 @@ public class JavaExtendsListHolder {
* @param extendedClass map of classes need to be extended
*/
private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) {
this.extendedClassStore = extendedClass;
extendedClassStore = extendedClass;
}
/**
......@@ -74,7 +74,7 @@ public class JavaExtendsListHolder {
public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
JavaImportData importData = getTempJavaFragment(node).getJavaImportData();
boolean qualified = importData.addImportInfo(info,
getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
......@@ -99,7 +99,7 @@ public class JavaExtendsListHolder {
* @param classInfoList the extends List to set
*/
private void setExtendsList(List<JavaQualifiedTypeInfo> classInfoList) {
this.extendsList = classInfoList;
extendsList = classInfoList;
}
/**
......
......@@ -54,11 +54,8 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirP
*/
public final class JavaIdentifierSyntax {
private static final int MAX_MONTHS = 12;
private static final int MAX_DAYS = 31;
private static final int INDEX_ZERO = 0;
private static final int INDEX_ONE = 1;
private static final int INDEX_TWO = 2;
private static final int VALUE_CHECK = 10;
private static final String ZERO = "0";
private static final String DATE_FORMAT = "yyyy-MM-dd";
......
/*
* 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.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.COMPONENT_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_FACTORY_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_ANNOTATION_IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
import static java.util.Collections.sort;
/**
* Represents utilities for temporary java code fragments.
*/
public final class TempJavaCodeFragmentFilesUtils {
/**
* Creates a private instance of temporary java code fragment utils.
*/
private TempJavaCodeFragmentFilesUtils() {
}
/**
* Adds import for AugmentationHolders class.
*
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
*/
public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) {
String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentationHolderImport();
performOperationOnImports(imports, thisImport, operation);
}
/**
* Adds import for AugmentedInfo class.
*
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
*/
public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentedInfoImport();
performOperationOnImports(imports, thisImport, operation);
}
/**
* Returns temp java fragment.
*
* @param curNode current YANG node
* @return temp java fragments
*/
public static TempJavaFragmentFiles getTempJavaFragement(YangNode curNode) {
TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles();
if (container.getBeanTempFiles() != null) {
return container.getBeanTempFiles();
}
if (container.getServiceTempFiles() != null) {
return container.getServiceTempFiles();
}
return null;
}
/**
* Adds import for array list.
*
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
*/
public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
String arrayListImport = getTempJavaFragement(curNode).getJavaImportData().getImportForArrayList();
String listImport = getTempJavaFragement(curNode).getJavaImportData().getImportForList();
performOperationOnImports(imports, arrayListImport, operation);
if (!imports.contains(listImport)) {
/**
* List can be there because of attribute also , so no need to remove it and operation will
* always be add(true).
*/
performOperationOnImports(imports, listImport, true);
}
}
/**
* Adds listener's imports.
*
* @param curNode currentYangNode.
* @param imports import list
* @param operation add or remove
* @param classInfo class info to be added to import list
*/
public static void addListnersImport(YangNode curNode, List<String> imports, boolean operation,
String classInfo) {
String thisImport = "";
if (classInfo.equals(LISTENER_SERVICE)) {
thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerServiceImport();
performOperationOnImports(imports, thisImport, operation);
} else {
thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerRegistryImport();
performOperationOnImports(imports, thisImport, operation);
}
}
/**
* Adds annotations imports.
*
* @param imports list if imports
* @param operation to add or to delete
*/
public static void addAnnotationsImports(List<String> imports, boolean operation) {
if (operation) {
imports.add(ACTIVATE_ANNOTATION_IMPORT);
imports.add(DEACTIVATE_ANNOTATION_IMPORT);
imports.add(COMPONENT_ANNOTATION_IMPORT);
imports.add(SERVICE_ANNOTATION_IMPORT);
imports.add(LOGGER_FACTORY_IMPORT);
imports.add(LOGGER_IMPORT);
} else {
imports.remove(ACTIVATE_ANNOTATION_IMPORT);
imports.remove(DEACTIVATE_ANNOTATION_IMPORT);
imports.remove(COMPONENT_ANNOTATION_IMPORT);
imports.remove(SERVICE_ANNOTATION_IMPORT);
imports.remove(LOGGER_FACTORY_IMPORT);
imports.remove(LOGGER_IMPORT);
}
sortImports(imports);
}
/**
* Performs given operations on import list.
*
* @param imports list of imports
* @param curImport current import
* @param operation add or remove
* @return import list
*/
private static List<String> performOperationOnImports(List<String> imports, String curImport,
boolean operation) {
if (operation) {
imports.add(curImport);
} else {
imports.remove(curImport);
}
sortImports(imports);
return imports;
}
/**
* Returns true if AugmentationHolder class needs to be extended.
*
* @param extendsList list of classes need to be extended
* @return true or false
*/
public static boolean isAugmentationHolderExtended(List<JavaQualifiedTypeInfo> extendsList) {
for (JavaQualifiedTypeInfo info : extendsList) {
return info.getClassInfo().equals(AUGMENTATION_HOLDER);
}
return false;
}
/**
* Returns true if AugmentedInfo class needs to be extended.
*
* @param extendsList list of classes need to be extended
* @return true or false
*/
public static boolean isAugmentedInfoExtended(List<JavaQualifiedTypeInfo> extendsList) {
for (JavaQualifiedTypeInfo info : extendsList) {
return info.getClassInfo().equals(AUGMENTED_INFO);
}
return false;
}
/**
* Closes the file handle for temporary file.
*
* @param file file to be closed
* @param toBeDeleted flag to indicate if file needs to be deleted
* @throws IOException when failed to close the file handle
*/
public static void closeFile(File file, boolean toBeDeleted)
throws IOException {
if (file != null) {
updateFileHandle(file, null, true);
if (toBeDeleted) {
file.delete();
}
}
}
/**
* Returns sorted import list.
*
* @param imports import list
* @return sorted import list
*/
public static List<String> sortImports(List<String> imports) {
sort(imports);
return imports;
}
/**
* Returns event enum start.
*
* @return event enum start
*/
public static String getEventEnumTypeStart() {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE + TYPE + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE;
}
}
......@@ -607,6 +607,11 @@ public final class UtilConstants {
public static final String CATCH = "catch";
/**
* Static attribute for super syntax.
*/
public static final String SUPER = "super";
/**
* Static attribute for eight space indentation.
*/
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
......
......@@ -123,4 +123,22 @@ public final class FileSystemUtil {
}
}
}
/**
* Closes the file handle for temporary file.
*
* @param file file to be closed
* @param toBeDeleted flag to indicate if file needs to be deleted
* @throws IOException when failed to close the file handle
*/
public static void closeFile(File file, boolean toBeDeleted)
throws IOException {
if (file != null) {
updateFileHandle(file, null, true);
if (toBeDeleted) {
file.delete();
}
}
}
}
......
......@@ -590,7 +590,7 @@ public final class JavaDocGen {
* @param attribute attribute string
* @return javaDocs for type constructor
*/
private static String generateForTypeConstructor(String attribute) {
public static String generateForTypeConstructor(String attribute) {
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
......
......@@ -28,11 +28,11 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.regex.Pattern;
import org.apache.commons.io.FileUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
......@@ -213,34 +213,16 @@ public final class YangIoUtils {
* Removes extra char from the string.
*
* @param valueString string to be trimmed
* @param removealStirng extra chars
* @param removalStirng extra chars
* @return new string
*/
public static String trimAtLast(String valueString, String removealStirng) {
public static String trimAtLast(String valueString, String removalStirng) {
StringBuilder stringBuilder = new StringBuilder(valueString);
int index = valueString.lastIndexOf(removealStirng);
int index = valueString.lastIndexOf(removalStirng);
if (index != -1) {
stringBuilder.deleteCharAt(index);
return stringBuilder.toString();
}
/**
* Returns new parted string.
*
* @param partString string to be parted
* @return parted string
*/
public static String partString(String partString) {
String[] strArray = partString.split(COMMA);
String newString = EMPTY_STRING;
for (int i = 0; i < strArray.length; i++) {
if (i % 4 != 0 || i == 0) {
newString = newString + strArray[i] + COMMA;
} else {
newString = newString + NEW_LINE + TWELVE_SPACE_INDENTATION
+ strArray[i] + COMMA;
}
}
return trimAtLast(newString, COMMA);
return stringBuilder.toString();
}
/**
......
......@@ -27,6 +27,11 @@ public final class YangPluginConfig {
private String codeGenDir;
/**
* Contains the code generation directory.
*/
private String managerCodeGenDir;
/**
* Contains information of naming conflicts that can be resolved.
*/
private YangToJavaNamingConflictUtil conflictResolver;
......@@ -72,4 +77,22 @@ public final class YangPluginConfig {
public YangToJavaNamingConflictUtil getConflictResolver() {
return conflictResolver;
}
/**
* Returns manager's code generation directory.
*
* @return manager's code generation directory
*/
public String getManagerCodeGenDir() {
return managerCodeGenDir;
}
/**
* Sets manager's code generation directory.
*
* @param moduleCodeGenDir manager's code generation directory
*/
public void setManagerCodeGenDir(String moduleCodeGenDir) {
this.managerCodeGenDir = moduleCodeGenDir;
}
}
......
......@@ -16,16 +16,16 @@
package org.onosproject.yangutils.ietfyang;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.linker.impl.YangLinkerManager;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import org.onosproject.yangutils.plugin.manager.YangUtilManager;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import java.io.IOException;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
......@@ -54,6 +54,7 @@ public class IetfYangFileTest {
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ietfyang/l3vpnservice/");
yangPluginConfig.setManagerCodeGenDir("target/ietfyang/l3vpnservice/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
......
......@@ -20,12 +20,12 @@ import java.io.IOException;
import java.util.ListIterator;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
......@@ -48,16 +48,16 @@ public class AugmentListenerTest {
YangNode node = manager.getDataModel("src/test/resources/ValidAugmentStatement.yang");
assertThat((node instanceof YangModule), is(true));
assertThat(node instanceof YangModule, is(true));
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
YangModule yangNode = (YangModule) node;
assertThat(yangNode.getName(), is("Test"));
YangAugment yangAugment = (YangAugment) yangNode.getChild();
ListIterator<YangNodeIdentifier> nodeIdentifierIterator = yangAugment.getTargetNode().listIterator();
YangNodeIdentifier yangNodeIdentifier = nodeIdentifierIterator.next();
assertThat(yangNodeIdentifier.getPrefix(), is("if"));
assertThat(yangNodeIdentifier.getName(), is("interfaces"));
ListIterator<YangAtomicPath> absPathIterator = yangAugment.getTargetNode().listIterator();
YangAtomicPath absPathIdentifier = absPathIterator.next();
assertThat(absPathIdentifier.getNodeIdentifier().getPrefix(), is("if"));
assertThat(absPathIdentifier.getNodeIdentifier().getName(), is("interfaces"));
ListIterator<YangLeaf> leafIterator = yangAugment.getListOfLeaf().listIterator();
YangLeaf leafInfo = leafIterator.next();
......
/*
* 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.plugin.manager;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test case for augment translator.
*/
public class AugmentTranslatorTest {
private final YangUtilManager utilManager = new YangUtilManager();
/**
* Checks augment translation should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processAugmentTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/augmentTranslator";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/augmentTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/augmentTranslator/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory("target/augmentTranslator/");
}
}
......@@ -44,6 +44,7 @@ public final class ChoiceCaseTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/ChoiceCaseTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/ChoiceCaseTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -45,6 +45,7 @@ public final class EnumTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/EnumTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/EnumTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
import java.util.ListIterator;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Rule;
import org.junit.Test;
......@@ -171,7 +172,7 @@ public class InterFileLinkingTest {
}
// Check whether the data model tree returned is of type module.
assertThat((selfNode instanceof YangModule), is(true));
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
......@@ -184,7 +185,7 @@ public class InterFileLinkingTest {
YangLeaf leafInfo;
// Check whether grouping is the sibling of module's child.
assertThat((refNode.getChild() instanceof YangGrouping), is(true));
assertThat(refNode.getChild() instanceof YangGrouping, is(true));
YangGrouping grouping = (YangGrouping) refNode.getChild();
leafIterator = grouping.getListOfLeaf().listIterator();
......@@ -196,7 +197,7 @@ public class InterFileLinkingTest {
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// Check whether uses is module's child.
assertThat((yangNode.getChild() instanceof YangUses), is(true));
assertThat(yangNode.getChild() instanceof YangUses, is(true));
YangUses uses = (YangUses) yangNode.getChild();
// Check whether uses get resolved.
......@@ -317,7 +318,7 @@ public class InterFileLinkingTest {
}
// Check whether the data model tree returned is of type module.
assertThat((selfNode instanceof YangModule), is(true));
assertThat(selfNode instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(YangNodeType.MODULE_NODE));
......@@ -330,7 +331,7 @@ public class InterFileLinkingTest {
YangLeaf leafInfo;
// Check whether grouping is the sibling of module's child.
assertThat((refNode.getChild() instanceof YangGrouping), is(true));
assertThat(refNode.getChild() instanceof YangGrouping, is(true));
YangGrouping grouping = (YangGrouping) refNode.getChild();
leafIterator = grouping.getListOfLeaf().listIterator();
......@@ -342,7 +343,7 @@ public class InterFileLinkingTest {
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.STRING));
// Check whether uses is module's child.
assertThat((yangNode.getChild() instanceof YangUses), is(true));
assertThat(yangNode.getChild() instanceof YangUses, is(true));
YangUses uses = (YangUses) yangNode.getChild();
// Check whether uses get resolved.
......@@ -637,13 +638,13 @@ public class InterFileLinkingTest {
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
yangPluginConfig.setManagerCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/interfilewithusesreferringtype/");
deleteDirectory("target/interfilewithusesreferringtype/");
}
......@@ -659,17 +660,16 @@ public class InterFileLinkingTest {
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
yangPluginConfig.setManagerCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/file1UsesFile2TypeDefFile3Type/");
deleteDirectory("target/file1UsesFile2TypeDefFile3Type/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
......@@ -682,17 +682,16 @@ public class InterFileLinkingTest {
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/interfileietf/");
yangPluginConfig.setManagerCodeGenDir("target/interfileietf/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/interfileietf/");
deleteDirectory("target/interfileietf/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
......@@ -705,17 +704,16 @@ public class InterFileLinkingTest {
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
yangPluginConfig.setManagerCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/usesInContainer/");
deleteDirectory("target/usesInContainer/");
}
/**
* Checks hierarchical intra with inter file type linking.
*/
......@@ -728,13 +726,13 @@ public class InterFileLinkingTest {
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
String userDir = System.getProperty("user.dir");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
yangPluginConfig.setManagerCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
deleteDirectory(userDir + "/target/groupingNodeSameAsModule/");
deleteDirectory("target/groupingNodeSameAsModule/");
}
......@@ -846,7 +844,7 @@ public class InterFileLinkingTest {
thrown.expect(LinkerException.class);
thrown.expectMessage(
"YANG file error: Unable to find base leaf/leaf-list for given leafref");
"YANG file error: Unable to find base leaf/leaf-list for given leafref networks");
String searchDir = "src/test/resources/interfileleafrefwithinvaliddestinationnode";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
......
......@@ -44,7 +44,7 @@ import static org.hamcrest.core.Is.is;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.deSerializeDataModel;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.deSerializeDataModel;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.parseJarFile;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.serializeDataModel;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
......@@ -189,6 +189,7 @@ public class InterJarLinkerTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(TARGET);
yangPluginConfig.setManagerCodeGenDir(TARGET);
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
......@@ -205,7 +206,7 @@ public class InterJarLinkerTest {
File folder = new File(System.getProperty("user.dir") + SLASH + FLOW_CLASSIFIER_FOLDER);
File file = new File(System.getProperty("user.dir") + SLASH + FLOW_CLASSIFIER_MANAGER);
assertThat(true, is(folder.exists()));
assertThat(true, is(file.exists()));
assertThat(false, is(file.exists()));
}
/**
......
......@@ -16,11 +16,17 @@
package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
......@@ -34,16 +40,10 @@ import org.onosproject.yangutils.datamodel.YangPathOperator;
import org.onosproject.yangutils.datamodel.YangPathPredicate;
import org.onosproject.yangutils.datamodel.YangRelativePath;
import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
......
/*
* 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.plugin.manager;
import java.io.File;
import java.io.IOException;
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test case to test code generation for root nodes.
*/
public class ManagerCodeGeneratorTest {
private final YangUtilManager utilManager = new YangUtilManager();
/**
* Checks manager translation should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/manager";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager = new File(file1);
assertThat(false, is(manager.exists()));
File manager2 = new File(file2);
assertThat(false, is(manager2.exists()));
File manager3 = new File(file3);
assertThat(true, is(manager3.exists()));
deleteDirectory("target/manager/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager1/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
String file3 = "target/manager1/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(true, is(manager3.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
}
......@@ -38,13 +38,14 @@ public final class NotificationTranslatorTest {
* Checks union translation should not result in any exception.
*/
@Test
public void processUnionTranslator()
public void processNotificationTranslator()
throws IOException, ParserException {
YangNode node = manager.getDataModel("src/test/resources/NotificationTest.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/NotificationTest/");
yangPluginConfig.setManagerCodeGenDir("target/NotificationTest1/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -45,6 +45,7 @@ public final class RpcTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/RpcTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/RpcTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
......@@ -45,6 +45,7 @@ public final class UnionTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
yangPluginConfig.setManagerCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
......
/*
* 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.plugin.manager;
import java.io.File;
......@@ -11,7 +27,7 @@ import org.sonatype.plexus.build.incremental.DefaultBuildContext;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
/**
* Created by root1 on 16/6/16.
* Unit test case for YANG plugin utils.
*/
public class YangPluginUtilsTest {
......
/*
* 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.translator.tojava.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
/**
* Unit tests for class definition generator for generated files.
*/
public final class ClassDefinitionGeneratorTest {
private static final String CLASS_NAME = "TestClass";
private static final String INTERFACE_CLASS_DEF = "public interface TestClass {\n";
private static final String BULDER_INTERFACE_CLASS_DEF = "interface TestClassBuilder {\n\n";
private static final String BUILDER_CLASS_DEF = "public class TestClassBuilder implements "
+ "TestClass.TestClassBuilder {\n";
private static final String IMPL_CLASS_DEF = "public final class TestClassImpl implements TestClass {\n";
private static final String TYPE_DEF_CLASS_DEF = "public final class TestClass {\n";
/**
* Unit test for private constructor.
*
* @throws SecurityException if any security violation is observed
* @throws NoSuchMethodException if when the method is not found
* @throws IllegalArgumentException if there is illegal argument found
* @throws InstantiationException if instantiation is provoked for the private constructor
* @throws IllegalAccessException if instance is provoked or a method is provoked
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
assertThat(null, not(constructor.newInstance()));
}
}
/**
* Unit test for builder class definition.
*/
@Test
public void generateBuilderClassDefinitionTest() {
String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME);
assertThat(true, is(builderClassDefinition.equals(BUILDER_CLASS_DEF)));
}
/**
* Unit test for builder interface definition.
*/
@Test
public void generateBuilderInterfaceDefinitionTest() {
String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME);
assertThat(true, is(builderInterfaceDefinition.equals(BULDER_INTERFACE_CLASS_DEF)));
}
/**
* Unit test for impl class definition.
*/
@Test
public void generateImplDefinitionTest() {
String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME);
assertThat(true, is(implDefinition.equals(IMPL_CLASS_DEF)));
}
/**
* Unit test for interface definition.
*/
@Test
public void generateinterfaceDefinitionTest() {
// TODO: need to add this test case.
}
/**
* Unit test for typedef generated type.
*/
@Test
public void generateTypeDefTest() {
String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME);
assertThat(true, is(typeDef.equals(TYPE_DEF_CLASS_DEF)));
}
}
......@@ -30,7 +30,6 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
......@@ -58,7 +57,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -83,6 +81,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Unit tests for generated methods from the file type.
......@@ -107,7 +106,7 @@ public final class MethodsGeneratorTest {
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {MethodsGenerator.class };
Class<?>[] classesToConstruct = {MethodsGenerator.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -135,7 +134,7 @@ public final class MethodsGeneratorTest {
String method = getBuild(CLASS_NAME);
assertThat(true, is(method.equals(FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_NAME + SPACE + BUILD
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + NEW + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
+ RETURN + SPACE + NEW + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS
+ SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET)));
}
......@@ -167,7 +166,7 @@ public final class MethodsGeneratorTest {
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
String method = getConstructor(testAttr, GENERATE_SERVICE_AND_MANAGER, pluginConfig);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
......@@ -179,7 +178,7 @@ public final class MethodsGeneratorTest {
public void getConstructorStartTest() {
YangPluginConfig pluginConfig = new YangPluginConfig();
String method = getConstructorStart(CLASS_NAME, pluginConfig);
assertThat(true, is(method.contains(PUBLIC + SPACE + CLASS_NAME + IMPL + OPEN_PARENTHESIS + CLASS_NAME
assertThat(true, is(method.contains(PUBLIC + SPACE + "Default" + CLASS_NAME + OPEN_PARENTHESIS + CLASS_NAME
+ BUILDER + SPACE + BUILDER.toLowerCase() + OBJECT + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE)));
}
......
module test {
namespace "test:test";
prefix test ;
import test1{
prefix test1;
}
import test2{
prefix test2;
}
include acme-types;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
container cont2 {
leaf leaf {
type int32;
}
}
}
augment /cont3 {
leaf leaf1 {
type int32;
}
}
augment /cont1/cont2 {
leaf leaf2 {
type int32;
}
}
augment /test1:cont1/test1:cont2 {
leaf a {
type int32;
}
}
augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s {
leaf a {
type int32;
}
}
augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s/test2:aa {
leaf a {
type int32;
}
container aa {
}
}
}
module test1 {
namespace "test1:test1";
prefix test1 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
container cont2 {
}
}
augment /cont1/cont2 {
leaf leaf4 {
type int32;
}
container cont1s {
container cont1s {
}
}
}
}
module test2 {
namespace "test2:test2";
prefix test2 ;
import test1{
prefix test1;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test1:cont1/test1:cont2/test1:cont1s/test1:cont1s {
leaf leaf5 {
type int32;
}
container aa {
}
}
}
submodule acme-types {
belongs-to "test" {
prefix "test";
}
import test1{
prefix test1;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont3 {
}
}
......@@ -1723,8 +1723,9 @@
uses tet:te-link-state-derived;
}
/*
augment "/te-link-event/te-link-attributes/underlay" {
description "Add state attributes to te-link underlay.";
uses te-link-state-underlay-attributes;
}
} */
}
......
module test5 {
namespace "test5:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
typedef abc {
type int32;
}
}
submodule test6 {
belongs-to "test5" {
prefix "test";
}
revision "2016-07-04" {
description "Initial revision.";
}
grouping abc {
leaf leaf1 {
type int32;
}
}
}
module test7 {
namespace "test5:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
leaf abc {
type int32;
}
}
module test {
namespace "xpath:inter:single";
prefix test ;
import test1{
prefix test1;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test1:cont1/test1:cont2 {
leaf a {
type int32;
}
}
}
module test1 {
namespace "xpath:inter:single";
prefix test1 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test {
namespace "xpath:inter:single";
prefix test ;
import test1{
prefix test1;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test1:cont1/test1:cont2/test1:cont2 {
leaf a {
type int32;
}
}
}
module test1 {
namespace "xpath:inter:single";
prefix test1 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
}
augment /cont1 {
container cont2 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
}
module test {
namespace "xpath:inter:single";
prefix test ;
import test1{
prefix test1;
}
import test2{
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test2:cont1/test2:cont2/test1:cont2 {
leaf a {
type int32;
}
}
}
module test1 {
namespace "xpath:inter:single";
prefix test1 ;
import test2{
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
}
augment /cont1 {
container cont2 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
augment /test2:cont1/test2:cont2 {
leaf a {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test2 {
namespace "xpath:inter:multi";
prefix test2 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test {
namespace "xpath:inter:single";
prefix test ;
import test1{
prefix test1;
}
import test2{
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test2:cont1/test2:cont2/test2:cont3/test1:cont2 {
leaf a {
type int32;
}
}
}
module test1 {
namespace "xpath:inter:single";
prefix test1 ;
import test2{
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
}
augment /cont1 {
container cont2 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
augment /test2:cont1/test2:cont2/test2:cont3 {
leaf a {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test2 {
namespace "xpath:inter:multi";
prefix test2 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
augment /cont1/cont2 {
container cont3 {
leaf a {
type string;
}
}
}
}
module test {
namespace "xpath:intra:single";
prefix test ;
import test2 {
prefix test2;
}
include test1;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test2:cont1/test2:cont2/cont2 {
leaf a {
type int32;
}
}
augment /cont2/cont3/cont4 {
leaf a {
type int32;
}
}
}
submodule test1 {
belongs-to test {
prefix test;
}
import test2 {
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont2 {
leaf leaf1 {
type int32;
}
container cont3 {
leaf leaf1 {
type int32;
}
}
}
augment /cont2/cont3 {
container cont4 {
leaf leaf1 {
type int32;
}
}
}
augment /test2:cont1/test2:cont2 {
leaf a {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test2 {
namespace "xpath:inter:multi";
prefix test2 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test {
namespace "xpath:intra:single";
prefix test ;
import test2 {
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont2 {
leaf a {
type int32;
}
uses test2:group1;
}
augment /cont2/group1/cont1/cont2 {
leaf a {
type int32;
}
}
}
module test2 {
namespace "xpath:inter:multi";
prefix test2 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
grouping group1 {
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
}
module test {
namespace "xpath:inter:single";
prefix test ;
import test1{
prefix test1;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test1:cont1 {
leaf a {
type int32;
}
}
}
module test1 {
namespace "xpath:inter:single";
prefix test1 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
}
}
module test {
namespace "xpath:inter:single";
prefix test ;
import test1{
prefix test1;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test1:cont1/test1:cont2 {
leaf a {
type int32;
}
}
}
module test1 {
namespace "xpath:inter:single";
prefix test1 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
}
augment /cont1 {
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test {
namespace "xpath:intra:single";
prefix test ;
import test2 {
prefix test2;
}
include test1;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test2:cont1/test2:cont2/cont2 {
leaf a {
type int32;
}
}
}
submodule test1 {
belongs-to test {
prefix test;
}
import test2 {
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test2:cont1/test2:cont2 {
leaf a {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test2 {
namespace "xpath:inter:multi";
prefix test2 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test {
namespace "xpath:intra:single";
prefix test ;
import test2 {
prefix test2;
}
include test1;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
augment /test2:cont1/test2:cont2/cont2 {
leaf a {
type int32;
}
uses group1;
}
augment /test2:cont1/test2:cont2/cont2/group1/cont1/cont2 {
leaf a {
type int32;
}
}
}
submodule test1 {
belongs-to test {
prefix test;
}
import test2 {
prefix test2;
}
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
grouping group1 {
container cont1 {
container cont2 {
leaf a {
type string;
}
}
}
}
augment /test2:cont1/test2:cont2 {
leaf a {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}
module test2 {
namespace "xpath:inter:multi";
prefix test2 ;
organization "";
contact "";
description
"Defines basic service types for L3VPN service.";
revision "2015-12-16" {
reference "";
}
container cont1 {
leaf leaf1 {
type int32;
}
container cont2 {
leaf leaf1 {
type int32;
}
}
}
}