Gaurav Agrawal
Committed by Gerrit Code Review

Optimizing Generate Code Function in Translator and updating enum/union to suppo…

…rt a special hierarchical scenario

Change-Id: I14a971ff6fcda6ae5e86ffe4c11d17a844e371ce
Showing 20 changed files with 442 additions and 365 deletions
......@@ -31,18 +31,19 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents the enumeration data type information.
*/
public class YangEnumeration implements Parsable {
public class YangEnumeration extends YangNode implements Parsable {
// Enumeration info set.
private Set<YangEnum> enumSet;
// Enumeration name.
private String enumerationName;
private String name;
/**
* Creates an enumeration object.
*/
public YangEnumeration() {
super(YangNodeType.ENUMERATION_NODE);
setEnumSet(new HashSet<YangEnum>());
}
......@@ -77,21 +78,23 @@ public class YangEnumeration implements Parsable {
}
/**
* Return enumeration name.
* Returns enumeration name.
*
* @return the enumeration name
*/
public String getEnumerationName() {
return enumerationName;
@Override
public String getName() {
return name;
}
/**
* Sets the enumeration name.
*
* @param enumerationName enumeration name
* @param name enumeration name
*/
public void setEnumerationName(String enumerationName) {
this.enumerationName = enumerationName;
@Override
public void setName(String name) {
this.name = name;
}
/**
......
......@@ -95,6 +95,11 @@ public enum YangNodeType {
RPC_NODE,
/**
* Node contains "YANG's union" information.
*/
UNION_NODE,
/**
* Node contains "YANG's list" information.
*/
LIST_NODE
......
......@@ -16,13 +16,13 @@
package org.onosproject.yangutils.datamodel;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
import java.util.LinkedList;
import java.util.List;
/*
* Reference RFC 6020.
*
......@@ -48,19 +48,24 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG union.
*/
public class YangUnion implements Parsable {
public class YangUnion extends YangNode implements Parsable {
// List of YANG type.
private List<YangType<?>> typeList;
// Name of union.
private String unionName;
private String name;
// Current child union number.
private int childUnionNumber;
/**
* Creates a YANG union node.
*/
public YangUnion() {
super(YangNodeType.UNION_NODE);
typeList = new LinkedList<>();
childUnionNumber = 1;
}
/**
......@@ -73,31 +78,40 @@ public class YangUnion implements Parsable {
}
/**
* Returns union name.
* Sets the list of YANG type.
*
* @return the union name
* @param typeList list of YANG type.
*/
public String getUnionName() {
return unionName;
public void setTypeList(List<YangType<?>> typeList) {
this.typeList = typeList;
}
/**
* Sets the list of YANG type.
* Returns running child union number.
*
* @param typeList list of YANG type.
* @return running child union number
*/
public void setTypeList(List<YangType<?>> typeList) {
this.typeList = typeList;
public int getChildUnionNumber() {
return childUnionNumber;
}
/**
* Sets the running child union number.
*
* @param childUnionNumber running child union number
*/
public void setChildUnionNumber(int childUnionNumber) {
this.childUnionNumber = childUnionNumber;
}
/**
* Adds YANG type to type list.
* Add YANG type to type list.
*
* @param yangType YANG type to be added to list
* @throws DataModelException union member type must not be one of the
* built-in types "empty" or "leafref"
*/
public void addToTypeList(YangType<?> yangType) throws DataModelException {
public void addType(YangType<?> yangType) throws DataModelException {
if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) {
throw new DataModelException("Union member type must not be one of the built-in types \"empty\" or " +
"\"leafref\"");
......@@ -106,12 +120,23 @@ public class YangUnion implements Parsable {
}
/**
* Returns union name.
*
* @return the union name
*/
@Override
public String getName() {
return name;
}
/**
* Sets the union name.
*
* @param unionName name of the union.
* @param name union name
*/
public void setUnionName(String unionName) {
this.unionName = unionName;
@Override
public void setName(String name) {
this.name = name;
}
@Override
......
......@@ -44,19 +44,25 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangEnumeration;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.ENUMERATION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
......@@ -69,6 +75,11 @@ import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
public final class EnumerationListener {
/**
* Suffix to be used while creating enumeration class.
*/
private static final String ENUMERATION_CLASS_SUFFIX = "_enum";
/**
* Creates a new enumeration listener.
*/
private EnumerationListener() {
......@@ -98,15 +109,48 @@ public final class EnumerationListener {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
enumerationNode.setEnumerationName(((YangLeaf) tmpData).getLeafName());
// Set the name of enumeration same as leaf.
enumerationNode.setName(((YangLeaf) tmpData).getLeafName() + ENUMERATION_CLASS_SUFFIX);
// Pop the stack entry to obtain the parent YANG node.
Parsable leaf = listener.getParsedDataStack().pop();
// Add the enumeration node to the parent holder of leaf.
addChildToParentNode(listener, enumerationNode);
// Push the popped entry back to the stack.
listener.getParsedDataStack().push(leaf);
break;
case LEAF_LIST_DATA:
enumerationNode.setEnumerationName(((YangLeafList) tmpData).getLeafName());
// Set the name of enumeration same as leaf list.
enumerationNode.setName(((YangLeafList) tmpData).getLeafName() + ENUMERATION_CLASS_SUFFIX);
// Pop the stack entry to obtain the parent YANG node.
Parsable leafList = listener.getParsedDataStack().pop();
// Add the enumeration node to the parent holder of leaf.
addChildToParentNode(listener, enumerationNode);
// Push the popped entry back to the stack.
listener.getParsedDataStack().push(leafList);
break;
case UNION_DATA:
enumerationNode.setEnumerationName(((YangUnion) tmpData).getUnionName());
YangUnion yangUnion = (YangUnion) tmpData;
/*
* In case parent of enumeration is a union, name of the
* enumeration is parent union name suffixed with running
* integer number, this is done because under union there
* could be multiple child union types.
*/
enumerationNode.setName(yangUnion.getName() + yangUnion.getChildUnionNumber()
+ ENUMERATION_CLASS_SUFFIX);
// Increment the running number.
yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1);
// Add union as a child to parent union.
addChildToParentNode(listener, enumerationNode);
break;
// TODO typedef, deviate.
case TYPEDEF_DATA:
YangTypeDef typeDef = (YangTypeDef) tmpData;
// Set the name of enumeration same as typedef name.
enumerationNode.setName(typeDef.getName() + ENUMERATION_CLASS_SUFFIX);
// Add enumeration as a child to parent type def.
addChildToParentNode(listener, enumerationNode);
break;
// TODO deviate.
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
((YangType<?>) typeData).getDataTypeName(), ENTRY));
......@@ -155,4 +199,25 @@ public final class EnumerationListener {
constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUMERATION_DATA, "", EXIT));
}
}
/**
* Adds the enumeration node to the parent holder.
*
* @param listener listener's object
* @param enumerationNode enumeration node which needs to be added to parent
*/
private static void addChildToParentNode(TreeWalkListener listener, YangEnumeration enumerationNode) {
if (!(listener.getParsedDataStack().peek() instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA,
"", ENTRY));
} else {
YangNode curNode = (YangNode) listener.getParsedDataStack().peek();
try {
curNode.addChild(enumerationNode);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
YangConstructType.ENUMERATION_DATA, "", ENTRY, e.getMessage()));
}
}
}
}
......
......@@ -204,7 +204,7 @@ public final class TypeListener {
case UNION_DATA:
YangUnion unionNode = (YangUnion) tmpData;
try {
unionNode.addToTypeList((YangType<?>) type);
unionNode.addType((YangType<?>) type);
} catch (DataModelException e) {
ParserException parserException = new ParserException(e.getMessage());
parserException.setLine(ctx.getStart().getLine());
......
......@@ -42,19 +42,25 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUnion;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNION_DATA;
......@@ -66,6 +72,11 @@ import static org.onosproject.yangutils.utils.YangConstructType.UNION_DATA;
public final class UnionListener {
/**
* Suffix to be used while creating union class.
*/
private static final String UNION_CLASS_SUFFIX = "_union";
/**
* Creates a new union listener.
*/
private UnionListener() {
......@@ -95,15 +106,47 @@ public final class UnionListener {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
unionNode.setUnionName(((YangLeaf) tmpData).getLeafName());
// Set the name of union same as leaf.
unionNode.setName(((YangLeaf) tmpData).getLeafName() + UNION_CLASS_SUFFIX);
// Pop the stack entry to obtain the parent YANG node.
Parsable leaf = listener.getParsedDataStack().pop();
// Add the union node to the parent holder of leaf.
addChildToParentNode(listener, unionNode);
// Push the popped entry back to the stack.
listener.getParsedDataStack().push(leaf);
break;
case LEAF_LIST_DATA:
unionNode.setUnionName(((YangLeafList) tmpData).getLeafName());
// Set the name of union same as leaf list.
unionNode.setName(((YangLeafList) tmpData).getLeafName() + UNION_CLASS_SUFFIX);
// Pop the stack entry to obtain the parent YANG node.
Parsable leafList = listener.getParsedDataStack().pop();
// Add the union node to the parent holder of leaf.
addChildToParentNode(listener, unionNode);
// Push the popped entry back to the stack.
listener.getParsedDataStack().push(leafList);
break;
case UNION_DATA:
unionNode.setUnionName(((YangUnion) tmpData).getUnionName());
YangUnion parentUnion = (YangUnion) tmpData;
/*
* In case parent of union is again a union, name of the
* child union is parent union name suffixed with running
* integer number, this is done because under union there
* could be multiple child union types.
*/
unionNode.setName(parentUnion.getName() + UNION_CLASS_SUFFIX + parentUnion.getChildUnionNumber());
// Increment the running number.
parentUnion.setChildUnionNumber(parentUnion.getChildUnionNumber() + 1);
// Add union as a child to parent union.
addChildToParentNode(listener, unionNode);
break;
// TODO typedef, deviate.
case TYPEDEF_DATA:
YangTypeDef typeDef = (YangTypeDef) tmpData;
// Set the name of union same as typedef name.
unionNode.setName(typeDef.getName() + UNION_CLASS_SUFFIX);
// Add union as a child to parent type def.
addChildToParentNode(listener, unionNode);
break;
// TODO deviate.
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
((YangType<?>) typeData).getDataTypeName(), ENTRY));
......@@ -152,4 +195,25 @@ public final class UnionListener {
constructListenerErrorMessage(MISSING_CURRENT_HOLDER, UNION_DATA, "", EXIT));
}
}
/**
* Adds the union node to the parent holder.
*
* @param listener listener's object
* @param unionNode union node which needs to be added to parent
*/
private static void addChildToParentNode(TreeWalkListener listener, YangUnion unionNode) {
if (!(listener.getParsedDataStack().peek() instanceof YangNode)) {
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNION_DATA,
"", ENTRY));
} else {
YangNode curNode = (YangNode) listener.getParsedDataStack().peek();
try {
curNode.addChild(unionNode);
} catch (DataModelException e) {
throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
YangConstructType.UNION_DATA, "", ENTRY, e.getMessage()));
}
}
}
}
\ No newline at end of file
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
/**
* Represents YANG java info containing interface for java code generator, java
* file information, java import data and temp java code fragment files. This
* interface serves as a generic interface and help to unify the generate code
* entry function.
*/
public interface JavaCodeGeneratorInfo extends HasJavaFileInfo, HasTempJavaCodeFragmentFiles, HasJavaImportData {
}
......@@ -16,30 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents augment information extended to support java code generation.
*/
public class YangJavaAugment extends YangAugment
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaAugment extends YangAugment implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -142,28 +132,11 @@ public class YangJavaAugment extends YangAugment
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
generateCodeOfNode(this, codeGenDir, false);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*/
@Override
public void generateCodeExit() {
......
......@@ -16,30 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents case information extended to support java code generation.
*/
public class YangJavaCase extends YangCase
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaCase extends YangCase implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -75,7 +65,6 @@ public class YangJavaCase extends YangCase
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -142,28 +131,11 @@ public class YangJavaCase extends YangCase
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
generateCodeOfNode(this, codeGenDir, false);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*/
@Override
public void generateCodeExit() {
......
......@@ -16,30 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents choice information extended to support java code generation.
*/
public class YangJavaChoice extends YangChoice
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaChoice extends YangChoice implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -75,7 +65,6 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -142,28 +131,12 @@ public class YangJavaChoice extends YangChoice
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
generateCodeOfNode(this, codeGenDir, false);
// TODO:getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*/
@Override
public void generateCodeExit() {
......
......@@ -16,30 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents container information extended to support java code generation.
*/
public class YangJavaContainer extends YangContainer
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaContainer extends YangContainer implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -75,7 +65,6 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -142,28 +131,11 @@ public class YangJavaContainer extends YangContainer
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
generateCodeOfNode(this, codeGenDir, false);
}
/**
* Create a java file using the YANG grouping info.
* Create a java file using the YANG container info.
*
* @throws IOException IO operation fail
*/
......
......@@ -16,30 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents grouping information extended to support java code generation.
*/
public class YangJavaGrouping extends YangGrouping
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaGrouping extends YangGrouping implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -75,7 +65,6 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -142,28 +131,11 @@ public class YangJavaGrouping extends YangGrouping
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
generateCodeOfNode(this, codeGenDir, false);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*/
@Override
public void generateCodeExit() {
......
......@@ -17,31 +17,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents input information extended to support java code generation.
*/
public class YangJavaInput extends YangInput
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaInput extends YangInput implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains information of the java file being generated.
......@@ -77,7 +66,6 @@ public class YangJavaInput extends YangInput
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -144,28 +132,11 @@ public class YangJavaInput extends YangInput
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
createPackage(absloutePath, getName());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
generateCodeOfNode(this, codeGenDir, false);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*
* @throws IOException IO operation fail
*/
......
......@@ -16,31 +16,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents YANG List information extended to support java code generation.
* Represents YANG list information extended to support java code generation.
*/
public class YangJavaList extends YangList
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaList extends YangList implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -76,7 +65,6 @@ public class YangJavaList extends YangList
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -143,30 +131,11 @@ public class YangJavaList extends YangList
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
createPackage(absloutePath, getName());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, true);
generateCodeOfNode(this, codeGenDir, true);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*
* @throws IOException IO operation fail
*/
......
......@@ -16,30 +16,21 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents module information extended to support java code generation.
*/
public class YangJavaModule extends YangModule
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -59,7 +50,7 @@ public class YangJavaModule extends YangModule
private TempJavaCodeFragmentFiles tempFileHandle;
/**
* Create a YANG node of module type.
* Creates a YANG node of module type.
*/
public YangJavaModule() {
super();
......@@ -75,7 +66,6 @@ public class YangJavaModule extends YangModule
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -141,23 +131,8 @@ public class YangJavaModule extends YangModule
*/
@Override
public void generateCodeEntry(String baseCodeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getRootPackage(getVersion(), getNameSpace().getUri(),
getRevision().getRevDate()));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(baseCodeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate());
YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, modulePkg);
}
@Override
......
......@@ -17,31 +17,20 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents output information extended to support java code generation.
*/
public class YangJavaOutput extends YangOutput
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaOutput extends YangOutput implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains information of the java file being generated.
......@@ -77,7 +66,6 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -144,28 +132,11 @@ public class YangJavaOutput extends YangOutput
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getCurNodePackage(this));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
createPackage(absloutePath, getName());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
getTempJavaCodeFragmentFiles().addCurNodeInfoInParentTempFile(this, false);
generateCodeOfNode(this, codeGenDir, false);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*
* @throws IOException IO operation fail
*/
......
......@@ -16,31 +16,22 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.HasJavaFileInfo;
import org.onosproject.yangutils.translator.tojava.HasJavaImportData;
import org.onosproject.yangutils.translator.tojava.HasTempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents Sub module information extended to support java code generation.
* Represents sub module information extended to support java code generation.
*/
public class YangJavaSubModule extends YangSubModule
implements JavaCodeGenerator, HasJavaFileInfo,
HasJavaImportData, HasTempJavaCodeFragmentFiles {
public class YangJavaSubModule extends YangSubModule implements JavaCodeGeneratorInfo, JavaCodeGenerator {
/**
* Contains the information of the java file being generated.
......@@ -76,7 +67,6 @@ public class YangJavaSubModule extends YangSubModule
*/
@Override
public JavaFileInfo getJavaFileInfo() {
if (javaFileInfo == null) {
throw new TranslatorException("Missing java info in java datamodel node");
}
......@@ -150,33 +140,18 @@ public class YangJavaSubModule extends YangSubModule
* Prepare the information for java code generation corresponding to YANG
* container info.
*
* @param codeGenDir code generation directory
* @param baseCodeGenDir code generation directory
* @throws IOException IO operation fail
*/
@Override
public void generateCodeEntry(String codeGenDir) throws IOException {
getJavaFileInfo().setJavaName(getCaptialCase(getCamelCase(getName())));
getJavaFileInfo().setPackage(getRootPackage(getVersion(),
getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate()));
getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(getJavaFileInfo().getPackage()));
getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
String absloutePath = getAbsolutePackagePath(
getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath());
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(
getJavaFileInfo().getGeneratedFileTypes(), absloutePath,
getJavaFileInfo().getJavaName()));
getTempJavaCodeFragmentFiles().addCurNodeLeavesInfoToTempFiles(this);
public void generateCodeEntry(String baseCodeGenDir) throws IOException {
String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate());
YangJavaModelUtils.generateCodeOfRootNode(this, baseCodeGenDir, subModulePkg);
}
/**
* Create a java file using the YANG grouping info.
* Creates a java file using the YANG grouping info.
*/
@Override
public void generateCodeExit() {
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents utility class for YANG java model.
*/
public final class YangJavaModelUtils {
/**
* Creates YANG java model utility.
*/
private YangJavaModelUtils() {
}
/**
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param codeGenDir code generation directory
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName())));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
}
/**
* Updates YANG java file package information for specified package.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param codeGenDir code generation directory
* @throws IOException IO operations fails
*/
private static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir, String pkg)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName())));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(pkg);
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(codeGenDir);
}
/**
* Updates temporary java code fragment files.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @throws IOException IO operations fails
*/
private static void createTempFragmentFile(JavaCodeGeneratorInfo javaCodeGeneratorInfo) throws IOException {
String absolutePath = getAbsolutePackagePath(javaCodeGeneratorInfo.getJavaFileInfo().getBaseCodeGenPath(),
javaCodeGeneratorInfo.getJavaFileInfo().getPackageFilePath());
javaCodeGeneratorInfo.setTempJavaCodeFragmentFiles(
new TempJavaCodeFragmentFiles(javaCodeGeneratorInfo.getJavaFileInfo().getGeneratedFileTypes(),
absolutePath, javaCodeGeneratorInfo.getJavaFileInfo().getJavaName()));
}
/**
* Updates leaf information in temporary java code fragment files.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @throws IOException IO operations fails
*/
private static void updateLeafInfoInTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
throws IOException {
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
} else {
// TODO: either write a util for ENUM and UNION or, call the
// corresponding implementation in ENUM and UNION
}
}
/**
* Process generate code entry of YANG node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param codeGenDir code generation directory
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
createTempFragmentFile(javaCodeGeneratorInfo);
updateLeafInfoInTempFragmentFiles(javaCodeGeneratorInfo);
}
/**
* Process generate code entry of YANG node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param codeGenDir code generation directory
* @param isMultiInstance flag to indicate whether it's a list
* @throws IOException IO operations fails
*/
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir,
boolean isMultiInstance) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, codeGenDir);
generateTempFiles(javaCodeGeneratorInfo, codeGenDir);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
}
/**
* Process generate code entry of root node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param codeGenDir code generation directory
* @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir,
String rootPkg) throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, codeGenDir, rootPkg);
generateTempFiles(javaCodeGeneratorInfo, codeGenDir);
}
}
......@@ -64,8 +64,8 @@ public class EnumListenerTest {
assertThat(leafInfo.getLeafName(), is("speed"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(),
is("speed"));
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
is("speed_enum"));
Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
for (YangEnum tmp : enumSet) {
......
......@@ -64,8 +64,8 @@ public class ValueListenerTest {
assertThat(leafInfo.getLeafName(), is("speed"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(),
is("speed"));
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
is("speed_enum"));
Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
for (YangEnum tmp : enumSet) {
......@@ -103,8 +103,8 @@ public class ValueListenerTest {
assertThat(leafInfo.getLeafName(), is("speed"));
assertThat(leafInfo.getDataType().getDataTypeName(), is("enumeration"));
assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.ENUMERATION));
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumerationName(),
is("speed"));
assertThat(((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getName(),
is("speed_enum"));
Set<YangEnum> enumSet = ((YangEnumeration) leafInfo.getDataType().getDataTypeExtendedInfo()).getEnumSet();
for (YangEnum tmp : enumSet) {
......