Bharat saraswal
Committed by Patrick Liu

[ONOS-4947][ONOS-4954][ONOS-4952]Defect Fixed: Invalid name in case of qualified…

… info for child nodes

Change-Id: I0b94455333afd9322c1e583a5c3ec311dbe99991
......@@ -302,8 +302,11 @@ public class YangType<T>
break;
}
case STRING: {
if (!(((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnLengthRestriction(value) &&
((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnPatternRestriction(value))) {
if (getDataTypeExtendedInfo() == null) {
break;
} else if (!(((YangStringRestriction) getDataTypeExtendedInfo()).isValidStringOnLengthRestriction(value)
&& ((YangStringRestriction) getDataTypeExtendedInfo())
.isValidStringOnPatternRestriction(value))) {
throw new DataTypeException("YANG file error : Input value \"" + value + "\" is not a valid " +
"string");
}
......@@ -319,7 +322,7 @@ public class YangType<T>
Iterator<YangEnum> iterator = ((YangEnumeration) getDataTypeExtendedInfo()).getEnumSet().iterator();
boolean isValidated = false;
while (iterator.hasNext()) {
YangEnum enumTemp = (YangEnum) iterator.next();
YangEnum enumTemp = iterator.next();
if (enumTemp.getNamedValue().equals(value)) {
isValidated = true;
break;
......
......@@ -19,12 +19,14 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.TraversalType;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
......@@ -305,4 +307,43 @@ public final class JavaCodeGeneratorUtil {
private static void setRootNode(YangNode rootNode) {
JavaCodeGeneratorUtil.rootNode = rootNode;
}
/**
* Searches child node in data model tree.
*
* @param parentNode parent node
* @param nodeType node type
* @param nodeName node name
* @return child node
*/
public static YangNode searchYangNode(YangNode parentNode, YangNodeType nodeType, String nodeName) {
YangNode child = parentNode.getChild();
TraversalType curTraversal = ROOT;
if (child == null) {
throw new IllegalArgumentException("given parent node does not contain any child nodes");
}
while (child != null) {
if (curTraversal != PARENT) {
if (child instanceof YangInput || child instanceof YangOutput) {
if (child.getNodeType().equals(nodeType)) {
return child;
}
} else if (child.getName().equals(nodeName) && child.getNodeType().equals(nodeType)) {
return child;
}
}
if (curTraversal != PARENT && child.getChild() != null) {
curTraversal = CHILD;
child = child.getChild();
} else if (child.getNextSibling() != null) {
curTraversal = SIBILING;
child = child.getNextSibling();
} else {
curTraversal = PARENT;
child = child.getParent();
}
}
return null;
}
}
......
......@@ -100,7 +100,7 @@ public class TempJavaEventFragmentFiles
/**
* File name for generated class file for special type like union, typedef suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "EventListener";
private static final String JAVA_FILE_EXTENSION = ".java";
......
......@@ -33,8 +33,6 @@ import org.onosproject.yangutils.datamodel.javadatamodel.YangPluginConfig;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
......@@ -494,7 +492,7 @@ public class TempJavaFragmentFiles {
JavaFileInfo fileInfo = ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
boolean isQualified;
if ((targetNode instanceof YangJavaModuleTranslator || targetNode instanceof YangJavaSubModuleTranslator)
if ((tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles)
&& (qualifiedTypeInfo.getClassInfo().contentEquals(SERVICE)
|| qualifiedTypeInfo.getClassInfo().contentEquals(COMPONENT)
|| qualifiedTypeInfo.getClassInfo().contentEquals(getCapitalCase(ACTIVATE))
......@@ -507,7 +505,7 @@ public class TempJavaFragmentFiles {
isQualified = true;
} else {
String className;
if (targetNode instanceof YangJavaModuleTranslator || targetNode instanceof YangJavaSubModuleTranslator) {
if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
className = getCapitalCase(fileInfo.getJavaName()) + "Service";
} else {
className = getCapitalCase(fileInfo.getJavaName());
......
......@@ -386,7 +386,7 @@ public final class ClassDefinitionGenerator {
throw new RuntimeException("Event listener interface name is error");
}
intfDef = intfDef.substring(0, intfDef.length() - 8);
intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
intfDef = intfDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return intfDef;
}
......
......@@ -1191,7 +1191,7 @@ public final class UtilConstants {
/**
* For event listener file generation.
*/
public static final String EVENT_LISTENER_STRING = "Listener";
public static final String EVENT_LISTENER_STRING = "EventListener";
/**
* For event subject file generation.
......
......@@ -41,7 +41,7 @@ public class TypeDefTranslatorTest {
@Test
public void processTypeDefTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/typedefTranslator";
String searchDir = "src/test/resources/typedefTranslator/without";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
......@@ -55,4 +55,27 @@ public class TypeDefTranslatorTest {
deleteDirectory("target/typedefTranslator/");
}
/**
* Checks typedef translation should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processTypeDefWithRestrictionsTranslator() throws IOException, ParserException, MojoExecutionException {
/*FIXME: After typedef with leafref is fixed.
String searchDir = "src/test/resources/typedefTranslator/with";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/typedefTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/typedefTranslator/");
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/typedefTranslator/");
*/
}
}
......
module typedef {
yang-version "1";
namespace "http://rob.sh/yang/test/list";
prefix "foo";
import remote { prefix defn; }
organization "BugReports Inc";
contact "A bug reporter";
description
"A test module";
revision 2014-01-01 {
description "april-fools";
reference "fooled-you";
}
typedef derived-string-type {
type string;
}
typedef restricted-integer-type {
type uint16 {
range 0..64;
}
}
typedef bgp-session-direction {
type enumeration {
enum INBOUND;
enum OUTBOUND;
}
}
typedef new-string-type {
type string;
default "defaultValue";
}
typedef restricted-inherit {
type string {
pattern "^a.*";
}
}
typedef restricted-int-inherit {
type int8 {
range 0..100;
}
}
typedef parent-union {
type union {
type string {
pattern "a.*";
}
type string {
pattern "b.*";
}
}
}
typedef child-union {
type union {
type parent-union;
type string {
pattern "z.*";
}
}
}
typedef union-included {
type union {
type string {
pattern "a.*";
}
type string {
pattern "b.*";
}
}
}
identity identity_base;
identity IDONE {
base "identity_base";
}
identity IDTWO {
base "identity_base";
}
typedef identity_one {
type identityref {
base identity_base;
}
}
typedef referenced-leaf {
type leafref {
path "/container/target";
require-instance false;
}
}
grouping scoped-typedef {
typedef scoped-type {
type string {
pattern "a.*";
}
}
leaf scoped-leaf {
type scoped-type;
}
}
container container {
description
"A container";
leaf-list target {
type string;
description
"A target leaf for leafref checks";
}
leaf string {
type derived-string-type;
}
leaf integer {
type restricted-integer-type;
}
leaf stringdefault {
type derived-string-type;
default "aDefaultValue";
}
leaf integerdefault {
type restricted-integer-type;
default 10;
}
leaf new-string {
type new-string-type;
}
leaf remote-new-type {
type defn:remote-definition;
}
leaf session-dir {
type bgp-session-direction;
}
leaf remote-local-type {
type defn:remote-local-definition;
}
leaf inheritance {
type restricted-inherit {
pattern ".*k";
}
}
leaf int-inheritance {
type restricted-int-inherit {
range 2..5;
}
}
leaf-list stacked-union {
type child-union;
}
leaf include-of-include-definition {
type defn:hybrid-definition;
}
leaf identity-one-typedef {
type identity_one;
}
leaf union-with-union {
type union {
type union-included;
type string {
pattern "q.*";
}
}
}
leaf reference {
type referenced-leaf;
}
uses scoped-typedef;
}
}
module remote {
yang-version "1";
namespace "http://rob.sh/yang/test/typedef/remote";
prefix "remote";
import second-remote { prefix sr; }
organization "BugReports Inc";
contact "A bug reporter";
description
"A test module";
revision 2014-01-01 {
description "april-fools";
reference "fooled-you";
}
typedef remote-definition {
type string;
}
typedef remote-local-definition {
type local-definition;
}
typedef local-definition {
type string;
}
typedef hybrid-definition {
type sr:second-remote-definition;
}
}
module second-remote {
yang-version "1";
namespace "http://rob.sh/yang/test/typedef/second-remote";
prefix "second-remote";
organization "BugReports Inc";
contact "A bug reporter";
description
"A test module";
revision 2014-01-01 {
description "april-fools";
reference "fooled-you";
}
typedef second-remote-definition {
type string {
pattern "z.*";
}
}
}