Bharat saraswal
Committed by Patrick Liu

[ONOS-4839] update file priority for translator and OP param file impl defect fix

Change-Id: Ieaef43f915996ed0a34dfa17c338ab612716b2bc
Showing 44 changed files with 1620 additions and 1390 deletions
......@@ -32,6 +32,11 @@ public class YangAtomicPath implements Serializable {
private List<YangPathPredicate> pathPredicatesList;
/**
* Resolved node for the absolute path.
*/
private YangNode resolvedNode;
/**
* Returns the node identifier.
*
* @return the node identifier
......@@ -75,4 +80,23 @@ public class YangAtomicPath implements Serializable {
public void addLeavesPredicate(YangPathPredicate predicatesExp) {
getPathPredicatesList().add(predicatesExp);
}
/**
* Returns resolved node.
*
* @return resolved node
*/
public YangNode getResolvedNode() {
return resolvedNode;
}
/**
* Sets resolved node.
*
* @param resolvedNode resolved node
*/
public void setResolvedNode(YangNode resolvedNode) {
this.resolvedNode = resolvedNode;
}
}
......
......@@ -15,10 +15,8 @@
*/
package org.onosproject.yangutils.datamodel;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.datamodel.utils.Parsable;
......@@ -130,11 +128,6 @@ public class YangAugment
private YangNode augmentedNode;
/**
* All resolved nodes in given xPath.
*/
private Map<YangAtomicPath, YangNode> resolveNodeInPath;
/**
* Status of resolution. If completely resolved enum value is "RESOLVED", if not enum value is "UNRESOLVED", in case
* reference of grouping/typedef is added to uses/type but it's not resolved value of enum should be
* "INTRA_FILE_RESOLVED".
......@@ -156,7 +149,6 @@ public class YangAugment
*/
public YangAugment() {
super(YangNodeType.AUGMENT_NODE);
resolveNodeInPath = new HashMap<>();
resolvableStatus = ResolvableStatus.UNRESOLVED;
}
......@@ -447,21 +439,4 @@ public class YangAugment
return null;
}
/**
* Returns all resolved node in path.
*
* @return all resolved node in path
*/
public Map<YangAtomicPath, YangNode> getResolveNodeInPath() {
return resolveNodeInPath;
}
/**
* Sets all resolved node in path.
*
* @param resolveNodeInPath all resolved node in path
*/
public void setResolveNodeInPath(Map<YangAtomicPath, YangNode> resolveNodeInPath) {
this.resolveNodeInPath = resolveNodeInPath;
}
}
......
/*
* 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.datamodel;
/**
* Abstraction of an entity which represent operation parameter info for augmentable node.
*/
public interface YangAugmentedOpParamInfo extends YangAugmentedInfo {
/**
* Returns class object of base class.
*
* @return class object of base class
*/
Class<?> getBaseClass();
/**
* Returns if augmented info's contents matches.
*
* @param augmentedInfo augmented info
* @return true or false
*/
boolean isFilterContentMatch(Object augmentedInfo);
}
......@@ -79,7 +79,7 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
*/
public class YangGrouping
extends YangNode
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201607L;
......
......@@ -64,6 +64,11 @@ public abstract class YangNode
private int priority;
/**
* Flag if the node is for translation.
*/
private boolean isToTranslate = true;
/**
* Returns the priority of the node.
*
* @return priority of the node
......@@ -268,6 +273,7 @@ public abstract class YangNode
/**
* Clones the current node contents and create a new node.
*
* @param yangUses YANG uses
* @return cloned node
* @throws CloneNotSupportedException clone is not supported by the referred
* node
......@@ -297,6 +303,7 @@ public abstract class YangNode
*
* @param srcRootNode source node for sub tree cloning
* @param dstRootNode destination node where the sub tree needs to be cloned
* @param yangUses YANG uses
* @throws DataModelException data model error
*/
public static void cloneSubTree(YangNode srcRootNode, YangNode dstRootNode, YangUses yangUses)
......@@ -411,6 +418,24 @@ public abstract class YangNode
}
/**
* /** Returns true if translation required.
*
* @return true if translation required
*/
public boolean isToTranslate() {
return isToTranslate;
}
/**
* Sest true if translation required.
*
* @param toTranslate true if translation required.
*/
public void setToTranslate(boolean toTranslate) {
isToTranslate = toTranslate;
}
/**
* Adds a new next sibling.
*
* @param newSibling new sibling to be added
......
/*
* 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.datamodel;
/**
* Abstraction of an entity which provides info about whether to translate module/submodule in manager and service
* classes.
*/
public interface YangTranslatorOperatorNode {
}
......@@ -57,7 +57,8 @@ import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.detectCol
/**
* Represents data model node to maintain information defined in YANG typedef.
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector {
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable, YangTypeHolder, CollisionDetector,
YangTranslatorOperatorNode {
private static final long serialVersionUID = 806201615L;
......
......@@ -370,6 +370,7 @@ public final class DataModelUtils {
*
* @param clonedLeaf cloned leaf in uses from grouping
* @param leafParentHolder holder of the leaf from uses
* @param yangUses YANG uses
* @return entity of leafref which has to be resolved
* @throws DataModelException data model error
*/
......
......@@ -19,7 +19,7 @@ package org.onosproject.yangutils.linker.impl;
/**
* Enum for prefix resolver type when augment has come in path.
*/
public enum PrefixResolverType {
enum PrefixResolverType {
/**
* When prefix changes from inter file to intra file.
......@@ -37,12 +37,12 @@ public enum PrefixResolverType {
INTER_TO_INTER,
/**
* When no prefix change occurres.
* When no prefix change occurs.
*/
NO_PREFIX_CHANGE_FOR_INTRA,
/**
* When no prefix change occurres.
* When no prefix change occurs.
*/
NO_PREFIX_CHANGE_FOR_INTER
}
......
......@@ -18,13 +18,11 @@ package org.onosproject.yangutils.linker.impl;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.YangSubModule;
......@@ -32,6 +30,7 @@ import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.linker.YangLinker;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
/**
......@@ -191,52 +190,4 @@ public class YangLinkerManager
}
}
/**
* Updates the priority for all the input files.
*
* @param yangNodeSet set of YANG files info
*/
public void updateFilePriority(Set<YangNode> yangNodeSet) {
for (YangNode yangNode : yangNodeSet) {
updateFilePriorityOfNode(yangNode);
}
}
/**
* Updates priority of the node.
*
* @param yangNode YANG node information
*/
public void updateFilePriorityOfNode(YangNode yangNode) {
int curNodePriority = yangNode.getPriority();
if (yangNode instanceof YangReferenceResolver) {
List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
if (yangImportList != null && !yangImportList.isEmpty()) {
Iterator<YangImport> importInfoIterator = yangImportList.iterator();
// Run through the imported list to update priority.
while (importInfoIterator.hasNext()) {
YangImport yangImport = importInfoIterator.next();
YangNode importedNode = yangImport.getImportedNode();
if (curNodePriority >= importedNode.getPriority()) {
importedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(importedNode);
}
}
}
List<YangInclude> yangIncludeList = ((YangReferenceResolver) yangNode).getIncludeList();
if (yangIncludeList != null && !yangIncludeList.isEmpty()) {
Iterator<YangInclude> includeInfoIterator = yangIncludeList.iterator();
// Run through the imported list to update priority.
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangNode includedNode = yangInclude.getIncludedNode();
if (curNodePriority >= includedNode.getPriority()) {
includedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(includedNode);
}
}
}
}
}
}
......
......@@ -16,24 +16,29 @@
package org.onosproject.yangutils.linker.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangAugmentedInfo;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeafRef;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangReferenceResolver;
import org.onosproject.yangutils.datamodel.utils.YangConstructType;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
......@@ -43,13 +48,13 @@ import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
*/
public final class YangLinkerUtils {
private YangLinkerUtils() {
}
private static final int IDENTIFIER_LENGTH = 64;
private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
private static final String XML = "xml";
private YangLinkerUtils() {
}
/**
* Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node.
*
......@@ -59,61 +64,75 @@ public final class YangLinkerUtils {
private static void detectCollision(YangNode targetNode, YangAugment augment) {
YangNode targetNodesChild = targetNode.getChild();
YangNode augmentsChild = augment.getChild();
YangLeavesHolder augmentsLeavesHolder = augment;
YangNode parent = targetNode;
if (targetNode instanceof YangAugment) {
parent = targetNode.getParent();
} else {
while (parent.getParent() != null) {
parent = parent.getParent();
}
}
if (targetNode instanceof YangChoice) {
if (augmentsLeavesHolder.getListOfLeaf() != null
|| augmentsLeavesHolder.getListOfLeafList() != null) {
throw new LinkerException("target node " + targetNode.getName()
+ "is a instance of choice. it can " +
"only be augmented with leaf using a case node.");
// no need to check here.
} else {
detectCollisionInLeaveHolders(targetNode, augment);
while (augmentsChild != null) {
detectCollisionInChildNodes(targetNodesChild, augmentsChild, targetNode.getName(), parent.getName());
augmentsChild = augmentsChild.getNextSibling();
}
}
}
/*Detects collision between leaves/leaflists*/
private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
if (targetNode instanceof YangAugment) {
parent = targetNode.getParent();
} else {
YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
YangNode parent = targetNode;
if (targetNode instanceof YangAugment) {
parent = targetNode.getParent();
} else {
while (parent.getParent() != null) {
parent = parent.getParent();
}
while (parent.getParent() != null) {
parent = parent.getParent();
}
if (augmentsLeavesHolder.getListOfLeaf() != null && augmentsLeavesHolder.getListOfLeaf().size() != 0
&& targetNodesLeavesHolder.getListOfLeaf() != null) {
for (YangLeaf leaf : augmentsLeavesHolder.getListOfLeaf()) {
for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
if (targetLeaf.getName().equals(leaf.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented leaf " + leaf.getName() + " in module "
+ parent.getName());
}
}
if (augment.getListOfLeaf() != null && augment.getListOfLeaf().size() != 0
&& targetNodesLeavesHolder.getListOfLeaf() != null) {
for (YangLeaf leaf : augment.getListOfLeaf()) {
for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
if (targetLeaf.getName().equals(leaf.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented leaf " + leaf.getName() + " in module "
+ parent.getName());
}
}
} else if (augmentsLeavesHolder.getListOfLeafList() != null
&& augmentsLeavesHolder.getListOfLeafList().size() != 0
&& targetNodesLeavesHolder.getListOfLeafList() != null) {
for (YangLeafList leafList : augmentsLeavesHolder.getListOfLeafList()) {
for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
if (targetLeafList.getName().equals(leafList.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented leaf-list" + leafList.getName() + " in module "
+ parent.getName());
}
}
} else if (augment.getListOfLeafList() != null
&& augment.getListOfLeafList().size() != 0
&& augment.getListOfLeafList() != null) {
for (YangLeafList leafList : augment.getListOfLeafList()) {
for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
if (targetLeafList.getName().equals(leafList.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented leaf-list" + leafList.getName() + " in module "
+ parent.getName());
}
}
} else {
while (augmentsChild != null) {
while (targetNodesChild != null) {
if (targetNodesChild.getName().equals(augmentsChild.getName())) {
throw new LinkerException("target node " + targetNode.getName()
+ " contains augmented child node" + augmentsChild.getName() + " in module "
+ parent.getName());
}
targetNodesChild = targetNodesChild.getNextSibling();
}
augmentsChild = augmentsChild.getNextSibling();
}
}
}
/*Detects collision for child nodes.*/
private static void detectCollisionInChildNodes(YangNode targetNodesChild, YangNode augmentsChild, String
targetName, String parentName) {
while (augmentsChild != null) {
while (targetNodesChild != null) {
if (targetNodesChild.getName().equals(augmentsChild.getName())) {
throw new LinkerException("target node " + targetName
+ " contains augmented child node" + augmentsChild.getName() + " in module "
+ parentName);
}
targetNodesChild = targetNodesChild.getNextSibling();
}
augmentsChild = augmentsChild.getNextSibling();
}
}
......@@ -124,7 +143,7 @@ public final class YangLinkerUtils {
* @param targetNode target node
* @param augment augment node
*/
public static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
// Detect collision for target node and augment node.
detectCollision(targetNode, augment);
List<YangAugmentedInfo> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
......@@ -228,4 +247,49 @@ public final class YangLinkerUtils {
return identifier;
}
}
/**
* Updates the priority for all the input files.
*
* @param yangNodeSet set of YANG files info
*/
public static void updateFilePriority(Set<YangNode> yangNodeSet) {
for (YangNode yangNode : yangNodeSet) {
updateFilePriorityOfNode(yangNode);
}
}
/**
* Updates priority of the node.
*
* @param yangNode YANG node information
*/
public static void updateFilePriorityOfNode(YangNode yangNode) {
int curNodePriority = yangNode.getPriority();
if (yangNode instanceof YangReferenceResolver) {
List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
Iterator<YangImport> importInfoIterator = yangImportList.iterator();
// Run through the imported list to update priority.
while (importInfoIterator.hasNext()) {
YangImport yangImport = importInfoIterator.next();
YangNode importedNode = yangImport.getImportedNode();
if (curNodePriority >= importedNode.getPriority()) {
importedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(importedNode);
}
}
List<YangInclude> yangIncludeList = ((YangReferenceResolver) yangNode).getIncludeList();
Iterator<YangInclude> includeInfoIterator = yangIncludeList.iterator();
// Run through the imported list to update priority.
while (includeInfoIterator.hasNext()) {
YangInclude yangInclude = includeInfoIterator.next();
YangNode includedNode = yangInclude.getIncludedNode();
if (curNodePriority >= includedNode.getPriority()) {
includedNode.setPriority(curNodePriority + 1);
updateFilePriorityOfNode(includedNode);
}
}
}
}
}
......
......@@ -1209,7 +1209,6 @@ public class YangResolutionInfoImpl<T>
detectCollisionForAugmentedNode(targetNode, augment);
((YangAugmentableNode) targetNode).addAugmentation(augment);
augment.setAugmentedNode(targetNode);
augment.setResolveNodeInPath(xPathLinker.getResolvedNodes());
Resolvable resolvable = (Resolvable) entityToResolve;
resolvable.setResolvableStatus(RESOLVED);
} else {
......
......@@ -16,6 +16,12 @@
package org.onosproject.yangutils.linker.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
......@@ -37,13 +43,6 @@ import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.linker.exceptions.LinkerException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA;
import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
......@@ -63,14 +62,12 @@ public class YangXpathLinker<T> {
private YangNode rootNode;
private Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes;
private String curPrefix;
private Map<YangAtomicPath, YangNode> resolvedNodes;
/**
* Creates an instance of x-path linker.
*/
public YangXpathLinker() {
absPaths = new ArrayList<>();
setResolvedNodes(new HashMap<>());
}
/**
......@@ -156,31 +153,13 @@ public class YangXpathLinker<T> {
}
/**
* Returns resolved nodes.
*
* @return resolved nodes
*/
public Map<YangAtomicPath, YangNode> getResolvedNodes() {
return resolvedNodes;
}
/**
* Sets resolved nodes.
*
* @param resolvedNodes resolved nodes
*/
private void setResolvedNodes(Map<YangAtomicPath, YangNode> resolvedNodes) {
this.resolvedNodes = resolvedNodes;
}
/**
* Adds node to resolved nodes.
*
* @param path absolute path
* @param node resolved node
*/
private void addToResolvedNodes(YangAtomicPath path, YangNode node) {
getResolvedNodes().put(path, node);
path.setResolvedNode(node);
}
/**
......@@ -205,13 +184,13 @@ public class YangXpathLinker<T> {
* Process absolute node path for target leaf.
*
* @param atomicPaths atomic path node list
* @param root root node
* @param leafref instance of YANG leafref
* @param root root node
* @param leafref instance of YANG leafref
* @return linked target node
*/
public T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root, YangLeafRef leafref) {
YangNode targetNode = null;
YangNode targetNode;
setRootNode(root);
setPrefixResolverTypes(new HashMap<>());
parsePrefixResolverList(atomicPaths);
......@@ -260,11 +239,8 @@ public class YangXpathLinker<T> {
* @param leafref instance of YANG leafref
*/
private void validateInvalidNodesInThePath(YangLeafRef leafref) {
Map<YangAtomicPath, YangNode> nodes = getResolvedNodes();
Iterator<Map.Entry<YangAtomicPath, YangNode>> nodesIterator = nodes.entrySet().iterator();
while (nodesIterator.hasNext()) {
Map.Entry<YangAtomicPath, YangNode> nodeInList = nodesIterator.next();
YangNode nodeInPath = nodeInList.getValue();
for (YangAtomicPath absolutePath : (Iterable<YangAtomicPath>) leafref.getAtomicPath()) {
YangNode nodeInPath = absolutePath.getResolvedNode();
if (nodeInPath instanceof YangGrouping || nodeInPath instanceof YangUses
|| nodeInPath instanceof YangTypeDef || nodeInPath instanceof YangCase
......@@ -331,9 +307,7 @@ public class YangXpathLinker<T> {
YangLeavesHolder holder = (YangLeavesHolder) targetNode;
List<YangLeaf> leaves = holder.getListOfLeaf();
if (leaves != null && !leaves.isEmpty()) {
Iterator<YangLeaf> leafIterator = leaves.listIterator();
while (leafIterator.hasNext()) {
YangLeaf leaf = leafIterator.next();
for (YangLeaf leaf : leaves) {
if (leaf.getName().equals(leafName)) {
return leaf;
}
......@@ -357,9 +331,7 @@ public class YangXpathLinker<T> {
YangLeavesHolder holder = (YangLeavesHolder) targetNode;
List<YangLeafList> leavesList = holder.getListOfLeafList();
if (leavesList != null && !leavesList.isEmpty()) {
Iterator<YangLeafList> leafListIterator = leavesList.listIterator();
while (leafListIterator.hasNext()) {
YangLeafList leafList = leafListIterator.next();
for (YangLeafList leafList : leavesList) {
if (leafList.getName().equals(leafListName)) {
return leafList;
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.plugin.manager;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
......@@ -43,6 +42,7 @@ import org.sonatype.plexus.build.incremental.BuildContext;
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.addToCompilationRoot;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.copyYangFilesToTarget;
import static org.onosproject.yangutils.plugin.manager.YangPluginUtils.resolveInterJarDependencies;
......@@ -67,17 +67,14 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirP
public class YangUtilManager
extends AbstractMojo {
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangNode rootNode;
// YANG file information set.
private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private YangLinker yangLinker = new YangLinkerManager();
private YangFileInfo curYangFileInfo = new YangFileInfo();
private Set<YangNode> yangNodeSet = new HashSet<>();
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
/**
* Source directory for YANG files.
*/
......@@ -144,9 +141,15 @@ public class YangUtilManager
@Component
private BuildContext context;
/**
* Local maven repository.
*/
@Parameter(readonly = true, defaultValue = "${localRepository}")
private ArtifactRepository localRepository;
/**
* Remote maven repositories.
*/
@Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
private List<ArtifactRepository> remoteRepository;
......@@ -196,7 +199,7 @@ public class YangUtilManager
return;
}
// Resolve inter jar dependency.
resolveInterJardependency();
resolveInterJarDependency();
// Carry out the parsing for all the YANG files.
parseYangFileInfoSet();
......@@ -205,7 +208,7 @@ public class YangUtilManager
resolveDependenciesUsingLinker();
// Perform translation to JAVA.
translateToJava(getYangFileInfoSet(), yangPlugin);
translateToJava(yangPlugin);
// Serialize data model.
serializeDataModel(getDirectory(baseDir, outputDirectory), getYangFileInfoSet(), project, true);
......@@ -237,7 +240,7 @@ public class YangUtilManager
*
* @return YANG node set
*/
public Set<YangNode> getYangNodeSet() {
Set<YangNode> getYangNodeSet() {
return yangNodeSet;
}
......@@ -246,12 +249,13 @@ public class YangUtilManager
*
* @throws IOException when fails to do IO operations
*/
public void resolveInterJardependency() throws IOException {
private void resolveInterJarDependency() throws IOException {
try {
List<YangNode> interJarResolvedNodes = resolveInterJarDependencies(project, localRepository,
remoteRepository, getDirectory(baseDir, outputDirectory));
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
node.setToTranslate(false);
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
......@@ -281,7 +285,7 @@ public class YangUtilManager
/**
* Creates YANG nodes set.
*/
public void createYangNodeSet() {
void createYangNodeSet() {
for (YangFileInfo yangFileInfo : getYangFileInfoSet()) {
getYangNodeSet().add(yangFileInfo.getRootNode());
}
......@@ -339,19 +343,15 @@ public class YangUtilManager
/**
* Translates to java code corresponding to the YANG schema.
*
* @param yangFileInfoSet YANG file information
* @param yangPlugin YANG plugin config
* @throws IOException when fails to generate java code file the current
* node
* @param yangPlugin YANG plugin config
* @throws IOException when fails to generate java code file the current node
*/
public void translateToJava(Set<YangFileInfo> yangFileInfoSet, YangPluginConfig yangPlugin)
public void translateToJava(YangPluginConfig yangPlugin)
throws IOException {
Iterator<YangFileInfo> yangFileIterator = yangFileInfoSet.iterator();
while (yangFileIterator.hasNext()) {
YangFileInfo yangFileInfo = yangFileIterator.next();
setCurYangFileInfo(yangFileInfo);
if (yangFileInfo.isForTranslator()) {
generateJavaCode(yangFileInfo.getRootNode(), yangPlugin);
updateFilePriority(getYangNodeSet());
for (YangNode node : getYangNodeSet()) {
if (node.isToTranslate()) {
generateJavaCode(node, yangPlugin);
}
}
}
......@@ -383,7 +383,7 @@ public class YangUtilManager
*
* @param yangFileInfoSet the YANG file info set
*/
public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
this.yangFileInfoSet = yangFileInfoSet;
}
......@@ -392,7 +392,7 @@ public class YangUtilManager
*
* @return the yangFileInfo
*/
public YangFileInfo getCurYangFileInfo() {
private YangFileInfo getCurYangFileInfo() {
return curYangFileInfo;
}
......@@ -401,7 +401,7 @@ public class YangUtilManager
*
* @param yangFileInfo the yangFileInfo to set
*/
public void setCurYangFileInfo(YangFileInfo yangFileInfo) {
private void setCurYangFileInfo(YangFileInfo yangFileInfo) {
curYangFileInfo = yangFileInfo;
}
}
......
......@@ -88,6 +88,12 @@ public final class GeneratedJavaFileType {
public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
/**
* Java classes for events.
*/
public static final int GENERATE_ALL_EVENT_CLASS_MASK = GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE
| GENERATE_EVENT_SUBJECT_CLASS;
/**
* Identity listener class.
*/
public static final int GENERATE_IDENTITY_CLASS = 2048;
......
......@@ -42,6 +42,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
import static java.util.Collections.sort;
/**
......@@ -289,4 +290,14 @@ public class JavaImportData {
public String getYangAugmentedInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + YANG_AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
/**
* Returns import string for YangAugmentedOpParamInfo class.
*
* @return import string for YangAugmentedOpParamInfo class
*/
public String getYangAugmentedOpParamInfoImport() {
return IMPORT + YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD +
YANG_AUGMENTED_OP_PARAM_INFO_CLASS;
}
}
......
......@@ -23,6 +23,7 @@ import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
......@@ -56,6 +57,11 @@ public class TempJavaCodeFragmentFiles {
private TempJavaEnumerationFragmentFiles enumerationTempFiles;
/**
* Has the temporary files required for enumeration generated classes.
*/
private TempJavaEventFragmentFiles tempJavaEventFragmentFiles;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated java file info
......@@ -80,6 +86,10 @@ public class TempJavaCodeFragmentFiles {
setServiceTempFiles(new TempJavaServiceFragmentFiles(javaFileInfo));
}
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
setEventFragmentFiles(new TempJavaEventFragmentFiles(javaFileInfo));
}
}
/**
......@@ -156,10 +166,29 @@ public class TempJavaCodeFragmentFiles {
}
/**
* Retrieves the temp file handle for event file generation.
*
* @return temp file handle for enumeration file generation
*/
public TempJavaEventFragmentFiles getEventFragmentFiles() {
return tempJavaEventFragmentFiles;
}
/**
* Sets temp file handle for event file generation.
*
* @param tempJavaEventFragmentFiles temp file handle for event file generation
*/
public void setEventFragmentFiles(TempJavaEventFragmentFiles tempJavaEventFragmentFiles) {
this.tempJavaEventFragmentFiles = tempJavaEventFragmentFiles;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateJavaFile(int fileType, YangNode curNode)
......@@ -183,6 +212,13 @@ public class TempJavaCodeFragmentFiles {
getServiceTempFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
}
/**
* Creates event, event listener and event subject files.
*/
if (fileType == GENERATE_ALL_EVENT_CLASS_MASK) {
getEventFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, curNode);
}
/*
* Creats enumeration class file.
*/
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.yangutils.translator.tojava;
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.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
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.JavaFileGenerator.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
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.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
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.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
/**
* Represent temporary java fragments for event files.
*/
public class TempJavaEventFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef suffix.
*/
public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
/**
* File name for event enum temp file.
*/
private static final String EVENT_ENUM_FILE_NAME = "EventEnum";
/**
* File name for event method temp file.
*/
private static final String EVENT_METHOD_FILE_NAME = "EventMethod";
/**
* File name for event subject attribute temp file.
*/
private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute";
/**
* File name for event subject getter temp file.
*/
private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter";
/**
* File name for event subject setter temp file.
*/
private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter";
/**
* File name for generated class file for special type like union, typedef suffix.
*/
private static final String EVENT_FILE_NAME_SUFFIX = "Event";
/**
* File name for generated class file for special type like union, typedef suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
private static final String JAVA_FILE_EXTENSION = ".java";
/**
* Java file handle for event subject file.
*/
private File eventSubjectJavaFileHandle;
/**
* Java file handle for event listener file.
*/
private File eventListenerJavaFileHandle;
/**
* Java file handle for event file.
*/
private File eventJavaFileHandle;
/**
* Java file handle for event enum impl file.
*/
private File eventEnumTempFileHandle;
/**
* Java file handle for event method impl file.
*/
private File eventMethodTempFileHandle;
/**
* Java file handle for event subject attribute file.
*/
private File eventSubjectAttributeTempFileHandle;
/**
* Java file handle for event subject getter impl file.
*/
private File eventSubjectGetterTempFileHandle;
/**
* Java file handle for event subject setter impl file.
*/
private File eventSubjectSetterTempFileHandle;
/**
* Creates an instance of temporary java code fragment.
*
* @param javaFileInfo generated file information
* @throws IOException when fails to create new file handle
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(EVENT_ENUM_MASK);
addGeneratedTempFile(EVENT_METHOD_MASK);
addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
}
/*Adds event method contents to event file.*/
private static String getEventFileContents(String eventClassname, String classname) {
return "\n" +
" /**\n" +
" * Creates " + classname + " event with type and subject.\n" +
" *\n" +
" * @param type event type\n" +
" * @param subject subject " + classname + "\n" +
" */\n" +
" public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " 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 " + classname + "\n" +
" * @param time time of event\n" +
" */\n" +
" public " + eventClassname + "(Type type, " + getCapitalCase(classname)
+ " subject, long time) {\n" +
" super(type, subject, time);\n" +
" }\n" +
"\n";
}
/**
* 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;
}
/**
* 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;
}
/**
* Returns event subject's java file handle.
*
* @return java file handle
*/
private File getEventSubjectJavaFileHandle() {
return eventSubjectJavaFileHandle;
}
/**
* Sets event's subject java file handle.
*
* @param eventSubjectJavaFileHandle file handle for event's subject
*/
private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) {
this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle;
}
public void generateJavaFile(int fileType, YangNode curNode) throws IOException {
generateEventJavaFile(curNode);
generateEventListenerJavaFile(curNode);
generateEventSubjectJavaFile(curNode);
}
/**
* Constructs java code exit.
*
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports.add(getJavaImportData().getAbstractEventsImport());
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName());
String nodeName = curNodeInfo + EVENT_STRING;
addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
/**
* Creates event interface file.
*/
setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX));
generateEventFile(getEventJavaFileHandle(), curNode, imports);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Constructs java code exit.
*
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventListenerJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports.add(getJavaImportData().getEventListenerImport());
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
/**
* Creates event listener interface file.
*/
setEventListenerJavaFileHandle(
getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Constructs java code exit.
*
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventSubjectJavaFile(YangNode curNode)
throws IOException {
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
/**
* Creates event interface file.
*/
setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo +
TempJavaEventFragmentFiles.EVENT_SUBJECT_NAME_SUFFIX));
generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Returns event enum temp file.
*
* @return event enum temp file
*/
public File getEventEnumTempFileHandle() {
return eventEnumTempFileHandle;
}
/**
* Sets event enum temp file.
*
* @param eventEnumTempFileHandle event enum temp file
*/
public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
this.eventEnumTempFileHandle = eventEnumTempFileHandle;
}
/**
* Returns event method temp file.
*
* @return event method temp file
*/
public File getEventMethodTempFileHandle() {
return eventMethodTempFileHandle;
}
/**
* Sets event method temp file.
*
* @param eventMethodTempFileHandle event method temp file
*/
public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
this.eventMethodTempFileHandle = eventMethodTempFileHandle;
}
/**
* Returns event subject attribute temp file.
*
* @return event subject attribute temp file
*/
public File getEventSubjectAttributeTempFileHandle() {
return eventSubjectAttributeTempFileHandle;
}
/**
* Sets event subject attribute temp file.
*
* @param eventSubjectAttributeTempFileHandle event subject attribute temp file
*/
public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle;
}
/**
* Returns event subject getter temp file.
*
* @return event subject getter temp file
*/
public File getEventSubjectGetterTempFileHandle() {
return eventSubjectGetterTempFileHandle;
}
/**
* Sets event subject getter temp file.
*
* @param eventSubjectGetterTempFileHandle event subject getter temp file
*/
public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle;
}
/**
* Returns event subject setter temp file.
*
* @return event subject setter temp file
*/
public File getEventSubjectSetterTempFileHandle() {
return eventSubjectSetterTempFileHandle;
}
/**
* Sets event subject setter temp file.
*
* @param eventSubjectSetterTempFileHandle event subject setter temp file
*/
public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle;
}
/**
* Adds java snippet for events to event subject file.
*
* @param curNode current node
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
String currentInfo = getCapitalCase(getCamelCase(curNode.getName(),
pluginConfig.getConflictResolver()));
String notificationName = curNode.getName();
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(currentInfo));
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo),
null, false, false);
/*Adds java info for event in respective temp files.*/
addEventEnum(notificationName, pluginConfig);
addEventSubjectAttribute(javaAttributeInfo, pluginConfig);
addEventSubjectGetter(javaAttributeInfo, pluginConfig);
addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo);
}
/*Adds event to enum temp file.*/
private void addEventEnum(String notificationName, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventEnumTempFileHandle(),
getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
}
/*Adds event method in event class*/
private void addEnumMethod(String eventClassname, String className)
throws IOException {
appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
}
/*Adds events to event subject file.*/
private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventSubjectAttributeTempFileHandle(),
FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig));
}
/*Adds getter method for event in event subject class.*/
private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventSubjectGetterTempFileHandle(),
getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
}
/*Adds setter method for event in event subject class.*/
private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className)
throws IOException {
appendToFile(getEventSubjectSetterTempFileHandle(),
getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
}
/**
* Returns a temporary file handle for the event's file type.
*
* @param name file name
* @return temporary file handle
* @throws IOException when fails to create new file handle
*/
private File getJavaFileHandle(YangNode curNode, String name)
throws IOException {
JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
JavaFileInfo childInfo = ((JavaFileInfoContainer) curNode.getChild()).getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
childInfo.getBaseCodeGenPath());
}
/**
* Returns the directory path.
*
* @return directory path
*/
private String getDirPath(JavaFileInfo parentInfo) {
return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase();
}
}
......@@ -19,19 +19,17 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangUses;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGrouping;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
......@@ -69,9 +67,9 @@ import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerato
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
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.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamBuilderClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateOpParamImplClassFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedConstructor;
......@@ -99,15 +97,16 @@ import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
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.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE;
import static org.onosproject.yangutils.utils.UtilConstants.REFERENCE_CARDINALITY;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
......@@ -340,6 +339,11 @@ public class TempJavaFragmentFiles {
private boolean isAttributePresent;
/**
* Base code gen path.
*/
private String baseCodePath;
/**
* Temporary file handle for augments copy constructor method of class.
*/
private File augmentConstructorImplTempFileHandle;
......@@ -358,9 +362,15 @@ public class TempJavaFragmentFiles {
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
if ((javaFileInfo.getGeneratedFileTypes() & GENERATE_SERVICE_AND_MANAGER) != 0) {
setBaseCodePath(getJavaFileInfo().getPluginConfig().getCodeGenDir());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getPluginConfig().getCodeGenDir(),
getJavaFileInfo().getPackageFilePath()));
} else {
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
}
/*
* Initialize getter when generation file type matches to interface
* mask.
......@@ -584,6 +594,24 @@ public class TempJavaFragmentFiles {
}
/**
* Returns base code path.
*
* @return base code path
*/
public String getBaseCodePath() {
return baseCodePath;
}
/**
* Sets base code path.
*
* @param baseCodePath base code path
*/
public void setBaseCodePath(String baseCodePath) {
this.baseCodePath = baseCodePath;
}
/*
* Retrieves the absolute path where the file needs to be generated.
*
* @return absolute path where the file needs to be generated
......@@ -1180,7 +1208,7 @@ public class TempJavaFragmentFiles {
*/
File getJavaFileHandle(String fileName)
throws IOException {
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getJavaFileInfo());
return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION, getBaseCodePath());
}
/**
......@@ -1500,6 +1528,8 @@ public class TempJavaFragmentFiles {
if (curNode instanceof YangModule || curNode instanceof YangSubModule) {
addResolvedAugmentedDataNodeImports(curNode);
}
TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles()
.getJavaImportData().getImports();
......@@ -1539,17 +1569,9 @@ public class TempJavaFragmentFiles {
if (curNode instanceof YangCase) {
removeCaseImport(imports);
}
if (curNode instanceof YangJavaAugment) {
updateAugmentConstructorTempFile(curNode, curInfo.getPluginConfig());
YangJavaAugment augment = (YangJavaAugment) curNode;
List<JavaQualifiedTypeInfo> infoList = augment.getExtendedClassInfo();
for (JavaQualifiedTypeInfo info : infoList) {
if (info.getClassInfo()
.equals(getCapitalCase(getCamelCase(augment.getAugmentedNode().getName(), null)))) {
removeAugmentedImport(imports, info);
}
}
if (curNode instanceof YangAugment) {
removeAugmentedInfoImport(imports);
}
}
if ((fileType & BUILDER_CLASS_MASK) != 0 || (fileType & IMPL_CLASS_MASK) != 0) {
......@@ -1557,7 +1579,7 @@ public class TempJavaFragmentFiles {
addImportsToStringAndHasCodeMethods(imports, true);
}
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports);
addImportsForAugmentableClass(imports, true);
}
sortImports(imports);
/*
......@@ -1582,19 +1604,33 @@ public class TempJavaFragmentFiles {
validateLineLength(getImplClassJavaFileHandle());
}
insertDataIntoJavaFile(getImplClassJavaFileHandle(), getJavaClassDefClose());
if (curNode instanceof YangAugmentableNode) {
addImportsForAugmentableClass(imports, false);
}
if (!(curNode instanceof YangModule)) {
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(imports, false);
}
if (curNode instanceof YangAugmentableNode) {
addYangAugmentedOpParamInfoImport(imports);
}
JavaQualifiedTypeInfo qualifiedTypeInfo = new JavaQualifiedTypeInfo();
qualifiedTypeInfo.setClassInfo(getCapitalCase(DEFAULT) + getCapitalCase(getJavaFileInfo()
.getJavaName()));
qualifiedTypeInfo.setPkgInfo(getJavaFileInfo().getPackage());
getJavaExtendsListHolder().addToExtendsList(qualifiedTypeInfo, curNode,
tempJavaBeanFragmentFiles);
addBitsetImport(imports, true);
if (curNode instanceof YangAugment) {
addYangAugmentedOpParamInfoImport(imports);
}
/*
* Create impl class file.
*/
setOpParamClassJavaFileHandle(getJavaFileHandle(getOpParamImplClassName()));
setOpParamClassJavaFileHandle(
generateOpParamImplClassFile(getOpParamClassJavaFileHandle(), curNode,
isAttributePresent(), imports));
isAttributePresent(), imports));
/*
* Create builder class file.
......@@ -1603,7 +1639,7 @@ public class TempJavaFragmentFiles {
setBuilderOpParmClassJavaFileHandle(getJavaFileHandle(getOpParamBuilderImplClassName()));
setBuilderOpParmClassJavaFileHandle(
generateOpParamBuilderClassFile(getBuilderOpParmClassJavaFileHandle(), curNode,
isAttributePresent()));
isAttributePresent()));
/*
* Append impl class to builder class and close it.
*/
......@@ -1613,6 +1649,7 @@ public class TempJavaFragmentFiles {
addBitsetImport(imports, false);
}
insertDataIntoJavaFile(getOpParamClassJavaFileHandle(), getJavaClassDefClose());
}
}
/*
......@@ -1621,56 +1658,15 @@ public class TempJavaFragmentFiles {
freeTemporaryResources(false);
}
/**
* Updates augment constructor temp file.
*
* @param curNode current augment node
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
private void updateAugmentConstructorTempFile(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
YangJavaAugment augment = (YangJavaAugment) curNode;
TempJavaBeanFragmentFiles tempJavaBeanFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
YangNode augmentedNode = augment.getAugmentedNode();
if (augmentedNode instanceof YangLeavesHolder) {
YangLeavesHolder holder = (YangLeavesHolder) augmentedNode;
if (holder.getListOfLeaf() != null) {
for (YangLeaf leaf : holder.getListOfLeaf()) {
addAugmentConstructor(getJavaAttributeOfLeaf(this, leaf,
pluginConfig), pluginConfig);
}
}
if (holder.getListOfLeafList() != null) {
for (YangLeafList leafList : holder.getListOfLeafList()) {
addAugmentConstructor(getJavaAttributeOfLeafList(this, leafList,
pluginConfig), pluginConfig);
}
}
}
augmentedNode = augmentedNode.getChild();
boolean isList = false;
while (augmentedNode != null) {
if (augmentedNode instanceof YangList) {
isList = true;
}
if (!(augmentedNode instanceof YangUses)) {
addAugmentConstructor(getCurNodeAsAttributeInTarget(augmentedNode, augment, isList,
tempJavaBeanFragmentFiles), pluginConfig);
}
augmentedNode = augmentedNode.getNextSibling();
}
/*Adds import for YANG augmented op param info.*/
private void addYangAugmentedOpParamInfoImport(List<String> imports) {
imports.add(getJavaImportData().getYangAugmentedOpParamInfoImport());
}
/**
* Adds imports for ToString and HashCodeMethod.
*
* @param imports import list
* @param imports import list
* @param operation add or remove
*/
public void addImportsToStringAndHasCodeMethods(List<String> imports, boolean operation) {
......@@ -1686,7 +1682,7 @@ public class TempJavaFragmentFiles {
/**
* Adds imports for bitset method.
*
* @param imports import list
* @param imports import list
* @param operation add or remove
*/
public void addBitsetImport(List<String> imports, boolean operation) {
......@@ -1701,32 +1697,31 @@ public class TempJavaFragmentFiles {
/**
* Adds import for map and hash map.
*
* @param imports import list
* @param imports import list
* @param operations true for adding and false for deletion
*/
public void addImportsForAugmentableClass(List<String> imports) {
imports.add(getJavaImportData().getHashMapImport());
imports.add(getJavaImportData().getMapImport());
imports.add(getJavaImportData().getYangAugmentedInfoImport());
public void addImportsForAugmentableClass(List<String> imports, boolean operations) {
if (operations) {
imports.add(getJavaImportData().getHashMapImport());
imports.add(getJavaImportData().getMapImport());
imports.add(getJavaImportData().getYangAugmentedInfoImport());
} else {
imports.remove(getJavaImportData().getHashMapImport());
imports.remove(getJavaImportData().getMapImport());
}
}
/**
* Removes augmented node import info from import list.
* Removes case import info from import list.
*
* @param imports list of imports
* @return import for class
*/
private List<String> removeAugmentedImport(List<String> imports, JavaQualifiedTypeInfo augmentedInfo) {
String augmentedNodeImport;
if (imports != null && augmentedInfo != null) {
augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD + getCapitalCase(DEFAULT)
+ augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
+ BUILDER + SEMI_COLAN + NEW_LINE;
imports.remove(augmentedNodeImport);
augmentedNodeImport = IMPORT + augmentedInfo.getPkgInfo() + PERIOD
+ augmentedInfo.getClassInfo() + PERIOD + augmentedInfo.getClassInfo()
+ BUILDER + SEMI_COLAN + NEW_LINE;
imports.remove(augmentedNodeImport);
imports.remove(getJavaImportData().getYangAugmentedInfoImport());
private List<String> removeCaseImport(List<String> imports) {
if (imports != null && caseImportInfo != null) {
String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
SEMI_COLAN + NEW_LINE;
imports.remove(caseImport);
}
return imports;
}
......@@ -1737,13 +1732,15 @@ public class TempJavaFragmentFiles {
* @param imports list of imports
* @return import for class
*/
private List<String> removeCaseImport(List<String> imports) {
if (imports != null && caseImportInfo != null) {
String caseImport = IMPORT + caseImportInfo.getPkgInfo() + PERIOD + caseImportInfo.getClassInfo() +
SEMI_COLAN + NEW_LINE;
imports.remove(caseImport);
private void removeAugmentedInfoImport(List<String> imports) {
imports.remove(getJavaImportData().getYangAugmentedInfoImport());
for (JavaQualifiedTypeInfo type : getJavaImportData().getImportSet()) {
if (type.getClassInfo().equals(YANG_AUGMENTED_INFO)) {
getJavaImportData().getImportSet().remove(type);
getJavaExtendsListHolder().getExtendsList().remove(type);
}
}
return imports;
}
/**
......@@ -1827,7 +1824,7 @@ public class TempJavaFragmentFiles {
/**
* Sets the java file handle for op param class file.
*
* @param opParamClassJavaFileHandle java file handle
* @param opParamClassJavaFileHandle java file handle
*/
public void setOpParamClassJavaFileHandle(File opParamClassJavaFileHandle) {
this.opParamClassJavaFileHandle = opParamClassJavaFileHandle;
......
......@@ -18,7 +18,6 @@ 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;
......@@ -27,52 +26,26 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_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.JavaAttributeInfo.getAttributeInfoForTheData;
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAnnotationsImports;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile;
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.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_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.LISTENER_REG;
import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
import static org.onosproject.yangutils.utils.UtilConstants.VOID;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
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.generateJavaDocForRpc;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
/**
......@@ -83,10 +56,6 @@ public class TempJavaServiceFragmentFiles
extends TempJavaFragmentFiles {
/**
* File name for generated class file for special type like union, typedef suffix.
*/
public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
/**
* File name for rpc method.
*/
private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
......@@ -97,69 +66,19 @@ public class TempJavaServiceFragmentFiles
private static final String RPC_IMPL_FILE_NAME = "RpcImpl";
/**
* File name for event enum temp file.
*/
private static final String EVENT_ENUM_FILE_NAME = "EventEnum";
/**
* File name for event method temp file.
*/
private static final String EVENT_METHOD_FILE_NAME = "EventMethod";
/**
* File name for event subject attribute temp file.
*/
private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME = "EventSubjectAttribute";
/**
* File name for event subject getter temp file.
*/
private static final String EVENT_SUBJECT_GETTER_FILE_NAME = "EventSubjectGetter";
/**
* File name for event subject setter temp file.
*/
private static final String EVENT_SUBJECT_SETTER_FILE_NAME = "EventSubjectSetter";
/**
* File name for generated class file for service
* suffix.
* 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.
* File name for generated class file for manager suffix.
*/
private static final String MANAGER_FILE_NAME_SUFFIX = "Manager";
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_FILE_NAME_SUFFIX = "Event";
/**
* File name for generated class file for special type like union, typedef
* suffix.
*/
private static final String EVENT_LISTENER_FILE_NAME_SUFFIX = "Listener";
private static final String JAVA_FILE_EXTENSION = ".java";
/**
* Java file handle for event subject file.
* Flag to set the manager files generation.
*/
private File eventSubjectJavaFileHandle;
/**
* Java file handle for event listener file.
*/
private File eventListenerJavaFileHandle;
/**
* Java file handle for event file.
*/
private File eventJavaFileHandle;
boolean isManagerNeedToBeGenerated = false;
/**
* Temporary file handle for rpc interface.
......@@ -177,34 +96,14 @@ public class TempJavaServiceFragmentFiles
private File serviceInterfaceJavaFileHandle;
/**
* Java file handle for manager impl file.
*/
private File managerJavaFileHandle;
/**
* Java file handle for event enum impl file.
*/
private File eventEnumTempFileHandle;
/**
* Java file handle for event method impl file.
* Path for serive file to be generated.
*/
private File eventMethodTempFileHandle;
private String serviceGenPath;
/**
* Java file handle for event subject attribute file.
*/
private File eventSubjectAttributeTempFileHandle;
/**
* Java file handle for event subject getter impl file.
*/
private File eventSubjectGetterTempFileHandle;
/**
* Java file handle for event subject setter impl file.
* Java file handle for manager impl file.
*/
private File eventSubjectSetterTempFileHandle;
private File managerJavaFileHandle;
/**
* Creates an instance of temporary java code fragment.
......@@ -217,52 +116,15 @@ public class TempJavaServiceFragmentFiles
setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
setServiceGenPath(getJavaFileInfo().getPluginConfig().getCodeGenDir());
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
getJavaFileInfo().getPackageFilePath()));
addGeneratedTempFile(RPC_INTERFACE_MASK);
addGeneratedTempFile(RPC_IMPL_MASK);
addGeneratedTempFile(EVENT_ENUM_MASK);
addGeneratedTempFile(EVENT_METHOD_MASK);
addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
setRpcInterfaceTempFileHandle(getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME));
setRpcImplTempFileHandle(getTemporaryFileHandle(RPC_IMPL_FILE_NAME));
setEventEnumTempFileHandle(getTemporaryFileHandle(EVENT_ENUM_FILE_NAME));
setEventMethodTempFileHandle(getTemporaryFileHandle(EVENT_METHOD_FILE_NAME));
setEventSubjectAttributeTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_ATTRIBUTE_FILE_NAME));
setEventSubjectGetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_GETTER_FILE_NAME));
setEventSubjectSetterTempFileHandle(getTemporaryFileHandle(EVENT_SUBJECT_SETTER_FILE_NAME));
}
/*Adds event method contents to event file.*/
private static String getEventFileContents(String eventClassname, String classname) {
return "\n" +
" /**\n" +
" * Creates " + classname + " event with type and subject.\n" +
" *\n" +
" * @param type event type\n" +
" * @param subject subject " + classname + "\n" +
" */\n" +
" public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " 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 " + classname + "\n" +
" * @param time time of event\n" +
" */\n" +
" public " + eventClassname + "(Type type, " + getCapitalCase(classname)
+ " subject, long time) {\n" +
" super(type, subject, time);\n" +
" }\n" +
"\n";
}
/**
......@@ -338,60 +200,6 @@ public class TempJavaServiceFragmentFiles
}
/**
* 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;
}
/**
* 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;
}
/**
* Returns event subject's java file handle.
*
* @return java file handle
*/
private File getEventSubjectJavaFileHandle() {
return eventSubjectJavaFileHandle;
}
/**
* Sets event's subject java file handle.
*
* @param eventSubjectJavaFileHandle file handle for event's subject
*/
private void setEventSubjectJavaFileHandle(File eventSubjectJavaFileHandle) {
this.eventSubjectJavaFileHandle = eventSubjectJavaFileHandle;
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
......@@ -403,9 +211,7 @@ public class TempJavaServiceFragmentFiles
throws IOException {
List<String> imports = ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles().getServiceTempFiles()
.getJavaImportData().getImports();
createPackage(curNode);
boolean isNotification = false;
if (curNode instanceof YangJavaModule) {
if (!((YangJavaModule) curNode).getNotificationNodes().isEmpty()) {
......@@ -423,9 +229,10 @@ public class TempJavaServiceFragmentFiles
/**
* Creates rpc interface file.
*/
setBaseCodePath(getServiceGenPath());
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports);
setBaseCodePath(getJavaFileInfo().getBaseCodeGenPath());
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_SERVICE);
addListenersImport(curNode, imports, true, LISTENER_REG);
......@@ -434,21 +241,16 @@ public class TempJavaServiceFragmentFiles
/**
* Create builder class file.
*/
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode);
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
if (isManagerNeedToBeGenerated()) {
setManagerJavaFileHandle(getJavaFileHandle(getJavaClassName(MANAGER_FILE_NAME_SUFFIX)));
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode);
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
}
if (isNotification) {
addListenersImport(curNode, imports, false, LISTENER_REG);
}
addAnnotationsImports(imports, false);
if (isNotification) {
generateEventJavaFile(curNode);
generateEventListenerJavaFile(GENERATE_EVENT_LISTENER_INTERFACE, curNode);
generateEventSubjectJavaFile(curNode);
}
/**
* Close all the file handles.
*/
......@@ -504,87 +306,6 @@ public class TempJavaServiceFragmentFiles
}
/**
* Constructs java code exit.
*
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventJavaFile(YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports.add(getJavaImportData().getAbstractEventsImport());
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName());
String nodeName = curNodeInfo + EVENT_STRING;
addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
/**
* Creates event interface file.
*/
setEventJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo + EVENT_FILE_NAME_SUFFIX));
generateEventFile(getEventJavaFileHandle(), curNode, imports);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventListenerJavaFile(int fileType, YangNode curNode)
throws IOException {
List<String> imports = new ArrayList<>();
imports.add(getJavaImportData().getEventListenerImport());
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
/**
* Creates event listener interface file.
*/
setEventListenerJavaFileHandle(
getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, imports);
/**
* Close all the file handles.
*/
freeTemporaryResources(false);
}
/**
* Constructs java code exit.
*
* @param curNode current YANG node
* @throws IOException when fails to generate java files
*/
public void generateEventSubjectJavaFile(YangNode curNode)
throws IOException {
String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
.getJavaFileInfo().getJavaName());
/**
* Creates event interface file.
*/
setEventSubjectJavaFileHandle(getJavaFileHandle(curNode, curNodeInfo +
EVENT_SUBJECT_NAME_SUFFIX));
generateEventSubjectFile(getEventSubjectJavaFileHandle(), curNode);
/**
* 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
......@@ -599,16 +320,6 @@ public class TempJavaServiceFragmentFiles
closeFile(getServiceInterfaceJavaFileHandle(), isError);
closeFile(getManagerJavaFileHandle(), isError);
if (getEventJavaFileHandle() != null) {
closeFile(getEventJavaFileHandle(), isError);
}
if (getEventListenerJavaFileHandle() != null) {
closeFile(getEventListenerJavaFileHandle(), isError);
}
if (getEventSubjectJavaFileHandle() != null) {
closeFile(getEventSubjectJavaFileHandle(), isError);
}
closeFile(getRpcInterfaceTempFileHandle(), true);
closeFile(getRpcImplTempFileHandle(), true);
closeFile(getGetterInterfaceTempFileHandle(), true);
......@@ -620,182 +331,39 @@ public class TempJavaServiceFragmentFiles
}
/**
* Returns event enum temp file.
*
* @return event enum temp file
*/
public File getEventEnumTempFileHandle() {
return eventEnumTempFileHandle;
}
/**
* Sets event enum temp file.
*
* @param eventEnumTempFileHandle event enum temp file
*/
public void setEventEnumTempFileHandle(File eventEnumTempFileHandle) {
this.eventEnumTempFileHandle = eventEnumTempFileHandle;
}
/**
* Returns event method temp file.
*
* @return event method temp file
*/
public File getEventMethodTempFileHandle() {
return eventMethodTempFileHandle;
}
/**
* Sets event method temp file.
*
* @param eventMethodTempFileHandle event method temp file
*/
public void setEventMethodTempFileHandle(File eventMethodTempFileHandle) {
this.eventMethodTempFileHandle = eventMethodTempFileHandle;
}
/**
* Returns event subject attribute temp file.
*
* @return event subject attribute temp file
*/
public File getEventSubjectAttributeTempFileHandle() {
return eventSubjectAttributeTempFileHandle;
}
/**
* Sets event subject attribute temp file.
* Returns the path where service file should be generated.
*
* @param eventSubjectAttributeTempFileHandle event subject attribute temp file
* @return path where service file should be generated
*/
public void setEventSubjectAttributeTempFileHandle(File eventSubjectAttributeTempFileHandle) {
this.eventSubjectAttributeTempFileHandle = eventSubjectAttributeTempFileHandle;
public String getServiceGenPath() {
return serviceGenPath;
}
/**
* Returns event subject getter temp file.
* Sets path where service file should be generated.
*
* @return event subject getter temp file
* @param serviceGenPath path where service file should be generated
*/
public File getEventSubjectGetterTempFileHandle() {
return eventSubjectGetterTempFileHandle;
public void setServiceGenPath(String serviceGenPath) {
this.serviceGenPath = serviceGenPath;
}
/**
* Sets event subject getter temp file.
* Returns true if manager needs to be generated.
*
* @param eventSubjectGetterTempFileHandle event subject getter temp file
* @return true if manager needs to be generated
*/
public void setEventSubjectGetterTempFileHandle(File eventSubjectGetterTempFileHandle) {
this.eventSubjectGetterTempFileHandle = eventSubjectGetterTempFileHandle;
}
/**
* Returns event subject setter temp file.
*
* @return event subject setter temp file
*/
public File getEventSubjectSetterTempFileHandle() {
return eventSubjectSetterTempFileHandle;
}
/**
* Sets event subject setter temp file.
*
* @param eventSubjectSetterTempFileHandle event subject setter temp file
*/
public void setEventSubjectSetterTempFileHandle(File eventSubjectSetterTempFileHandle) {
this.eventSubjectSetterTempFileHandle = eventSubjectSetterTempFileHandle;
}
/**
* Adds java snippet for events to event subject file.
*
* @param curNode current node
* @param pluginConfig plugin configurations
* @throws IOException when fails to do IO operations
*/
public void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
throws IOException {
String currentInfo = getCapitalCase(getCamelCase(curNode.getName(),
pluginConfig.getConflictResolver()));
String notificationName = curNode.getName();
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(currentInfo));
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(qualifiedTypeInfo, getSmallCase(currentInfo),
null, false, false);
/*Adds java info for event in respective temp files.*/
addEventEnum(notificationName, pluginConfig);
addEventSubjectAttribute(javaAttributeInfo, pluginConfig);
addEventSubjectGetter(javaAttributeInfo, pluginConfig);
addEventSubjectSetter(javaAttributeInfo, pluginConfig, currentInfo);
}
/*Adds event to enum temp file.*/
private void addEventEnum(String notificationName, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventEnumTempFileHandle(),
getJavaDoc(ENUM_ATTRIBUTE, notificationName, false, pluginConfig) + FOUR_SPACE_INDENTATION
+ getEnumJavaAttribute(notificationName).toUpperCase() + COMMA + NEW_LINE);
}
/*Adds event method in event class*/
private void addEnumMethod(String eventClassname, String className)
throws IOException {
appendToFile(getEventMethodTempFileHandle(), getEventFileContents(eventClassname, className));
}
/*Adds events to event subject file.*/
private void addEventSubjectAttribute(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventSubjectAttributeTempFileHandle(),
FOUR_SPACE_INDENTATION + parseAttribute(attr, pluginConfig));
}
/*Adds getter method for event in event subject class.*/
private void addEventSubjectGetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
throws IOException {
appendToFile(getEventSubjectGetterTempFileHandle(),
getJavaDoc(GETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getGetterForClass(attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
}
/*Adds setter method for event in event subject class.*/
private void addEventSubjectSetter(JavaAttributeInfo attr, YangPluginConfig pluginConfig, String className)
throws IOException {
appendToFile(getEventSubjectSetterTempFileHandle(),
getJavaDoc(MANAGER_SETTER_METHOD, getCapitalCase(attr.getAttributeName()), false, pluginConfig)
+ getSetterForClass(attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
public boolean isManagerNeedToBeGenerated() {
return isManagerNeedToBeGenerated;
}
/**
* Returns a temporary file handle for the event's file type.
* Sets true if manager needs to be generated.
*
* @param name file name
* @return temporary file handle
* @throws IOException when fails to create new file handle
* @param managerNeedToBeGenerated true if manager needs to be generated
*/
private File getJavaFileHandle(YangNode curNode, String name)
throws IOException {
JavaFileInfo parentInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
JavaFileInfo childInfo = ((JavaFileInfoContainer) curNode.getChild()).getJavaFileInfo();
return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
childInfo);
public void setManagerNeedToBeGenerated(boolean managerNeedToBeGenerated) {
isManagerNeedToBeGenerated = managerNeedToBeGenerated;
}
/**
* Returns the directory path.
*
* @return directory path
*/
private String getDirPath(JavaFileInfo parentInfo) {
return (parentInfo.getPackageFilePath() + SLASH + parentInfo.getJavaName()).toLowerCase();
}
}
......
......@@ -22,14 +22,15 @@ import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
import org.onosproject.yangutils.datamodel.YangGrouping;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangTranslatorOperatorNode;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
import org.onosproject.yangutils.translator.exception.TranslatorException;
......@@ -40,17 +41,12 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
......@@ -80,7 +76,8 @@ public final class YangJavaModelUtils {
throws IOException {
if (javaCodeGeneratorInfo instanceof YangJavaAugment) {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(((YangJavaAugment) javaCodeGeneratorInfo).getAugmentClassName());
.setJavaName(getAugmentClassName((YangJavaAugment) javaCodeGeneratorInfo,
yangPluginConfig));
} else {
javaCodeGeneratorInfo.getJavaFileInfo()
.setJavaName(getCamelCase(((YangNode) javaCodeGeneratorInfo).getName(),
......@@ -192,7 +189,7 @@ public final class YangJavaModelUtils {
* @throws IOException IO operations fails
*/
private static void generateTempFiles(JavaCodeGeneratorInfo javaCodeGeneratorInfo,
YangPluginConfig yangPluginConfig)
YangPluginConfig yangPluginConfig)
throws IOException {
if (!(javaCodeGeneratorInfo instanceof YangNode)) {
throw new TranslatorException("translation is not supported for the node");
......@@ -215,7 +212,7 @@ public final class YangJavaModelUtils {
if (javaCodeGeneratorInfo instanceof YangJavaModule) {
for (YangNode notificaiton : ((YangJavaModule) javaCodeGeneratorInfo).getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()
.getEventFragmentFiles()
.addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
}
}
......@@ -223,7 +220,7 @@ public final class YangJavaModelUtils {
for (YangNode notificaiton : ((YangJavaSubModule) javaCodeGeneratorInfo)
.getNotificationNodes()) {
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles()
.getEventFragmentFiles()
.addJavaSnippetOfEvent(notificaiton, yangPluginConfig);
}
}
......@@ -273,57 +270,13 @@ public final class YangJavaModelUtils {
TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles();
if (javaCodeGeneratorInfo instanceof YangJavaAugment) {
JavaQualifiedTypeInfo augmentedBuilderInfo = new JavaQualifiedTypeInfo();
JavaQualifiedTypeInfo augmentedBuilderClassInfo = new JavaQualifiedTypeInfo();
JavaQualifiedTypeInfo augmentedClassInfo = new JavaQualifiedTypeInfo();
JavaQualifiedTypeInfo augmentedImplInfo = new JavaQualifiedTypeInfo();
YangNode augmentedNode = ((YangJavaAugment) javaCodeGeneratorInfo).getAugmentedNode();
String name = null;
JavaFileInfo augmentedfileInfo = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo();
if (augmentedfileInfo.getJavaName() != null) {
name = getCapitalCase(augmentedfileInfo.getJavaName());
augmentedClassInfo.setClassInfo(name);
augmentedClassInfo.setPkgInfo(augmentedfileInfo.getPackage());
} else {
name = getCapitalCase(getCamelCase(augmentedNode.getName(), yangPlugin.getConflictResolver()));
augmentedClassInfo.setClassInfo(name);
augmentedClassInfo.setPkgInfo(getAugmentedNodesPackage(augmentedNode,
yangPlugin));
}
augmentedBuilderInfo.setClassInfo(name + PERIOD + name + BUILDER);
augmentedBuilderInfo.setPkgInfo(augmentedClassInfo.getPkgInfo());
augmentedBuilderClassInfo.setClassInfo(getCapitalCase(DEFAULT) + name + PERIOD + name + BUILDER);
augmentedBuilderClassInfo.setPkgInfo(augmentedClassInfo.getPkgInfo());
augmentedImplInfo.setClassInfo(getCapitalCase(DEFAULT) + name);
augmentedImplInfo.setPkgInfo(augmentedBuilderInfo.getPkgInfo());
((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedBuilderInfo);
((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedImplInfo);
((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedBuilderClassInfo);
((YangJavaAugment) javaCodeGeneratorInfo).addToExtendedClassInfo(augmentedClassInfo);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(augmentedClassInfo, (YangNode) javaCodeGeneratorInfo,
tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(augmentedBuilderInfo, (YangNode) javaCodeGeneratorInfo,
tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(augmentedImplInfo, (YangNode) javaCodeGeneratorInfo,
tempJavaCodeFragmentFiles.getBeanTempFiles());
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(augmentedBuilderClassInfo, (YangNode) javaCodeGeneratorInfo,
tempJavaCodeFragmentFiles.getBeanTempFiles());
JavaQualifiedTypeInfo yangAugmentedInfo = new JavaQualifiedTypeInfo();
yangAugmentedInfo.setClassInfo(YANG_AUGMENTED_INFO);
yangAugmentedInfo.setPkgInfo(YANG_AUGMENTED_INFO_CLASS_IMPORT_PKG);
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
.addToExtendsList(yangAugmentedInfo, (YangNode) javaCodeGeneratorInfo,
tempJavaCodeFragmentFiles.getBeanTempFiles());
}
if (javaCodeGeneratorInfo instanceof YangCase) {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
......@@ -378,27 +331,9 @@ public final class YangJavaModelUtils {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
}
if (javaCodeGeneratorInfo instanceof YangJavaModule) {
if (!((YangJavaModule) javaCodeGeneratorInfo)
.isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
}
} else if (javaCodeGeneratorInfo instanceof YangJavaSubModule) {
if (!((YangJavaSubModule) javaCodeGeneratorInfo)
.isNotificationChildNodePresent((YangNode) javaCodeGeneratorInfo)) {
updateCodeGenInfoForEvent(javaCodeGeneratorInfo);
}
}
generateTempFiles(javaCodeGeneratorInfo, yangPluginConfig);
}
/*Updates java code generator info with events info.*/
private static void updateCodeGenInfoForEvent(JavaCodeGeneratorInfo javaCodeGeneratorInfo) {
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_SUBJECT_CLASS);
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_CLASS);
javaCodeGeneratorInfo.getJavaFileInfo().addGeneratedFileTypes(GENERATE_EVENT_LISTENER_INTERFACE);
}
/**
* Returns the node package string.
*
......@@ -429,9 +364,6 @@ public final class YangJavaModelUtils {
* @return true if root node contains any data node
*/
public static boolean isManagerCodeGenRequired(YangNode node) {
YangLeavesHolder holder = (YangLeavesHolder) node;
boolean isCodeReq = true;
List<YangNode> childNodes = new ArrayList<>();
node = node.getChild();
......@@ -441,16 +373,19 @@ public final class YangJavaModelUtils {
}
if (childNodes.size() == 0) {
if (holder.getListOfLeaf() != null && !holder.getListOfLeaf().isEmpty()) {
isCodeReq = true;
} else if (holder.getListOfLeafList() != null && !holder.getListOfLeafList().isEmpty()) {
isCodeReq = true;
}
return isCodeReq;
return false;
} else if (childNodes.size() == 1) {
return childNodes.get(0) instanceof YangTypeDef && childNodes.get(0) instanceof YangGrouping;
return !(childNodes.get(0) instanceof YangTranslatorOperatorNode);
}
List<Boolean> booleanData = new ArrayList<>();
for (YangNode child : childNodes) {
if (child instanceof YangTranslatorOperatorNode) {
booleanData.add(false);
} else {
booleanData.add(true);
}
}
return isCodeReq;
return booleanData.contains(true);
}
/**
......@@ -465,8 +400,7 @@ public final class YangJavaModelUtils {
File[] files = codeGenDir.listFiles();
if (files.length >= 1) {
for (File file : files) {
if (file.getName().contentEquals(getCapitalCase(info.getJavaName() + MANAGER + ".java"))
|| file.getName().contentEquals(getCapitalCase(info.getJavaName() + SERVICE + ".java"))) {
if (file.getName().contentEquals(getCapitalCase(info.getJavaName() + MANAGER + ".java"))) {
return false;
}
}
......@@ -484,12 +418,11 @@ public final class YangJavaModelUtils {
public static String getAugmentedNodesPackage(YangNode node, YangPluginConfig yangPluginConfig) {
List<String> clsInfo = new ArrayList<>();
node = node.getParent();
while (node != null) {
while (node.getParent() != null) {
if (!(node instanceof YangModule)
|| !(node instanceof YangSubModule)) {
if (node instanceof YangJavaAugment) {
clsInfo.add(((YangJavaAugment) node).getAugmentClassName());
clsInfo.add(getAugmentClassName((YangAugment) node, yangPluginConfig));
} else {
clsInfo.add(getCamelCase(node.getName(), yangPluginConfig.getConflictResolver()));
}
......@@ -519,4 +452,21 @@ public final class YangJavaModelUtils {
return pkg.toString().toLowerCase();
}
/**
* Returns augment class name.
*
* @param augment YANG augment
* @param yangPluginConfig plugin configurations
* @return augment class name
*/
public static String getAugmentClassName(YangAugment augment, YangPluginConfig yangPluginConfig) {
YangNodeIdentifier nodeId = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier();
String name = getCapitalCase(getCamelCase(nodeId.getName(), yangPluginConfig.getConflictResolver()));
if (nodeId.getPrefix() != null) {
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + name;
} else {
return AUGMENTED + name;
}
}
}
......
......@@ -16,23 +16,17 @@
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represents augment information extended to support java code generation.
......@@ -44,23 +38,12 @@ public class YangJavaAugment
private static final long serialVersionUID = 806201632L;
/**
* Prefix to be added to generated java file for augment node.
*/
private static final String AUGMENTED = "Augmented";
/**
* Contains the information of the java file being generated.
*/
private JavaFileInfo javaFileInfo;
/**
* TargetNodes java qualified info.
*/
private List<JavaQualifiedTypeInfo> extendedClassInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
* File handle to maintain temporary java code fragments as per the code snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
......@@ -70,7 +53,6 @@ public class YangJavaAugment
public YangJavaAugment() {
super();
setJavaFileInfo(new JavaFileInfo());
setExtendedClassInfo(new ArrayList<>());
getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
}
......@@ -119,8 +101,7 @@ public class YangJavaAugment
}
/**
* Prepare the information for java code generation corresponding to YANG
* augment info.
* Prepare the information for java code generation corresponding to YANG augment info.
*
* @param yangPlugin YANG plugin config
* @throws TranslatorException translator operation fail
......@@ -148,46 +129,4 @@ public class YangJavaAugment
}
}
/**
* Returns augment class name.
*
* @return augment class name
*/
public String getAugmentClassName() {
YangNodeIdentifier nodeId = getTargetNode().get(getTargetNode().size() - 1).getNodeIdentifier();
String name = getCapitalCase(getCamelCase(nodeId.getName(), null));
if (nodeId.getPrefix() != null) {
return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + name;
} else {
return AUGMENTED + name;
}
}
/**
* Returns extended class info.
*
* @return extended class info
*/
public List<JavaQualifiedTypeInfo> getExtendedClassInfo() {
return extendedClassInfo;
}
/**
* Sets extended class info.
*
* @param augmentedInfo extended class info
*/
private void setExtendedClassInfo(List<JavaQualifiedTypeInfo> augmentedInfo) {
extendedClassInfo = augmentedInfo;
}
/**
* Adds to extended class info list.
*
* @param augmentedInfo extended class info
*/
public void addToExtendedClassInfo(JavaQualifiedTypeInfo augmentedInfo) {
getExtendedClassInfo().add(augmentedInfo);
}
}
......
......@@ -15,6 +15,10 @@
*/
package org.onosproject.yangutils.translator.tojava.javamodel;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
......@@ -25,12 +29,8 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
......@@ -145,7 +145,7 @@ public class YangJavaIdentity extends YangIdentity
}
}
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo().getBaseCodeGenPath());
initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
closeFile(file, false);
......
......@@ -29,14 +29,12 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
......@@ -56,8 +54,7 @@ public class YangJavaModule
private JavaFileInfo javaFileInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
* File handle to maintain temporary java code fragments as per the code snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
......@@ -73,12 +70,7 @@ public class YangJavaModule
super();
setJavaFileInfo(new JavaFileInfo());
setNotificationNodes(new ArrayList<>());
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
getJavaFileInfo().setGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER);
}
......@@ -135,6 +127,11 @@ public class YangJavaModule
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate(),
yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
| GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, modulePkg);
} catch (IOException e) {
......@@ -157,17 +154,22 @@ public class YangJavaModule
*
* The manager class needs to extend the "ListenerRegistry".
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
(!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
......
......@@ -31,14 +31,12 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGenerationOfCodeReq;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isManagerCodeGenRequired;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
import static org.onosproject.yangutils.utils.UtilConstants.SBI;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
......@@ -58,8 +56,7 @@ public class YangJavaSubModule
private JavaFileInfo javaFileInfo;
/**
* File handle to maintain temporary java code fragments as per the code
* snippet types.
* File handle to maintain temporary java code fragments as per the code snippet types.
*/
private transient TempJavaCodeFragmentFiles tempFileHandle;
......@@ -76,8 +73,7 @@ public class YangJavaSubModule
setJavaFileInfo(new JavaFileInfo());
int gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
if (isNotificationChildNodePresent(this)) {
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_EVENT_SUBJECT_CLASS | GENERATE_EVENT_CLASS
| GENERATE_EVENT_LISTENER_INTERFACE;
gentype = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
}
getJavaFileInfo().setGeneratedFileTypes(gentype);
}
......@@ -145,6 +141,11 @@ public class YangJavaSubModule
public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate(), yangPlugin.getConflictResolver());
if (isNotificationChildNodePresent(this)) {
getJavaFileInfo().setGeneratedFileTypes(getJavaFileInfo().getGeneratedFileTypes()
| GENERATE_ALL_EVENT_CLASS_MASK);
}
try {
generateCodeOfRootNode(this, yangPlugin, subModulePkg);
} catch (IOException e) {
......@@ -169,13 +170,21 @@ public class YangJavaSubModule
* The manager class needs to extend the "ListenerRegistry".
*/
try {
if (isManagerCodeGenRequired(this) && isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null) ||
(!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
if ((getJavaFileInfo().getGeneratedFileTypes() & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, this);
}
getTempJavaCodeFragmentFiles()
.generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
if (isManagerCodeGenRequired(this)) {
if (isGenerationOfCodeReq(getJavaFileInfo())) {
if ((getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi() == null)
|| (!getJavaFileInfo().getPluginConfig().getCodeGenerateForsbi().equals(SBI))) {
getTempJavaCodeFragmentFiles().getServiceTempFiles().setManagerNeedToBeGenerated(true);
}
}
}
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
getJavaFileInfo().getPackageFilePath());
searchAndDeleteTempDir(getJavaFileInfo().getPluginConfig().getCodeGenDir() +
......@@ -185,6 +194,7 @@ public class YangJavaSubModule
}
}
/**
* Returns notifications node list.
*
......
......@@ -17,6 +17,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangIdentity;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
......@@ -45,7 +46,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
......@@ -61,12 +61,14 @@ import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
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.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......@@ -82,8 +84,7 @@ public final class ClassDefinitionGenerator {
}
/**
* Based on the file type and the YANG name of the file, generate the class
* / interface definition start.
* Based on the file type and the YANG name of the file, generate the class / interface definition start.
*
* @param genFileTypes generated file type
* @param yangName class name
......@@ -107,8 +108,7 @@ public final class ClassDefinitionGenerator {
}
/**
* Based on the file type and the YANG name of the file, generate the class
* / interface definition start.
* Based on the file type and the YANG name of the file, generate the class / interface definition start.
*
* @param genFileTypes generated file type
* @param yangName class name
......@@ -131,7 +131,7 @@ public final class ClassDefinitionGenerator {
case IMPL_CLASS_MASK:
return getImplClassDefinition(yangName, curNode);
case OPERATION_CLASS_MASK:
return getOperClassDefinition(yangName, curNode);
return getOpPramImplClassDefinition(yangName, curNode);
case BUILDER_INTERFACE_MASK:
return getBuilderInterfaceDefinition(yangName, curNode);
case GENERATE_SERVICE_AND_MANAGER:
......@@ -178,14 +178,12 @@ public final class ClassDefinitionGenerator {
/**
* Returns builder interface file class definition.
*
* @param yangName java class name, corresponding to which the builder class
* is being generated
* @param yangName java class name, corresponding to which the builder class is being generated
* @return definition
*/
private static String getBuilderInterfaceDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK);
if (!(curNode instanceof YangCase)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_INTERFACE_MASK);
if (clsDef != null) {
return clsDef;
}
......@@ -200,9 +198,8 @@ public final class ClassDefinitionGenerator {
* @return definition
*/
private static String getBuilderClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_CLASS_MASK);
if (!(curNode instanceof YangCase)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, BUILDER_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
......@@ -215,15 +212,14 @@ public final class ClassDefinitionGenerator {
* Returns operation param builder file class definition.
*
* @param yangName class name
* @param curNode YANG node
* @param curNode YANG node
* @return definition returns operation param builder file class definition
*/
private static String getOpParamBuilderClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_BUILDER_CLASS_MASK);
if (!(curNode instanceof YangCase)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_BUILDER_CLASS_MASK);
if (clsDef != null) {
return clsDef;
return clsDef + OPEN_CURLY_BRACKET + NEW_LINE;
}
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + BUILDER + SPACE + EXTEND +
......@@ -238,9 +234,8 @@ public final class ClassDefinitionGenerator {
* @return definition
*/
private static String getImplClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, IMPL_CLASS_MASK);
if (!(curNode instanceof YangCase)) {
String clsDef = getClassDefinitionForWhenExtended(curNode, yangName, IMPL_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
......@@ -253,20 +248,26 @@ public final class ClassDefinitionGenerator {
* Returns operation param file class definition.
*
* @param yangName class name
* @param curNode YANG node
* @param curNode YANG node
* @return definition returns operation param file class definition
*/
private static String getOperClassDefinition(String yangName, YangNode curNode) {
private static String getOpPramImplClassDefinition(String yangName, YangNode curNode) {
String clsDef = "";
if (curNode instanceof YangAugment) {
if (!(curNode instanceof YangCase)) {
clsDef = getClassDefinitionForWhenExtended(curNode, yangName, OPERATION_CLASS_MASK);
if (clsDef != null) {
return clsDef;
}
}
return PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE
+ getCapitalCase(DEFAULT) + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
if (clsDef.equals("")) {
clsDef = PUBLIC + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE
+ getCapitalCase(DEFAULT) + yangName + SPACE;
}
if (curNode instanceof YangAugment) {
clsDef = clsDef + IMPLEMENTS + SPACE + YANG_AUGMENTED_OP_PARAM_INFO + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
} else {
clsDef = clsDef + OPEN_CURLY_BRACKET + NEW_LINE;
}
return clsDef;
}
/**
......@@ -407,72 +408,28 @@ public final class ClassDefinitionGenerator {
switch (genFileTypes) {
case INTERFACE_MASK:
def = def + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (curNode instanceof YangAugment) {
if (!info.getClassInfo().contains(BUILDER) && !info.getClassInfo().contains(
getCapitalCase(DEFAULT))) {
def = getDefinitionString(def, info, holder);
}
} else {
def = getDefinitionString(def, info, holder);
}
}
def = trimAtLast(def, COMMA);
def = getDefinitionString(def, holder);
return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case BUILDER_INTERFACE_MASK:
String builderDef = INTERFACE + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (info.getClassInfo().contains(BUILDER) && !info.getClassInfo().contains(
getCapitalCase(DEFAULT))) {
builderDef = getDefinitionString(builderDef, info, holder);
}
}
builderDef = trimAtLast(builderDef, COMMA);
builderDef = getDefinitionString(builderDef, holder);
return builderDef + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case BUILDER_CLASS_MASK:
def = def + CLASS + SPACE + yangName + BUILDER + SPACE + EXTEND + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (info.getClassInfo().contains(BUILDER)
&& info.getClassInfo().contains(getCapitalCase(DEFAULT))) {
def = getDefinitionString(def, info, holder);
}
}
def = trimAtLast(def, COMMA);
def = getDefinitionString(def, holder);
return def + SPACE + IMPLEMENTS + SPACE + yangName + PERIOD
+ yangName + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case IMPL_CLASS_MASK:
def = def + SPACE + CLASS + SPACE + getCapitalCase(DEFAULT) + yangName + SPACE + EXTEND + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (!info.getClassInfo().contains(BUILDER)
&& info.getClassInfo().contains(getCapitalCase(DEFAULT))) {
def = getDefinitionString(def, info, holder);
}
}
def = trimAtLast(def, COMMA);
def = getDefinitionString(def, holder);
return def + SPACE + IMPLEMENTS + SPACE
+ yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
case OPERATION_CLASS_MASK:
def = def + SPACE + CLASS + SPACE + yangName + OPERATION + SPACE;
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (!info.getClassInfo().contains(BUILDER)
&& info.getClassInfo().contains(OPERATION)) {
def = getDefinitionString(def, info, holder);
}
}
def = trimAtLast(def, COMMA);
return def + SPACE + EXTEND + SPACE
+ getCapitalCase(DEFAULT) + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
def = def + CLASS + SPACE + yangName + OPERATION + SPACE + EXTEND + SPACE;
def = getDefinitionString(def, holder);
return def + SPACE;
default:
return null;
}
......@@ -484,17 +441,18 @@ public final class ClassDefinitionGenerator {
* Returns updated class definition.
*
* @param def current definition
* @param info java qualified info
* @param holder extend list holder
* @return updated class definition
*/
private static String getDefinitionString(String def, JavaQualifiedTypeInfo info, JavaExtendsListHolder holder) {
if (!holder.getExtendedClassStore().get(info)) {
def = def + info.getClassInfo() + COMMA + SPACE;
} else {
def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
private static String getDefinitionString(String def, JavaExtendsListHolder holder) {
for (JavaQualifiedTypeInfo info : holder.getExtendsList()) {
if (!holder.getExtendedClassStore().get(info)) {
def = def + info.getClassInfo() + COMMA + SPACE;
} else {
def = def + info.getPkgInfo() + PERIOD + info.getClassInfo() + COMMA + SPACE;
}
}
return def;
return trimAtLast(def, COMMA);
}
}
......
......@@ -95,8 +95,7 @@ public final class JavaCodeSnippetGen {
* Returns the textual java code information corresponding to the import list.
*
* @param importInfo import info
* @return the textual java code information corresponding to the import
* list
* @return the textual java code information corresponding to the import list
*/
public static String getImportText(JavaQualifiedTypeInfo importInfo) {
return IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN + NEW_LINE;
......@@ -147,8 +146,7 @@ public final class JavaCodeSnippetGen {
}
/**
* Returns based on the file type and the YANG name of the file, generate the class
* / interface definition close.
* Returns based on the file type and the YANG name of the file, generate the class / interface definition close.
*
* @return corresponding textual java code information
*/
......
......@@ -31,8 +31,8 @@ import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
/**
* Represent the extends list for generated java classes. It holds the class details which needs
* to be extended by the generated java code.
* Represent the extends list for generated java classes. It holds the class details which needs to be extended by the
* generated java code.
*/
public class JavaExtendsListHolder {
......
......@@ -26,9 +26,10 @@ import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
......@@ -37,7 +38,9 @@ import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.YangJavaModelUtils;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
......@@ -54,7 +57,6 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.OPERATION_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.AUGMENTE_CLASS_CONSTRUCTOR_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;
......@@ -86,9 +88,10 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.addDeActivateMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentedNodesConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentInfoMapImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForManager;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBaseClassMethodImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfMethod;
......@@ -101,6 +104,7 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIsFilterContentMatch;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOmitNullValueString;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOpParamConstructorStart;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOperationTypeSetter;
......@@ -116,65 +120,61 @@ import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafListgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringSelectLeafgetter;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getisFilterContentMatch;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BINARY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.BITS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
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.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.CREATE;
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.DELETE;
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.ENCODE_TO_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
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.EVENT_SUBJECT_NAME_SUFFIX;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.GET_ENCODER;
import static org.onosproject.yangutils.utils.UtilConstants.ENCODE_TO_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_IMPORT_BASE64_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LOGGER_STATEMENT;
import static org.onosproject.yangutils.utils.UtilConstants.MANAGER;
import static org.onosproject.yangutils.utils.UtilConstants.MERGE;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SUPER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.REMOVE;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.MERGE;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.CREATE;
import static org.onosproject.yangutils.utils.UtilConstants.REMOVE;
import static org.onosproject.yangutils.utils.UtilConstants.DELETE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SUPER;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
......@@ -203,7 +203,13 @@ public final class JavaFileGenerator {
throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
String path;
if (curNode instanceof YangModule) {
path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath();
} else {
path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
}
String className = getCapitalCase(javaFileInfo.getJavaName());
......@@ -244,7 +250,12 @@ public final class JavaFileGenerator {
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
String path;
if (curNode instanceof YangModule) {
path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath();
} else {
path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode, className);
List<String> methods = new ArrayList<>();
......@@ -302,14 +313,16 @@ public final class JavaFileGenerator {
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
String path;
if (curNode instanceof YangModule) {
path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath();
} else {
path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode, className);
List<String> methods = new ArrayList<>();
boolean isAugmentNode = false;
if (curNode instanceof YangAugment) {
isAugmentNode = true;
}
if (isAttrPresent) {
/**
......@@ -339,21 +352,6 @@ public final class JavaFileGenerator {
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path));
if (isAugmentNode) {
YangAugment augment = (YangAugment) curNode;
String augmentNode = getCapitalCase(
getCamelCase(augment.getAugmentedNode().getName(), pluginConfig.getConflictResolver()));
/**
* Constructor.
*/
String constructor = getAugmentedNodesConstructorStart(className, augmentNode)
+ getDataFromTempFileHandle(AUGMENTE_CLASS_CONSTRUCTOR_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path);
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
NEW_LINE + NEW_LINE);
}
insertDataIntoJavaFile(file, NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
......@@ -382,14 +380,15 @@ public final class JavaFileGenerator {
/**
* Returns generated op param builder class file for current node.
* @param file file handle
* @param curNode current YANG node
*
* @param file file handle
* @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 generateOpParamBuilderClassFile(File file, YangNode curNode,
boolean isAttrPresent) throws IOException {
boolean isAttrPresent) throws IOException {
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
......@@ -409,7 +408,7 @@ public final class JavaFileGenerator {
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
+ " while impl class file generation");
}
try {
......@@ -445,7 +444,7 @@ public final class JavaFileGenerator {
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
+ " while impl class file generation");
}
try {
......@@ -476,7 +475,7 @@ public final class JavaFileGenerator {
insertDataIntoJavaFile(file, NEW_LINE);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while builder class file generation");
+ " while builder class file generation");
}
} else {
insertDataIntoJavaFile(file, NEW_LINE);
......@@ -579,15 +578,16 @@ public final class JavaFileGenerator {
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
String path;
if (curNode instanceof YangModule) {
path = javaFileInfo.getPluginConfig().getCodeGenDir() + javaFileInfo.getPackageFilePath();
} else {
path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
}
initiateJavaFileGeneration(file, IMPL_CLASS_MASK, imports, curNode, className);
List<String> methods = new ArrayList<>();
boolean isAugmentNode = false;
if (curNode instanceof YangAugment) {
isAugmentNode = true;
}
if (curNode instanceof YangAugmentableNode) {
insertDataIntoJavaFile(file, addAugmentationAttribute());
}
......@@ -648,11 +648,6 @@ public final class JavaFileGenerator {
* Constructor.
*/
String constructor = getConstructorStart(className, pluginConfig);
if (isAugmentNode) {
constructor = constructor + EIGHT_SPACE_INDENTATION + SUPER + OPEN_PARENTHESIS
+ BUILDER.toLowerCase() + OBJECT
+ CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
}
constructor = constructor + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
.getBeanTempFiles(), path);
......@@ -666,6 +661,7 @@ public final class JavaFileGenerator {
if (curNode instanceof YangAugmentableNode) {
methods.add(getAddAugmentInfoMethodImpl());
methods.add(getAugmentInfoImpl());
methods.add(getAugmentInfoMapImpl(javaFileInfo.getPluginConfig()));
}
/**
......@@ -681,11 +677,11 @@ public final class JavaFileGenerator {
/**
* Returns generated op param class file for current node.
*
* @param file file handle
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @param imports import list
* @return returns generated op param class file for current node
* @param file file handle
* @param curNode current YANG node
* @param isAttrPresent if any attribute is present or not
* @param imports import list
* @return returns generated op param class file for current node
* @throws IOException when fails to write in file
*/
public static File generateOpParamImplClassFile(File file, YangNode curNode,
......@@ -696,7 +692,6 @@ public final class JavaFileGenerator {
YangPluginConfig pluginConfig = javaFileInfo.getPluginConfig();
String className = getCapitalCase(javaFileInfo.getJavaName());
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, OPERATION_CLASS_MASK, imports, curNode, className);
......@@ -718,7 +713,7 @@ public final class JavaFileGenerator {
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
+ " while impl class file generation");
}
/**
......@@ -730,7 +725,7 @@ public final class JavaFileGenerator {
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
+ " while impl class file generation");
}
try {
......@@ -766,7 +761,7 @@ public final class JavaFileGenerator {
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
+ " while impl class file generation");
}
if (curNode instanceof YangLeavesHolder) {
......@@ -786,7 +781,7 @@ public final class JavaFileGenerator {
}
methods.add(getOperationTypegetter());
methods.add(getisFilterContentMatch(className, curNode, pluginConfig));
methods.add(getIsFilterContentMatch(className, curNode, pluginConfig));
} else {
insertDataIntoJavaFile(file, NEW_LINE);
......@@ -821,6 +816,12 @@ public final class JavaFileGenerator {
methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
if (curNode instanceof YangAugment) {
String clsName = getCapitalCase(DEFAULT) +
getCapitalCase(YangJavaModelUtils.getAugmentClassName((YangAugment) curNode, pluginConfig));
methods.add(getBaseClassMethodImpl(clsName));
}
/**
* Add methods in impl class.
*/
......@@ -925,9 +926,9 @@ public final class JavaFileGenerator {
*/
if (type.getDataType().equals(YangDataTypes.BINARY)) {
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(BINARY_STRING));
getCapitalCase("binary"));
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, BINARY_STRING, null, false,
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "binary", null, false,
false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
......@@ -939,10 +940,9 @@ public final class JavaFileGenerator {
methods.add(bitsToStringMethod);
} else if (type.getDataType().equals(YangDataTypes.BITS)) {
JavaQualifiedTypeInfo qualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(curNode,
getCapitalCase(BITS_STRING));
getCapitalCase("bits"));
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, BITS_STRING,
null, false, false);
JavaAttributeInfo attr = getAttributeInfoForTheData(qualifiedTypeInfo, "bits", null, false, false);
String attributeName = attr.getAttributeName();
String bitsToStringMethod = MethodsGenerator.getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC
+ SPACE + STRING_DATA_TYPE + SPACE + TO + STRING_DATA_TYPE + OPEN_PARENTHESIS
......@@ -1238,8 +1238,8 @@ public final class JavaFileGenerator {
String className = getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo().getJavaName())
+ EVENT_STRING;
TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
TempJavaEventFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getEventFragmentFiles();
String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath()
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath();
......@@ -1296,8 +1296,9 @@ public final class JavaFileGenerator {
String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo().getBaseCodeGenPath()
+ ((JavaFileInfoContainer) curNode).getJavaFileInfo().getPackageFilePath();
TempJavaServiceFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getServiceTempFiles();
TempJavaEventFragmentFiles tempFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
.getTempJavaCodeFragmentFiles().getEventFragmentFiles();
insertDataIntoJavaFile(file, NEW_LINE);
try {
......
......@@ -19,9 +19,7 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
......@@ -36,6 +34,7 @@ import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
......@@ -81,9 +80,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo.getQualifiedTypeInfoOfCurNode;
import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getAugmentedNodesPackage;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
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.DEFAULT;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
......@@ -97,9 +94,9 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENU
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.EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OPERATION_CLASS;
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.OPERATION_CLASS;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_MANAGER;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
......@@ -123,15 +120,15 @@ public final class JavaFileGeneratorUtils {
/**
* Returns a file object for generated file.
*
* @param fileName file name
* @param filePath file package path
* @param fileName file name
* @param extension file extension
* @param handle cached file handle
* @param baseCodePath cached file handle
* @return file object
*/
public static File getFileObject(String filePath, String fileName, String extension, JavaFileInfo handle) {
public static File getFileObject(String filePath, String fileName, String extension, String baseCodePath) {
return new File(handle.getBaseCodeGenPath() + filePath + SLASH + fileName + extension);
return new File(baseCodePath + filePath + SLASH + fileName + extension);
}
/**
......@@ -143,8 +140,8 @@ public final class JavaFileGeneratorUtils {
* @return data stored in temporary files
* @throws IOException when failed to get the data from temporary file handle
*/
public static String getDataFromTempFileHandle(int generatedTempFiles,
TempJavaFragmentFiles tempJavaFragmentFiles, String absolutePath)
static String getDataFromTempFileHandle(int generatedTempFiles,
TempJavaFragmentFiles tempJavaFragmentFiles, String absolutePath)
throws IOException {
TempJavaTypeFragmentFiles typeFragmentFiles = null;
......@@ -164,6 +161,11 @@ public final class JavaFileGeneratorUtils {
serviceFragmentFiles = (TempJavaServiceFragmentFiles) tempJavaFragmentFiles;
}
TempJavaEventFragmentFiles eventFragmentFiles = null;
if (tempJavaFragmentFiles instanceof TempJavaEventFragmentFiles) {
eventFragmentFiles = (TempJavaEventFragmentFiles) tempJavaFragmentFiles;
}
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
return tempJavaFragmentFiles
.getTemporaryDataFromFileHandle(tempJavaFragmentFiles.getAttributesTempFileHandle(),
......@@ -247,39 +249,39 @@ public final class JavaFileGeneratorUtils {
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getRpcImplTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & EVENT_ENUM_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
if (eventFragmentFiles == null) {
throw new TranslatorException("Required event enum implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventEnumTempFileHandle(),
return eventFragmentFiles
.getTemporaryDataFromFileHandle(eventFragmentFiles.getEventEnumTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & EVENT_METHOD_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
if (eventFragmentFiles == null) {
throw new TranslatorException("Required event method implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventMethodTempFileHandle(),
return eventFragmentFiles
.getTemporaryDataFromFileHandle(eventFragmentFiles.getEventMethodTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
if (eventFragmentFiles == null) {
throw new TranslatorException("Required event subject getter implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectGetterTempFileHandle(),
return eventFragmentFiles
.getTemporaryDataFromFileHandle(eventFragmentFiles.getEventSubjectGetterTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
if (eventFragmentFiles == null) {
throw new TranslatorException("Required event subject setter implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectSetterTempFileHandle(),
return eventFragmentFiles
.getTemporaryDataFromFileHandle(eventFragmentFiles.getEventSubjectSetterTempFileHandle(),
absolutePath);
} else if ((generatedTempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
if (serviceFragmentFiles == null) {
throw new TranslatorException("Required rpc implementation info is missing.");
if (eventFragmentFiles == null) {
throw new TranslatorException("Required event subject attribute implementation info is missing.");
}
return serviceFragmentFiles
.getTemporaryDataFromFileHandle(serviceFragmentFiles.getEventSubjectAttributeTempFileHandle(),
return eventFragmentFiles
.getTemporaryDataFromFileHandle(eventFragmentFiles.getEventSubjectAttributeTempFileHandle(),
absolutePath);
}
return null;
......@@ -300,11 +302,15 @@ public final class JavaFileGeneratorUtils {
String pkg, YangPluginConfig pluginConfig)
throws IOException {
boolean isFileCreated;
try {
file.createNewFile();
isFileCreated = file.createNewFile();
if (!isFileCreated) {
throw new IOException("Failed to create " + file.getName() + " class file.");
}
appendContents(file, className, genType, imports, pkg, pluginConfig);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
throw new IOException("Failed to append contents in " + file.getName() + " class file.");
}
}
......@@ -322,11 +328,15 @@ public final class JavaFileGeneratorUtils {
YangNode curNode, String className)
throws IOException {
boolean isFileCreated;
try {
file.createNewFile();
isFileCreated = file.createNewFile();
if (!isFileCreated) {
throw new IOException("Failed to create " + file.getName() + " class file.");
}
appendContents(file, genType, imports, curNode, className);
} catch (IOException e) {
throw new IOException("Failed to create " + file.getName() + " class file.");
throw new IOException("Failed to append contents in " + file.getName() + " class file.");
}
}
......@@ -349,11 +359,7 @@ public final class JavaFileGeneratorUtils {
String name = javaFileInfo.getJavaName();
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
YangNode augmentedNode = null;
if (curNode instanceof YangAugment) {
augmentedNode = ((YangAugment) curNode).getAugmentedNode();
}
String pkgString = null;
String pkgString;
if (genType == GENERATE_EVENT_CLASS
|| genType == GENERATE_EVENT_LISTENER_INTERFACE
|| genType == GENERATE_EVENT_SUBJECT_CLASS) {
......@@ -363,11 +369,7 @@ public final class JavaFileGeneratorUtils {
}
switch (genType) {
case INTERFACE_MASK:
if (augmentedNode != null) {
appendHeaderContents(file, pkgString, importsList, augmentedNode);
} else {
appendHeaderContents(file, pkgString, importsList);
}
appendHeaderContents(file, pkgString, importsList);
write(file, genType, INTERFACE, curNode, className);
break;
case IMPL_CLASS_MASK:
......@@ -470,8 +472,8 @@ public final class JavaFileGeneratorUtils {
}
/**
* Appends other contents to interface, impl and typedef classes.
* for example : ONOS copyright, imports and package.
* Appends other contents to interface, impl and typedef classes. for example : ONOS copyright, imports and
* package.
*
* @param file generated file
* @param pkg generated package
......@@ -485,7 +487,7 @@ public final class JavaFileGeneratorUtils {
insertDataIntoJavaFile(file, pkg);
/*
* TODO: add the file header using
* TODO: add the file header using comments for snippet of yang file.
* JavaCodeSnippetGen.getFileHeaderComment
*/
......@@ -498,39 +500,6 @@ public final class JavaFileGeneratorUtils {
}
/**
* Appends other contents to interface and impl classes when augmented node is not null.
* for example : ONOS copyright, imports and package.
*
* @param file generated file
* @param pkg generated package
* @param augmentedNode augmented node
* @param importsList list of imports
* @throws IOException when fails to append contents
*/
private static void appendHeaderContents(File file, String pkg, List<String> importsList, YangNode augmentedNode)
throws IOException {
insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader());
insertDataIntoJavaFile(file, pkg);
/*
* TODO: add the file header using
* JavaCodeSnippetGen.getFileHeaderComment
*/
if (importsList != null) {
insertDataIntoJavaFile(file, NEW_LINE);
for (String imports : importsList) {
if (!imports.contains(getCapitalCase(DEFAULT) + getCapitalCase(getCamelCase(augmentedNode.getName(),
null)))
&& !imports.contains(getCapitalCase(getCamelCase(augmentedNode.getName(), null)) + BUILDER)) {
insertDataIntoJavaFile(file, imports);
}
}
}
}
/**
* Writes data to the specific generated file.
*
* @param file generated file
......@@ -575,32 +544,12 @@ public final class JavaFileGeneratorUtils {
}
/**
* Returns resolved augments for manager classes.
*
* @param parent parent node
* @return resolved augments for manager classes
*/
public static Map<YangAtomicPath, YangAugment> getResolvedAugmentsForManager(YangNode parent) {
Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = new HashMap<>();
YangNodeIdentifier nodeId;
List<YangAtomicPath> targets = new ArrayList<>();
for (YangAugment augment : getListOfAugments(parent)) {
nodeId = augment.getTargetNode().get(0).getNodeIdentifier();
if (validateNodeIdentifierInSet(nodeId, targets)) {
targets.add(augment.getTargetNode().get(0));
resolvedAugmentsForManager.put(augment.getTargetNode().get(0), augment);
}
}
return resolvedAugmentsForManager;
}
/**
* Returns set of node identifiers.
*
* @param parent parent node
* @return set of node identifiers
*/
public static List<YangAtomicPath> getSetOfNodeIdentifiers(YangNode parent) {
static List<YangAtomicPath> getSetOfNodeIdentifiers(YangNode parent) {
List<YangAtomicPath> targets = new ArrayList<>();
YangNodeIdentifier nodeId;
......@@ -649,7 +598,6 @@ public final class JavaFileGeneratorUtils {
* @param parent parent node
*/
public static void addResolvedAugmentedDataNodeImports(YangNode parent) {
Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = getResolvedAugmentsForManager(parent);
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = ((JavaCodeGeneratorInfo) parent)
.getTempJavaCodeFragmentFiles();
......@@ -658,7 +606,7 @@ public final class JavaFileGeneratorUtils {
String curNodeName;
JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
for (YangAtomicPath nodeId : targets) {
augmentedNode = resolvedAugmentsForManager.get(nodeId).getResolveNodeInPath().get(nodeId);
augmentedNode = nodeId.getResolvedNode().getParent();
if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
} else {
......@@ -682,8 +630,8 @@ public final class JavaFileGeneratorUtils {
* @param pluginConfig plugin configurations
* @return qualified type info of augmented node
*/
public static JavaQualifiedTypeInfo getQualifiedTypeInfoOfAugmentedNode(YangNode augmentedNode, String curNodeName,
YangPluginConfig pluginConfig) {
private static JavaQualifiedTypeInfo getQualifiedTypeInfoOfAugmentedNode(YangNode augmentedNode, String curNodeName,
YangPluginConfig pluginConfig) {
JavaQualifiedTypeInfo javaQualifiedTypeInfo = getQualifiedTypeInfoOfCurNode(augmentedNode,
getCapitalCase(curNodeName));
if (javaQualifiedTypeInfo.getPkgInfo() == null) {
......@@ -719,7 +667,7 @@ public final class JavaFileGeneratorUtils {
* @param parent parent node
* @return augmented class name for data methods in manager and service
*/
public static String getAugmentedClassNameForDataMethods(YangNode augmentedNode, YangNode parent) {
static String getAugmentedClassNameForDataMethods(YangNode augmentedNode, YangNode parent) {
String curNodeName;
JavaQualifiedTypeInfo javaQualifiedTypeInfo;
JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
......@@ -751,7 +699,7 @@ public final class JavaFileGeneratorUtils {
* @param pluginConfig plugin configurations
* @return parent node name for data methods in manager and service
*/
public static String getParentNodeNameForDataMethods(YangNode parent, YangPluginConfig pluginConfig) {
static String getParentNodeNameForDataMethods(YangNode parent, YangPluginConfig pluginConfig) {
JavaFileInfo parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
if (parentInfo.getJavaName() != null) {
return getCapitalCase(parentInfo.getJavaName());
......
......@@ -19,49 +19,54 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import java.util.Map;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugmentableNode;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangAtomicPath;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import org.onosproject.yangutils.utils.io.impl.YangPluginConfig;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeaf;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeafList;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getParentNodeNameForDataMethods;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getResolvedAugmentsForManager;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeaf;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getJavaAttributeOfLeafList;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE;
import static org.onosproject.yangutils.utils.UtilConstants.ACTIVATE_ANNOTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
import static org.onosproject.yangutils.utils.UtilConstants.BASE_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
......@@ -75,6 +80,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.COLON;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
import static org.onosproject.yangutils.utils.UtilConstants.DEACTIVATE;
......@@ -91,17 +97,27 @@ import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FOR;
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;
import static org.onosproject.yangutils.utils.UtilConstants.GET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.GET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.HASH;
import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.IF;
import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ARGUMENT_EXCEPTION;
import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ARGUMENT_EXCEPTION_MSG;
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
......@@ -111,6 +127,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.MAP;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
......@@ -119,6 +136,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.OF;
import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
......@@ -129,15 +150,24 @@ import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
import static org.onosproject.yangutils.utils.UtilConstants.PUT;
import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
import static org.onosproject.yangutils.utils.UtilConstants.RECEIVED_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
import static org.onosproject.yangutils.utils.UtilConstants.SET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.STARTED_LOG_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
import static org.onosproject.yangutils.utils.UtilConstants.STOPPED_LOG_INFO;
......@@ -145,39 +175,18 @@ import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.UtilConstants.THROW;
import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
import static org.onosproject.yangutils.utils.UtilConstants.TO;
import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
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_AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF;
import static org.onosproject.yangutils.utils.UtilConstants.GET_FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.SELECT_LEAF_LIST;
import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_ENUM;
import static org.onosproject.yangutils.utils.UtilConstants.GET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.SET_OPERATION_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.RECEIVED_OBJECT;
import static org.onosproject.yangutils.utils.UtilConstants.FILTER_CONTENT_MATCH;
import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
import static org.onosproject.yangutils.utils.UtilConstants.NOT;
import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
import static org.onosproject.yangutils.utils.UtilConstants.REPLACE_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SINGLE_QUOTE;
import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
......@@ -190,14 +199,11 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SET
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForTypeConstructor;
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
/**
* Represents generator for methods of generated files based on the file type.
......@@ -205,7 +211,6 @@ import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangData
public final class MethodsGenerator {
private static final String BITS_STRING_ARRAY_VAR = "bitsTemp";
private static final String BIT_TEMP_VAR = "bitTemp";
private static final String FOR_TYPE = " for type ";
/**
* Creates an instance of method generator.
......@@ -588,9 +593,9 @@ public final class MethodsGenerator {
/**
* Returns constructor string for op param class.
*
* @param yangName class name
* @param pluginConfig plugin configurations
* @return constructor string
* @param yangName class name
* @param pluginConfig plugin configurations
* @return constructor string
*/
public static String getOpParamConstructorStart(String yangName, YangPluginConfig pluginConfig) {
......@@ -600,6 +605,7 @@ public final class MethodsGenerator {
+ CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return javadoc + constructor;
}
/**
* Returns the constructor strings for class file.
*
......@@ -718,11 +724,11 @@ public final class MethodsGenerator {
/**
* Returns to string leaf for get method.
*
* @return string leaf for get method
* @return string leaf for get method
*/
public static String getToStringLeafgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
......@@ -734,7 +740,7 @@ public final class MethodsGenerator {
*/
public static String getToStringSelectLeafgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
......@@ -742,11 +748,11 @@ public final class MethodsGenerator {
/**
* Returns to string leaf list for get method.
*
* @return string leaf list for get method
* @return string leaf list for get method
*/
public static String getToStringLeafListgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_FILTER_LEAF_LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + FILTER_LEAF_LIST + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
......@@ -758,7 +764,7 @@ public final class MethodsGenerator {
*/
public static String getToStringSelectLeafListgetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BITSET + SPACE + GET_SELECT_LEAF_LIST
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE
+ EIGHT_SPACE_INDENTATION + RETURN + SPACE + SELECT_LEAF_LIST + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
......@@ -770,7 +776,7 @@ public final class MethodsGenerator {
*/
public static String getOperationTypegetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + OPERATION_ENUM
+ SPACE + GET_OPERATION_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
+ SPACE + GET_OPERATION_TYPE + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + RETURN + SPACE
+ OP_PARAM_TYPE + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
}
......@@ -782,7 +788,7 @@ public final class MethodsGenerator {
*/
public static String getOperationTypeSetter() {
return NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + SET_OPERATION_TYPE
+ OPEN_PARENTHESIS + OPERATION_ENUM + SPACE + getSmallCase(OPERATION_ENUM) + CLOSE_PARENTHESIS
+ OPEN_PARENTHESIS + OPERATION_ENUM + SPACE + getSmallCase(OPERATION_ENUM) + CLOSE_PARENTHESIS
+ SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + THIS + PERIOD
+ OP_PARAM_TYPE + SPACE + EQUAL + SPACE + getSmallCase(OPERATION_ENUM) + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
......@@ -791,10 +797,10 @@ public final class MethodsGenerator {
/**
* Returns string for leaf set method.
*
* @param className class name
* @param curnode current YANG node
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for leaf set method
* @return string for leaf set method
*/
public static String getSetterForLeaf(String className, YangNode curnode, YangPluginConfig pluginConfig) {
......@@ -831,9 +837,9 @@ public final class MethodsGenerator {
/**
* Returns string for leaf list set method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for leaf list set method
*/
public static String getSetterForLeafList(String className, YangNode curnode, YangPluginConfig pluginConfig) {
......@@ -849,7 +855,7 @@ public final class MethodsGenerator {
if (listOfLeafList != null && !listOfLeafList.isEmpty()) {
for (YangLeafList leafList : listOfLeafList) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
pluginConfig);
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = getReturnType(javaAttributeInfo);
if (javaAttributeInfo.isListAttr()) {
......@@ -888,38 +894,44 @@ public final class MethodsGenerator {
|| dataType == UINT32
|| dataType == UINT64
|| dataType == DECIMAL64
|| dataType == BOOLEAN;
|| dataType == BOOLEAN
|| dataType == EMPTY;
}
/**
* Returns string for is filter content match method.
*
* @param className class name
* @param curnode current YANG node
* @param pluginConfig plugin configurations
* @return string for is filter content match method
* @param className class name
* @param curNode current YANG node
* @param pluginConfig plugin configurations
* @return string for is filter content match method
*/
public static String getisFilterContentMatch(String className, YangNode curnode, YangPluginConfig pluginConfig) {
public static String getIsFilterContentMatch(String className, YangNode curNode, YangPluginConfig pluginConfig) {
int numleaf = 1;
String filterMethod = "";
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curnode)
String filterMethod = NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE
+ SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + getCapitalCase(OBJECT)
+ SPACE + OBJ +
CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
TempJavaBeanFragmentFiles tempFragmentFiles = ((JavaCodeGeneratorInfo) curNode)
.getTempJavaCodeFragmentFiles().getBeanTempFiles();
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + getCapitalCase(DEFAULT)
+ getCapitalCase(className) + SPACE + APP_INSTANCE + SPACE + EQUAL + SPACE + OPEN_PARENTHESIS +
getCapitalCase(DEFAULT) + getCapitalCase(className) + CLOSE_PARENTHESIS + OBJ +
SEMI_COLAN + NEW_LINE;
if (curNode instanceof YangAugmentableNode) {
filterMethod = filterMethod + getAugmentableOpParamSyntax();
}
if (curnode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curnode;
if (curNode instanceof YangLeavesHolder) {
YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
List<YangLeafList> listOfLeafList = leavesHolder.getListOfLeafList();
if (leaves != null || listOfLeafList != null) {
filterMethod = NEW_LINE + NEW_LINE + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + BOOLEAN_DATA_TYPE
+ SPACE + FILTER_CONTENT_MATCH + OPEN_PARENTHESIS + getCapitalCase(DEFAULT)
+ getCapitalCase(className) + SPACE + APP_INSTANCE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
}
if (leaves != null) {
if (leaves != null) {
for (YangLeaf leaf : leaves) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeaf(tempFragmentFiles, leaf,
pluginConfig);
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = "";
......@@ -929,10 +941,10 @@ public final class MethodsGenerator {
+ CLOSE_PARENTHESIS;
} else {
attrQuaifiedType = APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + OR_OPERATION + SPACE + OPEN_PARENTHESIS
+ SPACE + EQUAL + EQUAL + SPACE + NULL + SPACE + OR_OPERATION + SPACE
+ NOT + OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD
+ attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS;
}
......@@ -948,11 +960,11 @@ public final class MethodsGenerator {
}
}
if (listOfLeafList != null) {
if (listOfLeafList != null) {
numleaf = 1;
for (YangLeafList leafList : listOfLeafList) {
JavaAttributeInfo javaAttributeInfo = getJavaAttributeOfLeafList(tempFragmentFiles, leafList,
pluginConfig);
pluginConfig);
String attributeName = javaAttributeInfo.getAttributeName();
String attrQuaifiedType = "";
if (isPrimitiveDataType(leafList.getDataType().getDataType())) {
......@@ -964,7 +976,8 @@ public final class MethodsGenerator {
+ SPACE + EQUAL + EQUAL + SPACE + NULL + OR_OPERATION + OPEN_PARENTHESIS + NOT
+ OPEN_PARENTHESIS + attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS
+ PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE + PERIOD
+ attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
+ attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS
+ CLOSE_PARENTHESIS + CLOSE_PARENTHESIS;
}
filterMethod = filterMethod + EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
......@@ -987,8 +1000,53 @@ public final class MethodsGenerator {
return filterMethod;
}
/**
* Returns omit null value string.
/*Returns method string for op parms augmented syntax*/
private static String getAugmentableOpParamSyntax() {
return EIGHT_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS + YANG_AUGMENTED_INFO + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + SPACE + COLAN + SPACE + APP_INSTANCE +
PERIOD + GET_METHOD_PREFIX + YANG_AUGMENTED_INFO + MAP + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD
+ VALUE + "s" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + NOT + OPEN_PARENTHESIS +
getSmallCase(YANG_AUGMENTED_INFO) + SPACE + INSTANCE_OF + SPACE + YANG_AUGMENTED_OP_PARAM_INFO +
CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
SIXTEEN_SPACE_INDENTATION + THROW + SPACE + NEW + SPACE + ILLEGAL_ARGUMENT_EXCEPTION +
OPEN_PARENTHESIS +
ILLEGAL_ARGUMENT_EXCEPTION_MSG + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE + TWELVE_SPACE_INDENTATION + YANG_AUGMENTED_INFO + SPACE +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) + SPACE + EQUAL + SPACE + APP_INSTANCE + PERIOD +
GET_METHOD_PREFIX + AUGMENTED_INFO + OPEN_PARENTHESIS + OPEN_PARENTHESIS + OPEN_PARENTHESIS +
YANG_AUGMENTED_OP_PARAM_INFO + CLOSE_PARENTHESIS + SPACE + getSmallCase(YANG_AUGMENTED_INFO) +
CLOSE_PARENTHESIS + PERIOD + GET_METHOD_PREFIX + BASE_CLASS + CLOSE_PARENTHESIS + SEMI_COLAN +
NEW_LINE + TWELVE_SPACE_INDENTATION + IF + OPEN_PARENTHESIS + NOT +
OPEN_PARENTHESIS + OPEN_PARENTHESIS + YANG_AUGMENTED_OP_PARAM_INFO + CLOSE_PARENTHESIS + SPACE +
getSmallCase(YANG_AUGMENTED_INFO) + CLOSE_PARENTHESIS
+ PERIOD + "isFilterContentMatch" + OPEN_PARENTHESIS +
getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) + CLOSE_PARENTHESIS +
CLOSE_PARENTHESIS +
SPACE + OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION + RETURN + SPACE + FALSE +
SEMI_COLAN + NEW_LINE + TWELVE_SPACE_INDENTATION
+ CLOSE_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns implementation of get base class method for op param files.
*
* @param baseClassName base class name
* @return implementation of get base class method for op param files
*/
public static String getBaseClassMethodImpl(String baseClassName) {
return NEW_LINE + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + CLASS_STRING +
DIAMOND_OPEN_BRACKET +
QUESTION_MARK +
DIAMOND_CLOSE_BRACKET + SPACE + GET_METHOD_PREFIX + BASE_CLASS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + RETURN + SPACE + baseClassName + PERIOD + CLASS + SEMI_COLAN + NEW_LINE +
FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET;
}
/*
* Retruns omit null value string.
*
* @return omit null value string
*/
......@@ -1047,8 +1105,7 @@ public final class MethodsGenerator {
* Return from string method's body string.
*
* @param attr attribute info
* @param fromStringAttributeInfo attribute info for the from string
* wrapper type
* @param fromStringAttributeInfo attribute info for the from string wrapper type
* @return from string method's body string
*/
public static String getFromStringMethod(JavaAttributeInfo attr,
......@@ -1128,7 +1185,7 @@ public final class MethodsGenerator {
+ FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
} else {
String parseFromStringMethod = getParseFromStringMethod(targetDataType,
fromStringAttributeInfo.getAttributeType());
fromStringAttributeInfo.getAttributeType());
return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL + SPACE + parseFromStringMethod
+ OPEN_PARENTHESIS + FROM_STRING_PARAM_NAME + CLOSE_PARENTHESIS + SEMI_COLAN;
}
......@@ -1324,13 +1381,12 @@ public final class MethodsGenerator {
*
* @return implementation of add augmentation
*/
public static String getAddAugmentInfoMethodImpl() {
return NEW_LINE + generateForAddAugmentation() + FOUR_SPACE_INDENTATION +
PUBLIC + SPACE + VOID + SPACE + ADD_STRING
+ AUGMENTATION + OPEN_PARENTHESIS + YANG_AUGMENTED_INFO + SPACE + VALUE + COMMA + SPACE + CLASS_STRING +
SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT + OPEN_PARENTHESIS +
CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
static String getAddAugmentInfoMethodImpl() {
return NEW_LINE + generateForAddAugmentation() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE +
ADD_STRING + AUGMENTED_INFO + OPEN_PARENTHESIS + YANG_AUGMENTED_INFO + SPACE + VALUE + COMMA +
SPACE + CLASS_STRING + SPACE + CLASS + OBJECT_STRING + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
NEW_LINE + EIGHT_SPACE_INDENTATION + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + PUT +
OPEN_PARENTHESIS + CLASS + OBJECT_STRING + COMMA + SPACE + VALUE +
CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
CLOSE_CURLY_BRACKET + NEW_LINE;
}
......@@ -1340,11 +1396,11 @@ public final class MethodsGenerator {
*
* @return implementation of get augment info
*/
public static String getAugmentInfoImpl() {
static String getAugmentInfoImpl() {
return generateForGetAugmentation() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
YANG_AUGMENTED_INFO + SPACE + GET_METHOD_PREFIX +
YANG_AUGMENTED_INFO + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
AUGMENTED_INFO + OPEN_PARENTHESIS + CLASS_STRING + SPACE + CLASS + OBJECT_STRING +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + PERIOD + GET + OPEN_PARENTHESIS + CLASS +
OBJECT_STRING + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION +
......@@ -1352,6 +1408,23 @@ public final class MethodsGenerator {
}
/**
* Returns implementation of get augment info.
*
* @return implementation of get augment info
*/
static String getAugmentInfoMapImpl(YangPluginConfig pluginConfig) {
return getJavaDoc(GETTER_METHOD, getSmallCase(YANG_AUGMENTED_INFO) + MAP, false, pluginConfig)
+ FOUR_SPACE_INDENTATION + PUBLIC + SPACE +
MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET + QUESTION_MARK +
DIAMOND_CLOSE_BRACKET + COMMA + SPACE + YANG_AUGMENTED_INFO + DIAMOND_CLOSE_BRACKET + SPACE +
GET_METHOD_PREFIX + YANG_AUGMENTED_INFO + MAP + OPEN_PARENTHESIS +
CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION +
RETURN + SPACE + getSmallCase(YANG_AUGMENTED_INFO) + MAP + SEMI_COLAN + NEW_LINE
+ FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
}
/**
* Returns enum's constructor.
*
* @param className enum's class name
......@@ -1396,7 +1469,7 @@ public final class MethodsGenerator {
+ RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET
+ NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
return getJavaDoc(OF_METHOD, getCapitalCase(className) + FOR_TYPE + attrName, false, pluginConfig)
return getJavaDoc(OF_METHOD, getCapitalCase(className) + " for type" + attrName, false, pluginConfig)
+ method;
}
......@@ -1475,24 +1548,6 @@ public final class MethodsGenerator {
}
/**
* Returns copy constructor for augmented class.
*
* @param yangName augmente class name
* @param augmentName augmented class name
* @return copy constructor for augmented class
*/
public static String getAugmentedNodesConstructorStart(String yangName,
String augmentName) {
String javadoc = generateForTypeConstructor(yangName);
String constructor = FOUR_SPACE_INDENTATION + PUBLIC + SPACE + yangName + BUILDER + OPEN_PARENTHESIS
+ augmentName + PERIOD + augmentName + BUILDER + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ OPEN_CURLY_BRACKET + NEW_LINE;
return javadoc + constructor;
}
/**
* Returns the constructor strings for class file.
*
* @param attr attribute info
......@@ -1514,8 +1569,7 @@ public final class MethodsGenerator {
* @param parent parent node
* @return augmented data getter and setter methods for service class
*/
public static String getAugmentsDataMethodForService(YangNode parent) {
Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = getResolvedAugmentsForManager(parent);
static String getAugmentsDataMethodForService(YangNode parent) {
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
YangNode augmentedNode;
String curNodeName;
......@@ -1525,7 +1579,7 @@ public final class MethodsGenerator {
String returnType;
YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
for (YangAtomicPath nodeId : targets) {
augmentedNode = resolvedAugmentsForManager.get(nodeId).getResolveNodeInPath().get(nodeId);
augmentedNode = nodeId.getResolvedNode().getParent();
if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
} else {
......@@ -1533,7 +1587,7 @@ public final class MethodsGenerator {
.getConflictResolver()));
}
returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
parentName = getParentNodeNameForDataMethods(augmentedNode.getParent(), pluginConfig);
parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
method = getJavaDoc(GETTER_METHOD, getSmallCase(AUGMENTED + parentName + curNodeName), false,
pluginConfig) + getGetterForInterface(AUGMENTED + parentName
+ getCapitalCase(curNodeName),
......@@ -1558,8 +1612,7 @@ public final class MethodsGenerator {
* @param parent parent node
* @return augmented data getter and setter methods for manager class
*/
public static String getAugmentsDataMethodForManager(YangNode parent) {
Map<YangAtomicPath, YangAugment> resolvedAugmentsForManager = getResolvedAugmentsForManager(parent);
static String getAugmentsDataMethodForManager(YangNode parent) {
List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
YangNode augmentedNode;
String curNodeName;
......@@ -1569,7 +1622,7 @@ public final class MethodsGenerator {
String parentName;
YangPluginConfig pluginConfig = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPluginConfig();
for (YangAtomicPath nodeId : targets) {
augmentedNode = resolvedAugmentsForManager.get(nodeId).getResolveNodeInPath().get(nodeId);
augmentedNode = nodeId.getResolvedNode().getParent();
if (((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName() != null) {
curNodeName = ((JavaFileInfoContainer) augmentedNode).getJavaFileInfo().getJavaName();
} else {
......@@ -1577,7 +1630,7 @@ public final class MethodsGenerator {
.getConflictResolver()));
}
returnType = getAugmentedClassNameForDataMethods(augmentedNode, parent);
parentName = getParentNodeNameForDataMethods(augmentedNode.getParent(), pluginConfig);
parentName = getParentNodeNameForDataMethods(augmentedNode, pluginConfig);
method = getOverRideString() + getGetter(returnType, AUGMENTED
+ parentName + getCapitalCase(curNodeName),
GENERATE_SERVICE_AND_MANAGER) + NEW_LINE;
......
......@@ -517,11 +517,6 @@ public final class UtilConstants {
public static final String IF = "if";
/**
* Static attribute for "for" syntax.
*/
public static final String FOR = "for";
/**
* Static attribute for of.
*/
public static final String OF = "of";
......@@ -1185,7 +1180,7 @@ public final class UtilConstants {
/**
* Static attribute for augmentation class.
*/
public static final String AUGMENTATION = "Augmentation";
public static final String AUGMENTED_INFO = "AugmentedInfo";
/**
* Static attribute for AugmentedInfo class.
......@@ -1383,6 +1378,43 @@ public final class UtilConstants {
public static final String JAR = "jar";
/**
* Static attribute for for.
*/
public static final String FOR = "for";
/**
* Static attribute for YangAugmentedOpParamInfo.
*/
public static final String YANG_AUGMENTED_OP_PARAM_INFO = "YangAugmentedOpParamInfo";
/**
* Static attribute for YangAugmentedOpParamInfo.
*/
public static final String YANG_AUGMENTED_OP_PARAM_INFO_CLASS = "YangAugmentedOpParamInfo;\n";
/**
* Static attribute for IllegalArgumentException.
*/
public static final String ILLEGAL_ARGUMENT_EXCEPTION = "IllegalArgumentException";
/**
* Static attribute for IllegalArgumentException.
*/
public static final String ILLEGAL_ARGUMENT_EXCEPTION_MSG = "\"provided augmented info is invalid for content " +
"match.\"";
/**
* Static attribute for throw.
*/
public static final String THROW = "throw";
/**
* Static attribute for baseClass().
*/
public static final String BASE_CLASS = "BaseClass()";
/**
* Creates an instance of util constants.
*/
private UtilConstants() {
......
......@@ -56,7 +56,7 @@ public class IetfYangFileTest {
yangPluginConfig.setCodeGenDir("target/ietfyang/l3vpnservice/");
yangPluginConfig.setManagerCodeGenDir("target/ietfyang/l3vpnservice/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory(userDir + "/target/ietfyang/");
}
......
......@@ -50,7 +50,7 @@ public class AugmentTranslatorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/augmentTranslator/");
yangPluginConfig.setManagerCodeGenDir("target/augmentTranslator/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/augmentTranslator/");
}
......
......@@ -638,7 +638,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/interfilewithusesreferringtype/");
yangPluginConfig.setManagerCodeGenDir("target/interfilewithusesreferringtype/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/interfilewithusesreferringtype/");
......@@ -660,7 +660,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
yangPluginConfig.setManagerCodeGenDir("target/file1UsesFile2TypeDefFile3Type/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/file1UsesFile2TypeDefFile3Type/");
......@@ -682,7 +682,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/interfileietf/");
yangPluginConfig.setManagerCodeGenDir("target/interfileietf/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/interfileietf/");
......@@ -704,7 +704,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/usesInContainer/");
yangPluginConfig.setManagerCodeGenDir("target/usesInContainer/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/usesInContainer/");
......@@ -726,7 +726,7 @@ public class InterFileLinkingTest {
yangPluginConfig.setCodeGenDir("target/groupingNodeSameAsModule/");
yangPluginConfig.setManagerCodeGenDir("target/groupingNodeSameAsModule/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
deleteDirectory("target/groupingNodeSameAsModule/");
......
......@@ -191,7 +191,7 @@ public class InterJarLinkerTest {
yangPluginConfig.setCodeGenDir(TARGET);
yangPluginConfig.setManagerCodeGenDir(TARGET);
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
testIfFlowClassifierFilesExists();
testIfPortPairFileDoesNotExist();
......@@ -308,6 +308,7 @@ public class InterJarLinkerTest {
for (YangNode node : interJarResolvedNodes) {
YangFileInfo dependentFileInfo = new YangFileInfo();
node.setToTranslate(false);
dependentFileInfo.setRootNode(node);
dependentFileInfo.setForTranslator(false);
dependentFileInfo.setYangFileName(node.getName());
......
......@@ -44,7 +44,7 @@ public class ManagerCodeGeneratorTest {
@Test
public void processManagerTranslator() throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/manager";
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
......@@ -54,7 +54,7 @@ public class ManagerCodeGeneratorTest {
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
......@@ -79,7 +79,7 @@ public class ManagerCodeGeneratorTest {
public void processManagerInDifferentPackageTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager";
String searchDir = "src/test/resources/manager/singleChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
......@@ -87,10 +87,10 @@ public class ManagerCodeGeneratorTest {
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager1/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(utilManager.getYangFileInfoSet(), yangPluginConfig);
String file3 = "target/manager1/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
utilManager.translateToJava(yangPluginConfig);
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(true, is(manager3.exists()));
......@@ -98,4 +98,48 @@ public class ManagerCodeGeneratorTest {
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
/**
* Checks manager translation in different package should not result in any exception.
*
* @throws MojoExecutionException
*/
@Test
public void processManagerforMultiChildTranslator() throws IOException, ParserException,
MojoExecutionException {
String searchDir = "src/test/resources/manager/MultiChild";
utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/manager/");
yangPluginConfig.setManagerCodeGenDir("target/manager/");
utilManager.translateToJava(yangPluginConfig);
String file1 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test5Manager.java";
File manager1 = new File(file1);
assertThat(false, is(manager1.exists()));
String file2 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test6Manager.java";
File manager2 = new File(file2);
assertThat(false, is(manager2.exists()));
String file3 = "target/manager/org/onosproject/yang/gen/v1/test5/test/rev20160704/Test7Manager.java";
File manager3 = new File(file3);
assertThat(false, is(manager3.exists()));
String file4 = "target/manager/org/onosproject/yang/gen/v1/test8/test/rev20160704/Test8Manager.java";
File manager4 = new File(file4);
assertThat(true, is(manager4.exists()));
deleteDirectory("target/manager/");
deleteDirectory("target/manager1/");
}
}
......
module test5 {
namespace "test5:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
typedef typedef1 {
type int32;
}
typedef typedef2 {
type int32;
}
typedef typedef3 {
type int32;
}
}
submodule test6 {
belongs-to "test5" {
prefix "test";
}
revision "2016-07-04" {
description "Initial revision.";
}
grouping grouping1 {
leaf leaf1 {
type int32;
}
}
grouping grouping2 {
leaf leaf1 {
type int32;
}
}
grouping grouping3 {
leaf leaf1 {
type int32;
}
}
}
module test7 {
namespace "test5:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
grouping grouping1 {
leaf leaf1 {
type int32;
}
}
typedef typedef3 {
type int32;
}
}
module test8 {
namespace "test8:test";
prefix test ;
revision "2016-07-04" {
description "Initial revision.";
}
grouping grouping1 {
leaf leaf1 {
type int32;
}
}
typedef typedef3 {
type int32;
}
container container2 {
}
}
......@@ -5,7 +5,7 @@ module test5 {
revision "2016-07-04" {
description "Initial revision.";
}
typedef abc {
typedef typedef1 {
type int32;
}
......
......@@ -7,7 +7,7 @@ submodule test6 {
revision "2016-07-04" {
description "Initial revision.";
}
grouping abc {
grouping grouping1 {
leaf leaf1 {
type int32;
}
......
......@@ -6,8 +6,7 @@ module test7 {
description "Initial revision.";
}
leaf abc {
type int32;
container cont1 {
}
}
......