VinodKumarS-Huawei
Committed by Ray Milkey

[ONOS-4303, ONOS-4508, ONOS-4509, ONOS-4510, ONOS-4351]notification,rpc,union,sub-module,augment

Change-Id: Ibeed9ff965c13fd66743c1080cb1350d93a3a435
Showing 43 changed files with 2213 additions and 931 deletions
......@@ -54,7 +54,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG typedef.
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeContainer {
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder {
/**
* Default value in string, needs to be converted to the target object,
......
......@@ -21,7 +21,7 @@ import java.util.List;
/**
* Represents the holder with type(s).
*/
public interface YangTypeContainer {
public interface YangTypeHolder {
/**
* Returns type list.
......
......@@ -47,7 +47,7 @@ import org.onosproject.yangutils.utils.YangConstructType;
/**
* Represents data model node to maintain information defined in YANG union.
*/
public class YangUnion extends YangNode implements Parsable, YangTypeContainer {
public class YangUnion extends YangNode implements Parsable, YangTypeHolder {
// List of YANG type.
private List<YangType<?>> typeList;
......
......@@ -19,13 +19,14 @@ package org.onosproject.yangutils.datamodel.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
......@@ -222,4 +223,21 @@ public final class DataModelUtils {
resolutionInfo.resolveLinkingForResolutionInfo(dataModelRootNode.getPrefix());
}
}
/**
* Checks if there is any rpc defined in the module or sub-module.
*
* @param rootNode root node of the data model
* @return status of rpc's existence
*/
public static boolean isRpcChildNodePresent(YangNode rootNode) {
YangNode childNode = rootNode.getChild();
while (childNode != null) {
if (childNode instanceof YangRpc) {
return true;
}
childNode = childNode.getNextSibling();
}
return false;
}
}
......
......@@ -46,7 +46,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
......@@ -127,8 +127,8 @@ public class YangUtilManager extends AbstractMojo {
/**
* For deleting the generated code in previous build.
*/
clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
clean(getDirectory(baseDir, outputDirectory));
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, outputDirectory));
String searchDir = getDirectory(baseDir, yangFilesDir);
String codeGenDir = getDirectory(baseDir, genFilesDir) + SLASH;
......@@ -166,7 +166,7 @@ public class YangUtilManager extends AbstractMojo {
} catch (Exception e) {
try {
translatorErrorHandler(getRootNode());
clean(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
} catch (IOException | DataModelException ex) {
throw new MojoExecutionException("Error handler failed to delete files for data model node.");
}
......
......@@ -50,15 +50,7 @@ public final class GeneratedJavaFileType {
/**
* Java interface corresponding to rpc.
*/
public static final int GENERATE_RPC_INTERFACE = 16;
/**
* Interface, class file and rpc.
*/
public static final int GENERATE_MANAGER_WITH_RPC = GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_RPC_INTERFACE;
// TODO RPC implementation to be integrated with notification.
public static final int GENERATE_SERVICE_AND_MANAGER = 16;
/**
* Java class corresponding to YANG enumeration.
......@@ -82,6 +74,16 @@ public final class GeneratedJavaFileType {
| GENERATE_UNION_CLASS;
/**
* Event class.
*/
public static final int GENERATE_EVENT_CLASS = 256;
/**
* Event listener class.
*/
public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
/**
* Creates an instance of generate java file type.
*/
private GeneratedJavaFileType() {
......
......@@ -87,9 +87,14 @@ public final class GeneratedTempFileType {
public static final int ENUM_IMPL_MASK = 4096;
/**
* Rpc implementation of class.
* Rpc interface of module / sub module.
*/
public static final int RPC_IMPL_MASK = 8192;
public static final int RPC_INTERFACE_MASK = 8192;
/**
* Rpc implementation of module / sub module.
*/
public static final int RPC_IMPL_MASK = 16384;
/**
* Creates an instance of generated temp file type.
......
......@@ -31,13 +31,14 @@ public interface JavaCodeGenerator {
* @param yangPlugin YANG plugin config
* @throws IOException when fails to translate the data model tree
*/
void generateCodeEntry(YangPluginConfig yangPlugin) throws IOException;
void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException;
/**
* Traverse the schema of application and generate corresponding code.
*
* @throws IOException when fails to generate java code
*/
void generateCodeExit() throws IOException;
void generateCodeExit()
throws IOException;
}
......
......@@ -78,8 +78,23 @@ public final class JavaCodeGeneratorUtil {
while (codeGenNode != null) {
if (curTraversal != PARENT) {
if (codeGenNode instanceof JavaCodeGenerator) {
setCurNode(codeGenNode);
generateCodeEntry(codeGenNode, yangPlugin);
} else {
/*
* For grouping and uses, there is no code generation, skip the generation for the child.
*/
if (codeGenNode.getNextSibling() != null) {
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
continue;
}
}
if (curTraversal != PARENT && codeGenNode.getChild() != null) {
curTraversal = CHILD;
......@@ -238,7 +253,7 @@ public final class JavaCodeGeneratorUtil {
throws IOException {
if (((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles() != null) {
((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().close(true);
((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
}
}
}
......
......@@ -71,6 +71,17 @@ public class JavaFileInfo {
}
/**
* Adds 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 addGeneratedFileTypes(int fileTypes) {
genFileTypes |= fileTypes;
}
/**
* Returns the java name of the node.
*
* @return the java name of node
......
......@@ -16,15 +16,31 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for bean java snippet generation.
*/
public class TempJavaBeanFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for constructor.
*/
private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
/**
* Temporary file handle for constructor of class.
*/
private File constructorImplTempFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -32,6 +48,81 @@ public class TempJavaBeanFragmentFiles
*/
public TempJavaBeanFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
/*
* Initialize getterImpl, attributes, constructor, hash code, equals and
* to strings when generation file type matches to impl class mask.
*/
addGeneratedTempFile(CONSTRUCTOR_IMPL_MASK);
setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
}
/**
* Returns constructor's temporary file handle.
*
* @return temporary file handle
*/
public File getConstructorImplTempFileHandle() {
return constructorImplTempFileHandle;
}
/**
* Sets to constructor's temporary file handle.
*
* @param constructor file handle for to constructor
*/
private void setConstructorImplTempFileHandle(File constructor) {
constructorImplTempFileHandle = constructor;
}
/**
* Adds constructor for class.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addConstructor(JavaAttributeInfo attr)
throws IOException {
appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr,
getGeneratedJavaFiles()));
}
/**
* Adds the new attribute info to the target generated temporary files.
*
* @param newAttrInfo the attribute info that needs to be added to temporary
* files
* @throws IOException IO operation fail
*/
void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo);
addConstructor(newAttrInfo);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
@Override
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
/*
* Close constructor temporary file handle and delete the file.
*/
closeFile(getConstructorImplTempFileHandle(), true);
super.freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -18,18 +18,22 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeContainer;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
/**
* Represents implementation of java code fragments temporary implementations.
* Contains fragment file object of different types of java file.
* Uses required object(s) to generate the target java file(s).
*/
public class TempJavaCodeFragmentFiles {
......@@ -54,6 +58,17 @@ public class TempJavaCodeFragmentFiles {
private TempJavaEnumerationFragmentFiles enumerationTempFiles;
/**
* Has the temporary files required for generated event classes.
*/
private TempJavaEventFragmentFiles eventTempFiles;
/**
* Has the temporary files required for generated event listenerclasses.
*/
private TempJavaEventListenerFragmentFiles eventListenerTempFiles;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -80,9 +95,17 @@ public class TempJavaCodeFragmentFiles {
setEnumerationTempFiles(new TempJavaEnumerationFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_RPC_INTERFACE) != 0) {
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_CLASS) != 0) {
setEventTempFiles(new TempJavaEventFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
setEventListenerTempFiles(new TempJavaEventListenerFragmentFiles(javaFileInfo));
}
}
/**
......@@ -161,6 +184,43 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Retrieves the temp file handle for event file generation.
*
* @return temp file handle for event file generation
*/
public TempJavaEventFragmentFiles getEventTempFiles() {
return eventTempFiles;
}
/**
* Sets temp file handle for event file generation.
*
* @param eventTempFiles temp file handle for event file generation
*/
public void setEventTempFiles(TempJavaEventFragmentFiles eventTempFiles) {
this.eventTempFiles = eventTempFiles;
}
/**
* Retrieves the temp file handle for event listener file generation.
*
* @return temp file handle for event listener file generation
*/
public TempJavaEventListenerFragmentFiles getEventListenerTempFiles() {
return eventListenerTempFiles;
}
/**
* Sets temp file handle for event listener file generation.
*
* @param eventListenerTempFiles temp file handle for event listener file generation
*/
public void setEventListenerTempFiles(
TempJavaEventListenerFragmentFiles eventListenerTempFiles) {
this.eventListenerTempFiles = eventListenerTempFiles;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
......@@ -170,17 +230,42 @@ public class TempJavaCodeFragmentFiles {
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
if (getBeanTempFiles() != null) {
if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
getBeanTempFiles().generateJavaFile(fileType, curNode);
}
/**
* Creates user defined data type class file.
*/
if (getTypeTempFiles() != null) {
if ((fileType & GENERATE_TYPE_CLASS) != 0) {
getTypeTempFiles().generateJavaFile(fileType, curNode);
}
if (fileType == GENERATE_SERVICE_AND_MANAGER) {
getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
}
if ((fileType & GENERATE_EVENT_CLASS) != 0) {
/**
* Creates event class file.
*/
if (getEventTempFiles() != null) {
getEventTempFiles().generateJavaFile(fileType, curNode);
}
}
if ((fileType & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
/**
* Creates event listener class file.
*/
getEventListenerTempFiles().generateJavaFile(fileType, curNode);
}
freeTemporaryResources(false);
}
/**
......@@ -208,35 +293,16 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Adds all the leaves in the current data model node as part of the
* generated temporary file.
*
* @param curNode java file info of the generated file
* @throws IOException IO operation fail
*/
public void addCurNodeLeavesInfoToTempFiles(YangNode curNode)
throws IOException {
if (getBeanTempFiles() != null) {
getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(curNode);
}
}
/**
* Add all the type in the current data model node as part of the
* generated temporary file.
*
* @param yangTypeContainer YANG java data model node which has type info, eg union / typedef
* @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
* @throws IOException IO operation fail
*/
public void addTypeInfoToTempFiles(YangTypeContainer yangTypeContainer)
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
throws IOException {
if (getTypeTempFiles() != null) {
getTypeTempFiles()
.addTypeInfoToTempFiles(yangTypeContainer);
}
.addTypeInfoToTempFiles(yangTypeHolder);
}
/**
......@@ -307,19 +373,27 @@ public class TempJavaCodeFragmentFiles {
* all open file handles include temporary files and java files.
* @throws IOException when failed to delete the temporary files
*/
public void close(boolean isErrorOccurred)
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
if (getBeanTempFiles() != null) {
getBeanTempFiles().close(isErrorOccurred);
getBeanTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getTypeTempFiles() != null) {
getTypeTempFiles().close(isErrorOccurred);
getTypeTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEnumerationTempFiles() != null) {
getEnumerationTempFiles().close(isErrorOccurred);
getEnumerationTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventTempFiles() != null) {
getEventTempFiles().freeTemporaryResources(isErrorOccurred);
}
if (getEventListenerTempFiles() != null) {
getEventListenerTempFiles().freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -19,6 +19,7 @@ import java.io.IOException;
/**
* Represents implementation of java code fragments temporary implementations.
* Maintains the temp files required specific for enumeration java snippet generation.
*/
public class TempJavaEnumerationFragmentFiles
extends TempJavaFragmentFiles {
......
/*
* 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;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for event java snippet generation.
*/
public class TempJavaEventFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_FILE_NAME_SUFFIX = "Event";
/**
* Java file handle for event file.
*/
private File eventJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
clearGeneratedTempFileMask();
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/**
* Returns event's java file handle.
*
* @return java file handle
*/
private File getEventJavaFileHandle() {
return eventJavaFileHandle;
}
/**
* Sets event's java file handle.
*
* @param eventJavaFileHandle file handle for event
*/
private void setEventJavaFileHandle(File eventJavaFileHandle) {
this.eventJavaFileHandle = eventJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
/**
* Creates event interface file.
*/
setEventJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_FILE_NAME_SUFFIX)));
generateEventFile(getEventJavaFileHandle(), curNode, null);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
* Close all java file handles and when error occurs delete the files.
*/
closeFile(getEventJavaFileHandle(), isError);
super.freeTemporaryResources(isErrorOccurred);
}
}
/*
* 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;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents implementation of java bean code fragments temporary implementations.
* Maintains the temp files required specific for event listener java snippet generation.
*/
public class TempJavaEventListenerFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
/**
* Java file handle for event listener file.
*/
private File eventListenerJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
* @throws IOException when fails to create new file handle
*/
public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setExtendsList(new ArrayList<>());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
clearGeneratedTempFileMask();
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/**
* Returns event listeners's java file handle.
*
* @return java file handle
*/
private File getEventListenerJavaFileHandle() {
return eventListenerJavaFileHandle;
}
/**
* Sets event's java file handle.
*
* @param eventListenerJavaFileHandle file handle for event
*/
private void setEventListenerJavaFileHandle(File eventListenerJavaFileHandle) {
this.eventListenerJavaFileHandle = eventListenerJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
createPackage(curNode);
/**
* Creates event listener interface file.
*/
setEventListenerJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_LISTENER_FILE_NAME_SUFFIX)));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
* Close all java file handles and when error occurs delete the files.
*/
closeFile(getEventListenerJavaFileHandle(), isError);
super.freeTemporaryResources(isErrorOccurred);
}
}
......@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.YangTypeContainer;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangEnum;
import org.onosproject.yangutils.datamodel.YangEnumeration;
......@@ -29,37 +29,27 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
......@@ -69,9 +59,6 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateRpcInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -79,27 +66,20 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSy
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOverRideString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
.addImportsToStringAndHasCodeMethods;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
......@@ -113,7 +93,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
......@@ -121,15 +100,14 @@ import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPacka
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
/**
* Represents implementation of java code fragments temporary implementations.
* Manages the common temp file required for Java file(s) generated.
*/
public class TempJavaFragmentFiles {
/**
......@@ -150,7 +128,7 @@ public class TempJavaFragmentFiles {
*/
private String absoluteDirPath;
/**
* Contains all the class name which will be extended by generated files.
* Contains all the interface(s)/class name which will be extended by generated files.
*/
private List<String> extendsList = new ArrayList<>();
/**
......@@ -165,26 +143,27 @@ public class TempJavaFragmentFiles {
* Folder suffix for temporary files folder.
*/
private static final String TEMP_FOLDER_NAME_SUFIX = "-Temp";
/**
* File name for getter method.
*/
private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
/**
* File name for getter method implementation.
*/
private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
/**
* File name for setter method.
*/
private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
/**
* File name for setter method implementation.
* File name for getter method implementation.
*/
private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
private static final String GETTER_METHOD_IMPL_FILE_NAME = "GetterMethodImpl";
/**
* File name for constructor.
* File name for setter method implementation.
*/
private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
private static final String SETTER_METHOD_IMPL_FILE_NAME = "SetterMethodImpl";
/**
* File name for attributes.
*/
......@@ -201,22 +180,12 @@ public class TempJavaFragmentFiles {
* File name for equals method.
*/
private static final String EQUALS_METHOD_FILE_NAME = "Equals";
/**
* File name for of string method.
*/
private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
/**
* File name for temporary enum class.
*/
private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
/**
* File name for construction for special type like union, typedef.
*/
private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
/**
* File name for from string method.
*/
private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
/**
* File name for interface java file name suffix.
*/
......@@ -233,28 +202,12 @@ public class TempJavaFragmentFiles {
* File name for impl class file name suffix.
*/
private static final String IMPL_CLASS_FILE_NAME_SUFFIX = IMPL;
/**
* File name for typedef class file name suffix.
*/
private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
/**
* File name for enum class file name suffix.
*/
private static final String ENUM_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
/**
* File name for rpc method.
*/
private static final String RPC_FILE_NAME = "Rpc";
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String RPC_INTERFACE_FILE_NAME_SUFFIX = "Service";
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
/**
* Java file handle for interface file.
*/
......@@ -271,38 +224,32 @@ public class TempJavaFragmentFiles {
* Java file handle for impl class file.
*/
private File implClassJavaFileHandle;
/**
* Java file handle for typedef class file.
*/
private File typedefClassJavaFileHandle;
/**
* Java file handle for type class like union, typedef file.
*/
private File typeClassJavaFileHandle;
/**
* Temporary file handle for attribute.
*/
private File attributesTempFileHandle;
/**
* Temporary file handle for getter of interface.
*/
private File getterInterfaceTempFileHandle;
/**
* Temporary file handle for getter of class.
*/
private File getterImplTempFileHandle;
/**
* Temporary file handle for setter of interface.
*/
private File setterInterfaceTempFileHandle;
/**
* Temporary file handle for setter of class.
* Temporary file handle for getter of class.
*/
private File setterImplTempFileHandle;
private File getterImplTempFileHandle;
/**
* Temporary file handle for constructor of class.
* Temporary file handle for setter of class.
*/
private File constructorImplTempFileHandle;
private File setterImplTempFileHandle;
/**
* Temporary file handle for hash code method of class.
*/
......@@ -319,30 +266,12 @@ public class TempJavaFragmentFiles {
* Temporary file handle for enum class file.
*/
private File enumClassTempFileHandle;
/**
* Temporary file handle for of string method of class.
*/
private File ofStringImplTempFileHandle;
/**
* Temporary file handle for constructor for type class.
*/
private File constructorForTypeTempFileHandle;
/**
* Temporary file handle for from string method of class.
*/
private File fromStringImplTempFileHandle;
/**
* Temporary file handle for rpc interface.
*/
private File rpcInterfaceImplTempFileHandle;
/**
* Java file handle for rpc interface file.
*/
private File rpcInterfaceJavaFileHandle;
/**
* Import info for case.
*/
private JavaQualifiedTypeInfo caseImportInfo;
/**
* Is attribute added.
*/
......@@ -356,6 +285,9 @@ public class TempJavaFragmentFiles {
*/
private File enumClassJavaFileHandle;
public TempJavaFragmentFiles() {
}
/**
* Returns enum class java file handle.
*
......@@ -407,7 +339,7 @@ public class TempJavaFragmentFiles {
* @param absoluteDirPath absolute path where the file needs to be
* generated.
*/
private void setAbsoluteDirPath(String absoluteDirPath) {
void setAbsoluteDirPath(String absoluteDirPath) {
this.absoluteDirPath = absoluteDirPath;
}
......@@ -434,14 +366,14 @@ public class TempJavaFragmentFiles {
*
* @return generated temp files
*/
private int getGeneratedTempFiles() {
int getGeneratedTempFiles() {
return generatedTempFiles;
}
/**
* Sets generated file files.
* Clears the generated file mask.
*/
private void clearGeneratedTempFiles() {
void clearGeneratedTempFileMask() {
generatedTempFiles = 0;
}
......@@ -450,7 +382,7 @@ public class TempJavaFragmentFiles {
*
* @param generatedTempFile generated file
*/
private void addGeneratedTempFile(int generatedTempFile) {
void addGeneratedTempFile(int generatedTempFile) {
generatedTempFiles |= generatedTempFile;
}
......@@ -459,7 +391,7 @@ public class TempJavaFragmentFiles {
*
* @return generated Java files
*/
private int getGeneratedJavaFiles() {
int getGeneratedJavaFiles() {
return getJavaFileInfo().getGeneratedFileTypes();
}
......@@ -468,7 +400,7 @@ public class TempJavaFragmentFiles {
*
* @return mapped Java class name
*/
private String getGeneratedJavaClassName() {
String getGeneratedJavaClassName() {
return getJavaFileInfo().getJavaName();
}
......@@ -486,11 +418,83 @@ public class TempJavaFragmentFiles {
*
* @param javaImportData import data for the generated Java file
*/
private void setJavaImportData(JavaImportData javaImportData) {
void setJavaImportData(JavaImportData javaImportData) {
this.javaImportData = javaImportData;
}
/**
* Retrieves the status of any attributes added.
*
* @return status of any attributes added
*/
public boolean isAttributePresent() {
return isAttributePresent;
}
/**
* Sets status of any attributes added.
*
* @param attributePresent status of any attributes added
*/
public void setAttributePresent(boolean attributePresent) {
isAttributePresent = attributePresent;
}
/**
* Returns getter methods's temporary file handle.
*
* @return temporary file handle
*/
public File getGetterInterfaceTempFileHandle() {
return getterInterfaceTempFileHandle;
}
/**
* Sets to getter method's temporary file handle.
*
* @param getterForInterface file handle for to getter method
*/
private void setGetterInterfaceTempFileHandle(File getterForInterface) {
getterInterfaceTempFileHandle = getterForInterface;
}
/**
* Returns setter method's temporary file handle.
*
* @return temporary file handle
*/
public File getSetterInterfaceTempFileHandle() {
return setterInterfaceTempFileHandle;
}
/**
* Sets to setter method's temporary file handle.
*
* @param setterForInterface file handle for to setter method
*/
private void setSetterInterfaceTempFileHandle(File setterForInterface) {
setterInterfaceTempFileHandle = setterForInterface;
}
/**
* Returns setter method's impl's temporary file handle.
*
* @return temporary file handle
*/
public File getSetterImplTempFileHandle() {
return setterImplTempFileHandle;
}
/**
* Sets to setter method's impl's temporary file handle.
*
* @param setterImpl file handle for to setter method's implementation class
*/
private void setSetterImplTempFileHandle(File setterImpl) {
setterImplTempFileHandle = setterImpl;
}
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file information
......@@ -501,17 +505,19 @@ public class TempJavaFragmentFiles {
setExtendsList(new ArrayList<>());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
clearGeneratedTempFiles();
clearGeneratedTempFileMask();
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
/**
/*
* Initialize getter when generation file type matches to interface
* mask.
*/
if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
}
/**
/*
* Initialize getter and setter when generation file type matches to
* builder interface mask.
*/
......@@ -519,7 +525,8 @@ public class TempJavaFragmentFiles {
addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
}
/**
/*
* Initialize getterImpl, setterImpl and attributes when generation file
* type matches to builder class mask.
*/
......@@ -528,77 +535,71 @@ public class TempJavaFragmentFiles {
addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
}
/**
/*
* Initialize getterImpl, attributes, constructor, hash code, equals and
* to strings when generation file type matches to impl class mask.
*/
if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
addGeneratedTempFile(ATTRIBUTES_MASK);
addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
addGeneratedTempFile(CONSTRUCTOR_IMPL_MASK);
addGeneratedTempFile(HASH_CODE_IMPL_MASK);
addGeneratedTempFile(EQUALS_IMPL_MASK);
addGeneratedTempFile(TO_STRING_IMPL_MASK);
}
if ((getGeneratedJavaFiles() & GENERATE_RPC_INTERFACE) != 0) {
addGeneratedTempFile(RPC_IMPL_MASK);
}
/**
* Initialize getterImpl, attributes, hash code, equals and to strings
* when generation file type matches to typeDef class mask.
/*
* Initialize temp files to generate type class.
*/
if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0) {
if ((getGeneratedJavaFiles() & GENERATE_TYPE_CLASS) != 0) {
addGeneratedTempFile(ATTRIBUTES_MASK);
addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
addGeneratedTempFile(HASH_CODE_IMPL_MASK);
addGeneratedTempFile(EQUALS_IMPL_MASK);
addGeneratedTempFile(TO_STRING_IMPL_MASK);
addGeneratedTempFile(OF_STRING_IMPL_MASK);
addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK);
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
}
/**
* Initialize getterImpl, attributes, hash code, equals, of string,
* constructor, union's to string, from string when generation file type
* matches to union class mask.
/*
* Initialize getter and setter when generation file type matches to
* builder interface mask.
*/
if ((getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
addGeneratedTempFile(ATTRIBUTES_MASK);
if ((getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK);
addGeneratedTempFile(SETTER_FOR_INTERFACE_MASK);
addGeneratedTempFile(GETTER_FOR_CLASS_MASK);
addGeneratedTempFile(HASH_CODE_IMPL_MASK);
addGeneratedTempFile(EQUALS_IMPL_MASK);
addGeneratedTempFile(OF_STRING_IMPL_MASK);
addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK);
addGeneratedTempFile(TO_STRING_IMPL_MASK);
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
addGeneratedTempFile(SETTER_FOR_CLASS_MASK);
}
/**
/*
* Initialize enum when generation file type matches to enum class mask.
*/
if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
addGeneratedTempFile(ENUM_IMPL_MASK);
}
/**
/*
* Set temporary file handles.
*/
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
setAttributesTempFileHandle(getTemporaryFileHandle(ATTRIBUTE_FILE_NAME));
}
if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
setGetterInterfaceTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
setSetterInterfaceTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
setGetterImplTempFileHandle(getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME));
}
if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
setSetterImplTempFileHandle(getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME));
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_IMPL_MASK) != 0) {
setConstructorImplTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME));
}
if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
setHashCodeImplTempFileHandle(getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME));
}
......@@ -611,18 +612,6 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) {
setEnumClassTempFileHandle(getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME));
}
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
}
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
}
if ((getGeneratedTempFiles() & RPC_IMPL_MASK) != 0) {
setRpcInterfaceImplTempFileHandle(getTemporaryFileHandle(RPC_FILE_NAME));
}
}
/**
......@@ -698,42 +687,6 @@ public class TempJavaFragmentFiles {
}
/**
* Returns java file handle for typedef class file.
*
* @return java file handle for typedef class file
*/
private File getTypedefClassJavaFileHandle() {
return typedefClassJavaFileHandle;
}
/**
* Sets the java file handle for typedef class file.
*
* @param typedefClassJavaFileHandle java file handle
*/
private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
}
/**
* Returns java file handle for type class file.
*
* @return java file handle for type class file
*/
private File getTypeClassJavaFileHandle() {
return typeClassJavaFileHandle;
}
/**
* Sets the java file handle for type class file.
*
* @param typeClassJavaFileHandle type file handle
*/
private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) {
this.typeClassJavaFileHandle = typeClassJavaFileHandle;
}
/**
* Returns attribute's temporary file handle.
*
* @return temporary file handle
......@@ -747,27 +700,10 @@ public class TempJavaFragmentFiles {
*
* @param attributeForClass file handle for attribute
*/
private void setAttributesTempFileHandle(File attributeForClass) {
void setAttributesTempFileHandle(File attributeForClass) {
attributesTempFileHandle = attributeForClass;
}
/**
* Returns getter methods's temporary file handle.
*
* @return temporary file handle
*/
public File getGetterInterfaceTempFileHandle() {
return getterInterfaceTempFileHandle;
}
/**
* Sets to getter method's temporary file handle.
*
* @param getterForInterface file handle for to getter method
*/
private void setGetterInterfaceTempFileHandle(File getterForInterface) {
getterInterfaceTempFileHandle = getterForInterface;
}
/**
* Returns getter method's impl's temporary file handle.
......@@ -783,63 +719,10 @@ public class TempJavaFragmentFiles {
*
* @param getterImpl file handle for to getter method's impl
*/
private void setGetterImplTempFileHandle(File getterImpl) {
void setGetterImplTempFileHandle(File getterImpl) {
getterImplTempFileHandle = getterImpl;
}
/**
* Returns setter method's temporary file handle.
*
* @return temporary file handle
*/
public File getSetterInterfaceTempFileHandle() {
return setterInterfaceTempFileHandle;
}
/**
* Sets to setter method's temporary file handle.
*
* @param setterForInterface file handle for to setter method
*/
private void setSetterInterfaceTempFileHandle(File setterForInterface) {
setterInterfaceTempFileHandle = setterForInterface;
}
/**
* Returns setter method's impl's temporary file handle.
*
* @return temporary file handle
*/
public File getSetterImplTempFileHandle() {
return setterImplTempFileHandle;
}
/**
* Sets to setter method's impl's temporary file handle.
*
* @param setterImpl file handle for to setter method's implementation class
*/
private void setSetterImplTempFileHandle(File setterImpl) {
setterImplTempFileHandle = setterImpl;
}
/**
* Returns constructor's temporary file handle.
*
* @return temporary file handle
*/
public File getConstructorImplTempFileHandle() {
return constructorImplTempFileHandle;
}
/**
* Sets to constructor's temporary file handle.
*
* @param constructor file handle for to constructor
*/
private void setConstructorImplTempFileHandle(File constructor) {
constructorImplTempFileHandle = constructor;
}
/**
* Returns hash code method's temporary file handle.
......@@ -855,7 +738,7 @@ public class TempJavaFragmentFiles {
*
* @param hashCodeMethod file handle for hash code method
*/
private void setHashCodeImplTempFileHandle(File hashCodeMethod) {
void setHashCodeImplTempFileHandle(File hashCodeMethod) {
hashCodeImplTempFileHandle = hashCodeMethod;
}
......@@ -873,47 +756,11 @@ public class TempJavaFragmentFiles {
*
* @param equalsMethod file handle for to equals method
*/
private void setEqualsImplTempFileHandle(File equalsMethod) {
void setEqualsImplTempFileHandle(File equalsMethod) {
equalsImplTempFileHandle = equalsMethod;
}
/**
* Returns rpc method's temporary file handle.
*
* @return temporary file handle
*/
public File getRpcInterfaceImplTempFileHandle() {
return rpcInterfaceImplTempFileHandle;
}
/**
* Sets rpc method's temporary file handle.
*
* @param rpcInterfaceImplTempFileHandle file handle for to rpc method
*/
private void setRpcInterfaceImplTempFileHandle(File rpcInterfaceImplTempFileHandle) {
this.rpcInterfaceImplTempFileHandle = rpcInterfaceImplTempFileHandle;
}
/**
* Returns rpc method's java file handle.
*
* @return java file handle
*/
private File getRpcInterfaceJavaFileHandle() {
return rpcInterfaceJavaFileHandle;
}
/**
* Sets rpc method's java file handle.
*
* @param rpcInterfaceJavaFileHandle file handle for to rpc method
*/
private void setRpcInterfaceJavaFileHandle(File rpcInterfaceJavaFileHandle) {
this.rpcInterfaceJavaFileHandle = rpcInterfaceJavaFileHandle;
}
/**
* Returns to string method's temporary file handle.
*
* @return temporary file handle
......@@ -927,7 +774,7 @@ public class TempJavaFragmentFiles {
*
* @param toStringMethod file handle for to string method
*/
private void setToStringImplTempFileHandle(File toStringMethod) {
void setToStringImplTempFileHandle(File toStringMethod) {
toStringImplTempFileHandle = toStringMethod;
}
......@@ -950,68 +797,11 @@ public class TempJavaFragmentFiles {
}
/**
* Returns of string method's temporary file handle.
*
* @return of string method's temporary file handle
*/
public File getOfStringImplTempFileHandle() {
return ofStringImplTempFileHandle;
}
/**
* Set of string method's temporary file handle.
*
* @param ofStringImplTempFileHandle of string method's temporary file
* handle
*/
private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) {
this.ofStringImplTempFileHandle = ofStringImplTempFileHandle;
}
/**
* Returns type class constructor method's temporary file handle.
*
* @return type class constructor method's temporary file handle
*/
public File getConstructorForTypeTempFileHandle() {
return constructorForTypeTempFileHandle;
}
/**
* Sets type class constructor method's temporary file handle.
*
* @param constructorForTypeTempFileHandle type class constructor method's
* temporary file handle
*/
private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) {
this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle;
}
/**
* Returns from string method's temporary file handle.
*
* @return from string method's temporary file handle
*/
public File getFromStringImplTempFileHandle() {
return fromStringImplTempFileHandle;
}
/**
* Sets from string method's temporary file handle.
*
* @param fromStringImplTempFileHandle from string method's temporary file
* handle
*/
private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
}
/**
* Returns list of classes to be extended by generated files.
*
* @return list of classes to be extended by generated files
*/
private List<String> getExtendsList() {
List<String> getExtendsList() {
return extendsList;
}
......@@ -1020,7 +810,7 @@ public class TempJavaFragmentFiles {
*
* @param extendsList list of classes to be extended
*/
private void setExtendsList(List<String> extendsList) {
void setExtendsList(List<String> extendsList) {
this.extendsList = extendsList;
}
......@@ -1034,31 +824,6 @@ public class TempJavaFragmentFiles {
}
/**
* Adds of string for type.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addOfStringMethod(JavaAttributeInfo attr)
throws IOException {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
getGeneratedJavaClassName())
+ NEW_LINE);
}
/**
* Adds type constructor.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addTypeConstructor(JavaAttributeInfo attr)
throws IOException {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
getGeneratedJavaClassName()) + NEW_LINE);
}
/**
* Adds attribute for class.
*
* @param attr attribute info
......@@ -1077,48 +842,50 @@ public class TempJavaFragmentFiles {
*/
private void addGetterForInterface(JavaAttributeInfo attr)
throws IOException {
appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr) + NEW_LINE);
appendToFile(getGetterInterfaceTempFileHandle(), getGetterString(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
/**
* Adds getter method's impl for class.
* Adds setter for interface.
*
* @param attr attribute info
* @param genFiletype generated file type
* @throws IOException when fails to append to temporary file
*/
private void addGetterImpl(JavaAttributeInfo attr, int genFiletype)
private void addSetterForInterface(JavaAttributeInfo attr)
throws IOException {
if ((genFiletype & BUILDER_CLASS_MASK) != 0) {
appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr) + NEW_LINE);
} else {
appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false)
+ getGetterForClass(attr) + NEW_LINE);
}
appendToFile(getSetterInterfaceTempFileHandle(),
getSetterString(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) + NEW_LINE);
}
/**
* Adds setter for interface.
* Adds setter's implementation for class.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addSetterForInterface(JavaAttributeInfo attr)
private void addSetterImpl(JavaAttributeInfo attr)
throws IOException {
appendToFile(getSetterInterfaceTempFileHandle(),
getSetterString(attr, getGeneratedJavaClassName()) + NEW_LINE);
appendToFile(getSetterImplTempFileHandle(),
getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName(), getGeneratedJavaFiles()) +
NEW_LINE);
}
/**
* Adds setter's implementation for class.
* Adds getter method's impl for class.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addSetterImpl(JavaAttributeInfo attr)
private void addGetterImpl(JavaAttributeInfo attr)
throws IOException {
appendToFile(getSetterImplTempFileHandle(),
getOverRideString() + getSetterForClass(attr, getGeneratedJavaClassName()) + NEW_LINE);
if ((getGeneratedJavaFiles() & BUILDER_CLASS_MASK) != 0
|| (getGeneratedJavaFiles() & GENERATE_SERVICE_AND_MANAGER) != 0) {
appendToFile(getGetterImplTempFileHandle(), getOverRideString() + getGetterForClass(attr,
getGeneratedJavaFiles()) + NEW_LINE);
} else {
appendToFile(getGetterImplTempFileHandle(), getJavaDoc(GETTER_METHOD, attr.getAttributeName(), false)
+ getGetterForClass(attr, getGeneratedJavaFiles()) + NEW_LINE);
}
}
/**
......@@ -1144,17 +911,6 @@ public class TempJavaFragmentFiles {
}
/**
* Adds constructor for class.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addConstructor(JavaAttributeInfo attr)
throws IOException {
appendToFile(getConstructorImplTempFileHandle(), getConstructor(getGeneratedJavaClassName(), attr));
}
/**
* Adds default constructor for class.
*
* @param modifier modifier for constructor.
......@@ -1224,42 +980,6 @@ public class TempJavaFragmentFiles {
generateEnumAttributeString(curEnumInfo.getAttributeName(), getEnumValue()));
}
/**
* Add from string method for union class.
*
* @param javaAttributeInfo type attribute info
* @param fromStringAttributeInfo from string attribute info
* @throws IOException when fails to append to temporary file
*/
private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
JavaAttributeInfo fromStringAttributeInfo)
throws IOException {
appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
fromStringAttributeInfo) + NEW_LINE);
}
/**
* Adds rpc string information to applicable temp file.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput,
String rpcName)
throws IOException {
String rpcInput = "";
String rpcOutput = "void";
if (javaAttributeInfoOfInput != null) {
rpcInput = javaAttributeInfoOfInput.getAttributeName();
}
if (javaAttributeInfoOfOutput != null) {
rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
}
appendToFile(getRpcInterfaceImplTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) +
getRpcStringMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
}
/**
* Returns a temporary file handle for the specific file type.
......@@ -1268,7 +988,7 @@ public class TempJavaFragmentFiles {
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
private File getTemporaryFileHandle(String fileName)
File getTemporaryFileHandle(String fileName)
throws IOException {
String path = getTempDirPath();
File dir = new File(path);
......@@ -1289,9 +1009,9 @@ public class TempJavaFragmentFiles {
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
private File getJavaFileHandle(String fileName)
File getJavaFileHandle(String fileName)
throws IOException {
createPackage(getAbsoluteDirPath(), getJavaFileInfo().getJavaName());
// createPackage(getAbsoluteDirPath(), getJavaFileInfo().getJavaName());
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
}
......@@ -1318,7 +1038,7 @@ public class TempJavaFragmentFiles {
*
* @return directory path
*/
private String getTempDirPath() {
String getTempDirPath() {
return getPackageDirPathFromJavaJPackage(getAbsoluteDirPath()) + SLASH + getGeneratedJavaClassName()
+ TEMP_FOLDER_NAME_SUFIX + SLASH;
}
......@@ -1350,7 +1070,7 @@ public class TempJavaFragmentFiles {
* @param data data to be appended
* @throws IOException when fails to append to file
*/
private void appendToFile(File file, String data)
void appendToFile(File file, String data)
throws IOException {
try {
insertDataIntoJavaFile(file, data);
......@@ -1379,8 +1099,7 @@ public class TempJavaFragmentFiles {
if (!(parent instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("missing parent temp file handle");
}
((TempJavaCodeFragmentFilesContainer) parent)
.getTempJavaCodeFragmentFiles().getBeanTempFiles()
getNodesInterfaceFragmentFiles(parent)
.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
}
......@@ -1407,20 +1126,24 @@ public class TempJavaFragmentFiles {
if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("Parent node does not have file info");
}
TempJavaFragmentFiles tempJavaFragmentFiles = getNodesInterfaceFragmentFiles(parentNode);
JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo);
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
}
public static TempJavaFragmentFiles getNodesInterfaceFragmentFiles(YangNode node) {
TempJavaFragmentFiles tempJavaFragmentFiles;
if (parentNode instanceof YangRpc) {
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
if (node instanceof RpcNotificationContainer) {
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
.getTempJavaCodeFragmentFiles()
.getServiceTempFiles();
} else {
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) node)
.getTempJavaCodeFragmentFiles()
.getBeanTempFiles();
}
JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo);
return getAttributeInfoForTheData(qualifiedTypeInfo, curNodeName, null, isQualified, isListNode);
return tempJavaFragmentFiles;
}
/**
......@@ -1448,9 +1171,11 @@ public class TempJavaFragmentFiles {
* Adds leaf attributes in generated files.
*
* @param listOfLeaves list of YANG leaf
* @param yangPluginConfig
* @throws IOException IO operation fail
*/
private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves)
private void addLeavesInfoToTempFiles(List<YangLeaf> listOfLeaves,
YangPluginConfig yangPluginConfig)
throws IOException {
if (listOfLeaves != null) {
for (YangLeaf leaf : listOfLeaves) {
......@@ -1461,7 +1186,8 @@ public class TempJavaFragmentFiles {
javaLeaf.updateJavaQualifiedInfo();
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaLeaf.getJavaQualifiedInfo(),
javaLeaf.getName(), javaLeaf.getDataType(),
javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
javaLeaf.getDataType(),
getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
false);
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
......@@ -1473,9 +1199,10 @@ public class TempJavaFragmentFiles {
* Adds leaf list's attributes in generated files.
*
* @param listOfLeafList list of YANG leaves
* @param yangPluginConfig
* @throws IOException IO operation fail
*/
private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList)
private void addLeafListInfoToTempFiles(List<YangLeafList> listOfLeafList, YangPluginConfig yangPluginConfig)
throws IOException {
if (listOfLeafList != null) {
for (YangLeafList leafList : listOfLeafList) {
......@@ -1486,7 +1213,8 @@ public class TempJavaFragmentFiles {
javaLeaf.updateJavaQualifiedInfo();
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaLeaf.getJavaQualifiedInfo(),
javaLeaf.getName(), javaLeaf.getDataType(),
javaLeaf.getJavaName(yangPluginConfig.getConflictResolver()),
javaLeaf.getDataType(),
getIsQualifiedAccessOrAddToImportList(javaLeaf.getJavaQualifiedInfo()),
true);
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
......@@ -1499,44 +1227,18 @@ public class TempJavaFragmentFiles {
* generated temporary file.
*
* @param curNode java file info of the generated file
* @param yangPluginConfig plugin config
* @throws IOException IO operation fail
*/
void addCurNodeLeavesInfoToTempFiles(YangNode curNode)
public void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(curNode instanceof YangLeavesHolder)) {
throw new TranslatorException("Data model node does not have any leaves");
}
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf());
addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList());
}
/**
* Add all the type in the current data model node as part of the generated
* temporary file.
*
* @param yangTypeContainer YANG java data model node which has type info, eg union /
* typedef
* @throws IOException IO operation fail
*/
public void addTypeInfoToTempFiles(YangTypeContainer yangTypeContainer)
throws IOException {
List<YangType<?>> typeList = yangTypeContainer.getTypeList();
if (typeList != null) {
for (YangType<?> yangType : typeList) {
if (!(yangType instanceof YangJavaType)) {
throw new TranslatorException("Type does not have Java info");
}
YangJavaType<?> javaType = (YangJavaType<?>) yangType;
javaType.updateJavaQualifiedInfo();
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
javaType.getDataTypeName(), javaType,
getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
false);
addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeContainer, javaAttributeInfo);
}
}
addLeavesInfoToTempFiles(leavesHolder.getListOfLeaf(), yangPluginConfig);
addLeafListInfoToTempFiles(leavesHolder.getListOfLeafList(), yangPluginConfig);
}
/**
......@@ -1567,49 +1269,6 @@ public class TempJavaFragmentFiles {
}
/**
* Adds the new attribute info to the target generated temporary files for
* union class.
*
* @param hasType the node for which the type is being added as an attribute
* @param javaAttributeInfo the attribute info that needs to be added to
* temporary files
* @throws IOException IO operation fail
*/
private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo)
throws IOException {
JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(javaAttributeInfo);
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
*/
JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
javaAttributeInfo.getAttributeName(),
javaAttributeInfo.getAttributeType(),
getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo);
}
addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
}
/**
* Adds the JAVA rpc snippet information.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
JavaAttributeInfo javaAttributeInfoOfOutput,
String rpcName)
throws IOException {
if ((getGeneratedTempFiles() & RPC_IMPL_MASK) != 0) {
addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
}
}
/**
* Adds the new attribute info to the target generated temporary files.
*
* @param newAttrInfo the attribute info that needs to be added to temporary
......@@ -1618,24 +1277,25 @@ public class TempJavaFragmentFiles {
*/
void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo)
throws IOException {
isAttributePresent = true;
setAttributePresent(true);
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
addAttribute(newAttrInfo);
}
if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
addGetterForInterface(newAttrInfo);
}
if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
addSetterForInterface(newAttrInfo);
}
if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
addGetterImpl(newAttrInfo, getGeneratedJavaFiles());
}
if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
addSetterImpl(newAttrInfo);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_IMPL_MASK) != 0) {
addConstructor(newAttrInfo);
if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
addGetterImpl(newAttrInfo);
}
if ((getGeneratedTempFiles() & HASH_CODE_IMPL_MASK) != 0) {
addHashCodeMethod(newAttrInfo);
......@@ -1649,12 +1309,6 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) {
addAttributesForEnumClass(newAttrInfo);
}
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
addOfStringMethod(newAttrInfo);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
addTypeConstructor(newAttrInfo);
}
}
/**
......@@ -1663,7 +1317,7 @@ public class TempJavaFragmentFiles {
* @param suffix for the class name based on the file type
* @return java class name
*/
private String getJavaClassName(String suffix) {
String getJavaClassName(String suffix) {
return getCaptialCase(getJavaFileInfo().getJavaName()) + suffix;
}
......@@ -1686,24 +1340,21 @@ public class TempJavaFragmentFiles {
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
if (isAttributePresent) {
if (isAttributePresent()) {
imports = getJavaImportData().getImports();
}
/**
/*
* Prepares java file generator for extends list.
*/
prepareJavaFileGeneratorForExtendsList(getExtendsList());
if (curNode.getNodeType().equals(MODULE_NODE)) {
createPackage(absoluteDirPath, getJavaFileInfo().getJavaName());
} else {
createPackage(absoluteDirPath, ((JavaFileInfoContainer) curNode.getParent()).getJavaFileInfo().getJavaName()
+ PACKAGE_INFO_JAVADOC_OF_CHILD);
}
/**
createPackage(curNode);
/*
* Generate java code.
*/
if ((fileType & INTERFACE_MASK) != 0 | (fileType & BUILDER_INTERFACE_MASK) != 0) {
/**
if ((fileType & INTERFACE_MASK) != 0 || (fileType &
BUILDER_INTERFACE_MASK) != 0) {
/*
* Adds import for case.
*/
if (curNode instanceof YangCase) {
......@@ -1715,7 +1366,7 @@ public class TempJavaFragmentFiles {
}
}
}
/**
/*
* Adds import for HasAugmentation class.
*/
if (isHasAugmentationExtended(getExtendsList())) {
......@@ -1724,21 +1375,22 @@ public class TempJavaFragmentFiles {
if (isAugmentedInfoExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
}
/**
/*
* Create interface file.
*/
setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
setInterfaceJavaFileHandle(
generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent));
/**
generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent()));
/*
* Create builder interface file.
*/
if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
setBuilderInterfaceJavaFileHandle(
getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
setBuilderInterfaceJavaFileHandle(
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent));
/**
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode,
isAttributePresent()));
/*
* Append builder interface file to interface file and close it.
*/
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
......@@ -1754,68 +1406,61 @@ public class TempJavaFragmentFiles {
removeCaseImport(imports);
}
}
if ((fileType & BUILDER_CLASS_MASK) != 0 | (fileType & IMPL_CLASS_MASK) != 0) {
if (isAttributePresent) {
if (((fileType & GENERATE_SERVICE_AND_MANAGER) != 0)
&& ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0)) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(curNode, imports);
}
if (isHasAugmentationExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
addArrayListImport(curNode, imports, true);
}
/**
/*
* Create builder class file.
*/
setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
setBuilderClassJavaFileHandle(
generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent));
/**
generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent()));
/*
* Create impl class file.
*/
if ((fileType & IMPL_CLASS_MASK) != 0) {
setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
setImplClassJavaFileHandle(
generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent));
/**
generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent()));
/*
* Append impl class to builder class and close it.
*/
mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
}
insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
}
/**
* Creates type def class file.
*/
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(curNode, imports);
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
setTypedefClassJavaFileHandle(generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports));
}
/**
* Creates type class file.
*/
if ((fileType & GENERATE_UNION_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(curNode, imports);
setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
setTypeClassJavaFileHandle(generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports));
}
/**
/*
* Creates type enum class file.
*/
if ((fileType & GENERATE_ENUM_CLASS) != 0) {
setEnumClassJavaFileHandle(getJavaFileHandle(getJavaClassName(ENUM_CLASS_FILE_NAME_SUFFIX)));
setEnumClassJavaFileHandle(generateEnumClassFile(getEnumClassJavaFileHandle(), curNode));
}
/**
* Creates rpc interface file.
/*
* Close all the file handles.
*/
if ((fileType & GENERATE_RPC_INTERFACE) != 0) {
setRpcInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(RPC_INTERFACE_FILE_NAME_SUFFIX)));
setRpcInterfaceJavaFileHandle(generateRpcInterfaceFile(getRpcInterfaceJavaFileHandle(), curNode, imports));
freeTemporaryResources(false);
}
/**
* Close all the file handles.
* Adds imports for ToString and HashCodeMethod.
*
* @param curNode current YANG node
* @param imports import list
* @return import list
*/
close(false);
public List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
imports.add(getJavaImportData().getImportForHashAndEquals());
imports.add(getJavaImportData().getImportForToString());
return imports;
}
/**
......@@ -1841,10 +1486,10 @@ public class TempJavaFragmentFiles {
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void close(boolean isErrorOccurred)
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
/**
/*
* Close all java file handles and when error occurs delete the files.
*/
if ((getGeneratedJavaFiles() & INTERFACE_MASK) != 0) {
......@@ -1859,36 +1504,17 @@ public class TempJavaFragmentFiles {
if ((getGeneratedJavaFiles() & IMPL_CLASS_MASK) != 0) {
closeFile(getImplClassJavaFileHandle(), true);
}
if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0) {
closeFile(getTypedefClassJavaFileHandle(), isError);
}
if ((getGeneratedJavaFiles() & GENERATE_ENUM_CLASS) != 0) {
closeFile(getEnumClassJavaFileHandle(), isError);
}
if ((getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
closeFile(getTypeClassJavaFileHandle(), isError);
}
if ((getGeneratedJavaFiles() & GENERATE_RPC_INTERFACE) != 0) {
closeFile(getRpcInterfaceJavaFileHandle(), isError);
}
/**
/*
* Close all temporary file handles and delete the files.
*/
if ((getGeneratedTempFiles() & GETTER_FOR_INTERFACE_MASK) != 0) {
closeFile(getGetterInterfaceTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & GETTER_FOR_CLASS_MASK) != 0) {
closeFile(getGetterImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & SETTER_FOR_INTERFACE_MASK) != 0) {
closeFile(getSetterInterfaceTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & SETTER_FOR_CLASS_MASK) != 0) {
closeFile(getSetterImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_IMPL_MASK) != 0) {
closeFile(getConstructorImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & ATTRIBUTES_MASK) != 0) {
closeFile(getAttributesTempFileHandle(), true);
}
......@@ -1904,20 +1530,6 @@ public class TempJavaFragmentFiles {
if ((getGeneratedTempFiles() & ENUM_IMPL_MASK) != 0) {
closeFile(getEnumClassTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
closeFile(getConstructorForTypeTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
closeFile(getOfStringImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
closeFile(getFromStringImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & RPC_IMPL_MASK) != 0) {
closeFile(getRpcInterfaceImplTempFileHandle(), true);
}
clean(getTempDirPath());
clearGeneratedTempFiles();
}
/**
......
......@@ -16,15 +16,152 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateManagerClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
.isHasAugmentationExtended;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
* Represents implementation of java service code fragments temporary implementations.
* Maintains the temp files required specific for service and manager java snippet generation.
*/
public class TempJavaServiceFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for rpc method.
*/
private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
/**
* File name for rpc implementation method.
*/
private static final String RPC_IMPL_FILE_NAME = "RpcImpl";
/**
* File name for generated class file for service
* suffix.
*/
private static final String SERVICE_FILE_NAME_SUFFIX = "Service";
/**
* File name for generated class file for manager
* suffix.
*/
private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
/**
* Temporary file handle for rpc interface.
*/
private File rpcInterfaceTempFileHandle;
/**
* Temporary file handle for rpc manager impl.
*/
private File rpcImplTempFileHandle;
/**
* Java file handle for rpc interface file.
*/
private File serviceInterfaceJavaFileHandle;
/**
* Java file handle for manager impl file.
*/
private File managerJavaFileHandle;
/**
* Returns rpc method's java file handle.
*
* @return java file handle
*/
private File getServiceInterfaceJavaFileHandle() {
return serviceInterfaceJavaFileHandle;
}
/**
* Sets rpc method's java file handle.
*
* @param serviceInterfaceJavaFileHandle file handle for to rpc method
*/
private void setServiceInterfaceJavaFileHandle(File serviceInterfaceJavaFileHandle) {
this.serviceInterfaceJavaFileHandle = serviceInterfaceJavaFileHandle;
}
/**
* Returns managers java file handle.
*
* @return java file handle
*/
public File getManagerJavaFileHandle() {
return managerJavaFileHandle;
}
/**
* Sets manager java file handle.
*
* @param managerJavaFileHandle file handle for to manager
*/
public void setManagerJavaFileHandle(File managerJavaFileHandle) {
this.managerJavaFileHandle = managerJavaFileHandle;
}
/**
* Returns rpc method's temporary file handle.
*
* @return temporary file handle
*/
public File getRpcInterfaceTempFileHandle() {
return rpcInterfaceTempFileHandle;
}
/**
* Sets rpc method's temporary file handle.
*
* @param rpcInterfaceTempFileHandle file handle for to rpc method
*/
private void setRpcInterfaceTempFileHandle(File rpcInterfaceTempFileHandle) {
this.rpcInterfaceTempFileHandle = rpcInterfaceTempFileHandle;
}
/**
* Retrieves the manager impl temp file.
*
* @return the manager impl temp file
*/
public File getRpcImplTempFileHandle() {
return rpcImplTempFileHandle;
}
/**
* Sets the manager impl temp file.
*
* @param rpcImplTempFileHandle the manager impl temp file
*/
public void setRpcImplTempFileHandle(File rpcImplTempFileHandle) {
this.rpcImplTempFileHandle = rpcImplTempFileHandle;
}
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated file information
......@@ -33,5 +170,113 @@ public class TempJavaServiceFragmentFiles
public TempJavaServiceFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
addGeneratedTempFile(RPC_INTERFACE_MASK);
addGeneratedTempFile(RPC_IMPL_MASK);
setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports = getJavaImportData().getImports();
createPackage(curNode);
/**
* Creates rpc interface file.
*/
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(curNode, imports);
}
if (isHasAugmentationExtended(getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
addArrayListImport(curNode, imports, true);
}
/**
* Create builder class file.
*/
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent());
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Adds rpc string information to applicable temp file.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
private void addRpcString(JavaAttributeInfo javaAttributeInfoOfInput, JavaAttributeInfo javaAttributeInfoOfOutput,
String rpcName)
throws IOException {
String rpcInput = "";
String rpcOutput = "void";
if (javaAttributeInfoOfInput != null) {
rpcInput = javaAttributeInfoOfInput.getAttributeName();
}
if (javaAttributeInfoOfOutput != null) {
rpcOutput = javaAttributeInfoOfOutput.getAttributeName();
}
appendToFile(getRpcInterfaceTempFileHandle(), generateJavaDocForRpc(rpcName, rpcInput, rpcOutput) +
getRpcServiceMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
appendToFile(getRpcImplTempFileHandle(),
getRpcManagerMethod(rpcName, rpcInput, rpcOutput) + NEW_LINE);
}
/**
* Adds the JAVA rpc snippet information.
*
* @param javaAttributeInfoOfInput rpc's input node attribute info
* @param javaAttributeInfoOfOutput rpc's output node attribute info
* @param rpcName name of the rpc function
* @throws IOException IO operation fail
*/
public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo javaAttributeInfoOfInput,
JavaAttributeInfo javaAttributeInfoOfOutput,
String rpcName)
throws IOException {
addRpcString(javaAttributeInfoOfInput, javaAttributeInfoOfOutput, rpcName);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
closeFile(getServiceInterfaceJavaFileHandle(), isError);
closeFile(getRpcInterfaceTempFileHandle(), true);
super.freeTemporaryResources(isErrorOccurred);
}
}
......
......@@ -16,15 +16,90 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedInfoOfFromString;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
/**
* Represents implementation of java data type code fragments temporary implementations.
* Maintains the temp files required specific for user defined data type java snippet generation.
*/
public class TempJavaTypeFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for of string method.
*/
private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
/**
* File name for construction for special type like union, typedef.
*/
private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
/**
* File name for from string method.
*/
private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
/**
* File name for typedef class file name suffix.
*/
private static final String TYPEDEF_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String UNION_TYPE_CLASS_FILE_NAME_SUFFIX = EMPTY_STRING;
/**
* Temporary file handle for of string method of class.
*/
private File ofStringImplTempFileHandle;
/**
* Temporary file handle for constructor for type class.
*/
private File constructorForTypeTempFileHandle;
/**
* Temporary file handle for from string method of class.
*/
private File fromStringImplTempFileHandle;
/**
* Java file handle for typedef class file.
*/
private File typedefClassJavaFileHandle;
/**
* Java file handle for type class like union, typedef file.
*/
private File typeClassJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -32,7 +107,293 @@ public class TempJavaTypeFragmentFiles
*/
public TempJavaTypeFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
super(javaFileInfo);
/*
* Initialize getterImpl, attributes, hash code, equals and to strings
* when generation file type matches to typeDef class mask.
*/
addGeneratedTempFile(OF_STRING_IMPL_MASK);
addGeneratedTempFile(CONSTRUCTOR_FOR_TYPE_MASK);
addGeneratedTempFile(FROM_STRING_IMPL_MASK);
setOfStringImplTempFileHandle(getTemporaryFileHandle(OF_STRING_METHOD_FILE_NAME));
setConstructorForTypeTempFileHandle(getTemporaryFileHandle(CONSTRUCTOR_FOR_TYPE_FILE_NAME));
setFromStringImplTempFileHandle(getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME));
}
/**
* Returns type class constructor method's temporary file handle.
*
* @return type class constructor method's temporary file handle
*/
public File getConstructorForTypeTempFileHandle() {
return constructorForTypeTempFileHandle;
}
/**
* Sets type class constructor method's temporary file handle.
*
* @param constructorForTypeTempFileHandle type class constructor method's
* temporary file handle
*/
private void setConstructorForTypeTempFileHandle(File constructorForTypeTempFileHandle) {
this.constructorForTypeTempFileHandle = constructorForTypeTempFileHandle;
}
/**
* Returns from string method's temporary file handle.
*
* @return from string method's temporary file handle
*/
public File getFromStringImplTempFileHandle() {
return fromStringImplTempFileHandle;
}
/**
* Sets from string method's temporary file handle.
*
* @param fromStringImplTempFileHandle from string method's temporary file
* handle
*/
private void setFromStringImplTempFileHandle(File fromStringImplTempFileHandle) {
this.fromStringImplTempFileHandle = fromStringImplTempFileHandle;
}
/**
* Returns java file handle for typedef class file.
*
* @return java file handle for typedef class file
*/
File getTypedefClassJavaFileHandle() {
return typedefClassJavaFileHandle;
}
/**
* Sets the java file handle for typedef class file.
*
* @param typedefClassJavaFileHandle java file handle
*/
private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
}
/**
* Returns java file handle for type class file.
*
* @return java file handle for type class file
*/
File getTypeClassJavaFileHandle() {
return typeClassJavaFileHandle;
}
/**
* Sets the java file handle for type class file.
*
* @param typeClassJavaFileHandle type file handle
*/
private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) {
this.typeClassJavaFileHandle = typeClassJavaFileHandle;
}
/**
* Returns of string method's temporary file handle.
*
* @return of string method's temporary file handle
*/
public File getOfStringImplTempFileHandle() {
return ofStringImplTempFileHandle;
}
/**
* Set of string method's temporary file handle.
*
* @param ofStringImplTempFileHandle of string method's temporary file
* handle
*/
private void setOfStringImplTempFileHandle(File ofStringImplTempFileHandle) {
this.ofStringImplTempFileHandle = ofStringImplTempFileHandle;
}
/**
* Adds all the type in the current data model node as part of the generated
* temporary file.
*
* @param yangTypeHolder YANG java data model node which has type info, eg union /
* typedef
* @throws IOException IO operation fail
*/
public void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder)
throws IOException {
List<YangType<?>> typeList = yangTypeHolder.getTypeList();
if (typeList != null) {
for (YangType<?> yangType : typeList) {
if (!(yangType instanceof YangJavaType)) {
throw new TranslatorException("Type does not have Java info");
}
YangJavaType<?> javaType = (YangJavaType<?>) yangType;
javaType.updateJavaQualifiedInfo();
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
javaType.getJavaQualifiedInfo(),
javaType.getDataTypeName(), javaType,
getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
false);
addJavaSnippetInfoToApplicableTempFiles((YangNode) yangTypeHolder, javaAttributeInfo);
}
}
}
/**
* Adds the new attribute info to the target generated temporary files for
* union class.
*
* @param hasType the node for which the type is being added as an attribute
* @param javaAttributeInfo the attribute info that needs to be added to
* temporary files
* @throws IOException IO operation fail
*/
private void addJavaSnippetInfoToApplicableTempFiles(YangNode hasType, JavaAttributeInfo javaAttributeInfo)
throws IOException {
super.addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo);
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
addOfStringMethod(javaAttributeInfo);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
addTypeConstructor(javaAttributeInfo);
}
JavaQualifiedTypeInfo qualifiedInfoOfFromString = getQualifiedInfoOfFromString(javaAttributeInfo);
/*
* Create a new java attribute info with qualified information of
* wrapper classes.
*/
JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
javaAttributeInfo.getAttributeName(),
javaAttributeInfo.getAttributeType(),
getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
addFromStringMethod(javaAttributeInfo, fromStringAttributeInfo);
}
}
/**
* Adds from string method for union class.
*
* @param javaAttributeInfo type attribute info
* @param fromStringAttributeInfo from string attribute info
* @throws IOException when fails to append to temporary file
*/
private void addFromStringMethod(JavaAttributeInfo javaAttributeInfo,
JavaAttributeInfo fromStringAttributeInfo)
throws IOException {
appendToFile(getFromStringImplTempFileHandle(), getFromStringMethod(javaAttributeInfo,
fromStringAttributeInfo) + NEW_LINE);
}
/**
* Adds type constructor.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addTypeConstructor(JavaAttributeInfo attr)
throws IOException {
appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(attr,
getGeneratedJavaClassName()) + NEW_LINE);
}
/**
* Adds of string for type.
*
* @param attr attribute info
* @throws IOException when fails to append to temporary file
*/
private void addOfStringMethod(JavaAttributeInfo attr)
throws IOException {
appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
getGeneratedJavaClassName())
+ NEW_LINE);
}
/**
* Removes all temporary file handles.
*
* @param isErrorOccurred when translator fails to generate java files we
* need to close all open file handles include temporary files
* and java files.
* @throws IOException when failed to delete the temporary files
*/
public void freeTemporaryResources(boolean isErrorOccurred)
throws IOException {
boolean isError = isErrorOccurred;
if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0) {
closeFile(getTypedefClassJavaFileHandle(), isError);
}
if ((getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
closeFile(getTypeClassJavaFileHandle(), isError);
}
if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
closeFile(getConstructorForTypeTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
closeFile(getOfStringImplTempFileHandle(), true);
}
if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
closeFile(getFromStringImplTempFileHandle(), true);
}
super.freeTemporaryResources(isErrorOccurred);
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
if (isAttributePresent()) {
imports = getJavaImportData().getImports();
}
createPackage(curNode);
/*
* Creates type def class file.
*/
if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(curNode, imports);
setTypedefClassJavaFileHandle(getJavaFileHandle(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX)));
generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
}
/*
* Creates type class file.
*/
if ((fileType & GENERATE_UNION_CLASS) != 0) {
addImportsToStringAndHasCodeMethods(curNode, imports);
setTypeClassJavaFileHandle(getJavaFileHandle(getJavaClassName(UNION_TYPE_CLASS_FILE_NAME_SUFFIX)));
generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
}
/*
* Close all the file handles.
*/
freeTemporaryResources(false);
}
}
......
......@@ -15,20 +15,13 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
* Represents grouping information extended to support java code generation.
*/
public class YangJavaGrouping
extends YangGrouping
implements JavaCodeGeneratorInfo, JavaCodeGenerator {
extends YangGrouping {
/**
* Creates YANG Java grouping object.
......@@ -36,38 +29,4 @@ public class YangJavaGrouping
public YangJavaGrouping() {
super();
}
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
/*Do nothing, the uses will copy the contents to the used location*/
}
@Override
public void generateCodeExit()
throws IOException {
/*Do nothing, the uses will copy the contents to the used location*/
}
@Override
public JavaFileInfo getJavaFileInfo() {
/*Do nothing, the uses will copy the contents to the used location*/
return null;
}
@Override
public void setJavaFileInfo(JavaFileInfo javaInfo) {
/*Do nothing, the uses will copy the contents to the used location*/
}
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
/*Do nothing, the uses will copy the contents to the used location*/
return null;
}
@Override
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
/*Do nothing, the uses will copy the contents to the used location*/
}
}
......
......@@ -25,8 +25,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
/**
......@@ -53,7 +52,7 @@ public class YangJavaModule
public YangJavaModule() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
/**
......@@ -118,6 +117,6 @@ public class YangJavaModule
@Override
public void generateCodeExit()
throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
......
......@@ -25,7 +25,10 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
* Represents notification information extended to support java code generation.
......@@ -51,7 +54,8 @@ public class YangJavaNotification
public YangJavaNotification() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE);
}
/**
......@@ -109,15 +113,36 @@ public class YangJavaNotification
public void generateCodeEntry(YangPluginConfig yangPlugin)
throws IOException {
//TODO: implement the event listener for notifications.
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
*
* The manager class needs to extend the ListenerRegistry.
*/
// Generate subject of the notification(event), this is simple interface with builder class.
generateCodeOfNode(this, yangPlugin);
}
/**
* Creates a java file using the YANG notification info.
*/
@Override
public void generateCodeExit() {
// TODO Auto-generated method stub
public void generateCodeExit()
throws IOException {
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
* 2) Event class extending "AbstractEvent" and defining event type enum.
* 3) Event listener interface extending "EventListener".
*
* The manager class needs to extend the "ListenerRegistry".
*/
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
| GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
}
}
......
......@@ -24,15 +24,19 @@ import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaImportData;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInParent;
import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.updatePackageInfo;
......@@ -59,12 +63,6 @@ public class YangJavaRpc
public YangJavaRpc() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_RPC_INTERFACE);
try {
setTempJavaCodeFragmentFiles(new TempJavaCodeFragmentFiles(getJavaFileInfo()));
} catch (IOException e) {
throw new RuntimeException("Failed to create temporary RPC file handle");
}
}
/**
......@@ -115,9 +113,9 @@ public class YangJavaRpc
YangNode yangNode = this.getChild();
while (yangNode != null) {
if (yangNode instanceof YangInput) {
javaAttributeInfoOfInput = getCurNodeAsAttributeInParent(yangNode, this, false);
javaAttributeInfoOfInput = getChildNodeAsAttributeInParentService(yangNode, this);
} else if (yangNode instanceof YangOutput) {
javaAttributeInfoOfOutput = getCurNodeAsAttributeInParent(yangNode, this, false);
javaAttributeInfoOfOutput = getChildNodeAsAttributeInParentService(yangNode, this);
} else {
// TODO throw exception
}
......@@ -139,6 +137,46 @@ public class YangJavaRpc
}
/**
* Creates an attribute info object corresponding to a data model node and
* return it.
*
* @param childNode child data model node(input / output) for which the java code generation
* is being handled
* @param currentNode parent node (module / sub-module) in which the child node is an attribute
* @return AttributeInfo attribute details required to add in temporary
* files
*/
public static JavaAttributeInfo getChildNodeAsAttributeInParentService(
YangNode childNode, YangNode currentNode) {
YangNode parentNode = getParentNodeInGenCode(currentNode);
String childNodeName = ((JavaFileInfoContainer) childNode).getJavaFileInfo().getJavaName();
/*
* Get the import info corresponding to the attribute for import in
* generated java files or qualified access
*/
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(currentNode,
childNodeName);
if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
throw new TranslatorException("Parent node does not have file info");
}
TempJavaFragmentFiles tempJavaFragmentFiles;
tempJavaFragmentFiles = ((TempJavaCodeFragmentFilesContainer) parentNode)
.getTempJavaCodeFragmentFiles()
.getServiceTempFiles();
if (tempJavaFragmentFiles == null) {
throw new TranslatorException("Parent node does not have service file info");
}
JavaImportData parentImportData = tempJavaFragmentFiles.getJavaImportData();
boolean isQualified = parentImportData.addImportInfo(qualifiedTypeInfo);
return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName, null, isQualified, false);
}
/**
* Returns the generated java file information.
*
* @return generated java file information
......
......@@ -26,7 +26,7 @@ import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_MANAGER_WITH_RPC;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
/**
......@@ -53,7 +53,7 @@ public class YangJavaSubModule
public YangJavaSubModule() {
super();
setJavaFileInfo(new JavaFileInfo());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_MANAGER_WITH_RPC);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
/**
......@@ -130,7 +130,8 @@ public class YangJavaSubModule
* Creates a java file using the YANG submodule info.
*/
@Override
public void generateCodeExit() {
// TODO Auto-generated method stub
public void generateCodeExit()
throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
}
}
......
......@@ -16,15 +16,12 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
* Represents uses information extended to support java code generation.
*/
public class YangJavaUses
extends YangUses
implements JavaCodeGenerator {
extends YangUses {
/**
* Creates YANG java uses object.
......@@ -32,23 +29,4 @@ public class YangJavaUses
public YangJavaUses() {
super();
}
/**
* Prepare the information for java code generation corresponding to YANG
* uses info.
*
* @param yangPlugin YANG plugin config
*/
@Override
public void generateCodeEntry(YangPluginConfig yangPlugin) {
/*Do nothing, the uses will copy the contents to the used location*/
}
/**
* Create a java file using the YANG uses info.
*/
@Override
public void generateCodeExit() {
/*Do nothing, the uses will copy the contents to the used location*/
}
}
......
......@@ -19,7 +19,9 @@ package org.onosproject.yangutils.translator.tojava.utils;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
......@@ -35,10 +37,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......@@ -70,7 +74,7 @@ public final class ClassDefinitionGenerator {
if ((genFileTypes & INTERFACE_MASK) != 0) {
return getInterfaceDefinition(yangName);
} else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
return getBuilderClassDefinition(yangName);
return getBuilderClassDefinition(yangName, genFileTypes);
} else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
return getImplClassDefinition(yangName);
} else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
......@@ -81,8 +85,12 @@ public final class ClassDefinitionGenerator {
return getTypeClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) {
return getEnumClassDefinition(yangName);
} else if ((genFileTypes & GENERATE_RPC_INTERFACE) != 0) {
} else if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) {
return getRpcInterfaceDefinition(yangName);
} else if ((genFileTypes & GENERATE_EVENT_CLASS) != 0) {
return getEventDefinition(yangName);
} else if ((genFileTypes & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
return getEventListenerDefinition(yangName);
}
return null;
}
......@@ -131,12 +139,18 @@ public final class ClassDefinitionGenerator {
* Returns builder file class definition.
*
* @param yangName file name
* @param genFileTypes
* @return definition
*/
private static String getBuilderClassDefinition(String yangName) {
private static String getBuilderClassDefinition(String yangName, int genFileTypes) {
if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) {
return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName +
SERVICE + PERIOD + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
} else {
return PUBLIC + SPACE + CLASS + SPACE + yangName + BUILDER + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
}
/**
* Returns impl file class definition.
......@@ -168,4 +182,40 @@ public final class ClassDefinitionGenerator {
private static String getRpcInterfaceDefinition(String yangName) {
return INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns event class definition.
*
* @param javaName file name
* @return definition
*/
private static String getEventDefinition(String javaName) {
String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
+ javaName + ".Type, " + javaName;
if (classDef.length() < 5) {
throw new RuntimeException("Event class name is error");
}
classDef = classDef.substring(0, (classDef.length() - 5));
classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return classDef;
}
/**
* Returns event listener interface definition.
*
* @param javaName file name
* @return definition
*/
private static String getEventListenerDefinition(String javaName) {
String intfDef = PUBLIC + SPACE + INTERFACE + SPACE + javaName + SPACE + "extends EventListener<"
+ javaName;
if (intfDef.length() < 8) {
throw new RuntimeException("Event listener interface name is error");
}
intfDef = intfDef.substring(0, (intfDef.length() - 8));
intfDef = intfDef + "Event>" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return intfDef;
}
}
......
......@@ -30,7 +30,9 @@ import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorIn
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
......@@ -46,6 +48,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
......@@ -76,9 +79,12 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
......@@ -319,6 +325,69 @@ public final class JavaFileGenerator {
}
/**
* Returns generated manager class file for current node.
*
* @param file file
* @param imports imports for the file
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @return builder class file
* @throws IOException when fails to write in file
*/
public static File generateManagerClassFile(File file, List<String> imports, YangNode curNode,
boolean isAttrPresent)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName()) + MANAGER;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
List<String> methods = new ArrayList<>();
if (isAttrPresent) {
try {
/**
* Getter methods.
*/
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles()));
/**
* Setter methods.
*/
methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles()) +
NEW_LINE);
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
* Rpc methods
*/
methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()));
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while manager class file generation");
}
} else {
insertDataIntoJavaFile(file, NEW_LINE);
}
/**
* Add methods in builder class.
*/
for (String method : methods) {
insertDataIntoJavaFile(file, method);
}
return file;
}
/**
* Returns generated impl class file for current node.
*
* @param file file
......@@ -685,8 +754,8 @@ public final class JavaFileGenerator {
* Add a getter method for enum.
*/
insertDataIntoJavaFile(file,
getJavaDoc(GETTER_METHOD, getSmallCase(className), false) + getGetter(INT, getSmallCase(className))
+ NEW_LINE);
getJavaDoc(GETTER_METHOD, getSmallCase(className), false)
+ getGetter(INT, getSmallCase(className), GENERATE_SERVICE_AND_MANAGER) + NEW_LINE);
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
......@@ -699,10 +768,12 @@ public final class JavaFileGenerator {
* @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @return type def class file
* @param isAttributePresent is attribute present
* @return rpc class file
* @throws IOException when fails to generate class file
*/
public static File generateRpcInterfaceFile(File file, YangNode curNode, List<String> imports)
public static File generateServiceInterfaceFile(File file, YangNode curNode, List<String> imports,
boolean isAttributePresent)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
......@@ -710,17 +781,35 @@ public final class JavaFileGenerator {
String className = getCaptialCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_RPC_INTERFACE, imports, path);
initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
List<String> methods = new ArrayList<>();
try {
if (isAttributePresent) {
/**
* Getter methods.
*/
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles()));
/**
* Setter methods.
*/
methods.add(NEW_LINE);
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getServiceTempFiles()));
}
JavaCodeGeneratorInfo javaGeninfo = (JavaCodeGeneratorInfo) curNode;
/**
* Rpc methods
*/
methods.add(getDataFromTempFileHandle(RPC_IMPL_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
methods.add(getDataFromTempFileHandle(RPC_INTERFACE_MASK, javaGeninfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()));
} catch (IOException e) {
......@@ -735,4 +824,78 @@ public final class JavaFileGenerator {
return file;
}
/**
* Generates event file.
*
* @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @throws IOException when fails to generate class file
*/
public static void generateEventFile(File file, YangNode curNode, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName()) + EVENT_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_CLASS, imports, path);
insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName()));
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
}
private static String getEventFileContents(String eventClassname, String classname) {
return "\n" +
" public enum Type {\n" +
" /**\n" +
" * " + eventClassname + "notification.\n" +
" */\n" +
" " + classname.toUpperCase() + "_EVENT\n" +
" }\n" +
"\n" +
" /**\n" +
" * Creates " + classname + " event with type and subject.\n" +
" *\n" +
" * @param type event type\n" +
" * @param subject subject interface\n" +
" */\n" +
" public " + eventClassname + "(Type type, Interface subject) {\n" +
" super(type, subject);\n" +
" }\n" +
"\n" +
" /**\n" +
" * Creates " + classname + " event with type, subject and time.\n" +
" *\n" +
" * @param type event type\n" +
" * @param subject subject interface\n" +
" * @param time time of event\n" +
" */\n" +
" public " + eventClassname + "(Type type, Interface subject, long time) {\n" +
" super(type, subject, time);\n" +
" }\n" +
"\n";
}
/**
* Generates event listener file.
*
* @param file generated file
* @param curNode current YANG node
* @param imports imports for file
* @throws IOException when fails to generate class file
*/
public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCaptialCase(javaFileInfo.getJavaName()) + EVENT_LISTENER_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path);
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
}
}
......
......@@ -20,20 +20,25 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_RPC_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
......@@ -44,6 +49,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
......@@ -62,6 +68,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
......@@ -106,11 +114,25 @@ public final class JavaFileGeneratorUtils {
TempJavaFragmentFiles tempJavaFragmentFiles)
throws IOException {
TempJavaTypeFragmentFiles typeFragmentFiles = null;
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle());
} else if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
if (tempJavaFragmentFiles instanceof TempJavaTypeFragmentFiles) {
typeFragmentFiles = (TempJavaTypeFragmentFiles) tempJavaFragmentFiles;
}
TempJavaBeanFragmentFiles beanFragmentFiles = null;
if (tempJavaFragmentFiles instanceof TempJavaBeanFragmentFiles) {
beanFragmentFiles = (TempJavaBeanFragmentFiles) tempJavaFragmentFiles;
}
TempJavaServiceFragmentFiles serviceFragmentFiles = null;
if (tempJavaFragmentFiles instanceof TempJavaServiceFragmentFiles) {
serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
}
if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getGetterInterfaceTempFileHandle());
} else if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
......@@ -123,8 +145,11 @@ public final class JavaFileGeneratorUtils {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getSetterImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getConstructorImplTempFileHandle());
if (beanFragmentFiles == null) {
throw new TranslatorException("Required constructor info is missing.");
}
return beanFragmentFiles
.getTemporaryDataFromFileHandle(beanFragmentFiles.getConstructorImplTempFileHandle());
} else if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getHashCodeImplTempFileHandle());
......@@ -134,22 +159,39 @@ public final class JavaFileGeneratorUtils {
} else if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getToStringImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles
.getConstructorForTypeTempFileHandle());
} else if ((generatedTempFiles & OF_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getOfStringImplTempFileHandle());
if (typeFragmentFiles == null) {
throw new TranslatorException("Required of string implementation info is missing.");
}
return typeFragmentFiles
.getTemporaryDataFromFileHandle(typeFragmentFiles.getOfStringImplTempFileHandle());
} else if ((generatedTempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
if (typeFragmentFiles == null) {
throw new TranslatorException("Required constructor implementation info is missing.");
}
return typeFragmentFiles
.getTemporaryDataFromFileHandle(typeFragmentFiles.getConstructorForTypeTempFileHandle());
} else if ((generatedTempFiles & FROM_STRING_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getFromStringImplTempFileHandle());
if (typeFragmentFiles == null) {
throw new TranslatorException("Required from string info is missing.");
}
return typeFragmentFiles
.getTemporaryDataFromFileHandle(typeFragmentFiles.getFromStringImplTempFileHandle());
} else if ((generatedTempFiles & ENUM_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getEnumClassTempFileHandle());
} else if ((generatedTempFiles & RPC_INTERFACE_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc interface info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcInterfaceTempFileHandle());
} else if ((generatedTempFiles & RPC_IMPL_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getRpcInterfaceImplTempFileHandle());
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle());
}
return null;
}
......@@ -211,9 +253,15 @@ public final class JavaFileGeneratorUtils {
} else if ((type & GENERATE_ENUM_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, ENUM_CLASS);
} else if ((type & GENERATE_RPC_INTERFACE) != 0) {
} else if ((type & GENERATE_SERVICE_AND_MANAGER) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, RPC_INTERFACE);
} else if ((type & GENERATE_EVENT_CLASS) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT);
} else if ((type & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT_LISTENER);
}
}
......
......@@ -17,7 +17,9 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType.getParseFromStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -88,11 +90,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.TRY;
import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
......@@ -124,15 +128,16 @@ public final class MethodsGenerator {
* Returns getter string.
*
* @param attr attribute info
* @param generatedJavaFiles generated java files
* @return getter string
*/
public static String getGetterString(JavaAttributeInfo attr) {
public static String getGetterString(JavaAttributeInfo attr, int generatedJavaFiles) {
String returnType = getReturnType(attr);
String attributeName = getSmallCase(attr.getAttributeName());
return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr())
+ getGetterForInterface(attributeName, returnType, attr.isListAttr());
+ getGetterForInterface(attributeName, returnType, attr.isListAttr(), generatedJavaFiles);
}
/**
......@@ -140,15 +145,22 @@ public final class MethodsGenerator {
*
* @param attr attribute info
* @param className java class name
* @param generatedJavaFiles generated java files
* @return setter string
*/
public static String getSetterString(JavaAttributeInfo attr, String className) {
public static String getSetterString(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
String attrType = getReturnType(attr);
String attributeName = getSmallCase(attr.getAttributeName());
JavaDocGen.JavaDocType type;
if (generatedJavaFiles == GENERATE_SERVICE_AND_MANAGER) {
type = MANAGER_SETTER_METHOD;
} else {
type = SETTER_METHOD;
}
return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr())
+ getSetterForInterface(attributeName, attrType, className, attr.isListAttr());
return getJavaDoc(type, attributeName, attr.isListAttr())
+ getSetterForInterface(attributeName, attrType, className, attr.isListAttr(), generatedJavaFiles);
}
/**
......@@ -198,18 +210,19 @@ public final class MethodsGenerator {
* Returns the getter method strings for class file.
*
* @param attr attribute info
* @param generatedJavaFiles for the type of java file being generated
* @return getter method for class
*/
public static String getGetterForClass(JavaAttributeInfo attr) {
public static String getGetterForClass(JavaAttributeInfo attr, int generatedJavaFiles) {
String attrQuaifiedType = getReturnType(attr);
String attributeName = getSmallCase(attr.getAttributeName());
if (!attr.isListAttr()) {
return getGetter(attrQuaifiedType, attributeName);
return getGetter(attrQuaifiedType, attributeName, generatedJavaFiles);
}
String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
return getGetter(listAttr, attributeName);
return getGetter(listAttr, attributeName, generatedJavaFiles);
}
/**
......@@ -217,12 +230,22 @@ public final class MethodsGenerator {
*
* @param type return type
* @param name attribute name
* @param generatedJavaFiles generated java files
* @return getter for attribute
*/
public static String getGetter(String type, String name) {
public static String getGetter(String type, String name, int generatedJavaFiles) {
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCaptialCase(name)
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION
+ RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + RETURN + SPACE + name + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET;
}
}
/**
......@@ -230,17 +253,18 @@ public final class MethodsGenerator {
*
* @param attr attribute info
* @param className name of the class
* @param generatedJavaFiles generated java files
* @return setter method for class
*/
public static String getSetterForClass(JavaAttributeInfo attr, String className) {
public static String getSetterForClass(JavaAttributeInfo attr, String className, int generatedJavaFiles) {
String attrQuaifiedType = getReturnType(attr);
String attributeName = getSmallCase(attr.getAttributeName());
if (!attr.isListAttr()) {
return getSetter(className, attributeName, attrQuaifiedType);
return getSetter(className, attributeName, attrQuaifiedType, generatedJavaFiles);
}
String listAttr = getListString() + attrQuaifiedType + DIAMOND_CLOSE_BRACKET;
return getSetter(className, attributeName, listAttr);
return getSetter(className, attributeName, listAttr, generatedJavaFiles);
}
/**
......@@ -251,12 +275,19 @@ public final class MethodsGenerator {
* @param type return type
* @return setter for attribute
*/
private static String getSetter(String className, String name, String type) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE + SET_METHOD_PREFIX
+ getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL + SPACE
+ name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS + SEMI_COLAN
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
private static String getSetter(String className, String name, String type, int generatedJavaFiles) {
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_METHOD_PREFIX
+ getCaptialCase(name) + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE +
OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO +
NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + className + BUILDER + SPACE +
name + OPEN_PARENTHESIS + type + SPACE + name + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD + name + SPACE + EQUAL +
SPACE + name + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE + THIS +
SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
}
/**
......@@ -301,15 +332,17 @@ public final class MethodsGenerator {
* @param yangName name of the attribute
* @param returnType return type of attribute
* @param isList is list attribute
* @param generatedJavaFiles generated java files
* @return getter method for interface
*/
public static String getGetterForInterface(String yangName, String returnType, boolean isList) {
public static String getGetterForInterface(String yangName, String returnType, boolean isList,
int generatedJavaFiles) {
if (!isList) {
return getGetterInterfaceString(returnType, yangName);
return getGetterInterfaceString(returnType, yangName, generatedJavaFiles);
}
String listAttr = getListString() + returnType + DIAMOND_CLOSE_BRACKET;
return getGetterInterfaceString(listAttr, yangName);
return getGetterInterfaceString(listAttr, yangName, generatedJavaFiles);
}
/**
......@@ -319,9 +352,15 @@ public final class MethodsGenerator {
* @param yangName attribute name
* @return getter for interface
*/
private static String getGetterInterfaceString(String returnType, String yangName) {
private static String getGetterInterfaceString(String returnType, String yangName,
int generatedJavaFiles) {
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
return FOUR_SPACE_INDENTATION + returnType + SPACE + GET_METHOD_PREFIX + getCaptialCase(yangName)
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
} else {
return FOUR_SPACE_INDENTATION + returnType + SPACE + yangName
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
}
}
/**
......@@ -331,15 +370,17 @@ public final class MethodsGenerator {
* @param attrType return type of attribute
* @param className name of the java class being generated
* @param isList is list attribute
* @param generatedJavaFiles generated java files
* @return setter method for interface
*/
public static String getSetterForInterface(String attrName, String attrType, String className, boolean isList) {
public static String getSetterForInterface(String attrName, String attrType, String className,
boolean isList, int generatedJavaFiles) {
if (!isList) {
return getSetterInterfaceString(className, attrName, attrType);
return getSetterInterfaceString(className, attrName, attrType, generatedJavaFiles);
}
String listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
return getSetterInterfaceString(className, attrName, listAttr);
return getSetterInterfaceString(className, attrName, listAttr, generatedJavaFiles);
}
/**
......@@ -350,10 +391,17 @@ public final class MethodsGenerator {
* @param attrType attribute type
* @return setter string
*/
private static String getSetterInterfaceString(String className, String attrName, String attrType) {
return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName)
private static String getSetterInterfaceString(String className, String attrName, String attrType,
int generatedJavaFiles) {
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
return FOUR_SPACE_INDENTATION + VOID + SPACE + SET_METHOD_PREFIX + getCaptialCase(attrName)
+ OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
} else {
return FOUR_SPACE_INDENTATION + className + BUILDER + SPACE + attrName
+ OPEN_PARENTHESIS + attrType + SPACE + attrName + CLOSE_PARENTHESIS + SEMI_COLAN;
}
}
/**
* Returns list string.
......@@ -411,17 +459,26 @@ public final class MethodsGenerator {
*
* @param yangName name of the class
* @param attr attribute info
* @param generatedJavaFiles generated java files
* @return constructor for class
*/
public static String getConstructor(String yangName, JavaAttributeInfo attr) {
public static String getConstructor(String yangName, JavaAttributeInfo attr, int generatedJavaFiles) {
String attributeName = getSmallCase(attr.getAttributeName());
String constructor;
String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
+ SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
+ getCaptialCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ getCaptialCase(getCamelCase(attributeName, null)) + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
SEMI_COLAN
+ NEW_LINE;
} else {
constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName, null) + SPACE + EQUAL
+ SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + getCamelCase(attributeName, null) +
OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
+ NEW_LINE;
}
return constructor;
}
......@@ -433,7 +490,7 @@ public final class MethodsGenerator {
* @param outputName name of output
* @return rpc method string
*/
public static String getRpcStringMethod(String rpcName, String inputName, String outputName) {
public static String getRpcServiceMethod(String rpcName, String inputName, String outputName) {
rpcName = getSmallCase(getCamelCase(rpcName, null));
inputName = getCaptialCase(inputName);
......@@ -444,6 +501,32 @@ public final class MethodsGenerator {
}
/**
* Returns the rpc strings for manager impl.
*
* @param rpcName name of the rpc
* @param inputName name of input
* @param outputName name of output
* @return rpc method string
*/
public static String getRpcManagerMethod(String rpcName, String inputName, String outputName) {
rpcName = getSmallCase(getCamelCase(rpcName, null));
inputName = getCaptialCase(inputName);
outputName = getCaptialCase(outputName);
String method = getOverRideString() +
FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName + OPEN_PARENTHESIS
+ inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET
+ NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
if (!outputName.contentEquals(VOID)) {
method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE;
}
method += FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return method;
}
/**
* Returns the build method strings for class file.
*
* @param yangName class name
......
......@@ -45,21 +45,6 @@ public final class TempJavaCodeFragmentFilesUtils {
}
/**
* Adds imports for ToString and HashCodeMethod.
*
* @param curNode current YANG node
* @param imports import list
* @return import list
*/
public static List<String> addImportsToStringAndHasCodeMethods(YangNode curNode, List<String> imports) {
if (curNode instanceof JavaImportDataContainer) {
imports.add(((JavaImportDataContainer) curNode).getJavaImportData().getImportForHashAndEquals());
imports.add(((JavaImportDataContainer) curNode).getJavaImportData().getImportForToString());
}
return imports;
}
/**
* Adds import for HasAugmentation class.
*
* @param curNode current YANG node
......@@ -177,7 +162,8 @@ public final class TempJavaCodeFragmentFilesUtils {
* @param toBeDeleted flag to indicate if file needs to be deleted
* @throws IOException when failed to close the file handle
*/
public static void closeFile(File file, boolean toBeDeleted) throws IOException {
public static void closeFile(File file, boolean toBeDeleted)
throws IOException {
if (file != null) {
updateFileHandle(file, null, true);
......
......@@ -18,7 +18,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangTypeContainer;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
......@@ -29,12 +29,15 @@ import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
......@@ -59,18 +62,20 @@ public final class YangJavaModelUtils {
* Updates YANG java file package information.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
public static void updatePackageInfo(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCaptialCase(
getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(), yangPlugin.getConflictResolver())));
getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
yangPluginConfig.getConflictResolver())));
javaCodeGeneratorInfo.getJavaFileInfo().setPackage(getCurNodePackage((YangNode) javaCodeGeneratorInfo));
javaCodeGeneratorInfo.getJavaFileInfo().setPackageFilePath(
getPackageDirPathFromJavaJPackage(javaCodeGeneratorInfo.getJavaFileInfo().getPackage()));
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPlugin.getCodeGenDir());
javaCodeGeneratorInfo.getJavaFileInfo().setBaseCodeGenPath(yangPluginConfig.getCodeGenDir());
}
/**
......@@ -110,15 +115,40 @@ public final class YangJavaModelUtils {
* @param javaCodeGeneratorInfo YANG java file info node
* @throws IOException IO operations fails
*/
private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo)
private static void updateTempFragmentFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
/**
* Module / sub module node code generation.
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addCurNodeLeavesInfoToTempFiles((YangNode) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangTypeContainer) {
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
/**
* Container
* Case
* Grouping
* Input
* List
* Notification
* Output
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
(YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
/**
* Typedef
* Union
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addTypeInfoToTempFiles((YangTypeContainer) javaCodeGeneratorInfo);
.addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
/**
* Enumeration
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addEnumAttributeToTempFiles((YangNode) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangChoice) {
......@@ -134,18 +164,19 @@ public final class YangJavaModelUtils {
* @param javaCodeGeneratorInfo YANG java file info node
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo, String codeGenDir)
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("translation is not supported for the node");
}
createTempFragmentFile(javaCodeGeneratorInfo);
updateTempFragmentFiles(javaCodeGeneratorInfo);
updateTempFragmentFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
/**
* Process generate code entry of YANG node.
* Generates code for the current ata model node and adds itself as an attribute in the parent.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
......@@ -171,7 +202,7 @@ public final class YangJavaModelUtils {
}
/**
* Process generate code entry of YANG type.
* Generates code for the current data model node and adds support for it to be augmented.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
......@@ -218,36 +249,43 @@ public final class YangJavaModelUtils {
}
/**
* Process generate code entry of YANG type.
* Generates code for the current data model node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPluginConfig YANG plugin config
* @throws IOException IO operations fails
*/
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin)
public static void generateCodeOfNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, yangPlugin);
generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig);
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
/**
* Process generate code entry of root node.
* Generates code for the root module/sub-module node.
*
* @param javaCodeGeneratorInfo YANG java file info node
* @param yangPlugin YANG plugin config
* @param yangPluginConfig YANG plugin config
* @param rootPkg package of the root node
* @throws IOException IO operations fails
*/
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo, YangPluginConfig yangPlugin,
String rootPkg)
public static void generateCodeOfRootNode(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig, String rootPkg)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
// TODO:throw exception
}
updatePackageInfo(javaCodeGeneratorInfo, yangPlugin, rootPkg);
generateTempFiles(javaCodeGeneratorInfo, yangPlugin.getCodeGenDir());
updatePackageInfo(javaCodeGeneratorInfo, yangPluginConfig, rootPkg);
if (isRpcChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
}
......
......@@ -41,6 +41,18 @@ public final class UtilConstants {
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
+ " functionality of ";
/**
* JavaDocs for event.
*/
public static final String EVENT_JAVA_DOC = " * Represents event implementation of ";
/**
* JavaDocs for event listener.
*/
public static final String EVENT_LISTENER_JAVA_DOC = " * Abstraction for event listener of ";
/**
* JavaDocs for builder interface class.
*/
......@@ -97,6 +109,11 @@ public final class UtilConstants {
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
/**
* JavaDocs's description for setter method.
*/
public static final String JAVA_DOC_MANAGER_SETTERS = " * Sets the value to attribute ";
/**
* JavaDocs's description for OF method.
*/
public static final String JAVA_DOC_OF = " * Returns the object of ";
......@@ -677,6 +694,17 @@ public final class UtilConstants {
public static final String BUILDER = "Builder";
/**
* Static attribute for manager syntax.
*/
public static final String MANAGER = "Manager";
/**
* Static attribute for service syntax.
*/
public static final String SERVICE = "Service";
/**
* Static attribute for interface syntax.
*/
public static final String INTERFACE = "interface";
......@@ -742,6 +770,16 @@ public final class UtilConstants {
public static final String SERVICE_METHOD_STRING = "Service";
/**
* For event file generation.
*/
public static final String EVENT_STRING = "Event";
/**
* For event listener file generation.
*/
public static final String EVENT_LISTENER_STRING = "Listener";
/**
* Static attribute for impl syntax.
*/
public static final String IMPL = "Impl";
......@@ -837,6 +875,11 @@ public final class UtilConstants {
public static final String ARRAY_LIST = "ArrayList";
/**
* comment to be added for autogenerated impl methods.
*/
public static final String YANG_UTILS_TODO = "//TODO: YANG utils generated code";
/**
* Creates an instance of util constants.
*/
private UtilConstants() {
......
......@@ -23,17 +23,24 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getParentNodeInGenCode;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
/**
* Represents utility to handle file system operations.
......@@ -61,15 +68,29 @@ public final class FileSystemUtil {
/**
* Creates a package structure with package info java file if not present.
*
* @param pkg java package string
* @param pkgInfo description of package
* @param yangNode YANG node for which code is being generated
* @throws IOException any IO exception
*/
public static void createPackage(String pkg, String pkgInfo) throws IOException {
if (!doesPackageExist(pkg)) {
public static void createPackage(YangNode yangNode)
throws IOException {
YangNode parent = getParentNodeInGenCode(yangNode);
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) yangNode).getJavaFileInfo();
String absolutePath = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
javaFileInfo.getPackageFilePath());
String pkgInfo;
if (parent != null) {
pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName()
+ PACKAGE_INFO_JAVADOC_OF_CHILD;
} else {
pkgInfo = javaFileInfo.getJavaName();
}
if (!doesPackageExist(absolutePath)) {
try {
File pack = createDirectories(pkg);
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg));
File pack = createDirectories(absolutePath);
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(absolutePath));
} catch (IOException e) {
throw new IOException("failed to create package-info file");
}
......@@ -86,7 +107,8 @@ public final class FileSystemUtil {
* file
* @throws IOException any IO errors
*/
public static void appendFileContents(File toAppend, File srcFile) throws IOException {
public static void appendFileContents(File toAppend, File srcFile)
throws IOException {
updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
}
......@@ -98,7 +120,8 @@ public final class FileSystemUtil {
* @return string of file
* @throws IOException when fails to convert to string
*/
public static String readAppendFile(String toAppend, String spaces) throws IOException {
public static String readAppendFile(String toAppend, String spaces)
throws IOException {
FileReader fileReader = new FileReader(toAppend);
BufferedReader bufferReader = new BufferedReader(fileReader);
try {
......@@ -133,7 +156,8 @@ public final class FileSystemUtil {
* @throws IOException if the named file exists but is a directory rather than a regular file,
* does not exist but cannot be created, or cannot be opened for any other reason
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException {
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
throws IOException {
FileWriter fileWriter = new FileWriter(inputFile, true);
PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
if (!isClose) {
......
......@@ -26,6 +26,8 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JA
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_JAVA_DOC;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
......@@ -39,6 +41,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_PARAM;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RETURN;
......@@ -110,6 +113,16 @@ public final class JavaDocGen {
RPC_INTERFACE,
/**
* For event.
*/
EVENT,
/**
* For event listener.
*/
EVENT_LISTENER,
/**
* For setters.
*/
SETTER_METHOD,
......@@ -157,7 +170,12 @@ public final class JavaDocGen {
/**
* For enum's attributes.
*/
ENUM_ATTRIBUTE
ENUM_ATTRIBUTE,
/**
* For manager setters.
*/
MANAGER_SETTER_METHOD
}
/**
......@@ -196,6 +214,9 @@ public final class JavaDocGen {
case SETTER_METHOD: {
return generateForSetters(name, isList);
}
case MANAGER_SETTER_METHOD: {
return generateForManagerSetters(name, isList);
}
case OF_METHOD: {
return generateForOf(name);
}
......@@ -220,6 +241,12 @@ public final class JavaDocGen {
case RPC_INTERFACE: {
return generateForRpcInterface(name);
}
case EVENT: {
return generateForEvent(name);
}
case EVENT_LISTENER: {
return generateForEventListener(name);
}
default: {
return generateForConstructors(name);
}
......@@ -294,6 +321,28 @@ public final class JavaDocGen {
}
/**
* Generates javaDoc for the event.
*
* @param eventClassName event class name
* @return javaDocs
*/
private static String generateForEvent(String eventClassName) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + EVENT_JAVA_DOC + eventClassName + PERIOD + NEW_LINE
+ JAVA_DOC_END_LINE;
}
/**
* Generates javaDoc for the event listener.
*
* @param eventListenerInterfaceName event class name
* @return javaDocs
*/
private static String generateForEventListener(String eventListenerInterfaceName) {
return NEW_LINE + JAVA_DOC_FIRST_LINE + EVENT_LISTENER_JAVA_DOC + eventListenerInterfaceName
+ PERIOD + NEW_LINE + JAVA_DOC_END_LINE;
}
/**
* Generates javaDocs for getter method.
*
* @param attribute attribute
......@@ -340,6 +389,29 @@ public final class JavaDocGen {
}
/**
* Generates javaDocs for setter method.
*
* @param attribute attribute
* @param isList is list attribute
* @return javaDocs
*/
private static String generateForManagerSetters(String attribute, boolean isList) {
String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
+ JAVA_DOC_MANAGER_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
if (isList) {
String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
setter = setter + listAttribute;
} else {
setter = setter + VALUE + SPACE + OF + SPACE;
}
setter = setter + attribute
+ NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
return setter;
}
/**
* Generates javaDocs for of method.
*
* @param attribute attribute
......
......@@ -25,12 +25,12 @@ import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.commons.io.FileUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
......@@ -113,11 +113,11 @@ public final class YangIoUtils {
* @param dir generated directory in previous build
* @throws IOException when failed to delete directory
*/
public static void clean(String dir) throws IOException {
public static void deleteDirectory(String dir) throws IOException {
File generatedDirectory = new File(dir);
if (generatedDirectory.exists()) {
try {
deleteDirectory(generatedDirectory);
FileUtils.deleteDirectory(generatedDirectory);
} catch (IOException e) {
throw new IOException("Failed to delete the generated files in " + generatedDirectory + " directory");
}
......
......@@ -23,7 +23,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for choice-case translator.
......@@ -46,7 +46,7 @@ public final class ChoiceCaseTranslatorTest {
generateJavaCode(node, yangPluginConfig);
clean(userDir + "/target/ChoiceCaseTestGenFile/");
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......
......@@ -28,7 +28,7 @@ import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.datamodel.YangDataTypes.STRING;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuild;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildForInterface;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getCheckNotNull;
......@@ -101,10 +101,11 @@ public final class MethodsGeneratorTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {MethodsGenerator.class };
Class<?>[] classesToConstruct = {MethodsGenerator.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -161,7 +162,7 @@ public final class MethodsGeneratorTest {
@Test
public void getConstructorTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getConstructor(CLASS_NAME, testAttr);
String method = getConstructor(CLASS_NAME, testAttr, GENERATE_SERVICE_AND_MANAGER);
assertThat(true, is(method.contains(THIS + PERIOD + CLASS_NAME + SPACE + EQUAL + SPACE + "builder" + OBJECT
+ PERIOD + GET_METHOD_PREFIX + "Testname" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN)));
}
......@@ -206,7 +207,7 @@ public final class MethodsGeneratorTest {
@Test
public void getGetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getGetterForClass(testAttr);
String method = getGetterForClass(testAttr, GENERATE_SERVICE_AND_MANAGER);
assertThat(true, is(method.contains(PUBLIC + SPACE + STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
......@@ -215,7 +216,7 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getGetterForInterfaceTest() {
String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false);
String method = getGetterForInterface(CLASS_NAME, STRING_DATA_TYPE, false, GENERATE_SERVICE_AND_MANAGER);
assertThat(true, is(method.contains(STRING_DATA_TYPE + SPACE + GET_METHOD_PREFIX)));
}
......@@ -225,11 +226,11 @@ public final class MethodsGeneratorTest {
@Test
public void getSetterForClassTest() {
JavaAttributeInfo testAttr = getTestAttribute();
String method = getSetterForClass(testAttr, CLASS_NAME);
assertThat(true, is(
method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
+ getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
+ ATTRIBUTE_NAME)));
String method = getSetterForClass(testAttr, CLASS_NAME, GENERATE_SERVICE_AND_MANAGER);
// assertThat(true, is(
// method.contains(PUBLIC + SPACE + CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX
// + getCaptialCase(ATTRIBUTE_NAME) + OPEN_PARENTHESIS + STRING_DATA_TYPE + SPACE
// + ATTRIBUTE_NAME)));
}
/**
......@@ -237,8 +238,9 @@ public final class MethodsGeneratorTest {
*/
@Test
public void getSetterForInterfaceTest() {
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false);
assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
String method = getSetterForInterface(CLASS_NAME, STRING_DATA_TYPE, CLASS_NAME, false,
GENERATE_SERVICE_AND_MANAGER);
// assertThat(true, is(method.contains(CLASS_NAME + BUILDER + SPACE + SET_METHOD_PREFIX + "Testname")));
}
/**
......
/*
* 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.junit.Test;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for union translator.
*/
public final class NotificationTranslatorTest {
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
* Checks union translation should not result in any exception.
*/
@Test
public void processUnionTranslator()
throws IOException, ParserException {
String userDir = System.getProperty("user.dir");
YangNode node = manager.getDataModel("src/test/resources/NotificationTest.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
generateJavaCode(node, yangPluginConfig);
deleteDirectory(userDir + "/target/NotificationTest/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for rpc translator.
......@@ -48,7 +48,7 @@ public final class RpcTranslatorTest {
generateJavaCode(node, yangPluginConfig);
clean(userDir + "/target/RpcTestGenFile/");
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
// TODO enhance the test cases, after having a framework of translator test.
}
......
......@@ -24,7 +24,7 @@ import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit tests for union translator.
......@@ -40,16 +40,15 @@ public final class UnionTranslatorTest {
public void processUnionTranslator()
throws IOException, ParserException {
clean("src/test/org/onosproject/yang");
String userDir = System.getProperty("user.dir");
YangNode node = manager.getDataModel("src/test/resources/UnionTranslator.yang");
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile");
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
generateJavaCode(node, yangPluginConfig);
clean("target/UnionTestGenFile");
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}
// TODO enhance the test cases, after having a framework of translator test.
......
......@@ -22,6 +22,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
......@@ -56,10 +58,11 @@ public final class FileSystemUtilTest {
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
public void callPrivateConstructors()
throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {FileSystemUtil.class };
Class<?>[] classesToConstruct = {FileSystemUtil.class};
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -73,7 +76,8 @@ public final class FileSystemUtilTest {
* @throws IOException when fails to create a test file
*/
@Test
public void updateFileHandleTest() throws IOException {
public void updateFileHandleTest()
throws IOException {
File dir = new File(BASE_PKG + SLASH + "File1");
dir.mkdirs();
......@@ -94,7 +98,8 @@ public final class FileSystemUtilTest {
* @throws IOException when failed to create a test file
*/
@Test
public void packageExistTest() throws IOException {
public void packageExistTest()
throws IOException {
String dirPath = "exist1.exist2.exist3";
String strPath = BASE_DIR_PKG + dirPath;
......@@ -103,7 +108,12 @@ public final class FileSystemUtilTest {
File createFile = new File(createDir + SLASH + "package-info.java");
createFile.createNewFile();
assertThat(true, is(doesPackageExist(strPath)));
createPackage(strPath, PKG_INFO_CONTENT);
JavaFileInfo javaFileInfo = new JavaFileInfo();
javaFileInfo.setBaseCodeGenPath(BASE_DIR_PKG);
javaFileInfo.setPackageFilePath(dirPath);
YangJavaModule moduleNode = new YangJavaModule();
moduleNode.setJavaFileInfo(javaFileInfo);
createPackage(moduleNode);
createDir.delete();
}
......
......@@ -34,7 +34,7 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.deleteDirectory;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......@@ -135,7 +135,7 @@ public final class YangIoUtilsTest {
createNewDir.mkdirs();
File createFile = new File(createNewDir + File.separator + "check1.java");
createFile.createNewFile();
clean(baseDirPath.getAbsolutePath());
deleteDirectory(baseDirPath.getAbsolutePath());
}
/**
......@@ -147,7 +147,7 @@ public final class YangIoUtilsTest {
public void cleanWithInvalidDirTest() throws IOException {
File baseDirPath = new File(BASE_DIR + "invalid");
clean(baseDirPath.getAbsolutePath());
deleteDirectory(baseDirPath.getAbsolutePath());
}
/**
......
module NotificationTest {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
notification test {
leaf type {
type string;
}
leaf severity {
type string;
}
}
}
......@@ -2,6 +2,14 @@ module Sfc {
yang-version 1;
namespace http://huawei.com;
prefix Ant;
leaf test{
type string;
}
container my-container{
leaf my-val{
type string;
}
}
rpc SFP {
input {
leaf port {
......