mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-16 01:41:26 +02:00
[ONOS-3906],[ONOS-3910] Implementation of YANG module and leaf/leaf-list translator.
Change-Id: If1a8a991ffafa14b51211f97c435176ee1bf856f
This commit is contained in:
parent
1a66d61e4c
commit
870c56f408
@ -44,23 +44,17 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-artifact</artifactId>
|
||||
<version>2.0.8</version>
|
||||
<version>3.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-project</artifactId>
|
||||
<version>2.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>1.7.0</version>
|
||||
<scope>test</scope>
|
||||
<version>2.2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-testing</groupId>
|
||||
<artifactId>maven-plugin-testing-harness</artifactId>
|
||||
<version>2.1</version>
|
||||
<version>3.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -74,12 +68,13 @@
|
||||
<version>3.2.5</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>1.9.5</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@ -95,13 +90,15 @@
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-configuration</groupId>
|
||||
<artifactId>commons-configuration</artifactId>
|
||||
<version>1.10</version>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.onosproject</groupId>
|
||||
<artifactId>onlab-junit</artifactId>
|
||||
@ -113,21 +110,6 @@
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
<version>4.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.19.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.sonatype.aether</groupId>
|
||||
<artifactId>aether-api</artifactId>
|
||||
<version>1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.sonatype.aether</groupId>
|
||||
<artifactId>aether-util</artifactId>
|
||||
<version>1.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
@ -237,4 +219,5 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
@ -76,8 +76,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
/**
|
||||
* Data model node to maintain information defined in YANG augment.
|
||||
*/
|
||||
public class YangAugment extends YangNode
|
||||
implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
public class YangAugment extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
|
||||
/**
|
||||
* Augment target node.
|
||||
@ -92,14 +91,12 @@ public class YangAugment extends YangNode
|
||||
/**
|
||||
* List of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf-lists.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* reference.
|
||||
@ -141,6 +138,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -150,6 +148,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param description set the description.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -159,8 +158,8 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -169,8 +168,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -179,10 +177,10 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -193,8 +191,8 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -203,8 +201,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -213,10 +210,10 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -227,6 +224,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -236,6 +234,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -245,6 +244,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @return the status.
|
||||
*/
|
||||
@Override
|
||||
public YangStatusType getStatus() {
|
||||
return status;
|
||||
}
|
||||
@ -254,6 +254,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @param status the status to set.
|
||||
*/
|
||||
@Override
|
||||
public void setStatus(YangStatusType status) {
|
||||
this.status = status;
|
||||
}
|
||||
@ -263,6 +264,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @return returns AUGMENT_DATA.
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.AUGMENT_DATA;
|
||||
}
|
||||
@ -272,6 +274,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -281,6 +284,7 @@ public class YangAugment extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -324,6 +328,7 @@ public class YangAugment extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -332,6 +337,7 @@ public class YangAugment extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeExit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
@ -88,8 +88,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
/**
|
||||
* Data model node to maintain information defined in YANG case.
|
||||
*/
|
||||
public class YangCase extends YangNode
|
||||
implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
public class YangCase extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
|
||||
/**
|
||||
* Case name.
|
||||
@ -106,14 +105,12 @@ public class YangCase extends YangNode
|
||||
/**
|
||||
* List of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf lists.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* Reference of the module.
|
||||
@ -153,6 +150,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -162,6 +160,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param description set the description.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -171,8 +170,8 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -181,8 +180,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -191,10 +189,10 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -205,8 +203,8 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -215,8 +213,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -225,10 +222,10 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -239,6 +236,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -248,6 +246,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -257,6 +256,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @return the status.
|
||||
*/
|
||||
@Override
|
||||
public YangStatusType getStatus() {
|
||||
return status;
|
||||
}
|
||||
@ -266,6 +266,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @param status the status to set.
|
||||
*/
|
||||
@Override
|
||||
public void setStatus(YangStatusType status) {
|
||||
this.status = status;
|
||||
}
|
||||
@ -275,6 +276,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @return returns CASE_DATA
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.CASE_DATA;
|
||||
}
|
||||
@ -284,6 +286,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -293,6 +296,7 @@ public class YangCase extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -318,6 +322,7 @@ public class YangCase extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -326,6 +331,7 @@ public class YangCase extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeExit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
@ -16,13 +16,17 @@
|
||||
|
||||
package org.onosproject.yangutils.datamodel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
|
||||
import org.onosproject.yangutils.parser.Parsable;
|
||||
import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
import org.onosproject.yangutils.utils.io.CachedFileHandle;
|
||||
import org.onosproject.yangutils.translator.CachedFileHandle;
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
|
||||
import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
|
||||
/*-
|
||||
* Reference RFC 6020.
|
||||
*
|
||||
@ -105,14 +109,12 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
/**
|
||||
* List of leaves contained.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf-lists contained.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* If it is a presence container, then the textual documentation of presence
|
||||
@ -186,6 +188,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -195,6 +198,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param description set the description.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -204,8 +208,8 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -214,8 +218,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -224,10 +227,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -238,8 +241,8 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -248,8 +251,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -258,10 +260,10 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -290,6 +292,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -299,6 +302,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -308,6 +312,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @return the status.
|
||||
*/
|
||||
@Override
|
||||
public YangStatusType getStatus() {
|
||||
return status;
|
||||
}
|
||||
@ -317,6 +322,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @param status the status to set.
|
||||
*/
|
||||
@Override
|
||||
public void setStatus(YangStatusType status) {
|
||||
this.status = status;
|
||||
}
|
||||
@ -344,6 +350,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @return returns CONTAINER_DATA.
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.CONTAINER_DATA;
|
||||
}
|
||||
@ -353,6 +360,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -362,6 +370,7 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -388,17 +397,62 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
|
||||
|
||||
/**
|
||||
* Generate the java code corresponding to YANG container.
|
||||
*
|
||||
* @throws IOException when fails to generate the source files.
|
||||
*/
|
||||
public void generateJavaCodeEntry() {
|
||||
//TODO: autogenerated method stub, to be implemented
|
||||
return;
|
||||
@Override
|
||||
public void generateJavaCodeEntry() throws IOException {
|
||||
YangNode parent = getParent();
|
||||
String modPkg = JavaIdentifierSyntax.getPackageFromParent(parent.getPackage(), getName());
|
||||
setPackage(modPkg);
|
||||
|
||||
CachedFileHandle handle = null;
|
||||
try {
|
||||
FileSystemUtil.createPackage(getPackage(), getName());
|
||||
handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create the source files.");
|
||||
}
|
||||
setFileHandle(handle);
|
||||
addLavesAttributes();
|
||||
addLeafListAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds leaf attributes in generated files.
|
||||
*/
|
||||
private void addLavesAttributes() {
|
||||
|
||||
List<YangLeaf<?>> leaves = getListOfLeaf();
|
||||
if (leaves != null) {
|
||||
for (YangLeaf<?> leaf : leaves) {
|
||||
getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds leaf list's attributes in generated files.
|
||||
*/
|
||||
private void addLeafListAttributes() {
|
||||
List<YangLeafList<?>> leavesList = getListOfLeafList();
|
||||
if (leavesList != null) {
|
||||
for (YangLeafList<?> leafList : leavesList) {
|
||||
getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources used to generate code.
|
||||
*
|
||||
* @throws IOException when fails to generate source files.
|
||||
*/
|
||||
public void generateJavaCodeExit() {
|
||||
//TODO: autogenerated method stub, to be implemented
|
||||
@Override
|
||||
public void generateJavaCodeExit() throws IOException {
|
||||
getFileHandle().close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -75,8 +75,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
/**
|
||||
* Data model node to maintain information defined in YANG grouping.
|
||||
*/
|
||||
public class YangGrouping extends YangNode
|
||||
implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
public class YangGrouping extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
|
||||
/**
|
||||
* Name of the grouping.
|
||||
@ -91,14 +90,12 @@ public class YangGrouping extends YangNode
|
||||
/**
|
||||
* List of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf lists.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* Reference of the module.
|
||||
@ -138,6 +135,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -147,6 +145,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param description set the description.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -156,8 +155,8 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -166,8 +165,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -176,10 +174,10 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -190,8 +188,8 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -200,8 +198,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -210,10 +207,10 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -224,6 +221,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -233,6 +231,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -242,6 +241,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @return the status.
|
||||
*/
|
||||
@Override
|
||||
public YangStatusType getStatus() {
|
||||
return status;
|
||||
}
|
||||
@ -251,6 +251,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @param status the status to set.
|
||||
*/
|
||||
@Override
|
||||
public void setStatus(YangStatusType status) {
|
||||
this.status = status;
|
||||
}
|
||||
@ -260,6 +261,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @return returns GROUPING_DATA.
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.GROUPING_DATA;
|
||||
}
|
||||
@ -269,6 +271,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -278,6 +281,7 @@ public class YangGrouping extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -285,6 +289,7 @@ public class YangGrouping extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -293,6 +298,7 @@ public class YangGrouping extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeExit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
@ -27,8 +27,7 @@ public interface YangLeavesHolder {
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf();
|
||||
public List<YangLeaf<?>> getListOfLeaf();
|
||||
|
||||
/**
|
||||
* Add a leaf in data holder like container / list.
|
||||
@ -42,8 +41,7 @@ public interface YangLeavesHolder {
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
List<YangLeafList> getListOfLeafList();
|
||||
List<YangLeafList<?>> getListOfLeafList();
|
||||
|
||||
/**
|
||||
* Add a leaf-list in data holder like container / list.
|
||||
|
@ -65,8 +65,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
/**
|
||||
* List data represented in YANG.
|
||||
*/
|
||||
public class YangList extends YangNode
|
||||
implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
public class YangList extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable {
|
||||
|
||||
/**
|
||||
* name of the YANG list.
|
||||
@ -113,14 +112,12 @@ public class YangList extends YangNode
|
||||
/**
|
||||
* List of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf-lists.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* The "max-elements" statement, which is optional, takes as an argument a
|
||||
@ -209,6 +206,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -218,6 +216,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param description set the description.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -258,8 +257,8 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -268,8 +267,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -278,10 +276,10 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -292,8 +290,8 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -302,8 +300,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -312,10 +309,10 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -362,6 +359,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -371,6 +369,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -380,6 +379,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @return the status.
|
||||
*/
|
||||
@Override
|
||||
public YangStatusType getStatus() {
|
||||
return status;
|
||||
}
|
||||
@ -389,6 +389,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @param status the status to set.
|
||||
*/
|
||||
@Override
|
||||
public void setStatus(YangStatusType status) {
|
||||
this.status = status;
|
||||
}
|
||||
@ -398,6 +399,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @return returns LIST_DATA.
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.LIST_DATA;
|
||||
}
|
||||
@ -407,6 +409,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -416,6 +419,7 @@ public class YangList extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -423,6 +427,7 @@ public class YangList extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -431,6 +436,7 @@ public class YangList extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeExit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
@ -15,14 +15,18 @@
|
||||
*/
|
||||
package org.onosproject.yangutils.datamodel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
|
||||
import org.onosproject.yangutils.parser.Parsable;
|
||||
import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
import org.onosproject.yangutils.translator.CachedFileHandle;
|
||||
import org.onosproject.yangutils.translator.CodeGenerator;
|
||||
import org.onosproject.yangutils.utils.io.CachedFileHandle;
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
|
||||
import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
|
||||
|
||||
/*-
|
||||
* Reference:RFC 6020.
|
||||
@ -67,8 +71,7 @@ import org.onosproject.yangutils.utils.io.CachedFileHandle;
|
||||
/**
|
||||
* Data model node to maintain information defined in YANG module.
|
||||
*/
|
||||
public class YangModule extends YangNode
|
||||
implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
|
||||
public class YangModule extends YangNode implements YangLeavesHolder, YangDesc, YangReference, Parsable, CodeGenerator {
|
||||
|
||||
/**
|
||||
* Name of the module.
|
||||
@ -109,14 +112,12 @@ public class YangModule extends YangNode
|
||||
/**
|
||||
* List of leaves at root level in the module.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf-lists at root level in the module.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* Name space of the module.
|
||||
@ -209,6 +210,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @return the description of YANG module.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -218,6 +220,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @param description set the description of YANG module.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -294,8 +297,8 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -304,8 +307,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -314,10 +316,10 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -328,8 +330,8 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -338,8 +340,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -348,10 +349,10 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -416,6 +417,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -425,6 +427,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -508,6 +511,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @return returns MODULE_DATA.
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.MODULE_DATA;
|
||||
}
|
||||
@ -517,6 +521,7 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -526,24 +531,67 @@ public class YangModule extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates java code for module.
|
||||
*
|
||||
* @throws IOException when fails to generate the source files.
|
||||
*/
|
||||
public void generateJavaCodeEntry() {
|
||||
//TODO: autogenerated method stub, to be implemented
|
||||
@Override
|
||||
public void generateJavaCodeEntry() throws IOException {
|
||||
String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
|
||||
getRevision().getRevDate());
|
||||
setPackage(modPkg);
|
||||
|
||||
return;
|
||||
CachedFileHandle handle = null;
|
||||
try {
|
||||
FileSystemUtil.createPackage(getPackage(), getName());
|
||||
handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create the source files.");
|
||||
}
|
||||
setFileHandle(handle);
|
||||
addLavesAttributes();
|
||||
addLeafListAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds leaf attributes in generated files.
|
||||
*/
|
||||
private void addLavesAttributes() {
|
||||
|
||||
List<YangLeaf<?>> leaves = getListOfLeaf();
|
||||
if (leaves != null) {
|
||||
for (YangLeaf<?> leaf : leaves) {
|
||||
getFileHandle().addAttributeInfo(leaf.getDataType(), leaf.getLeafName(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds leaf list's attributes in generated files.
|
||||
*/
|
||||
private void addLeafListAttributes() {
|
||||
List<YangLeafList<?>> leavesList = getListOfLeafList();
|
||||
if (leavesList != null) {
|
||||
for (YangLeafList<?> leafList : leavesList) {
|
||||
getFileHandle().addAttributeInfo(leafList.getDataType(), leafList.getLeafName(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Free resources used to generate code.
|
||||
*
|
||||
* @throws IOException when fails to generate source files.
|
||||
*/
|
||||
public void generateJavaCodeExit() {
|
||||
//TODO: autogenerated method stub, to be implemented
|
||||
@Override
|
||||
public void generateJavaCodeExit() throws IOException {
|
||||
getFileHandle().close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -72,8 +72,7 @@ import org.onosproject.yangutils.parser.ParsableDataType;
|
||||
/**
|
||||
* Data model node to maintain information defined in YANG sub-module.
|
||||
*/
|
||||
public class YangSubModule extends YangNode
|
||||
implements YangLeavesHolder, YangDesc, YangReference, Parsable {
|
||||
public class YangSubModule extends YangNode implements YangLeavesHolder, YangDesc, YangReference, Parsable {
|
||||
|
||||
/**
|
||||
* Name of sub module.
|
||||
@ -114,14 +113,12 @@ public class YangSubModule extends YangNode
|
||||
/**
|
||||
* List of leaves at root level in the sub-module.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeaf> listOfLeaf;
|
||||
private List<YangLeaf<?>> listOfLeaf;
|
||||
|
||||
/**
|
||||
* List of leaf-lists at root level in the sub-module.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private List<YangLeafList> listOfLeafList;
|
||||
private List<YangLeafList<?>> listOfLeafList;
|
||||
|
||||
/**
|
||||
* organization owner of the sub-module.
|
||||
@ -207,6 +204,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@ -216,6 +214,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @param description set the description.
|
||||
*/
|
||||
@Override
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@ -292,8 +291,8 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @return the list of leaves.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeaf> getListOfLeaf() {
|
||||
@Override
|
||||
public List<YangLeaf<?>> getListOfLeaf() {
|
||||
return listOfLeaf;
|
||||
}
|
||||
|
||||
@ -302,8 +301,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @param leafsList the list of leaf to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeaf(List<YangLeaf> leafsList) {
|
||||
private void setListOfLeaf(List<YangLeaf<?>> leafsList) {
|
||||
listOfLeaf = leafsList;
|
||||
}
|
||||
|
||||
@ -312,10 +310,10 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @param leaf the leaf to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeaf(YangLeaf<?> leaf) {
|
||||
if (getListOfLeaf() == null) {
|
||||
setListOfLeaf(new LinkedList<YangLeaf>());
|
||||
setListOfLeaf(new LinkedList<YangLeaf<?>>());
|
||||
}
|
||||
|
||||
getListOfLeaf().add(leaf);
|
||||
@ -326,8 +324,8 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @return the list of leaf-list.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public List<YangLeafList> getListOfLeafList() {
|
||||
@Override
|
||||
public List<YangLeafList<?>> getListOfLeafList() {
|
||||
return listOfLeafList;
|
||||
}
|
||||
|
||||
@ -336,8 +334,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @param listOfLeafList the list of leaf-list to set.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setListOfLeafList(List<YangLeafList> listOfLeafList) {
|
||||
private void setListOfLeafList(List<YangLeafList<?>> listOfLeafList) {
|
||||
this.listOfLeafList = listOfLeafList;
|
||||
}
|
||||
|
||||
@ -346,10 +343,10 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @param leafList the leaf-list to be added.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void addLeafList(YangLeafList<?> leafList) {
|
||||
if (getListOfLeafList() == null) {
|
||||
setListOfLeafList(new LinkedList<YangLeafList>());
|
||||
setListOfLeafList(new LinkedList<YangLeafList<?>>());
|
||||
}
|
||||
|
||||
getListOfLeafList().add(leafList);
|
||||
@ -378,6 +375,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @return the reference.
|
||||
*/
|
||||
@Override
|
||||
public String getReference() {
|
||||
return reference;
|
||||
}
|
||||
@ -387,6 +385,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @param reference the reference to set.
|
||||
*/
|
||||
@Override
|
||||
public void setReference(String reference) {
|
||||
this.reference = reference;
|
||||
}
|
||||
@ -432,6 +431,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @return returns SUB_MODULE_DATA.
|
||||
*/
|
||||
@Override
|
||||
public ParsableDataType getParsableDataType() {
|
||||
return ParsableDataType.SUB_MODULE_DATA;
|
||||
}
|
||||
@ -441,6 +441,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnEntry() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -450,6 +451,7 @@ public class YangSubModule extends YangNode
|
||||
*
|
||||
* @throws DataModelException a violation of data model rules.
|
||||
*/
|
||||
@Override
|
||||
public void validateDataOnExit() throws DataModelException {
|
||||
// TODO auto-generated method stub, to be implemented by parser
|
||||
}
|
||||
@ -457,6 +459,7 @@ public class YangSubModule extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeEntry() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@ -465,6 +468,7 @@ public class YangSubModule extends YangNode
|
||||
/* (non-Javadoc)
|
||||
* @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
|
||||
*/
|
||||
@Override
|
||||
public void generateJavaCodeExit() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
@ -24,24 +24,26 @@ import java.util.List;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.sonatype.plexus.build.incremental.BuildContext;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.parser.YangUtilsParser;
|
||||
import org.onosproject.yangutils.parser.exceptions.ParserException;
|
||||
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
|
||||
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
|
||||
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
|
||||
import org.onosproject.yangutils.utils.io.impl.YangIoUtils;
|
||||
import org.sonatype.plexus.build.incremental.BuildContext;
|
||||
|
||||
/**
|
||||
* ONOS YANG utility maven plugin.
|
||||
* Goal of plugin is yang2java
|
||||
* Execution phase in generate-sources
|
||||
* requiresDependencyResolution at compile time
|
||||
* ONOS YANG utility maven plugin. Goal of plugin is yang2java Execution phase
|
||||
* in generate-sources requiresDependencyResolution at compile time
|
||||
*/
|
||||
@Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
|
||||
requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
|
||||
@ -71,24 +73,32 @@ public class YangUtilManager extends AbstractMojo {
|
||||
@Component
|
||||
private BuildContext context;
|
||||
|
||||
private YangUtilsParser yangUtilsParser;
|
||||
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
|
||||
private String baseDir;
|
||||
private String searchDir;
|
||||
|
||||
/**
|
||||
* Set current project.
|
||||
*
|
||||
* @param project maven project.
|
||||
* @param curProject maven project.
|
||||
*/
|
||||
public void setCurrentProject(final MavenProject project) {
|
||||
this.project = project;
|
||||
public void setCurrentProject(final MavenProject curProject) {
|
||||
project = curProject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
try {
|
||||
|
||||
CopyrightHeader.parseCopyrightHeader();
|
||||
baseDir = project.getBasedir().toString();
|
||||
|
||||
/**
|
||||
* For deleting the generated code in previous build.
|
||||
*/
|
||||
YangIoUtils.clean(baseDir);
|
||||
|
||||
searchDir = baseDir + File.separator + yangFilesDir;
|
||||
|
||||
List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
|
||||
@ -97,13 +107,25 @@ public class YangUtilManager extends AbstractMojo {
|
||||
String yangFile = yangFileIterator.next();
|
||||
try {
|
||||
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
|
||||
//TODO: send this data model to translator and create the corresponding java files.
|
||||
JavaCodeGenerator.generateJavaCode(yangNode);
|
||||
} catch (ParserException e) {
|
||||
getLog().info("Invalid yang file.");
|
||||
String logInfo = "Error in file: " + e.getFileName();
|
||||
if (e.getLineNumber() != 0) {
|
||||
logInfo = logInfo + " at line: " + e.getLineNumber() + " at position: "
|
||||
+ e.getCharPositionInLine();
|
||||
|
||||
}
|
||||
if (e.getMessage() != null) {
|
||||
logInfo = logInfo + "\n" + e.getMessage();
|
||||
}
|
||||
getLog().info(logInfo);
|
||||
}
|
||||
}
|
||||
|
||||
YangIoUtils.addToSource(baseDir + File.separator + UtilConstants.YANG_GEN_DIR, project, context);
|
||||
} catch (final IOException e) {
|
||||
getLog().info("Exception occured");
|
||||
getLog().info("IOException occured");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
|
||||
/**
|
||||
* Cached java file handle, which supports the addition of member attributes and
|
||||
* methods.
|
||||
*/
|
||||
public interface CachedFileHandle {
|
||||
|
||||
/**
|
||||
* Add a new attribute to the file(s).
|
||||
*
|
||||
* @param attrType data type of the added attribute.
|
||||
* @param name name of the attribute.
|
||||
* @param isListAttr if the current added attribute needs to be maintained
|
||||
* in a list.
|
||||
*/
|
||||
void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr);
|
||||
|
||||
/**
|
||||
* Flushes the cached contents to the target file, frees used resources.
|
||||
*
|
||||
* @throws IOException when failes to generated java files.
|
||||
*/
|
||||
void close() throws IOException;
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
|
||||
package org.onosproject.yangutils.translator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Abstraction of an entity which provides Code generator functionalities.
|
||||
*/
|
||||
@ -23,12 +25,16 @@ public interface CodeGenerator {
|
||||
|
||||
/**
|
||||
* Traverse the schema of application and generate corresponding code.
|
||||
*
|
||||
* @throws IOException when fails to translate the data model tree.
|
||||
*/
|
||||
void generateJavaCodeEntry();
|
||||
void generateJavaCodeEntry() throws IOException;
|
||||
|
||||
/**
|
||||
* Traverse the schema of application and generate corresponding code.
|
||||
*
|
||||
* @throws IOException when fails to generate java code.
|
||||
*/
|
||||
void generateJavaCodeExit();
|
||||
void generateJavaCodeExit() throws IOException;
|
||||
|
||||
}
|
||||
|
@ -1,16 +1,19 @@
|
||||
/*Copyright 2016.year Open Networking Laboratory
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -18,17 +21,27 @@ package org.onosproject.yangutils.translator;
|
||||
*/
|
||||
public enum GeneratedFileType {
|
||||
/**
|
||||
* interface file.
|
||||
* Interface file.
|
||||
*/
|
||||
INTERFACE,
|
||||
|
||||
/**
|
||||
* class file.
|
||||
* Builder class file.
|
||||
*/
|
||||
BUILDER_CLASS,
|
||||
|
||||
/**
|
||||
* Builder interface file.
|
||||
*/
|
||||
BUILDER_INTERFACE,
|
||||
|
||||
/**
|
||||
* Impl class file.
|
||||
*/
|
||||
IMPL,
|
||||
|
||||
/**
|
||||
* interface and class file.
|
||||
*/
|
||||
BOTH
|
||||
ALL
|
||||
}
|
||||
|
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
|
||||
/**
|
||||
* Maintains the attribute info corresponding to class/interface generated.
|
||||
*/
|
||||
public class AttributeInfo implements Serializable {
|
||||
|
||||
/**
|
||||
* version of serialized info.
|
||||
*/
|
||||
private static final long serialVersionUID = 201602151004L;
|
||||
|
||||
/**
|
||||
* The data type info of attribute.
|
||||
*/
|
||||
private YangType<?> attrType;
|
||||
|
||||
/**
|
||||
* Name of the attribute.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* If the added attribute is a list of info.
|
||||
*/
|
||||
private boolean isListAttr;
|
||||
|
||||
/**
|
||||
* If the added attribute has to be accessed in a fully qualified manner.
|
||||
*/
|
||||
private boolean isQualifiedName;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public AttributeInfo() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data type info of attribute.
|
||||
*
|
||||
* @return the data type info of attribute.
|
||||
*/
|
||||
public YangType<?> getAttributeType() {
|
||||
return attrType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the data type info of attribute.
|
||||
*
|
||||
* @param type the data type info of attribute.
|
||||
*/
|
||||
public void setAttributeType(YangType<?> type) {
|
||||
attrType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of the attribute.
|
||||
*
|
||||
* @return name of the attribute.
|
||||
*/
|
||||
public String getAttributeName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name of the attribute.
|
||||
*
|
||||
* @param attrName name of the attribute.
|
||||
*/
|
||||
public void setAttributeName(String attrName) {
|
||||
name = attrName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the added attribute is a list of info.
|
||||
*
|
||||
* @return the if the added attribute is a list of info.
|
||||
*/
|
||||
public boolean isListAttr() {
|
||||
return isListAttr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the added attribute is a list of info.
|
||||
*
|
||||
* @param isList if the added attribute is a list of info.
|
||||
*/
|
||||
public void setListAttr(boolean isList) {
|
||||
isListAttr = isList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the added attribute has to be accessed in a fully qualified
|
||||
* manner.
|
||||
*
|
||||
* @return the if the added attribute has to be accessed in a fully
|
||||
* qualified manner.
|
||||
*/
|
||||
public boolean isQualifiedName() {
|
||||
return isQualifiedName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if the added attribute has to be accessed in a fully qualified
|
||||
* manner.
|
||||
*
|
||||
* @param isQualified if the added attribute has to be accessed in a fully
|
||||
* qualified manner.
|
||||
*/
|
||||
public void setQualifiedName(boolean isQualified) {
|
||||
isQualifiedName = isQualified;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,652 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
import org.onosproject.yangutils.translator.CachedFileHandle;
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen;
|
||||
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
|
||||
import org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
|
||||
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
|
||||
import org.onosproject.yangutils.utils.io.impl.SerializedDataStore;
|
||||
import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
|
||||
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Maintain the information about the java file to be generated.
|
||||
*/
|
||||
public class CachedJavaFileHandle implements CachedFileHandle {
|
||||
|
||||
private static final Logger log = getLogger(CachedJavaFileHandle.class);
|
||||
|
||||
private static final int MAX_CACHABLE_ATTR = 64;
|
||||
private static final String JAVA_FILE_EXTENSION = ".java";
|
||||
private static final String TEMP_FILE_EXTENSION = ".tmp";
|
||||
|
||||
/**
|
||||
* The type(s) of java source file(s) to be generated when the cached file
|
||||
* handle is closed.
|
||||
*/
|
||||
private GeneratedFileType genFileTypes;
|
||||
|
||||
/**
|
||||
* The type(s) of java method to be generated when the cached file handle is
|
||||
* closed.
|
||||
*/
|
||||
private GeneratedMethodTypes genMethodTypes;
|
||||
|
||||
/**
|
||||
* Java package in which the class/interface needs to be generated.
|
||||
*/
|
||||
private String pkg;
|
||||
|
||||
/**
|
||||
* Name of the object in YANG file.
|
||||
*/
|
||||
private String yangName;
|
||||
|
||||
/**
|
||||
* Sorted set of import info, to be used to maintain the set of classes to
|
||||
* be imported in the generated class.
|
||||
*/
|
||||
private SortedSet<ImportInfo> importSet;
|
||||
|
||||
/**
|
||||
* Cached list of attribute info.
|
||||
*/
|
||||
private List<AttributeInfo> attributeList;
|
||||
|
||||
/**
|
||||
* Prevent invoking default constructor.
|
||||
*/
|
||||
private CachedJavaFileHandle() {
|
||||
setCachedAttributeList(new LinkedList<AttributeInfo>());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a cached file handle which takes care of adding attributes to the
|
||||
* generated java file.
|
||||
*
|
||||
* @param pcg package in which class/interface need to be generated.
|
||||
* @param yangName name of the attribute in YANG file.
|
||||
* @param types the types of files that needs to be generated.
|
||||
* @throws IOException file IO exception.
|
||||
*/
|
||||
public CachedJavaFileHandle(String pcg, String yangName, GeneratedFileType types) throws IOException {
|
||||
if ((new File(pcg).exists())) {
|
||||
setGeneratedFileTypes(types);
|
||||
setPackage(pcg);
|
||||
setYangName(yangName);
|
||||
} else {
|
||||
FileSystemUtil.createPackage(pcg, yangName);
|
||||
setGeneratedFileTypes(types);
|
||||
setPackage(pcg);
|
||||
setYangName(yangName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the types of files being generated corresponding to the YANG
|
||||
* definition.
|
||||
*
|
||||
* @return the types of files being generated corresponding to the YANG
|
||||
* definition.
|
||||
*/
|
||||
public GeneratedFileType getGeneratedFileTypes() {
|
||||
return genFileTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the types of files being generated corresponding to the YANG
|
||||
* definition.
|
||||
*
|
||||
* @param fileTypes the types of files being generated corresponding to the
|
||||
* YANG definition.
|
||||
*/
|
||||
public void setGeneratedFileTypes(GeneratedFileType fileTypes) {
|
||||
genFileTypes = fileTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the corresponding name defined in YANG.
|
||||
*
|
||||
* @return the corresponding name defined in YANG.
|
||||
*/
|
||||
public String getYangName() {
|
||||
return yangName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the corresponding name defined in YANG.
|
||||
*
|
||||
* @param yangName the corresponding name defined in YANG.
|
||||
*/
|
||||
public void setYangName(String yangName) {
|
||||
this.yangName = yangName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the java package.
|
||||
*
|
||||
* @return the java package.
|
||||
*/
|
||||
public String getPackage() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the java package.
|
||||
*
|
||||
* @param pcg the package to set
|
||||
*/
|
||||
public void setPackage(String pcg) {
|
||||
pkg = pcg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the set containing the imported class/interface info.
|
||||
*
|
||||
* @return the set containing the imported class/interface info.
|
||||
*/
|
||||
public SortedSet<ImportInfo> getImportSet() {
|
||||
return importSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign the set containing the imported class/interface info.
|
||||
*
|
||||
* @param importSet the set containing the imported class/interface info.
|
||||
*/
|
||||
private void setImportSet(SortedSet<ImportInfo> importSet) {
|
||||
this.importSet = importSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an imported class/interface info is it is not already part of the
|
||||
* set. If already part of the set, return false, else add to set and return
|
||||
* true.
|
||||
*
|
||||
* @param importInfo class/interface info being imported.
|
||||
* @return status of new addition of class/interface to the import set
|
||||
*/
|
||||
public boolean addImportInfo(ImportInfo importInfo) {
|
||||
/*
|
||||
* implement the import info adding. The return value will be used to
|
||||
* check if the qualified name will be used or class/interface name will
|
||||
* be used in the generated class.
|
||||
*/
|
||||
if (getImportSet() == null) {
|
||||
setImportSet(new TreeSet<ImportInfo>());
|
||||
}
|
||||
return getImportSet().add(importInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of cached attribute list.
|
||||
*
|
||||
* @return the set containing the imported class/interface info.
|
||||
*/
|
||||
public List<AttributeInfo> getCachedAttributeList() {
|
||||
return attributeList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cached attribute list.
|
||||
*
|
||||
* @param attrList attribute list.
|
||||
*/
|
||||
private void setCachedAttributeList(List<AttributeInfo> attrList) {
|
||||
attributeList = attrList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the cached attribute list to the serialized file.
|
||||
*/
|
||||
private void flushCacheAttrToSerFile() {
|
||||
|
||||
for (AttributeInfo attr : getCachedAttributeList()) {
|
||||
parseAttributeInfo(attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* clear the contents from the cached attribute list.
|
||||
*/
|
||||
getCachedAttributeList().clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new attribute to the file(s).
|
||||
*
|
||||
* @param attrType data type of the added attribute.
|
||||
* @param name name of the attribute.
|
||||
* @param isListAttr if the current added attribute needs to be maintained
|
||||
* in a list.
|
||||
*/
|
||||
@Override
|
||||
public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) {
|
||||
|
||||
AttributeInfo newAttr = new AttributeInfo();
|
||||
attrType.setDataTypeName(attrType.getDataTypeName().replace("\"", ""));
|
||||
if (attrType.getDataTypeName().equals("string")) {
|
||||
attrType.setDataTypeName(
|
||||
attrType.getDataTypeName().substring(0, 1).toUpperCase() + attrType.getDataTypeName().substring(1));
|
||||
}
|
||||
newAttr.setAttributeType(attrType);
|
||||
newAttr.setAttributeName(name);
|
||||
newAttr.setListAttr(isListAttr);
|
||||
|
||||
/*
|
||||
* TODO: get the prefix and name of data type from attrType and
|
||||
* initialize in importInfo.
|
||||
*/
|
||||
|
||||
/**
|
||||
* TODO: Handle QualifiedFlag for imports.
|
||||
*/
|
||||
|
||||
if (getCachedAttributeList() != null) {
|
||||
if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) {
|
||||
flushCacheAttrToSerFile();
|
||||
}
|
||||
getCachedAttributeList().add(newAttr);
|
||||
} else {
|
||||
List<AttributeInfo> newAttributeInfo = new LinkedList<>();
|
||||
newAttributeInfo.add(newAttr);
|
||||
setCachedAttributeList(newAttributeInfo);
|
||||
}
|
||||
name = JavaIdentifierSyntax.getCamelCase(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes the cached contents to the target file, frees used resources.
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
|
||||
String className = getYangName();
|
||||
className = (className.substring(0, 1).toUpperCase() + className.substring(1));
|
||||
String packagePath = getPackage();
|
||||
String filePath = UtilConstants.YANG_GEN_DIR + packagePath.replace(".", "/");
|
||||
GeneratedFileType fileType = getGeneratedFileTypes();
|
||||
|
||||
/**
|
||||
* Create interface file.
|
||||
*/
|
||||
String interfaceFileName = className + JAVA_FILE_EXTENSION;
|
||||
File interfaceFile = new File(filePath + File.separator + interfaceFileName);
|
||||
|
||||
/**
|
||||
* Create temp builder interface file.
|
||||
*/
|
||||
String builderInterfaceFileName = interfaceFileName + TEMP_FILE_EXTENSION;
|
||||
File builderInterfaceFile = new File(filePath + File.separator + builderInterfaceFileName);
|
||||
|
||||
/**
|
||||
* Create builder class file.
|
||||
*/
|
||||
String builderFileName = className + UtilConstants.BUILDER + JAVA_FILE_EXTENSION;
|
||||
File builderFile = new File(filePath + File.separator + builderFileName);
|
||||
MethodsGenerator.setBuilderClassName(className + UtilConstants.BUILDER);
|
||||
|
||||
/**
|
||||
* Create temp impl class file.
|
||||
*/
|
||||
|
||||
String implFileName = className + UtilConstants.IMPL + TEMP_FILE_EXTENSION;
|
||||
File implTempFile = new File(filePath + File.separator + implFileName);
|
||||
|
||||
if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
|
||||
|
||||
try {
|
||||
interfaceFile.createNewFile();
|
||||
appendContents(interfaceFile, className, GeneratedFileType.INTERFACE);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create interface file.");
|
||||
}
|
||||
}
|
||||
|
||||
if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) {
|
||||
|
||||
try {
|
||||
builderFile.createNewFile();
|
||||
appendContents(builderFile, className, GeneratedFileType.BUILDER_CLASS);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create builder class file.");
|
||||
}
|
||||
}
|
||||
|
||||
if (fileType.equals(GeneratedFileType.IMPL) || fileType.equals(GeneratedFileType.ALL)) {
|
||||
|
||||
try {
|
||||
implTempFile.createNewFile();
|
||||
appendContents(implTempFile, className, GeneratedFileType.IMPL);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create impl class file.");
|
||||
}
|
||||
}
|
||||
|
||||
if (fileType.equals(GeneratedFileType.BUILDER_INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
|
||||
|
||||
try {
|
||||
builderInterfaceFile.createNewFile();
|
||||
appendContents(builderInterfaceFile, className, GeneratedFileType.BUILDER_INTERFACE);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to create builder interface class file.");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* TODO: add the file header using
|
||||
* JavaCodeSnippetGen.getFileHeaderComment
|
||||
*/
|
||||
/*
|
||||
* TODO: get the import list using getImportText and add to the
|
||||
* generated java file using JavaCodeSnippetGen.getImportText
|
||||
*/
|
||||
|
||||
List<String> attributes = new LinkedList<>();
|
||||
List<String> interfaceMethods = new LinkedList<>();
|
||||
List<String> builderInterfaceMethods = new LinkedList<>();
|
||||
List<String> builderClassMethods = new LinkedList<>();
|
||||
List<String> implClassMethods = new LinkedList<>();
|
||||
//TODO: Handle imports for the attributes.
|
||||
try {
|
||||
attributes = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.ATTRIBUTE);
|
||||
|
||||
interfaceMethods = SerializedDataStore
|
||||
.getSerializeData(SerializedDataStore.SerializedDataStoreType.INTERFACE_METHODS);
|
||||
|
||||
builderInterfaceMethods = SerializedDataStore
|
||||
.getSerializeData(SerializedDataStore.SerializedDataStoreType.BUILDER_INTERFACE_METHODS);
|
||||
|
||||
builderClassMethods = SerializedDataStore
|
||||
.getSerializeData(SerializedDataStore.SerializedDataStoreType.BUILDER_METHODS);
|
||||
|
||||
implClassMethods = SerializedDataStore
|
||||
.getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPL_METHODS);
|
||||
|
||||
//TODO:imports = SerializedDataStore.getSerializeData(SerializedDataStore.SerializedDataStoreType.IMPORT);
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
log.info("There is no attribute info of " + className + " YANG file in the serialized files.");
|
||||
}
|
||||
|
||||
if (getCachedAttributeList() != null) {
|
||||
MethodsGenerator.setAttrInfo(getCachedAttributeList());
|
||||
for (AttributeInfo attr : getCachedAttributeList()) {
|
||||
attributes.add(getAttributeString(attr));
|
||||
|
||||
interfaceMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE));
|
||||
|
||||
builderClassMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_CLASS));
|
||||
|
||||
builderInterfaceMethods
|
||||
.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE));
|
||||
|
||||
implClassMethods.add(MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL));
|
||||
}
|
||||
}
|
||||
|
||||
builderInterfaceMethods.add(MethodsGenerator.parseBuilderInterfaceBuildMethodString(className));
|
||||
builderClassMethods.add(UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
|
||||
+ MethodsGenerator.getDefaultConstructorString(GeneratedFileType.BUILDER_CLASS, className));
|
||||
builderClassMethods.add(MethodsGenerator.getBuildString(className));
|
||||
|
||||
implClassMethods.add(UtilConstants.JAVA_DOC_FIRST_LINE
|
||||
+ MethodsGenerator.getDefaultConstructorString(GeneratedFileType.IMPL, className));
|
||||
implClassMethods.add(MethodsGenerator.getConstructorString(className));
|
||||
|
||||
/**
|
||||
* Add attributes to the file.
|
||||
*/
|
||||
for (String attribute : attributes) {
|
||||
insert(builderFile, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
|
||||
insert(implTempFile, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
|
||||
}
|
||||
|
||||
insert(builderFile, UtilConstants.NEW_LINE);
|
||||
insert(implTempFile, UtilConstants.NEW_LINE);
|
||||
|
||||
/**
|
||||
* Add getter methods to interface file.
|
||||
*/
|
||||
for (String method : interfaceMethods) {
|
||||
appendMethod(interfaceFile, method + UtilConstants.NEW_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add getters and setters in builder interface.
|
||||
*/
|
||||
for (String method : builderInterfaceMethods) {
|
||||
appendMethod(builderInterfaceFile, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE);
|
||||
}
|
||||
|
||||
insert(builderInterfaceFile, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE);
|
||||
/**
|
||||
* Add methods in builder class.
|
||||
*/
|
||||
for (String method : builderClassMethods) {
|
||||
appendMethod(builderFile, method + UtilConstants.NEW_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add methods in impl class.
|
||||
*/
|
||||
for (String method : implClassMethods) {
|
||||
appendMethod(implTempFile, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE);
|
||||
}
|
||||
|
||||
insert(implTempFile, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE);
|
||||
|
||||
/**
|
||||
* Append builder interface file to interface file and close it.
|
||||
*/
|
||||
appendFileContents(builderInterfaceFile, interfaceFile);
|
||||
insert(interfaceFile, closeFile(GeneratedFileType.INTERFACE, interfaceFileName));
|
||||
|
||||
/**
|
||||
* Append impl class to builder class and close it.
|
||||
*/
|
||||
appendFileContents(implTempFile, builderFile);
|
||||
insert(builderFile, closeFile(GeneratedFileType.BUILDER_CLASS, builderFileName));
|
||||
|
||||
/**
|
||||
* Remove temp files.
|
||||
*/
|
||||
clean(implTempFile);
|
||||
clean(builderInterfaceFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends the temp files to main files.
|
||||
*
|
||||
* @param appendFile temp file
|
||||
* @param srcFile main file
|
||||
*/
|
||||
private static void appendFileContents(File appendFile, File srcFile) throws IOException {
|
||||
try {
|
||||
FileSystemUtil.appendFileContents(appendFile, srcFile);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to append " + appendFile + " in " + srcFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append methods to the generated files.
|
||||
*
|
||||
* @param file file in which method needs to be appended.
|
||||
* @param method method which needs to be appended.
|
||||
*/
|
||||
private static void appendMethod(File file, String method) throws IOException {
|
||||
insert(file, method);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the current generated file.
|
||||
*
|
||||
* @param fileType generate file type
|
||||
* @param yangName file name
|
||||
* @return end of class definition string.
|
||||
*/
|
||||
private static String closeFile(GeneratedFileType fileType, String yangName) {
|
||||
return JavaCodeSnippetGen.getJavaClassDefClose(fileType, yangName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses attribute info and fetch specific data and creates serialized
|
||||
* files of it.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
*/
|
||||
private void parseAttributeInfo(AttributeInfo attr) {
|
||||
|
||||
String attrString = "";
|
||||
String methodString = "";
|
||||
String getterString = "";
|
||||
|
||||
try {
|
||||
/*
|
||||
* Serialize attributes.
|
||||
*/
|
||||
attrString = getAttributeString(attr);
|
||||
attrString = attrString.replace("\"", "");
|
||||
SerializedDataStore.setSerializeData(attrString, SerializedDataStore.SerializedDataStoreType.ATTRIBUTE);
|
||||
|
||||
if (getGeneratedFileTypes().equals(GeneratedFileType.ALL)) {
|
||||
|
||||
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE);
|
||||
SerializedDataStore.setSerializeData(methodString,
|
||||
SerializedDataStore.SerializedDataStoreType.INTERFACE_METHODS);
|
||||
|
||||
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_CLASS);
|
||||
SerializedDataStore.setSerializeData(methodString,
|
||||
SerializedDataStore.SerializedDataStoreType.BUILDER_METHODS);
|
||||
|
||||
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE);
|
||||
SerializedDataStore.setSerializeData(methodString,
|
||||
SerializedDataStore.SerializedDataStoreType.BUILDER_INTERFACE_METHODS);
|
||||
|
||||
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL);
|
||||
SerializedDataStore.setSerializeData(methodString,
|
||||
SerializedDataStore.SerializedDataStoreType.IMPL_METHODS);
|
||||
|
||||
} else if (getGeneratedFileTypes().equals(GeneratedFileType.INTERFACE)) {
|
||||
|
||||
getterString = MethodsGenerator.getGetterString(attr);
|
||||
SerializedDataStore.setSerializeData(methodString,
|
||||
SerializedDataStore.SerializedDataStoreType.INTERFACE_METHODS);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("Failed to get data for " + attr.getAttributeName() + " from serialized files.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attribute string.
|
||||
*
|
||||
* @param attr attribute info
|
||||
* @return attribute string
|
||||
*/
|
||||
private String getAttributeString(AttributeInfo attr) {
|
||||
return JavaCodeSnippetGen.getJavaAttributeInfo(getGeneratedFileTypes(), attr.getAttributeName(),
|
||||
attr.getAttributeType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all the contents into a generated java file.
|
||||
*
|
||||
* @param file generated file
|
||||
* @param fileName generated file name
|
||||
* @param type generated file type
|
||||
*/
|
||||
private void appendContents(File file, String fileName, GeneratedFileType type) throws IOException {
|
||||
|
||||
if (type.equals(GeneratedFileType.IMPL)) {
|
||||
|
||||
write(file, fileName, type, JavaDocType.IMPL_CLASS);
|
||||
} else if (type.equals(GeneratedFileType.BUILDER_INTERFACE)) {
|
||||
|
||||
write(file, fileName, type, JavaDocType.BUILDER_INTERFACE);
|
||||
} else {
|
||||
|
||||
// TODO: handle imports for attributes.
|
||||
|
||||
if (type.equals(GeneratedFileType.INTERFACE)) {
|
||||
insert(file, CopyrightHeader.getCopyrightHeader());
|
||||
insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN
|
||||
+ UtilConstants.NEW_LINE);
|
||||
write(file, fileName, type, JavaDocType.INTERFACE);
|
||||
} else if (type.equals(GeneratedFileType.BUILDER_CLASS)) {
|
||||
insert(file, CopyrightHeader.getCopyrightHeader());
|
||||
insert(file, "package" + UtilConstants.SPACE + getPackage() + UtilConstants.SEMI_COLAN
|
||||
+ UtilConstants.NEW_LINE);
|
||||
write(file, fileName, type, JavaDocType.BUILDER_CLASS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data to the specific generated file.
|
||||
*
|
||||
* @param file generated file
|
||||
* @param fileName file name
|
||||
* @param genType generated file type
|
||||
* @param javaDocType java doc type
|
||||
*/
|
||||
private static void write(File file, String fileName, GeneratedFileType genType, JavaDocGen.JavaDocType javaDocType)
|
||||
throws IOException {
|
||||
|
||||
insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName));
|
||||
insert(file, JavaCodeSnippetGen.getJavaClassDefStart(genType, fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert in the generated file.
|
||||
*
|
||||
* @param file file in which need to be inserted.
|
||||
* @param data data which need to be inserted.
|
||||
*/
|
||||
private static void insert(File file, String data) throws IOException {
|
||||
try {
|
||||
FileSystemUtil.insertStringInFile(file, data);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Failed to insert in " + file + "file");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes temp files.
|
||||
*
|
||||
* @param file file to be removed.
|
||||
*/
|
||||
private static void clean(File file) {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava;
|
||||
|
||||
/**
|
||||
* Type of method generated.
|
||||
*/
|
||||
public enum GeneratedMethodTypes {
|
||||
/**
|
||||
* getter method.
|
||||
*/
|
||||
GETTER,
|
||||
|
||||
/**
|
||||
* setter method.
|
||||
*/
|
||||
SETTER,
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
CONSTRUCTOR,
|
||||
|
||||
/**
|
||||
* Build.
|
||||
*/
|
||||
BUILD,
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*/
|
||||
DEFAULT_CONSTRUCTOR
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
/**
|
||||
* Maintains the information about individual imports in the generated file.
|
||||
*/
|
||||
public class ImportInfo {
|
||||
|
||||
/**
|
||||
* Package location where the imported class/interface is defined.
|
||||
*/
|
||||
private String pkgInfo;
|
||||
|
||||
/**
|
||||
* class/interface being referenced.
|
||||
*/
|
||||
private String classInfo;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public ImportInfo() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the imported package info.
|
||||
*
|
||||
* @return the imported package info.
|
||||
*/
|
||||
public String getPkgInfo() {
|
||||
return pkgInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the imported package info.
|
||||
*
|
||||
* @param pkgInfo the imported package info.
|
||||
*/
|
||||
public void setPkgInfo(String pkgInfo) {
|
||||
this.pkgInfo = pkgInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the imported class/interface info.
|
||||
*
|
||||
* @return the imported class/interface info.
|
||||
*/
|
||||
public String getClassInfo() {
|
||||
return classInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the imported class/interface info.
|
||||
*
|
||||
* @param classInfo the imported class/interface info.
|
||||
*/
|
||||
public void setClassInfo(String classInfo) {
|
||||
this.classInfo = classInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(pkgInfo, classInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof ImportInfo) {
|
||||
ImportInfo other = (ImportInfo) obj;
|
||||
return Objects.equals(pkgInfo, other.pkgInfo) &&
|
||||
Objects.equals(classInfo, other.classInfo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the import info matches.
|
||||
*
|
||||
* @param importInfo matched import
|
||||
* @return if equal or not
|
||||
*/
|
||||
public boolean exactMatch(ImportInfo importInfo) {
|
||||
return equals(importInfo)
|
||||
&& Objects.equals(pkgInfo, importInfo.getPkgInfo())
|
||||
&& Objects.equals(classInfo, importInfo.getClassInfo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(getClass())
|
||||
.add("pkgInfo", pkgInfo)
|
||||
.add("classInfo", classInfo).toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
|
||||
/**
|
||||
* Implementation of Java code generator based on application schema.
|
||||
*/
|
||||
public final class JavaCodeGenerator {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
private JavaCodeGenerator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate Java code files corresponding to the YANG schema.
|
||||
*
|
||||
* @param rootNode root node of the data model tree.
|
||||
* @throws IOException when fails to generate java code file the current node.
|
||||
*/
|
||||
public static void generateJavaCode(YangNode rootNode) throws IOException {
|
||||
YangNode curNode = rootNode;
|
||||
TraversalType curTraversal = TraversalType.ROOT;
|
||||
|
||||
while (!(curNode == null)) {
|
||||
if (curTraversal != TraversalType.PARENT) {
|
||||
curNode.generateJavaCodeEntry();
|
||||
}
|
||||
if (curTraversal != TraversalType.PARENT && !(curNode.getChild() == null)) {
|
||||
curTraversal = TraversalType.CHILD;
|
||||
curNode = curNode.getChild();
|
||||
} else if (!(curNode.getNextSibling() == null)) {
|
||||
curTraversal = TraversalType.SIBILING;
|
||||
curNode = curNode.getNextSibling();
|
||||
} else {
|
||||
curTraversal = TraversalType.PARENT;
|
||||
curNode.generateJavaCodeExit();
|
||||
curNode = curNode.getParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
|
||||
/**
|
||||
* Generates class definition for generated files.
|
||||
*/
|
||||
public final class ClassDefinitionGenerator {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
private ClassDefinitionGenerator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate class definition for specific classes.
|
||||
*
|
||||
* @param genFileTypes generated file type
|
||||
* @param yangName class name
|
||||
* @return class definition
|
||||
*/
|
||||
public static String generateClassDefinition(GeneratedFileType genFileTypes, String yangName) {
|
||||
|
||||
/**
|
||||
* based on the file type and the YANG name of the file, generate
|
||||
* the class / interface definition start.
|
||||
*/
|
||||
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
|
||||
|
||||
return getInterfaceDefinition(yangName);
|
||||
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
|
||||
|
||||
return getBuilderClassDefinition(yangName);
|
||||
} else if (genFileTypes.equals(GeneratedFileType.IMPL)) {
|
||||
|
||||
return getImplClassDefinition(yangName);
|
||||
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_INTERFACE)) {
|
||||
|
||||
return getBuilderInterfaceDefinition();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns interface file class definition.
|
||||
*
|
||||
* @param yangName file name
|
||||
* @return definition
|
||||
*/
|
||||
private static String getInterfaceDefinition(String yangName) {
|
||||
|
||||
return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.INTERFACE + UtilConstants.SPACE + yangName
|
||||
+ UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns builder interface file class definition.
|
||||
*
|
||||
* @return definition
|
||||
*/
|
||||
private static String getBuilderInterfaceDefinition() {
|
||||
return UtilConstants.INTERFACE + UtilConstants.SPACE + UtilConstants.BUILDER + UtilConstants.SPACE
|
||||
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns builder file class definition.
|
||||
*
|
||||
* @param yangName file name
|
||||
* @return definition
|
||||
*/
|
||||
private static String getBuilderClassDefinition(String yangName) {
|
||||
|
||||
return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.CLASS + UtilConstants.SPACE + yangName
|
||||
+ UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.IMPLEMENTS + UtilConstants.SPACE
|
||||
+ yangName + UtilConstants.PERIOD + UtilConstants.BUILDER + UtilConstants.SPACE
|
||||
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns impl file class definition.
|
||||
*
|
||||
* @param yangName file name
|
||||
* @return definition
|
||||
*/
|
||||
private static String getImplClassDefinition(String yangName) {
|
||||
|
||||
return UtilConstants.PUBLIC + UtilConstants.SPACE + UtilConstants.FINAL + UtilConstants.SPACE
|
||||
+ UtilConstants.CLASS + UtilConstants.SPACE + yangName + UtilConstants.IMPL + UtilConstants.SPACE
|
||||
+ UtilConstants.IMPLEMENTS + UtilConstants.SPACE + yangName + UtilConstants.OPEN_CURLY_BRACKET
|
||||
+ UtilConstants.SPACE + UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
|
||||
import org.onosproject.yangutils.translator.tojava.ImportInfo;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
|
||||
/**
|
||||
* Utility class to generate the java snippet.
|
||||
*/
|
||||
public final class JavaCodeSnippetGen {
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
private JavaCodeSnippetGen() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the java file header comment.
|
||||
*
|
||||
* @return the java file header comment.
|
||||
*/
|
||||
public static String getFileHeaderComment() {
|
||||
|
||||
/**
|
||||
* TODO return the file header.
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* reorder the import list based on the ONOS import rules.
|
||||
*
|
||||
* @param importInfo the set of classes/interfaces to be imported.
|
||||
* @return string of import info.
|
||||
*/
|
||||
public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) {
|
||||
/* TODO: reorder the import list based on the ONOS import rules. */
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the textual java code information corresponding to the import list.
|
||||
*
|
||||
* @param importInfo sorted list of import info.
|
||||
* @return the textual java code information corresponding to the import
|
||||
* list.
|
||||
*/
|
||||
public static String getImportText(List<ImportInfo> importInfo) {
|
||||
/*
|
||||
* TODO: get the textual java code information corresponding to the
|
||||
* import list
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the file type and the YANG name of the file, generate the class
|
||||
* / interface definition start.
|
||||
*
|
||||
* @param genFileTypes type of file being generated.
|
||||
* @param yangName YANG name.
|
||||
* @return corresponding textual java code information.
|
||||
*/
|
||||
public static String getJavaClassDefStart(GeneratedFileType genFileTypes, String yangName) {
|
||||
/*
|
||||
* get the camel case name for java class / interface.
|
||||
*/
|
||||
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
|
||||
return ClassDefinitionGenerator.generateClassDefinition(genFileTypes, yangName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the textual java code for attribute definition in class.
|
||||
*
|
||||
* @param genFileTypes type of file being generated.
|
||||
* @param yangName YANG name of the the attribute.
|
||||
* @param type type of the the attribute.
|
||||
* @return the textual java code for attribute definition in class.
|
||||
*/
|
||||
public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) {
|
||||
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
|
||||
return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName
|
||||
+ UtilConstants.SEMI_COLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the file type and method type(s) and the YANG name of the
|
||||
* method, generate the method definitions(s).
|
||||
*
|
||||
* @param genFileTypes type of file being generated
|
||||
* @param yangName name if the attribute whose getter / setter is required.
|
||||
* @param methodTypes getter and / or setter type of method indicator.
|
||||
* @param returnType type return type of the method.
|
||||
* @return based on the file type and method type(s) the method
|
||||
* definitions(s).
|
||||
*/
|
||||
public static String getJavaMethodInfo(GeneratedFileType genFileTypes, String yangName,
|
||||
GeneratedMethodTypes methodTypes, YangType<?> returnType) {
|
||||
|
||||
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
|
||||
return MethodsGenerator.constructMethodInfo(genFileTypes, yangName, methodTypes, returnType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on the file type and the YANG name of the file, generate the class
|
||||
* / interface definition close.
|
||||
*
|
||||
* @param genFileTypes type of file being generated.
|
||||
* @param yangName YANG name.
|
||||
* @return corresponding textual java code information.
|
||||
*/
|
||||
public static String getJavaClassDefClose(GeneratedFileType genFileTypes, String yangName) {
|
||||
|
||||
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
|
||||
|
||||
return UtilConstants.CLOSE_CURLY_BRACKET;
|
||||
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
|
||||
|
||||
return UtilConstants.CLOSE_CURLY_BRACKET;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
|
||||
/**
|
||||
* Utility Class for translating the name from YANG to java convention.
|
||||
*/
|
||||
public final class JavaIdentifierSyntax {
|
||||
|
||||
/**
|
||||
* Util class, with static functions only.
|
||||
*/
|
||||
private JavaIdentifierSyntax() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root package string.
|
||||
*
|
||||
* @param version YANG version.
|
||||
* @param nameSpace name space of the module.
|
||||
* @param revision revision of the module defined
|
||||
* @return returns the root package string.
|
||||
*/
|
||||
public static String getRootPackage(byte version, String nameSpace, String revision) {
|
||||
|
||||
String pkg;
|
||||
pkg = UtilConstants.DEFAULT_BASE_PKG;
|
||||
pkg = pkg + UtilConstants.PERIOD;
|
||||
pkg = pkg + getYangVersion(version);
|
||||
pkg = pkg + UtilConstants.PERIOD;
|
||||
pkg = pkg + getPkgFromNameSpace(nameSpace);
|
||||
pkg = pkg + UtilConstants.PERIOD;
|
||||
pkg = pkg + getYangRevisionStr(revision);
|
||||
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns version.
|
||||
*
|
||||
* @param ver YANG version.
|
||||
* @return version
|
||||
*/
|
||||
private static String getYangVersion(byte ver) {
|
||||
return "v" + ver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package name from name space.
|
||||
*
|
||||
* @param nameSpace name space of YANG module
|
||||
* @return java package name as per java rules.
|
||||
*/
|
||||
public static String getPkgFromNameSpace(String nameSpace) {
|
||||
ArrayList<String> pkgArr = new ArrayList<String>();
|
||||
nameSpace = nameSpace.replace("\"", "");
|
||||
|
||||
String[] nameSpaceArr = nameSpace.split(UtilConstants.COLAN);
|
||||
|
||||
for (String nameSpaceString : nameSpaceArr) {
|
||||
pkgArr.add(nameSpaceString);
|
||||
}
|
||||
return getPkgFrmArr(pkgArr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns revision string array.
|
||||
*
|
||||
* @param date YANG module revision
|
||||
* @return revision string
|
||||
*/
|
||||
public static String getYangRevisionStr(String date) {
|
||||
String[] revisionArr = date.split(UtilConstants.HYPHEN);
|
||||
|
||||
String rev = "rev";
|
||||
for (String element : revisionArr) {
|
||||
Integer val = Integer.parseInt(element);
|
||||
if (val < 10) {
|
||||
rev = rev + "0";
|
||||
}
|
||||
rev = rev + val;
|
||||
}
|
||||
return rev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package string.
|
||||
*
|
||||
* @param pkgArr package array
|
||||
* @return package string
|
||||
*/
|
||||
public static String getPkgFrmArr(ArrayList<String> pkgArr) {
|
||||
|
||||
String pkg = "";
|
||||
int size = pkgArr.size();
|
||||
int i = 0;
|
||||
for (String member : pkgArr) {
|
||||
pkg = pkg + member;
|
||||
if (i != size - 1) {
|
||||
pkg = pkg + UtilConstants.PERIOD;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the package from parent's package and string.
|
||||
*
|
||||
* @param parentPkg parent's package.
|
||||
* @param childName child's name.
|
||||
* @return package string.
|
||||
*/
|
||||
public static String getPackageFromParent(String parentPkg, String childName) {
|
||||
return parentPkg + UtilConstants.PERIOD + getSubPkgFromName(childName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package sub name from YANG identifier name.
|
||||
*
|
||||
* @param name YANG identifier name.
|
||||
* @return java package sub name as per java rules.
|
||||
*/
|
||||
public static String getSubPkgFromName(String name) {
|
||||
ArrayList<String> pkgArr = new ArrayList<String>();
|
||||
String[] nameArr = name.split(UtilConstants.COLAN);
|
||||
|
||||
for (String nameString : nameArr) {
|
||||
pkgArr.add(nameString);
|
||||
}
|
||||
return getPkgFrmArr(pkgArr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the YANG identifier name to java identifier.
|
||||
*
|
||||
* @param yangIdentifier identifier in YANG file.
|
||||
* @return corresponding java identifier
|
||||
*/
|
||||
public static String getCamelCase(String yangIdentifier) {
|
||||
String[] strArray = yangIdentifier.split(UtilConstants.HYPHEN);
|
||||
String camelCase = strArray[0];
|
||||
for (int i = 1; i < strArray.length; i++) {
|
||||
camelCase = camelCase + (strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1));
|
||||
}
|
||||
return camelCase;
|
||||
}
|
||||
}
|
@ -0,0 +1,432 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.translator.tojava.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangType;
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.translator.tojava.AttributeInfo;
|
||||
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
|
||||
|
||||
/**
|
||||
* Generated methods for generated files based on the file type.
|
||||
*/
|
||||
public final class MethodsGenerator {
|
||||
|
||||
private static String builderClassName;
|
||||
private static List<AttributeInfo> attrInfo;
|
||||
|
||||
/**
|
||||
* Sets the builder class name for setter methods of builder class.
|
||||
*
|
||||
* @param name builder class name
|
||||
*/
|
||||
public static void setBuilderClassName(String name) {
|
||||
builderClassName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the attribute info for the impl class's constructor method.
|
||||
*
|
||||
* @param attr list of attribute info
|
||||
*/
|
||||
public static void setAttrInfo(List<AttributeInfo> attr) {
|
||||
attrInfo = attr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns attribute info for the impl class's constructor method.
|
||||
*
|
||||
* @return list of attribute info
|
||||
*/
|
||||
public static List<AttributeInfo> getAttrInfo() {
|
||||
return attrInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class name.
|
||||
*
|
||||
* @return class name
|
||||
*/
|
||||
public static String getBuilderClassName() {
|
||||
return builderClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
private MethodsGenerator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return method strings.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
* @param type generated file type
|
||||
* @return method string
|
||||
*/
|
||||
public static String getMethodString(AttributeInfo attr, GeneratedFileType type) {
|
||||
|
||||
if (type.equals(GeneratedFileType.BUILDER_CLASS)) {
|
||||
|
||||
return parseBuilderMethodString(attr);
|
||||
} else if (type.equals(GeneratedFileType.INTERFACE)) {
|
||||
|
||||
return getGetterString(attr);
|
||||
} else if (type.equals(GeneratedFileType.BUILDER_INTERFACE)) {
|
||||
|
||||
return parseBuilderInterfaceMethodString(attr);
|
||||
} else if (type.equals(GeneratedFileType.IMPL)) {
|
||||
|
||||
return parseImplMethodString(attr);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns constructed method impl for specific generated file type.
|
||||
*
|
||||
* @param genFileTypes generated file type
|
||||
* @param yangName class name
|
||||
* @param methodTypes method types
|
||||
* @param returnType return type of method
|
||||
* @return constructed method impl
|
||||
*/
|
||||
public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName,
|
||||
GeneratedMethodTypes methodTypes, YangType<?> returnType) {
|
||||
|
||||
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
|
||||
|
||||
/**
|
||||
* If interface, only getter will be there.
|
||||
*/
|
||||
return getGetterForInterface(yangName, returnType);
|
||||
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_INTERFACE)) {
|
||||
|
||||
/**
|
||||
* If builder interface, getters and setters will be there.
|
||||
*/
|
||||
if (methodTypes.equals(GeneratedMethodTypes.GETTER)) {
|
||||
|
||||
return getGetterForInterface(yangName, returnType);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.SETTER)) {
|
||||
|
||||
return getSetterForInterface(yangName, returnType);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.BUILD)) {
|
||||
|
||||
return getBuildForInterface(yangName);
|
||||
}
|
||||
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
|
||||
|
||||
/**
|
||||
* If Builder class , getters, setters ,build and default constructor impls will be there.
|
||||
*/
|
||||
if (methodTypes.equals(GeneratedMethodTypes.GETTER)) {
|
||||
|
||||
return getGetterForClass(yangName, returnType);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.SETTER)) {
|
||||
|
||||
return getSetterForClass(yangName, returnType);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.BUILD)) {
|
||||
|
||||
return getBuild(yangName);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.DEFAULT_CONSTRUCTOR)) {
|
||||
|
||||
return getDefaultConstructor(yangName + UtilConstants.BUILDER);
|
||||
}
|
||||
} else if (genFileTypes.equals(GeneratedFileType.IMPL)) {
|
||||
|
||||
if (methodTypes.equals(GeneratedMethodTypes.GETTER)) {
|
||||
|
||||
return getGetterForClass(yangName, returnType);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.CONSTRUCTOR)) {
|
||||
|
||||
return getConstructor(yangName);
|
||||
} else if (methodTypes.equals(GeneratedMethodTypes.DEFAULT_CONSTRUCTOR)) {
|
||||
|
||||
return getDefaultConstructor(yangName + UtilConstants.IMPL);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the methods strings for builder class.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
* @return method string for builder class.
|
||||
*/
|
||||
private static String parseBuilderMethodString(AttributeInfo attr) {
|
||||
|
||||
String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
|
||||
+ UtilConstants.NEW_LINE;
|
||||
|
||||
String getterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
|
||||
attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType());
|
||||
String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
|
||||
attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType());
|
||||
|
||||
return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString
|
||||
+ UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the methods strings for builder class.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
* @return method string for builder class.
|
||||
*/
|
||||
private static String parseImplMethodString(AttributeInfo attr) {
|
||||
|
||||
return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
|
||||
+ UtilConstants.NEW_LINE + JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
|
||||
attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType())
|
||||
+ UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the methods strings for builder interface.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
* @return method string for builder interface.
|
||||
*/
|
||||
private static String parseBuilderInterfaceMethodString(AttributeInfo attr) {
|
||||
|
||||
return getGetterString(attr) + UtilConstants.NEW_LINE + getSetterString(attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the methods strings for builder interface.
|
||||
*
|
||||
* @param name attribute name.
|
||||
* @return method string for builder interface.
|
||||
*/
|
||||
public static String parseBuilderInterfaceBuildMethodString(String name) {
|
||||
|
||||
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.BUILD, name) + JavaCodeSnippetGen
|
||||
.getJavaMethodInfo(GeneratedFileType.BUILDER_INTERFACE, name, GeneratedMethodTypes.BUILD, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns getter string.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
* @return getter string
|
||||
*/
|
||||
public static String getGetterString(AttributeInfo attr) {
|
||||
|
||||
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.GETTER, attr.getAttributeName())
|
||||
+ JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.INTERFACE, attr.getAttributeName(),
|
||||
GeneratedMethodTypes.GETTER, attr.getAttributeType())
|
||||
+ UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns setter string.
|
||||
*
|
||||
* @param attr attribute info.
|
||||
* @return setter string
|
||||
*/
|
||||
private static String getSetterString(AttributeInfo attr) {
|
||||
|
||||
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.SETTER, attr.getAttributeName())
|
||||
+ JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_INTERFACE, attr.getAttributeName(),
|
||||
GeneratedMethodTypes.SETTER, attr.getAttributeType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns constructor method string.
|
||||
*
|
||||
* @param name class name
|
||||
* @return constructor string
|
||||
*/
|
||||
public static String getConstructorString(String name) {
|
||||
|
||||
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.CONSTRUCTOR, name) + JavaCodeSnippetGen
|
||||
.getJavaMethodInfo(GeneratedFileType.IMPL, name, GeneratedMethodTypes.CONSTRUCTOR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default constructor method string.
|
||||
*
|
||||
* @param type generated file type
|
||||
* @param name class name
|
||||
* @return default constructor string
|
||||
*/
|
||||
public static String getDefaultConstructorString(GeneratedFileType type, String name) {
|
||||
|
||||
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR, name)
|
||||
+ JavaCodeSnippetGen.getJavaMethodInfo(type, name, GeneratedMethodTypes.DEFAULT_CONSTRUCTOR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns build method string.
|
||||
*
|
||||
* @param name class name
|
||||
* @return build string
|
||||
*/
|
||||
public static String getBuildString(String name) {
|
||||
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE + UtilConstants.NEW_LINE
|
||||
+ JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, name,
|
||||
GeneratedMethodTypes.BUILD, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the getter method strings for class file.
|
||||
*
|
||||
* @param yangName name of the attribute.
|
||||
* @param returnType return type of attribute
|
||||
* @return getter method for class.
|
||||
*/
|
||||
private static String getGetterForClass(String yangName, YangType<?> returnType) {
|
||||
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
|
||||
+ returnType.getDataTypeName() + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX + yangName
|
||||
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
|
||||
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
|
||||
+ UtilConstants.RETURN + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN
|
||||
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the setter method strings for class file.
|
||||
*
|
||||
* @param yangName name of the attribute.
|
||||
* @param returnType return type of attribute
|
||||
* @return setter method for class.
|
||||
*/
|
||||
private static String getSetterForClass(String yangName, YangType<?> returnType) {
|
||||
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + getBuilderClassName()
|
||||
+ UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS
|
||||
+ returnType.getDataTypeName() + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS
|
||||
+ UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
|
||||
+ UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD + yangName
|
||||
+ UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN
|
||||
+ UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN
|
||||
+ UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the getter method strings for interface file.
|
||||
*
|
||||
* @param yangName name of the attribute.
|
||||
* @param returnType return type of attribute
|
||||
* @return getter method for interface.
|
||||
*/
|
||||
private static String getGetterForInterface(String yangName, YangType<?> returnType) {
|
||||
returnType.setDataTypeName(returnType.getDataTypeName().replace("\"", ""));
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + returnType.getDataTypeName() + UtilConstants.SPACE
|
||||
+ UtilConstants.GET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS
|
||||
+ UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the setter method strings for interface file.
|
||||
*
|
||||
* @param yangName name of the attribute.
|
||||
* @param returnType return type of attribute
|
||||
* @return setter method for interface.
|
||||
*/
|
||||
private static String getSetterForInterface(String yangName, YangType<?> returnType) {
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.BUILDER + UtilConstants.SPACE
|
||||
+ UtilConstants.SET_METHOD_PREFIX + yangName + UtilConstants.OPEN_PARENTHESIS
|
||||
+ returnType.getDataTypeName() + UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS
|
||||
+ UtilConstants.SEMI_COLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the build method strings for interface file.
|
||||
*
|
||||
* @param yangName name of the attribute.
|
||||
* @param returnType return type of attribute
|
||||
* @return build method for interface.
|
||||
*/
|
||||
private static String getBuildForInterface(String yangName) {
|
||||
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + yangName + UtilConstants.SPACE + UtilConstants.BUILD
|
||||
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constructor strings for class file.
|
||||
*
|
||||
* @param yangName name of the class.
|
||||
* @return constructor for class
|
||||
*/
|
||||
private static String getConstructor(String yangName) {
|
||||
|
||||
String builderAttribute = (yangName.substring(0, 1).toLowerCase() + yangName.substring(1));
|
||||
String constructor = UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
|
||||
+ yangName + UtilConstants.IMPL + UtilConstants.OPEN_PARENTHESIS + yangName + UtilConstants.BUILDER
|
||||
+ UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT + UtilConstants.CLOSE_PARENTHESIS
|
||||
+ UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
|
||||
|
||||
if (getAttrInfo() != null) {
|
||||
for (AttributeInfo attribute : getAttrInfo()) {
|
||||
attribute.setAttributeName(JavaIdentifierSyntax.getCamelCase(attribute.getAttributeName()));
|
||||
constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS
|
||||
+ UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE
|
||||
+ UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT
|
||||
+ UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX + attribute.getAttributeName()
|
||||
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
|
||||
+ UtilConstants.NEW_LINE;
|
||||
}
|
||||
getAttrInfo().clear();
|
||||
}
|
||||
return constructor + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET
|
||||
+ UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the build method strings for class file.
|
||||
*
|
||||
* @param yangName class name
|
||||
* @return build method string for class.
|
||||
*/
|
||||
private static String getBuild(String yangName) {
|
||||
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + yangName
|
||||
+ UtilConstants.SPACE + UtilConstants.BUILD + UtilConstants.OPEN_PARENTHESIS
|
||||
+ UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
|
||||
+ UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN
|
||||
+ UtilConstants.SPACE + UtilConstants.NEW + UtilConstants.SPACE + yangName + UtilConstants.IMPL
|
||||
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.THIS + UtilConstants.CLOSE_PARENTHESIS
|
||||
+ UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.CLOSE_CURLY_BRACKET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Default constructor strings for class file.
|
||||
*
|
||||
* @param yangName name of the class.
|
||||
* @return Default constructor for class
|
||||
*/
|
||||
private static String getDefaultConstructor(String name) {
|
||||
|
||||
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + name
|
||||
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
|
||||
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*Copyright 2016.year Open Networking Laboratory
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.*/
|
||||
package org.onosproject.yangutils.utils.io;
|
||||
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
|
||||
/**
|
||||
* Cached java file handle, which supports the addition of member attributes and
|
||||
* methods.
|
||||
*/
|
||||
public interface CachedFileHandle {
|
||||
|
||||
/**
|
||||
* Add a new attribute to the file(s).
|
||||
*
|
||||
* @param attrType data type of the added attribute.
|
||||
* @param name name of the attribute.
|
||||
* @param isListAttr if the current added attribute needs to be maintained
|
||||
* in a list.
|
||||
* @param fileTypes types of files in which the attribute needs to be added.
|
||||
*/
|
||||
void addAttributeInfo(String attrType, String name, boolean isListAttr, GeneratedFileType fileTypes);
|
||||
|
||||
/**
|
||||
* Flushes the cached contents to the target file, frees used resources.
|
||||
*/
|
||||
void close();
|
||||
}
|
@ -33,9 +33,11 @@ import org.slf4j.Logger;
|
||||
public final class CopyrightHeader {
|
||||
|
||||
private static final Logger log = getLogger(CopyrightHeader.class);
|
||||
private static final int NULL = -1;
|
||||
private static final int EOF = -1;
|
||||
private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader();
|
||||
|
||||
private static String copyrightHeader;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
@ -43,21 +45,30 @@ public final class CopyrightHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Copyright file header.
|
||||
* Returns copyright file header.
|
||||
*
|
||||
* @return Copyright file header
|
||||
* @return copyright file header
|
||||
* @throws IOException when fails to parse copyright header.
|
||||
*/
|
||||
public static String getCopyrightHeader() {
|
||||
return parseOnosHeader();
|
||||
public static String getCopyrightHeader() throws IOException {
|
||||
return copyrightHeader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the copyright header.
|
||||
*
|
||||
* @param header copyright header
|
||||
*/
|
||||
private static void setCopyrightHeader(String header) {
|
||||
copyrightHeader = header;
|
||||
}
|
||||
|
||||
/**
|
||||
* parse Copyright to the temporary file.
|
||||
*
|
||||
* @param file generated file
|
||||
* @param stream input stream
|
||||
* @throws IOException when fails to get the copyright header.
|
||||
*/
|
||||
private static String parseOnosHeader() {
|
||||
public static void parseCopyrightHeader() throws IOException {
|
||||
|
||||
File temp = new File("temp.txt");
|
||||
|
||||
@ -65,17 +76,18 @@ public final class CopyrightHeader {
|
||||
InputStream stream = classLoader.getResourceAsStream("CopyrightHeader.txt");
|
||||
OutputStream out = new FileOutputStream(temp);
|
||||
int index;
|
||||
while ((index = stream.read()) != NULL) {
|
||||
while ((index = stream.read()) != EOF) {
|
||||
out.write(index);
|
||||
}
|
||||
out.close();
|
||||
return convertToString(temp.toString());
|
||||
stream.close();
|
||||
getStringFileContent(temp);
|
||||
setCopyrightHeader(getStringFileContent(temp));
|
||||
} catch (IOException e) {
|
||||
log.info("Failed to insert onos header in files.");
|
||||
throw new IOException("failed to parse the Copyright header");
|
||||
} finally {
|
||||
temp.delete();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +97,8 @@ public final class CopyrightHeader {
|
||||
* @return string of file.
|
||||
* @throws IOException when fails to convert to string
|
||||
*/
|
||||
private static String convertToString(String toAppend) throws IOException {
|
||||
private static String getStringFileContent(File toAppend) throws IOException {
|
||||
|
||||
BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend));
|
||||
try {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
@ -0,0 +1,150 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.utils.io.impl;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import org.onosproject.yangutils.translator.CachedFileHandle;
|
||||
import org.onosproject.yangutils.translator.GeneratedFileType;
|
||||
import org.onosproject.yangutils.translator.tojava.CachedJavaFileHandle;
|
||||
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
|
||||
/**
|
||||
* Utility to handle file system operations.
|
||||
*/
|
||||
public final class FileSystemUtil {
|
||||
/**
|
||||
* Hiding constructor of a utility class.
|
||||
*/
|
||||
private FileSystemUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the package directory structure created.
|
||||
*
|
||||
* @param pkg Package to check if it is created.
|
||||
* @return existence status of package.
|
||||
*/
|
||||
public static boolean doesPackageExist(File pkg) {
|
||||
if (pkg.exists()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a package structure with package info java file if not present.
|
||||
*
|
||||
* @param pkg java package string
|
||||
* @param pkgInfo description of package
|
||||
* @throws IOException any IO exception
|
||||
*/
|
||||
public static void createPackage(String pkg, String pkgInfo) throws IOException {
|
||||
if (!doesPackageExist(new File(pkg))) {
|
||||
try {
|
||||
File pack = YangIoUtils
|
||||
.createDirectories(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
|
||||
YangIoUtils.addPackageInfo(pack, pkgInfo, pkg);
|
||||
} catch (IOException e) {
|
||||
throw new IOException("failed to create package-info file");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a java source file in the specified package.
|
||||
*
|
||||
* @param pkg java package under which the interface file needs to be created.
|
||||
* @param yangName YANG name of the node for which java file needs to be created.
|
||||
* @param types types of files to be created.
|
||||
* @throws IOException when fails to create interface file.
|
||||
* @return the cached java file handle, which can be used to further add methods.
|
||||
*/
|
||||
public static CachedFileHandle createSourceFiles(String pkg, String yangName, GeneratedFileType types)
|
||||
throws IOException {
|
||||
//if (!doesPackageExist(new File(pkg))) {
|
||||
// throw new IOException("package does not exist.");
|
||||
//}
|
||||
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
|
||||
CachedFileHandle handler = new CachedJavaFileHandle(pkg, yangName, types);
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the contents from source file and append its contents to append
|
||||
* file.
|
||||
*
|
||||
* @param toAppend destination file in which the contents of source file is
|
||||
* appended.
|
||||
* @param srcFile source file from which data is read and added to to append
|
||||
* file.
|
||||
* @throws IOException any IO errors.
|
||||
*/
|
||||
public static void appendFileContents(File toAppend, File srcFile) throws IOException {
|
||||
|
||||
insertStringInFile(srcFile, UtilConstants.NEW_LINE + readAppendFile(toAppend.toString()));
|
||||
//TODO: read the contents from src file and append its contents to append file.
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads file and convert it to string.
|
||||
*
|
||||
* @param toAppend file to be converted.
|
||||
* @return string of file.
|
||||
* @throws IOException when fails to convert to string
|
||||
*/
|
||||
private static String readAppendFile(String toAppend) throws IOException {
|
||||
BufferedReader bufferReader = new BufferedReader(new FileReader(toAppend));
|
||||
try {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String line = bufferReader.readLine();
|
||||
|
||||
while (line != null) {
|
||||
stringBuilder.append(UtilConstants.FOUR_SPACE_INDENTATION + line);
|
||||
stringBuilder.append("\n");
|
||||
line = bufferReader.readLine();
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
} finally {
|
||||
bufferReader.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert content to the generated file.
|
||||
*
|
||||
* @param inputFile input file
|
||||
* @param contentTobeAdded content to be appended to the file.
|
||||
* @throws IOException when fails to append content to the file.
|
||||
*/
|
||||
public static void insertStringInFile(File inputFile, String contentTobeAdded) throws IOException {
|
||||
FileWriter fileWriter = new FileWriter(inputFile, true);
|
||||
PrintWriter outputPrintWriter = new PrintWriter(fileWriter);
|
||||
outputPrintWriter.write(contentTobeAdded);
|
||||
outputPrintWriter.flush();
|
||||
outputPrintWriter.close();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.utils.io.impl;
|
||||
|
||||
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
|
||||
/**
|
||||
* Provides javadoc for the generated classes.
|
||||
*/
|
||||
public final class JavaDocGen {
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
*/
|
||||
private JavaDocGen() {
|
||||
}
|
||||
|
||||
/**
|
||||
* JavaDocs types.
|
||||
*/
|
||||
public static enum JavaDocType {
|
||||
|
||||
/**
|
||||
* For class.
|
||||
*/
|
||||
IMPL_CLASS,
|
||||
|
||||
/**
|
||||
* For builder class.
|
||||
*/
|
||||
BUILDER_CLASS,
|
||||
|
||||
/**
|
||||
* For interface.
|
||||
*/
|
||||
INTERFACE,
|
||||
|
||||
/**
|
||||
* For builder interface.
|
||||
*/
|
||||
BUILDER_INTERFACE,
|
||||
|
||||
/**
|
||||
* For package-info.
|
||||
*/
|
||||
PACKAGE_INFO,
|
||||
|
||||
/**
|
||||
* For getters.
|
||||
*/
|
||||
GETTER,
|
||||
|
||||
/**
|
||||
* For setters.
|
||||
*/
|
||||
SETTER,
|
||||
|
||||
/**
|
||||
* For default constructor.
|
||||
*/
|
||||
DEFAULT_CONSTRUCTOR,
|
||||
|
||||
/**
|
||||
* For constructor.
|
||||
*/
|
||||
CONSTRUCTOR,
|
||||
|
||||
/**
|
||||
* For build.
|
||||
*/
|
||||
BUILD
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns java docs.
|
||||
*
|
||||
* @param type java doc type
|
||||
* @param name name of the YangNode
|
||||
* @return javadocs.
|
||||
*/
|
||||
public static String getJavaDoc(JavaDocType type, String name) {
|
||||
name = JavaIdentifierSyntax.getCamelCase(name);
|
||||
String javaDoc = "";
|
||||
if (type.equals(JavaDocType.IMPL_CLASS)) {
|
||||
javaDoc = generateForImplClass(name);
|
||||
} else if (type.equals(JavaDocType.BUILDER_CLASS)) {
|
||||
javaDoc = generateForBuilderClass(name);
|
||||
} else if (type.equals(JavaDocType.INTERFACE)) {
|
||||
javaDoc = generateForInterface(name);
|
||||
} else if (type.equals(JavaDocType.BUILDER_INTERFACE)) {
|
||||
javaDoc = generateForBuilderInterface(name);
|
||||
} else if (type.equals(JavaDocType.PACKAGE_INFO)) {
|
||||
javaDoc = generateForPackage(name);
|
||||
} else if (type.equals(JavaDocType.GETTER)) {
|
||||
javaDoc = generateForGetters(name);
|
||||
} else if (type.equals(JavaDocType.SETTER)) {
|
||||
javaDoc = generateForSetters(name);
|
||||
} else if (type.equals(JavaDocType.DEFAULT_CONSTRUCTOR)) {
|
||||
javaDoc = generateForDefaultConstructors();
|
||||
} else if (type.equals(JavaDocType.BUILD)) {
|
||||
javaDoc = generateForBuild(name);
|
||||
} else if (type.equals(JavaDocType.CONSTRUCTOR)) {
|
||||
javaDoc = generateForConstructors(name);
|
||||
}
|
||||
return javaDoc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for getter method.
|
||||
*
|
||||
* @param attribute attribute
|
||||
* @return javaDocs
|
||||
*/
|
||||
private static String generateForGetters(String attribute) {
|
||||
return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute
|
||||
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
|
||||
+ attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates javaDocs for setter method.
|
||||
*
|
||||
* @param attribute attribute
|
||||
* @return javaDocs
|
||||
*/
|
||||
private static String generateForSetters(String attribute) {
|
||||
return (UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute
|
||||
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
|
||||
+ attribute + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT
|
||||
+ attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for the impl class.
|
||||
*
|
||||
* @param className class name
|
||||
* @return javaDocs.
|
||||
*/
|
||||
private static String generateForImplClass(String className) {
|
||||
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC + className + UtilConstants.PERIOD
|
||||
+ UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for the builder class.
|
||||
*
|
||||
* @param className class name
|
||||
* @return javaDocs.
|
||||
*/
|
||||
private static String generateForBuilderClass(String className) {
|
||||
return (UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC
|
||||
+ className + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDoc for the interface.
|
||||
*
|
||||
* @param interfaceName interface name
|
||||
* @return javaDocs.
|
||||
*/
|
||||
private static String generateForInterface(String interfaceName) {
|
||||
return (UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC
|
||||
+ interfaceName + UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDoc for the builder interface.
|
||||
*
|
||||
* @param builderforName builder for name
|
||||
* @return javaDocs.
|
||||
*/
|
||||
private static String generateForBuilderInterface(String builderforName) {
|
||||
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_INTERFACE_JAVA_DOC + builderforName
|
||||
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for package-info.
|
||||
*
|
||||
* @param packageName package name
|
||||
* @return javaDocs
|
||||
*/
|
||||
private static String generateForPackage(String packageName) {
|
||||
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.PACKAGE_INFO_JAVADOC + packageName
|
||||
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for default constructor.
|
||||
*
|
||||
* @return javaDocs
|
||||
*/
|
||||
private static String generateForDefaultConstructors() {
|
||||
return (UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for constructor with parameters.
|
||||
*
|
||||
* @param params list of parameters
|
||||
* @param className class name
|
||||
* @return javaDocs
|
||||
*/
|
||||
private static String generateForConstructors(String className) {
|
||||
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION
|
||||
+ UtilConstants.JAVA_DOC_SETTERS + className + UtilConstants.PERIOD + UtilConstants.NEW_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
|
||||
+ (className.substring(0, 1).toLowerCase() + className.substring(1)) + UtilConstants.OBJECT
|
||||
+ UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className
|
||||
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate javaDocs for build.
|
||||
*
|
||||
* @return javaDocs
|
||||
*/
|
||||
private static String generateForBuild(String buildName) {
|
||||
return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_BUILD + buildName + UtilConstants.PERIOD
|
||||
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
|
||||
+ UtilConstants.JAVA_DOC_BUILD_RETURN + buildName + UtilConstants.PERIOD + UtilConstants.NEW_LINE
|
||||
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
|
||||
}
|
||||
}
|
@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.utils.io.impl;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides storage for serialized data while traversing data model tree for code generation.
|
||||
*/
|
||||
public final class SerializedDataStore {
|
||||
|
||||
/**
|
||||
* Data Store types.
|
||||
*/
|
||||
public static enum SerializedDataStoreType {
|
||||
|
||||
/**
|
||||
* Methods.
|
||||
*/
|
||||
INTERFACE_METHODS,
|
||||
|
||||
/**
|
||||
* Methods.
|
||||
*/
|
||||
BUILDER_METHODS,
|
||||
|
||||
/**
|
||||
* Methods.
|
||||
*/
|
||||
BUILDER_INTERFACE_METHODS,
|
||||
|
||||
/**
|
||||
* Methods.
|
||||
*/
|
||||
IMPL_METHODS,
|
||||
|
||||
/**
|
||||
* Attributes.
|
||||
*/
|
||||
ATTRIBUTE,
|
||||
|
||||
/**
|
||||
* Imports.
|
||||
*/
|
||||
IMPORT
|
||||
}
|
||||
|
||||
/**
|
||||
* File name string for serialized files of methods.
|
||||
*/
|
||||
private static final String INTERFACE_METHOD_FILE_NAME = "SerializedInterfaceMethodDataStore";
|
||||
|
||||
/**
|
||||
* File name string for serialized files of methods.
|
||||
*/
|
||||
private static final String BUILDER_METHOD_FILE_NAME = "SerializedBuilderMethodDataStore";
|
||||
|
||||
/**
|
||||
* File name string for serialized files of methods.
|
||||
*/
|
||||
private static final String BUILDER_INTERFACE_METHOD_FILE_NAME = "SerializedBuilderInterfaceMethodDataStore";
|
||||
|
||||
/**
|
||||
* File name string for serialized files of methods.
|
||||
*/
|
||||
private static final String IMPL_METHOD_FILE_NAME = "SerializedImplMethodDataStore";
|
||||
|
||||
/**
|
||||
* File name string for serialized files of attributes.
|
||||
*/
|
||||
private static final String ATTRIBUTE_FILE_NAME = "SerializedAttributeDataStore";
|
||||
|
||||
/**
|
||||
* File name string for serialized files of imports.
|
||||
*/
|
||||
private static final String IMPORT_FILE_NAME = "SerializedImportDataStore";
|
||||
|
||||
/**
|
||||
* File extension of serialized files.
|
||||
*/
|
||||
private static final String SERIALIZE_FILE_EXTENSION = ".ser";
|
||||
|
||||
/**
|
||||
* Buffer size.
|
||||
*/
|
||||
private static final int BUFFER_SIZE = 8 * 1024;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
private SerializedDataStore() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes specific info to a serialized file.
|
||||
*
|
||||
* @param data data to be stored
|
||||
* @param type type of serialized data store
|
||||
* @throws IOException when fails to create a serialized data file.
|
||||
*/
|
||||
public static void setSerializeData(String data, SerializedDataStoreType type) throws IOException {
|
||||
|
||||
String fileName = "";
|
||||
if (type.equals(SerializedDataStoreType.ATTRIBUTE)) {
|
||||
fileName = ATTRIBUTE_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.INTERFACE_METHODS)) {
|
||||
fileName = INTERFACE_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.BUILDER_INTERFACE_METHODS)) {
|
||||
fileName = BUILDER_INTERFACE_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.BUILDER_METHODS)) {
|
||||
fileName = BUILDER_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.IMPL_METHODS)) {
|
||||
fileName = IMPL_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.IMPORT)) {
|
||||
fileName = IMPORT_FILE_NAME;
|
||||
} else {
|
||||
throw new IOException("Unresolved file type.");
|
||||
}
|
||||
|
||||
try {
|
||||
OutputStream file = new FileOutputStream(fileName + SERIALIZE_FILE_EXTENSION);
|
||||
OutputStream buffer = new BufferedOutputStream(file, BUFFER_SIZE);
|
||||
|
||||
ObjectOutput output = new ObjectOutputStream(buffer);
|
||||
try {
|
||||
output.writeObject(data);
|
||||
} finally {
|
||||
output.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new IOException("failed to serialize data");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the serialized data.
|
||||
*
|
||||
* @param type type of serialized data store
|
||||
* @return list of attribute info.
|
||||
* @throws IOException when fails to read from the file.
|
||||
* @throws ClassNotFoundException when file is missing.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<String> getSerializeData(SerializedDataStoreType type)
|
||||
throws IOException, ClassNotFoundException {
|
||||
|
||||
String fileName = "";
|
||||
if (type.equals(SerializedDataStoreType.ATTRIBUTE)) {
|
||||
fileName = ATTRIBUTE_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.INTERFACE_METHODS)) {
|
||||
fileName = INTERFACE_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.BUILDER_INTERFACE_METHODS)) {
|
||||
fileName = BUILDER_INTERFACE_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.BUILDER_METHODS)) {
|
||||
fileName = BUILDER_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.IMPL_METHODS)) {
|
||||
fileName = IMPL_METHOD_FILE_NAME;
|
||||
} else if (type.equals(SerializedDataStoreType.IMPORT)) {
|
||||
fileName = IMPORT_FILE_NAME;
|
||||
} else {
|
||||
throw new IOException("Unresolved file type.");
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream file = new FileInputStream(fileName + SERIALIZE_FILE_EXTENSION);
|
||||
InputStream buffer = new BufferedInputStream(file);
|
||||
ObjectInput input = new ObjectInputStream(buffer);
|
||||
try {
|
||||
List<String> recoveredData = (List<String>) input.readObject();
|
||||
return recoveredData;
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new ClassNotFoundException("failed to fetch the serialized data file.");
|
||||
}
|
||||
}
|
||||
}
|
@ -34,14 +34,39 @@ public final class YangFileScanner {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of yang files.
|
||||
* Returns the list of YANG files.
|
||||
*
|
||||
* @param root specified directory
|
||||
* @return list of yang files.
|
||||
* @throws IOException when files get deleted while performing the operations.
|
||||
* @return list of YANG files.
|
||||
* @throws IOException when files get deleted while performing the
|
||||
* operations.
|
||||
*/
|
||||
public static List<String> getYangFiles(String root) throws IOException {
|
||||
return getFiles(root, ".yang");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of java files.
|
||||
*
|
||||
* @param root specified directory
|
||||
* @return list of java files.
|
||||
* @throws IOException when files get deleted while performing the
|
||||
* operations.
|
||||
*/
|
||||
public static List<String> getJavaFiles(String root) throws IOException {
|
||||
return getFiles(root, ".java");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of required files.
|
||||
*
|
||||
* @param root specified directory
|
||||
* @param extension file extension.
|
||||
* @return list of required files.
|
||||
* @throws IOException when files get deleted while performing the
|
||||
* operations.
|
||||
*/
|
||||
public static List<String> getFiles(String root, String extension) throws IOException {
|
||||
List<String> store = new LinkedList<>();
|
||||
Stack<String> stack = new Stack<>();
|
||||
stack.push(root);
|
||||
@ -60,7 +85,7 @@ public final class YangFileScanner {
|
||||
stack.push(current.toString());
|
||||
} else {
|
||||
String yangFile = current.getCanonicalPath();
|
||||
if (yangFile.endsWith(".yang")) {
|
||||
if (yangFile.endsWith(extension)) {
|
||||
store.add(yangFile);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2016 Open Networking Laboratory
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.onosproject.yangutils.utils.io.impl;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.sonatype.plexus.build.incremental.BuildContext;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.model.Resource;
|
||||
|
||||
import org.onosproject.yangutils.utils.UtilConstants;
|
||||
|
||||
import static org.slf4j.LoggerFactory.getLogger;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Provides common utility functionalities for code generation.
|
||||
*/
|
||||
public final class YangIoUtils {
|
||||
|
||||
private static final Logger log = getLogger(YangIoUtils.class);
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
private YangIoUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the directory structure.
|
||||
*
|
||||
* @param path directory path
|
||||
* @return directory structure
|
||||
*/
|
||||
public static File createDirectories(String path) {
|
||||
|
||||
File generatedDir = new File(UtilConstants.YANG_GEN_DIR + File.separator + path);
|
||||
generatedDir.mkdirs();
|
||||
return generatedDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds package info file for the created directory.
|
||||
*
|
||||
* @param path directory path
|
||||
* @param classInfo class info for the package
|
||||
* @param pack package of the directory
|
||||
* @throws IOException when fails to create package info file.
|
||||
*/
|
||||
public static void addPackageInfo(File path, String classInfo, String pack) throws IOException {
|
||||
|
||||
try {
|
||||
|
||||
File packageInfo = new File(path + File.separator + "package-info.java");
|
||||
packageInfo.createNewFile();
|
||||
if (packageInfo.exists()) {
|
||||
|
||||
FileWriter fileWriter = null;
|
||||
BufferedWriter bufferedWriter = null;
|
||||
fileWriter = new FileWriter(packageInfo);
|
||||
bufferedWriter = new BufferedWriter(fileWriter);
|
||||
bufferedWriter.write(CopyrightHeader.getCopyrightHeader());
|
||||
bufferedWriter.write(JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.PACKAGE_INFO, classInfo));
|
||||
bufferedWriter.write(UtilConstants.PACKAGE + UtilConstants.SPACE + pack + UtilConstants.SEMI_COLAN);
|
||||
bufferedWriter.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Exception occured while creating package info file.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans the generated directory if already exist in source folder.
|
||||
*
|
||||
* @param baseDir generated directory in previous build.
|
||||
*/
|
||||
public static void clean(String baseDir) {
|
||||
File generatedDirectory = new File(baseDir + File.separator + UtilConstants.YANG_GEN_DIR);
|
||||
if (generatedDirectory.exists()) {
|
||||
List<String> javafiles;
|
||||
try {
|
||||
javafiles = YangFileScanner.getJavaFiles(generatedDirectory.toString());
|
||||
for (String file : javafiles) {
|
||||
File currentFile = new File(file);
|
||||
currentFile.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.info("Failed to delete the generated files in " + generatedDirectory + " directory");
|
||||
}
|
||||
generatedDirectory.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds generated source directory to the compilation root.
|
||||
*
|
||||
* @param source directory
|
||||
* @param project current maven project
|
||||
* @param context current build context
|
||||
*/
|
||||
public static void addToSource(String source, MavenProject project, BuildContext context) {
|
||||
|
||||
project.addCompileSourceRoot(source);
|
||||
Resource rsc = new Resource();
|
||||
rsc.setDirectory(source);
|
||||
project.addResource(rsc);
|
||||
context.refresh(project.getBasedir());
|
||||
log.info("Source directory added to compilation root: " + source);
|
||||
}
|
||||
|
||||
}
|
@ -66,8 +66,8 @@ public class ConfigListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the Config value is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -92,8 +92,8 @@ public class ConfigListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the Config value is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -136,10 +136,10 @@ public class ConfigListenerTest {
|
||||
@Test
|
||||
public void processModuleSubStatementConfig() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container'," +
|
||||
" 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', " +
|
||||
"'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
|
||||
" 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container',"
|
||||
+ " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', "
|
||||
+ "'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
|
||||
+ " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang");
|
||||
}
|
||||
|
||||
@ -167,8 +167,8 @@ public class ConfigListenerTest {
|
||||
assertThat(container.isConfig(), is(true));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -203,8 +203,8 @@ public class ConfigListenerTest {
|
||||
assertThat(yangList.isConfig(), is(true));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -234,8 +234,8 @@ public class ConfigListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
// Check whether config value is set correctly.
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
|
@ -154,8 +154,8 @@ public class ContainerListenerTest {
|
||||
assertThat(yangContainer.getReference(), is("\"container reference\""));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangContainer.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangContainer.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
|
@ -66,8 +66,8 @@ public class DescriptionListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the description is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -175,8 +175,8 @@ public class DescriptionListenerTest {
|
||||
assertThat(container.getDescription(), is("\"container description\""));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -212,8 +212,8 @@ public class DescriptionListenerTest {
|
||||
assertThat(yangList.getDescription(), is("\"list description\""));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -243,8 +243,8 @@ public class DescriptionListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
// Check whether description value is set correctly.
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
|
@ -66,8 +66,8 @@ public class LeafListListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -98,10 +98,10 @@ public class LeafListListenerTest {
|
||||
@Test
|
||||
public void processLeafListInvalidStatement() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container'," +
|
||||
" 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
|
||||
" 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
|
||||
" 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
thrown.expectMessage("mismatched input 'leaflist' expecting {'augment', 'choice', 'contact', 'container',"
|
||||
+ " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
|
||||
+ " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
|
||||
+ " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/LeafListInvalidStatement.yang");
|
||||
}
|
||||
|
||||
@ -161,8 +161,8 @@ public class LeafListListenerTest {
|
||||
assertThat(container.getName(), is("valid"));
|
||||
|
||||
// Check whether leaf-list properties as set correctly.
|
||||
ListIterator<YangLeafList> leafListIterator = container.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = container.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -198,8 +198,8 @@ public class LeafListListenerTest {
|
||||
assertThat(yangList.getName(), is("valid"));
|
||||
|
||||
// Check whether leaf-list properties as set correctly.
|
||||
ListIterator<YangLeafList> leafListIterator = yangList.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangList.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
|
@ -66,8 +66,8 @@ public class LeafListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -98,10 +98,10 @@ public class LeafListenerTest {
|
||||
@Test
|
||||
public void processLeafInvalidStatement() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container'," +
|
||||
" 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
|
||||
" 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
|
||||
" 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
thrown.expectMessage("mismatched input 'leafs' expecting {'augment', 'choice', 'contact', 'container',"
|
||||
+ " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
|
||||
+ " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
|
||||
+ " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/LeafInvalidStatement.yang");
|
||||
}
|
||||
|
||||
@ -161,8 +161,8 @@ public class LeafListenerTest {
|
||||
assertThat(container.getName(), is("valid"));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -197,8 +197,8 @@ public class LeafListenerTest {
|
||||
assertThat(yangList.getName(), is("valid"));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
|
@ -159,8 +159,8 @@ public class ListListenerTest {
|
||||
assertThat(yangList.getReference(), is("\"list reference\""));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
|
@ -60,8 +60,8 @@ public class MandatoryListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the mandatory value is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -86,8 +86,8 @@ public class MandatoryListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the mandatory value is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -112,8 +112,8 @@ public class MandatoryListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the mandatory value is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -146,10 +146,10 @@ public class MandatoryListenerTest {
|
||||
@Test
|
||||
public void processModuleSubStatementMandatory() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container'," +
|
||||
" 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
|
||||
" 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference'," +
|
||||
" 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
thrown.expectMessage("mismatched input 'mandatory' expecting {'augment', 'choice', 'contact', 'container',"
|
||||
+ " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
|
||||
+ " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference',"
|
||||
+ " 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementMandatory.yang");
|
||||
}
|
||||
}
|
@ -62,8 +62,8 @@ public class MaxElementsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getMaxElelements(), is(3));
|
||||
@ -99,9 +99,9 @@ public class MaxElementsListenerTest {
|
||||
@Test
|
||||
public void processMaxElementsInvalidStatement() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("extraneous input 'max-element' expecting {'config', 'description', 'if-feature'," +
|
||||
" 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units', " +
|
||||
"'when', '}'}");
|
||||
thrown.expectMessage("extraneous input 'max-element' expecting {'config', 'description', 'if-feature',"
|
||||
+ " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units', "
|
||||
+ "'when', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/MaxElementsInvalidStatement.yang");
|
||||
}
|
||||
|
||||
@ -145,8 +145,8 @@ public class MaxElementsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getMaxElelements(), is(2147483647));
|
||||
|
@ -62,8 +62,8 @@ public class MinElementsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getMinElements(), is(3));
|
||||
@ -99,9 +99,9 @@ public class MinElementsListenerTest {
|
||||
@Test
|
||||
public void processMinElementsInvalidKeyword() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("extraneous input 'min-element' expecting {'config', 'description', 'if-feature'," +
|
||||
" 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units'," +
|
||||
" 'when', '}'}");
|
||||
thrown.expectMessage("extraneous input 'min-element' expecting {'config', 'description', 'if-feature',"
|
||||
+ " 'max-elements', 'min-elements', 'must', 'ordered-by', 'reference', 'status', 'type', 'units',"
|
||||
+ " 'when', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidKeyword.yang");
|
||||
}
|
||||
|
||||
@ -134,8 +134,8 @@ public class MinElementsListenerTest {
|
||||
@Test
|
||||
public void processMinElementsInvalidCardinality() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("Internal parser error detected: Invalid cardinality in" +
|
||||
" min-elements before processing.");
|
||||
thrown.expectMessage(
|
||||
"Internal parser error detected: Invalid cardinality in" + " min-elements before processing.");
|
||||
YangNode node = manager.getDataModel("src/test/resources/MinElementsInvalidCardinality.yang");
|
||||
}
|
||||
}
|
@ -66,8 +66,8 @@ public class ReferenceListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the reference is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -174,8 +174,8 @@ public class ReferenceListenerTest {
|
||||
assertThat(container.getReference(), is("\"container reference\""));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -211,8 +211,8 @@ public class ReferenceListenerTest {
|
||||
assertThat(yangList.getReference(), is("\"list reference\""));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -242,8 +242,8 @@ public class ReferenceListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
// Check whether description value is set correctly.
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
|
@ -66,8 +66,8 @@ public class StatusListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the status is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -92,8 +92,8 @@ public class StatusListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the status is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -118,8 +118,8 @@ public class StatusListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether the status is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -152,10 +152,10 @@ public class StatusListenerTest {
|
||||
@Test
|
||||
public void processModuleSubStatementStatus() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("mismatched input 'status' expecting {'augment', 'choice', 'contact', 'container', " +
|
||||
"'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include'," +
|
||||
" 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference', " +
|
||||
"'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
thrown.expectMessage("mismatched input 'status' expecting {'augment', 'choice', 'contact', 'container', "
|
||||
+ "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include',"
|
||||
+ " 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', 'prefix', 'reference', "
|
||||
+ "'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementStatus.yang");
|
||||
}
|
||||
|
||||
@ -184,8 +184,8 @@ public class StatusListenerTest {
|
||||
assertThat(container.getStatus(), is(YangStatusType.OBSOLETE));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = container.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -221,8 +221,8 @@ public class StatusListenerTest {
|
||||
assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
|
||||
|
||||
// Check whether leaf properties as set correctly.
|
||||
ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangList.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -252,8 +252,8 @@ public class StatusListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
// Check whether status is set correctly.
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
|
@ -41,8 +41,8 @@ public class TypeListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"hello\""));
|
||||
@ -67,8 +67,8 @@ public class TypeListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
@ -93,8 +93,8 @@ public class TypeListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafListInfo.getDataType().getDataTypeName(), is("\"uint16\""));
|
||||
|
@ -64,8 +64,8 @@ public class UnitsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether units value is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -78,10 +78,10 @@ public class UnitsListenerTest {
|
||||
@Test
|
||||
public void processModuleSubStatementUnits() throws IOException, ParserException {
|
||||
thrown.expect(ParserException.class);
|
||||
thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', " +
|
||||
"'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', " +
|
||||
"'include', 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', " +
|
||||
"'prefix', 'reference', 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
thrown.expectMessage("mismatched input 'type' expecting {'augment', 'choice', 'contact', 'container', "
|
||||
+ "'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', "
|
||||
+ "'include', 'leaf', 'leaf-list', 'list', 'namespace', 'notification', 'organization', "
|
||||
+ "'prefix', 'reference', 'revision', 'rpc', 'typedef', 'uses', 'yang-version', '}'}");
|
||||
YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementUnits.yang");
|
||||
}
|
||||
|
||||
@ -113,8 +113,8 @@ public class UnitsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
// Check whether leaf properties is set correctly.
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
@ -145,8 +145,8 @@ public class UnitsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf leafInfo = leafIterator.next();
|
||||
ListIterator<YangLeaf<?>> leafIterator = yangNode.getListOfLeaf().listIterator();
|
||||
YangLeaf<?> leafInfo = leafIterator.next();
|
||||
|
||||
assertThat(leafInfo.getLeafName(), is("invalid-interval"));
|
||||
assertThat(leafInfo.getUnits(), is(nullValue()));
|
||||
@ -180,8 +180,8 @@ public class UnitsListenerTest {
|
||||
YangModule yangNode = (YangModule) node;
|
||||
assertThat(yangNode.getName(), is("Test"));
|
||||
|
||||
ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList leafListInfo = leafListIterator.next();
|
||||
ListIterator<YangLeafList<?>> leafListIterator = yangNode.getListOfLeafList().listIterator();
|
||||
YangLeafList<?> leafListInfo = leafListIterator.next();
|
||||
|
||||
// Check whether units value is set correctly.
|
||||
assertThat(leafListInfo.getLeafName(), is("invalid-interval"));
|
||||
|
@ -31,7 +31,7 @@ public class YangFileScannerTest {
|
||||
|
||||
private final Logger log = getLogger(getClass());
|
||||
|
||||
String baseDir = "target/UnitTestCase";
|
||||
private static final String BASEDIR = "target/UnitTestCase";
|
||||
|
||||
/**
|
||||
* Checks an empty directory.
|
||||
@ -39,9 +39,9 @@ public class YangFileScannerTest {
|
||||
@Test
|
||||
public void testWithSingleEmptyDirectoryInRoot() {
|
||||
try {
|
||||
File dir = new File(baseDir);
|
||||
File dir = new File(BASEDIR);
|
||||
dir.mkdirs();
|
||||
List<String> list = YangFileScanner.getYangFiles(baseDir.toString());
|
||||
List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
|
||||
} catch (IOException e) {
|
||||
log.info("IO Exception throwed");
|
||||
}
|
||||
@ -63,7 +63,7 @@ public class YangFileScannerTest {
|
||||
File firstpath2 = createDirectory(dir2);
|
||||
File firstpath3 = createDirectory(dir3);
|
||||
File firstpath4 = createDirectory(dir4);
|
||||
List<String> list = YangFileScanner.getYangFiles(baseDir.toString());
|
||||
List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
|
||||
} catch (IOException e) {
|
||||
log.info("IO Exception throwed");
|
||||
}
|
||||
@ -79,7 +79,7 @@ public class YangFileScannerTest {
|
||||
String firstFileName1 = "secondFile.yang";
|
||||
File firstpath1 = createDirectory(dir1);
|
||||
createFile(firstpath1, firstFileName1);
|
||||
List<String> list = YangFileScanner.getYangFiles(baseDir.toString());
|
||||
List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
|
||||
} catch (IOException e) {
|
||||
log.info("IO Exception throwed");
|
||||
}
|
||||
@ -101,7 +101,7 @@ public class YangFileScannerTest {
|
||||
createFile(firstpath2, firstFileName3);
|
||||
createFile(firstpath2, firstFileName4);
|
||||
createFile(firstpath2, firstFileName5);
|
||||
List<String> list = YangFileScanner.getYangFiles(baseDir.toString());
|
||||
List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
|
||||
} catch (IOException e) {
|
||||
log.info("IO Exception throwed");
|
||||
}
|
||||
@ -143,7 +143,49 @@ public class YangFileScannerTest {
|
||||
createFile(dir6, firstFileName3);
|
||||
createFile(dir6, firstFileName4);
|
||||
createFile(dir6, firstFileName5);
|
||||
List<String> list = YangFileScanner.getYangFiles(baseDir.toString());
|
||||
List<String> list = YangFileScanner.getYangFiles(BASEDIR.toString());
|
||||
} catch (IOException e) {
|
||||
log.info("IO Exception throwed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks multi directories with many .java file.
|
||||
*/
|
||||
@Test
|
||||
public void testWithMultiDirectoriesMultiJavaFiles() {
|
||||
try {
|
||||
String dir2 = "newDir1/newDir2/newDir3/newDir4";
|
||||
File dir3 = new File("target/UnitTestCase/newDir1");
|
||||
File dir4 = new File("target/UnitTestCase/newDir1/newDir2");
|
||||
File dir5 = new File("target/UnitTestCase/newDir1/newDir2/newDir3");
|
||||
File dir6 = new File("target/UnitTestCase/newDir1/newDir2/newDir3/newDir4");
|
||||
String firstFileName2 = "thirdFile.java";
|
||||
String firstFileName3 = "fourthFile.java";
|
||||
String firstFileName4 = "fifthFile.java";
|
||||
String firstFileName5 = "sixthFile.java";
|
||||
File firstpath2 = createDirectory(dir2);
|
||||
createFile(firstpath2, firstFileName2);
|
||||
createFile(firstpath2, firstFileName3);
|
||||
createFile(firstpath2, firstFileName4);
|
||||
createFile(dir3, firstFileName5);
|
||||
createFile(dir3, firstFileName2);
|
||||
createFile(dir3, firstFileName3);
|
||||
createFile(dir3, firstFileName4);
|
||||
createFile(dir3, firstFileName5);
|
||||
createFile(dir4, firstFileName2);
|
||||
createFile(dir4, firstFileName3);
|
||||
createFile(dir4, firstFileName4);
|
||||
createFile(dir4, firstFileName5);
|
||||
createFile(dir5, firstFileName2);
|
||||
createFile(dir5, firstFileName3);
|
||||
createFile(dir5, firstFileName4);
|
||||
createFile(dir5, firstFileName5);
|
||||
createFile(dir6, firstFileName2);
|
||||
createFile(dir6, firstFileName3);
|
||||
createFile(dir6, firstFileName4);
|
||||
createFile(dir6, firstFileName5);
|
||||
List<String> list = YangFileScanner.getJavaFiles(BASEDIR.toString());
|
||||
} catch (IOException e) {
|
||||
log.info("IO Exception throwed");
|
||||
}
|
||||
@ -156,18 +198,18 @@ public class YangFileScannerTest {
|
||||
* @return directory path
|
||||
*/
|
||||
public File createDirectory(String path) {
|
||||
File myDir = new File(baseDir + File.separator + path);
|
||||
File myDir = new File(BASEDIR + File.separator + path);
|
||||
myDir.mkdirs();
|
||||
return myDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method used for creating file inside the specified directory.
|
||||
*
|
||||
* @param myDir my current dirctory
|
||||
* @param fileName file name
|
||||
* @throws IOException io exception when fails to create a file.
|
||||
*/
|
||||
* Method used for creating file inside the specified directory.
|
||||
*
|
||||
* @param myDir my current dirctory
|
||||
* @param fileName file name
|
||||
* @throws IOException io exception when fails to create a file.
|
||||
*/
|
||||
public void createFile(File myDir, String fileName) throws IOException {
|
||||
File file = null;
|
||||
try {
|
Loading…
x
Reference in New Issue
Block a user