[ONOS-4351][ONOS-4524] Augment linking and defect fixed.
Change-Id: I7c8e8c90579eea4631e014c4906a543a3c249427
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java b/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java
new file mode 100644
index 0000000..aa2b678
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangAugmentationHolder.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+/**
+ * Represents YANG constructs which can be augmented.
+ */
+public interface YangAugmentationHolder {
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java b/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
index e61d273..6787dc9 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangCase.java
@@ -92,7 +92,7 @@
* Represents data model node to maintain information defined in YANG case.
*/
public class YangCase extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Case name.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java b/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
index f05a11c..49a96d9 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangChoice.java
@@ -59,7 +59,8 @@
/**
* Represents data model node to maintain information defined in YANG choice.
*/
-public class YangChoice extends YangNode implements YangCommonInfo, Parsable, CollisionDetector {
+public class YangChoice extends YangNode
+ implements YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of choice.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java b/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
index 5941837..3930433 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
@@ -87,7 +87,8 @@
/**
* Represents data model node to maintain information defined in YANG container.
*/
-public class YangContainer extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
+public class YangContainer extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the container.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java b/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
index 10f1ef4..4d7f2df 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangInput.java
@@ -68,7 +68,8 @@
/**
* Represents data model node to maintain information defined in YANG input.
*/
-public class YangInput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector {
+public class YangInput extends YangNode
+ implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the input.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
index e82132f..2b0bb53 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -68,7 +68,7 @@
* Represents list data represented in YANG.
*/
public class YangList extends YangNode
- implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector {
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the YANG list.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java b/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
index e7b0241..5e81f64 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangNotification.java
@@ -74,8 +74,8 @@
/**
* Represents data model node to maintain information defined in YANG notification.
*/
-public class YangNotification extends YangNode implements YangLeavesHolder, YangCommonInfo, Parsable,
- CollisionDetector {
+public class YangNotification extends YangNode
+ implements YangLeavesHolder, YangCommonInfo, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the notification.
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java b/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
index e9fa9c3..97072cf 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangOutput.java
@@ -67,7 +67,8 @@
/**
* Represents data model node to maintain information defined in YANG output.
*/
-public class YangOutput extends YangNode implements YangLeavesHolder, Parsable, CollisionDetector {
+public class YangOutput extends YangNode
+ implements YangLeavesHolder, Parsable, CollisionDetector, YangAugmentationHolder {
/**
* Name of the output.
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
index 68a1b36..b3b22ae 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
@@ -18,7 +18,6 @@
import java.util.List;
-import org.onosproject.yangutils.datamodel.CollisionDetector;
import org.onosproject.yangutils.datamodel.YangAugment;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
@@ -33,9 +32,10 @@
import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangAugmentNode;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.generateNameForAugmentNode;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getParentsPrefix;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.parserException;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.validateNodeInTargetPath;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
@@ -119,8 +119,11 @@
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangUses) {
YangNode curNode = (YangNode) curData;
YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
+
+ validateTargetNodePath(targetNodes, curNode, ctx);
+
yangAugment.setTargetNode(targetNodes);
- yangAugment.setName(detectCollisionForTargetNode(curData, targetNodes, line, charPositionInLine, listener));
+ yangAugment.setName(generateNameForAugmentNode(curData, targetNodes, listener));
try {
curNode.addChild(yangAugment);
@@ -171,58 +174,34 @@
}
/**
- * Detects collision for java file generation of augment node when
- * it is updating the same target node in same parent multiple times.
- * Returns name for generated java file of augment node
+ * Validates whether the current target node path is correct or not.
*
- * @param curData parsable data
* @param targetNodes list of target nodes
* @param line line in YANG file
* @param charPositionInLine char position in YANG file
- * @param listener tree walk listener
- * @return name for generated java file for augment node
+ * @param curNode current YANG node
*/
- private static String detectCollisionForTargetNode(Parsable curData, List<YangNodeIdentifier> targetNodes, int line,
- int charPositionInLine, TreeWalkListener listener) {
+ private static void validateTargetNodePath(List<YangNodeIdentifier> targetNodes, YangNode curNode,
+ GeneratedYangParser.AugmentStatementContext ctx) {
- String curPrefix = null;
- if (curData instanceof YangModule) {
- curPrefix = ((YangModule) curData).getPrefix();
- } else if (curData instanceof YangSubModule) {
- curPrefix = ((YangSubModule) curData).getPrefix();
- }
- YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
- boolean isPrefix = isPrefixPresent(nodeId, curPrefix);
- String xpath = createValidNameForAugment(nodeId, isPrefix);
-
- if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
- try {
- ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(xpath,
- AUGMENT_DATA);
- } catch (DataModelException e) {
- return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix);
+ YangNodeIdentifier moduleId = targetNodes.get(0);
+ if (moduleId.getPrefix() == null) {
+ if (!moduleId.getName().equals(curNode.getName())) {
+ throw parserException(ctx);
+ } else {
+ validateNodeInTargetPath(curNode, targetNodes, ctx);
+ }
+ } else {
+ String parentPrefix = getParentsPrefix(curNode);
+ if (parentPrefix != null) {
+ if (!parentPrefix.equals(moduleId.getPrefix())) {
+ // TODO: handle in linker.
+ } else {
+ validateNodeInTargetPath(curNode, targetNodes, ctx);
+ }
+ } else {
+ // TODO: handle in linker.
}
}
-
- clearOccurrenceCount();
- return xpath;
- }
-
- /**
- * Returns true if a prefix is present and it is not equals to parents prefix.
- *
- * @param nodeId YANG node identifier
- * @param parentsPrefix parent's prefix
- * @return true if a prefix is present and it is not equals to parents prefix
- */
- private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) {
- return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix;
- }
-
- /**
- * Validates for the child nodes of augment node.
- */
- private static void validateForChildNodes() {
- //TODO: implement with linker.
}
}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
index afe3a02..08edab1 100644
--- a/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
@@ -110,7 +110,7 @@
listener.getParsedDataStack().push(enumNode);
}
- /* Removes quotes from the enum name if present.*/
+ /*Removes quotes from the enum name if present.*/
private static String getValidNamedValue(String name) {
if (name.contains(QUOTES)) {
name = name.replace(QUOTES, EMPTY_STRING);
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentJavaFileNameGenUtil.java b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentJavaFileNameGenUtil.java
deleted file mode 100644
index 730923a..0000000
--- a/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentJavaFileNameGenUtil.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * 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.parser.impl.parserutils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
-
-/**
- * Represents a utility which provides valid name for generated java file for augment node.
- */
-public final class AugmentJavaFileNameGenUtil {
-
- /**
- * Prefix to be added to generated java file for augment node.
- */
- private static final String AUGMENTED = "Augmented";
-
- /**
- * The number of time augment has updated the same target node in same module/submodule.
- */
- private static int occurrenceCount = 1;
-
- /**
- * List of names for generated augment java file.
- */
- private static List<String> augmentJavaFileNameList = new ArrayList<>();
-
- private static final int ONE = 1;
- private static final int TWO = 2;
- private static final int ZERO = 0;
-
- /**
- * Creates an instance of augment java file name generator utility.
- */
- private AugmentJavaFileNameGenUtil() {
- }
-
- /**
- * Sets the augment java file name list.
- *
- * @param nameList name list
- */
- private static void setAugmentJavaFileNameList(List<String> nameList) {
- augmentJavaFileNameList = nameList;
- }
-
- /**
- * Returns augment java file name list.
- *
- * @return augment java file name list
- */
- public static List<String> getAugmentJavaFileNameList() {
- return augmentJavaFileNameList;
- }
-
- /**
- * Sets occurrence count.
- *
- * @param occurrence occurrence count
- */
- private static void setOccurrenceCount(int occurrence) {
- occurrenceCount = occurrence;
- }
-
- /**
- * Returns occurrence count.
- *
- * @return occurrence count
- */
- private static int getOccurrenceCount() {
- return occurrenceCount;
- }
-
- /**
- * Creates a name identifier for augment.
- *
- * @param nodeId node identifier
- * @param isPrefix if prefix is present or it is not equals to parent's prefix
- * @return valid name for augment
- */
- public static String createValidNameForAugment(YangNodeIdentifier nodeId, boolean isPrefix) {
- getAugmentJavaFileNameList().add(createName(nodeId, isPrefix));
- setAugmentJavaFileNameList(getAugmentJavaFileNameList());
- return getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - 1);
- }
-
- /**
- * Creates name for the current augment file.
- *
- * @param nodeId node identifier
- * @param isPrefix if prefix is present or it is not equals to parent's prefix
- */
- private static String createName(YangNodeIdentifier nodeId, boolean isPrefix) {
- if (isPrefix) {
- return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
- } else {
- return AUGMENTED + getCapitalCase(nodeId.getName());
- }
- }
-
- /**
- * Updates occurrence count of augment.
- */
- public static void updateOccurenceCount() {
- int count = getOccurrenceCount();
- count++;
- setOccurrenceCount(count);
- }
-
- /**
- * Updates the list of name when augment has occurred multiple times to update the same target node
- * and returns a valid name for augment node's generated java file.
- *
- * @param nodeId YANG node identifier
- * @param isPrefix true if a prefix is present and it is not equals to parents prefix
- * @return valid name for augment node
- */
- public static String updateNameWhenHasMultipleOuccrrence(YangNodeIdentifier nodeId, boolean isPrefix) {
- String name = "";
- updateOccurenceCount();
-
- if (getOccurrenceCount() == TWO) {
- String previousAugmentsName = getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - ONE);
- getAugmentJavaFileNameList().remove(ZERO);
- getAugmentJavaFileNameList().add(previousAugmentsName + ONE);
- //TODO: update when already contains the name.
- name = createName(nodeId, isPrefix) + TWO;
- } else {
- name = createName(nodeId, isPrefix) + getOccurrenceCount();
- }
- getAugmentJavaFileNameList().add(name);
- return name;
- }
-
- /**
- * Resets occurrence count to one.
- */
- public static void clearOccurrenceCount() {
- setOccurrenceCount(ONE);
- }
-
-}
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentListenerUtil.java b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentListenerUtil.java
new file mode 100644
index 0000000..764cef4
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/AugmentListenerUtil.java
@@ -0,0 +1,309 @@
+/*
+ * 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.parser.impl.parserutils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onosproject.yangutils.datamodel.CollisionDetector;
+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.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.Parsable;
+import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.utils.YangConstructType.AUGMENT_DATA;
+
+/**
+ * Represents a utility which provides listener utilities augment node.
+ */
+public final class AugmentListenerUtil {
+
+ /**
+ * Prefix to be added to generated java file for augment node.
+ */
+ private static final String AUGMENTED = "Augmented";
+
+ /**
+ * The number of time augment has updated the same target node in same module/submodule.
+ */
+ private static int occurrenceCount = 1;
+
+ /**
+ * List of names for augment's generated java file.
+ */
+ private static List<String> augmentJavaFileNameList = new ArrayList<>();
+
+ private static final int ONE = 1;
+ private static final int TWO = 2;
+ private static final int ZERO = 0;
+
+ /**
+ * Creates an instance of augment java file name generator utility.
+ */
+ private AugmentListenerUtil() {
+ }
+
+ /**
+ * Sets the augment java file name list.
+ *
+ * @param nameList name list
+ */
+ private static void setAugmentJavaFileNameList(List<String> nameList) {
+ augmentJavaFileNameList = nameList;
+ }
+
+ /**
+ * Returns augment java file name list.
+ *
+ * @return augment java file name list
+ */
+ public static List<String> getAugmentJavaFileNameList() {
+ return augmentJavaFileNameList;
+ }
+
+ /**
+ * Sets occurrence count.
+ *
+ * @param occurrence occurrence count
+ */
+ private static void setOccurrenceCount(int occurrence) {
+ occurrenceCount = occurrence;
+ }
+
+ /**
+ * Returns occurrence count.
+ *
+ * @return occurrence count
+ */
+ private static int getOccurrenceCount() {
+ return occurrenceCount;
+ }
+
+ /**
+ * Generates name for augment node also detects collision for java file generation of augment node when
+ * augment is updating the same target node in same parent multiple times.
+ *
+ * @param curData parsable data
+ * @param targetNodes list of target nodes
+ * @param listener tree walk listener
+ * @return name for augment node
+ */
+ public static String generateNameForAugmentNode(Parsable curData, List<YangNodeIdentifier> targetNodes,
+ TreeWalkListener listener) {
+
+ String curPrefix = getParentsPrefix((YangNode) curData);
+ YangNodeIdentifier nodeId = targetNodes.get(targetNodes.size() - 1);
+ boolean isPrefix = isPrefixPresent(nodeId, curPrefix);
+ String generateName = createValidNameForAugment(nodeId, isPrefix);
+
+ if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
+ try {
+ ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(generateName,
+ AUGMENT_DATA);
+ } catch (DataModelException e) {
+ return updateNameWhenHasMultipleOuccrrence(nodeId, isPrefix);
+ }
+ }
+
+ clearOccurrenceCount();
+ return generateName;
+ }
+
+ /**
+ * Creates a name identifier for augment.
+ *
+ * @param nodeId node identifier
+ * @param isPrefix if prefix is present or it is not equals to parent's prefix
+ * @return valid name for augment
+ */
+ public static String createValidNameForAugment(YangNodeIdentifier nodeId, boolean isPrefix) {
+ getAugmentJavaFileNameList().add(createName(nodeId, isPrefix));
+ setAugmentJavaFileNameList(getAugmentJavaFileNameList());
+ return getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - 1);
+ }
+
+ /**
+ * Creates name for the current augment file.
+ *
+ * @param nodeId node identifier
+ * @param isPrefix if prefix is present or it is not equals to parent's prefix
+ */
+ private static String createName(YangNodeIdentifier nodeId, boolean isPrefix) {
+ if (isPrefix) {
+ return AUGMENTED + getCapitalCase(nodeId.getPrefix()) + getCapitalCase(nodeId.getName());
+ } else {
+ return AUGMENTED + getCapitalCase(nodeId.getName());
+ }
+ }
+
+ /**
+ * Updates occurrence count of augment.
+ */
+ private static void updateOccurenceCount() {
+ int count = getOccurrenceCount();
+ count++;
+ setOccurrenceCount(count);
+ }
+
+ /**
+ * Updates the list of name when augment has occurred multiple times to update the same target node
+ * and returns a valid name for augment node's generated java file.
+ *
+ * @param nodeId YANG node identifier
+ * @param isPrefix true if a prefix is present and it is not equals to parents prefix
+ * @return valid name for augment node
+ */
+ public static String updateNameWhenHasMultipleOuccrrence(YangNodeIdentifier nodeId, boolean isPrefix) {
+ String name = "";
+ updateOccurenceCount();
+
+ if (getOccurrenceCount() == TWO) {
+ String previousAugmentsName = getAugmentJavaFileNameList().get(getAugmentJavaFileNameList().size() - ONE);
+ getAugmentJavaFileNameList().remove(ZERO);
+ getAugmentJavaFileNameList().add(previousAugmentsName + ONE);
+ //TODO: update when already contains the name.
+ name = createName(nodeId, isPrefix) + TWO;
+ } else {
+ name = createName(nodeId, isPrefix) + getOccurrenceCount();
+ }
+ getAugmentJavaFileNameList().add(name);
+ return name;
+ }
+
+ /**
+ * Resets occurrence count to one.
+ */
+ public static void clearOccurrenceCount() {
+ setOccurrenceCount(ONE);
+ }
+
+ /**
+ * Returns true if a prefix is present and it is not equals to parents prefix.
+ *
+ * @param nodeId YANG node identifier
+ * @param parentsPrefix parent's prefix
+ * @return true if a prefix is present and it is not equals to parents prefix
+ */
+ private static boolean isPrefixPresent(YangNodeIdentifier nodeId, String parentsPrefix) {
+ return nodeId.getPrefix() != null && nodeId.getPrefix() != parentsPrefix;
+ }
+
+ /**
+ * Validates whether current node in target path is valid or not.
+ *
+ * @param curNode current YANG node
+ * @param targetNodes list of target nodes
+ * @param ctx augment statement context
+ */
+ public static void validateNodeInTargetPath(YangNode curNode, List<YangNodeIdentifier> targetNodes,
+ GeneratedYangParser.AugmentStatementContext ctx) {
+
+ curNode = curNode.getChild();
+ YangNode tempNode = validateCurrentTargetNode(targetNodes, curNode);
+ if (tempNode != null) {
+ switch (tempNode.getNodeType()) {
+ case CONTAINER_NODE:
+ break;
+ case LIST_NODE:
+ break;
+ case CHOICE_NODE:
+ break;
+ case CASE_NODE:
+ break;
+ case INPUT_NODE:
+ break;
+ case OUTPUT_NODE:
+ break;
+ case NOTIFICATION_NODE:
+ break;
+ default:
+ throw parserException(ctx);
+ }
+ } else {
+ throw parserException(ctx);
+ }
+ }
+
+ /**
+ * Validates whether nodes in target node list are valid or not.
+ *
+ * @param targetNodeName current target node
+ * @param curNode YANG node
+ * @return true or false
+ */
+ private static YangNode validateCurrentTargetNode(List<YangNodeIdentifier> targetNodes, YangNode curNode) {
+ YangNode tempNode = null;
+ while (curNode != null) {
+ tempNode = curNode;
+ for (int i = 1; i < targetNodes.size(); i++) {
+ if (curNode.getName().equals(targetNodes.get(i).getName())) {
+ if (curNode.getChild() != null && targetNodes.size() - 1 != i) {
+ curNode = curNode.getChild();
+ } else if (curNode.getChild() != null && targetNodes.size() - 1 == i) {
+ return curNode;
+ } else if (curNode.getChild() == null && targetNodes.size() - 1 == i) {
+ return curNode;
+ } else {
+ break;
+ }
+ } else {
+ curNode = tempNode;
+ break;
+ }
+ }
+ curNode = curNode.getNextSibling();
+ }
+ return null;
+ }
+
+ /**
+ * Builds parser exception.
+ *
+ * @param ctx augment statement context
+ * @return parser exception
+ */
+ public static ParserException parserException(GeneratedYangParser.AugmentStatementContext ctx) {
+ int line = ctx.getStart().getLine();
+ int charPositionInLine = ctx.getStart().getCharPositionInLine();
+ ParserException exception = new ParserException("invalid target node path.");
+ exception.setLine(line);
+ exception.setCharPosition(charPositionInLine);
+ return exception;
+ }
+
+ /**
+ * Returns parent nodes prefix.
+ *
+ * @param curNode current YANG node
+ * @return parent nodes prefix
+ */
+ public static String getParentsPrefix(YangNode curNode) {
+ String curPrefix = null;
+ if (curNode instanceof YangModule) {
+ curPrefix = ((YangModule) curNode).getPrefix();
+ } else if (curNode instanceof YangSubModule) {
+ curPrefix = ((YangSubModule) curNode).getPrefix();
+ }
+ return curPrefix;
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java b/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
index bd214a6..f15d3b8 100644
--- a/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
+++ b/src/main/java/org/onosproject/yangutils/plugin/manager/YangUtilManager.java
@@ -28,10 +28,10 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.YangUtilsParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
@@ -114,7 +114,8 @@
@Component
private BuildContext context;
- private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
+ private static final String DEFAULT_PKG = SLASH
+ + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
private YangNode rootNode;
@@ -124,7 +125,7 @@
try {
- /**
+ /*
* For deleting the generated code in previous build.
*/
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
@@ -146,7 +147,7 @@
try {
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
setRootNode(yangNode);
- generateJavaCode(yangNode, yangPlugin);
+ generateJavaCode(yangNode, yangPlugin, yangFile);
} catch (ParserException e) {
String logInfo = "Error in file: " + e.getFileName();
if (e.getLineNumber() != 0) {
@@ -165,13 +166,20 @@
addToSource(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG, project, context);
copyYangFilesToTarget(yangFiles, getDirectory(baseDir, outputDirectory), project);
} catch (Exception e) {
+ String fileName = "";
+ if (e instanceof TranslatorException) {
+ fileName = ((TranslatorException) e).getFileName();
+ }
try {
translatorErrorHandler(getRootNode());
deleteDirectory(getDirectory(baseDir, genFilesDir) + DEFAULT_PKG);
- } catch (IOException | DataModelException ex) {
- throw new MojoExecutionException("Error handler failed to delete files for data model node.");
+ } catch (IOException ex) {
+ throw new MojoExecutionException(
+ "Error handler failed to delete files for data model node.");
}
- throw new MojoExecutionException("Exception occured due to " + e.getLocalizedMessage());
+ throw new MojoExecutionException(
+ "Exception occured due to " + e.getLocalizedMessage() + " in " + fileName
+ + " YANG file.");
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/HasAugmentation.java b/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentationHolder.java
similarity index 96%
rename from src/main/java/org/onosproject/yangutils/translator/tojava/HasAugmentation.java
rename to src/main/java/org/onosproject/yangutils/translator/tojava/AugmentationHolder.java
index 0be2b69..324a27f 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/HasAugmentation.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/AugmentationHolder.java
@@ -21,7 +21,7 @@
/**
* Abstraction of an entity which represents augmentation of a YANG node.
*/
-public interface HasAugmentation {
+public interface AugmentationHolder {
/**
* Adds augment info to the augment info list.
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
index 70f96d9..277038c 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
@@ -16,8 +16,7 @@
package org.onosproject.yangutils.translator.tojava;
-import java.io.IOException;
-
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
/**
@@ -29,16 +28,16 @@
* Traverse the schema of application and generate corresponding code.
*
* @param yangPlugin YANG plugin config
- * @throws IOException when fails to translate the data model tree
+ * @throws TranslatorException when fails to translate the data model tree
*/
void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException;
+ throws TranslatorException;
/**
* Traverse the schema of application and generate corresponding code.
*
- * @throws IOException when fails to generate java code
+ * @throws TranslatorException when fails to generate java code
*/
void generateCodeExit()
- throws IOException;
+ throws TranslatorException;
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
index 86c6787..6ec67e4 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
@@ -19,7 +19,6 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
@@ -67,11 +66,12 @@
*
* @param rootNode root node of the data model tree
* @param yangPlugin YANG plugin config
- * @throws IOException when fails to generate java code file the current
+ * @param fileName YANG file name
+ * @throws TranslatorException when fails to generate java code file the current
* node
*/
- public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
- throws IOException {
+ public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin, String fileName)
+ throws TranslatorException {
YangNode codeGenNode = rootNode;
TraversalType curTraversal = ROOT;
@@ -80,7 +80,7 @@
if (curTraversal != PARENT) {
if (codeGenNode instanceof JavaCodeGenerator) {
setCurNode(codeGenNode);
- generateCodeEntry(codeGenNode, yangPlugin);
+ generateCodeEntry(codeGenNode, yangPlugin, fileName);
} else {
/*
* For grouping and uses, there is no code generation, skip the generation for the child.
@@ -100,11 +100,11 @@
curTraversal = CHILD;
codeGenNode = codeGenNode.getChild();
} else if (codeGenNode.getNextSibling() != null) {
- generateCodeExit(codeGenNode);
+ generateCodeExit(codeGenNode, fileName);
curTraversal = SIBILING;
codeGenNode = codeGenNode.getNextSibling();
} else {
- generateCodeExit(codeGenNode);
+ generateCodeExit(codeGenNode, fileName);
curTraversal = PARENT;
codeGenNode = codeGenNode.getParent();
}
@@ -117,16 +117,20 @@
* @param codeGenNode current data model node for which the code needs to be
* generated
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation exception
+ * @param fileName YANG file name
+ * @throws TranslatorException when fails to generate java code file the current
+ * node
*/
- private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
- throws IOException {
+ private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin, String fileName)
+ throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
} else {
- throw new TranslatorException(
+ TranslatorException ex = new TranslatorException(
"Generated data model node cannot be translated to target language code");
+ ex.setFileName(fileName);
+ throw ex;
}
}
@@ -135,27 +139,27 @@
*
* @param codeGenNode current data model node for which the code needs to be
* generated
- * @throws IOException IO operation exception
+ * @param fileName YANG file name
+ * @throws TranslatorException when fails to generate java code file the current
+ * node
*/
- private static void generateCodeExit(YangNode codeGenNode)
- throws IOException {
+ private static void generateCodeExit(YangNode codeGenNode, String fileName) throws TranslatorException {
if (codeGenNode instanceof JavaCodeGenerator) {
((JavaCodeGenerator) codeGenNode).generateCodeExit();
} else {
- throw new TranslatorException(
+ TranslatorException ex = new TranslatorException(
"Generated data model node cannot be translated to target language code");
+ ex.setFileName(fileName);
+ throw ex;
}
}
/**
* Free other YANG nodes of data-model tree when error occurs while file
* generation of current node.
- *
- * @throws DataModelException when fails to do datamodel operations
*/
- private static void freeRestResources()
- throws DataModelException {
+ private static void freeRestResources() {
YangNode freedNode = getCurNode();
YangNode tempNode = freedNode;
@@ -205,10 +209,9 @@
*
* @param rootNode root node of data-model tree
* @throws IOException when fails to delete java code file the current node
- * @throws DataModelException when fails to do datamodel operations
*/
public static void translatorErrorHandler(YangNode rootNode)
- throws IOException, DataModelException {
+ throws IOException {
/**
* Free other resources where translator has failed.
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
index 958201b..7661172 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
@@ -20,26 +20,29 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import static java.util.Collections.sort;
+
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_PKG;
+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.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
-import static java.util.Collections.sort;
-
/**
* Represents that generated Java file can contain imports.
*/
@@ -178,7 +181,7 @@
*
* @return import for list attribute
*/
- public static String getImportForList() {
+ public String getImportForList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + LIST + SEMI_COLAN + NEW_LINE;
}
@@ -187,17 +190,17 @@
*
* @return import for array list attribute
*/
- public static String getImportForArrayList() {
+ public String getImportForArrayList() {
return IMPORT + COLLECTION_IMPORTS + PERIOD + ARRAY_LIST + SEMI_COLAN + NEW_LINE;
}
/**
- * Returns import string for HasAugmentation class.
+ * Returns import string for AugmentationHolder class.
*
- * @return import string for HasAugmentation class
+ * @return import string for AugmentationHolder class
*/
- public static String getHasAugmentationImport() {
- return IMPORT + HAS_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + HAS_AUGMENTATION_CLASS_IMPORT_CLASS;
+ public String getAugmentationHolderImport() {
+ return IMPORT + PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG + PERIOD + AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS;
}
/**
@@ -205,7 +208,25 @@
*
* @return import string for AugmentedInfo class
*/
- public static String getAugmentedInfoImport() {
+ public String getAugmentedInfoImport() {
return IMPORT + AUGMENTED_INFO_CLASS_IMPORT_PKG + PERIOD + AUGMENTED_INFO_CLASS_IMPORT_CLASS;
}
+
+ /**
+ * Returns import string for ListenerService class.
+ *
+ * @return import string for ListenerService class
+ */
+ public String getListenerServiceImport() {
+ return IMPORT + LISTENER_PKG + PERIOD + LISTENER_SERVICE + SEMI_COLAN + NEW_LINE;
+ }
+
+ /**
+ * Returns import string for ListenerRegistry class.
+ *
+ * @return import string for ListenerRegistry class
+ */
+ public String getListenerRegistryImport() {
+ return IMPORT + LISTENER_PKG + PERIOD + LISTENER_REG + SEMI_COLAN + NEW_LINE;
+ }
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
index b1aa5d9..b7e7d4a 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
@@ -28,7 +28,6 @@
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.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
/**
* Represents implementation of java code fragments temporary implementations.
@@ -309,15 +308,6 @@
}
/**
- * Adds class to the extends list.
- *
- * @param extend class to be extended
- */
- public void addToExtendsList(String extend) {
- getExtendsList().add(extend);
- }
-
- /**
* Adds build method for interface.
*
* @return build method for interface
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
index 4f40ea9..bd2742f 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
@@ -18,11 +18,12 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
@@ -53,7 +54,7 @@
*/
public TempJavaEventFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
- setExtendsList(new ArrayList<>());
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
@@ -92,11 +93,13 @@
throws IOException {
createPackage(curNode);
+ String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
+ .getJavaFileInfo().getJavaName());
/**
* Creates event interface file.
*/
- setEventJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_FILE_NAME_SUFFIX)));
+ setEventJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_FILE_NAME_SUFFIX));
generateEventFile(getEventJavaFileHandle(), curNode, null);
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java
index d1b0176..8009e45 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventListenerFragmentFiles.java
@@ -18,11 +18,12 @@
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.createPackage;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
@@ -53,7 +54,7 @@
*/
public TempJavaEventListenerFragmentFiles(JavaFileInfo javaFileInfo)
throws IOException {
- setExtendsList(new ArrayList<>());
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
@@ -90,11 +91,12 @@
throws IOException {
createPackage(curNode);
-
+ String parentInfo = getCapitalCase(((JavaFileInfoContainer) curNode.getParent())
+ .getJavaFileInfo().getJavaName());
/**
* Creates event listener interface file.
*/
- setEventListenerJavaFileHandle(getJavaFileHandle(getJavaClassName(EVENT_LISTENER_FILE_NAME_SUFFIX)));
+ setEventListenerJavaFileHandle(getJavaFileHandle(parentInfo + EVENT_LISTENER_FILE_NAME_SUFFIX));
generateEventListenerFile(getEventListenerJavaFileHandle(), curNode, null);
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
index b0a65a4..59cd01b 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
@@ -28,6 +28,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
@@ -74,13 +75,12 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentationHoldersImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addHasAugmentationImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.detectCollisionBwParentAndChildForImport;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentedInfoExtended;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.prepareJavaFileGeneratorForExtendsList;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.sortImports;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
@@ -131,8 +131,7 @@
/**
* Contains all the interface(s)/class name which will be extended by generated files.
*/
- private List<String> extendsList = new ArrayList<>();
-
+ private JavaExtendsListHolder javaExtendsListHolder;
/**
* File type extension for java classes.
*/
@@ -499,9 +498,8 @@
* @param javaFileInfo generated java file information
* @throws IOException when fails to create new file handle
*/
- TempJavaFragmentFiles(JavaFileInfo javaFileInfo)
- throws IOException {
- setExtendsList(new ArrayList<>());
+ TempJavaFragmentFiles(JavaFileInfo javaFileInfo) throws IOException {
+ setJavaExtendsListHolder(new JavaExtendsListHolder());
setJavaImportData(new JavaImportData());
setJavaFileInfo(javaFileInfo);
setAbsoluteDirPath(getAbsolutePackagePath(getJavaFileInfo().getBaseCodeGenPath(),
@@ -776,30 +774,21 @@
}
/**
- * Returns list of classes to be extended by generated files.
+ * Returns java extends list holder.
*
- * @return list of classes to be extended by generated files
+ * @return java extends list holder
*/
- List<String> getExtendsList() {
- return extendsList;
+ public JavaExtendsListHolder getJavaExtendsListHolder() {
+ return javaExtendsListHolder;
}
/**
- * Sets class to be extended by generated file.
+ * Sets java extends list holder.
*
- * @param extendsList list of classes to be extended
+ * @param javaExtendsListHolder java extends list holder
*/
- void setExtendsList(List<String> extendsList) {
- this.extendsList = extendsList;
- }
-
- /**
- * Adds class to the extends list.
- *
- * @param extend class to be extended
- */
- public void addToExtendsList(String extend) {
- getExtendsList().add(extend);
+ public void setJavaExtendsListHolder(JavaExtendsListHolder javaExtendsListHolder) {
+ this.javaExtendsListHolder = javaExtendsListHolder;
}
/**
@@ -1323,10 +1312,6 @@
if (isAttributePresent()) {
imports = getJavaImportData().getImports();
}
- /*
- * Prepares java file generator for extends list.
- */
- prepareJavaFileGeneratorForExtendsList(getExtendsList());
createPackage(curNode);
/*
@@ -1347,16 +1332,7 @@
}
}
}
- /*
- * Adds import for HasAugmentation class.
- */
- if (isHasAugmentationExtended(getExtendsList())) {
- addHasAugmentationImport(curNode, imports, true);
- }
- if (isAugmentedInfoExtended(getExtendsList())) {
- addAugmentedInfoImport(curNode, imports, true);
- }
- sortImports(imports);
+
/*
* Create interface file.
*/
@@ -1378,10 +1354,10 @@
mergeJavaFiles(getBuilderInterfaceJavaFileHandle(), getInterfaceJavaFileHandle());
}
insertDataIntoJavaFile(getInterfaceJavaFileHandle(), getJavaClassDefClose());
- if (isHasAugmentationExtended(getExtendsList())) {
- addHasAugmentationImport(curNode, imports, false);
+ if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
+ addAugmentationHoldersImport(curNode, imports, false);
}
- if (isAugmentedInfoExtended(getExtendsList())) {
+ if (isAugmentedInfoExtended(getJavaExtendsListHolder().getExtendsList())) {
addAugmentedInfoImport(curNode, imports, false);
}
if (curNode instanceof YangCase) {
@@ -1392,7 +1368,7 @@
if (isAttributePresent()) {
addImportsToStringAndHasCodeMethods(curNode, imports);
}
- if (isHasAugmentationExtended(getExtendsList())) {
+ if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
addAugmentedInfoImport(curNode, imports, true);
addArrayListImport(curNode, imports, true);
}
@@ -1417,8 +1393,11 @@
mergeJavaFiles(getImplClassJavaFileHandle(), getBuilderClassJavaFileHandle());
}
insertDataIntoJavaFile(getBuilderClassJavaFileHandle(), getJavaClassDefClose());
+ if (isAugmentationHolderExtended(getJavaExtendsListHolder().getExtendsList())) {
+ addAugmentedInfoImport(curNode, imports, false);
+ addArrayListImport(curNode, imports, false);
+ }
}
-
/*
* Close all the file handles.
*/
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
index 4fe9cd6..d26d07e 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
@@ -22,6 +22,7 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_IMPL_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
@@ -31,11 +32,11 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcManagerMethod;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addArrayListImport;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addAugmentedInfoImport;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.addListnersImport;
import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.closeFile;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isHasAugmentationExtended;
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+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.VOID;
@@ -183,7 +184,7 @@
}
/**
- * Generate java code.
+ * Constructs java code exit.
*
* @param fileType generated file type
* @param curNode current YANG node
@@ -197,17 +198,29 @@
createPackage(curNode);
+ boolean isNotification = false;
+ YangNode tempNode = curNode.getChild();
+ while (tempNode != null) {
+ if (tempNode instanceof YangJavaNotification) {
+ isNotification = true;
+ break;
+ }
+ tempNode = tempNode.getNextSibling();
+ }
+
+ if (isNotification) {
+ addListnersImport(curNode, imports, true, LISTENER_SERVICE);
+ }
/**
* Creates rpc interface file.
*/
setServiceInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(SERVICE_FILE_NAME_SUFFIX)));
generateServiceInterfaceFile(getServiceInterfaceJavaFileHandle(), curNode, imports, isAttributePresent());
- if (isHasAugmentationExtended(getExtendsList())) {
- addAugmentedInfoImport(curNode, imports, true);
- addArrayListImport(curNode, imports, true);
+ if (isNotification) {
+ addListnersImport(curNode, imports, false, LISTENER_SERVICE);
+ addListnersImport(curNode, imports, true, LISTENER_REG);
}
-
/**
* Create builder class file.
*/
@@ -215,7 +228,9 @@
generateManagerClassFile(getManagerJavaFileHandle(), imports, curNode, isAttributePresent());
insertDataIntoJavaFile(getManagerJavaFileHandle(), getJavaClassDefClose());
-
+ if (isNotification) {
+ addListnersImport(curNode, imports, false, LISTENER_REG);
+ }
/**
* Close all the file handles.
*/
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
index d9a44d6..3261e08 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
@@ -21,13 +21,13 @@
import java.util.ArrayList;
import java.util.List;
-import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaType;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DERIVED;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
@@ -211,7 +211,7 @@
javaType.updateJavaQualifiedInfo();
String typeName = javaType.getDataTypeName();
- if (javaType.getDataType().equals(YangDataTypes.DERIVED)) {
+ if (javaType.getDataType().equals(DERIVED)) {
typeName = getCamelCase(typeName, null);
}
JavaAttributeInfo javaAttributeInfo = getAttributeInfoForTheData(
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
index be005e4..f393a56 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
@@ -19,7 +19,6 @@
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoContainer;
import org.onosproject.yangutils.translator.tojava.utils.YangToJavaNamingConflictUtil;
-
/**
* Represent java based identification of the YANG leaves.
*/
@@ -47,7 +46,6 @@
*/
String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig);
-
/**
* Identifies if object is a leaf-list.
*
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
index dbe006c..7e8ee05 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugment.java
@@ -103,22 +103,28 @@
* augment info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfAugmentableNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for augmentable node " + this.getName());
+ }
}
/**
* Create a java file using the YANG augment info.
*
- * @throws IOException when failed to do IO operations
+ * @throws TranslatorException when failed to do translator operations
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for augmentable node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
index 6d1ac21..eaf5f30 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCase.java
@@ -102,20 +102,27 @@
* case info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfAugmentableNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for case node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG case info.
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for case node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
index cc12782..de21a26 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoice.java
@@ -22,10 +22,10 @@
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeAndUpdateInParent;
/**
* Represents choice information extended to support java code generation.
@@ -102,20 +102,27 @@
* choice info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- YangJavaModelUtils.generateCodeAndUpdateInParent(this, yangPlugin, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeAndUpdateInParent(this, yangPlugin, false);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for choice node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG choice info.
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(INTERFACE_MASK, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for choice node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
index 0222e12..406a499 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainer.java
@@ -102,23 +102,30 @@
* container info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeAndUpdateInParent(this, yangPlugin, false);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeAndUpdateInParent(this, yangPlugin, false);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for container node " + this.getName());
+ }
}
/**
* Create a java file using the YANG container info.
*
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for container node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
index 0eeb78e..bd98f9b 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumeration.java
@@ -104,23 +104,30 @@
* enumeration info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operations fails
+ * @throws TranslatorException translator operations fails
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for enumeration node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG enumeration info.
*
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_ENUM_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for enumeration node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
index 0f07262..e5f2dab 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInput.java
@@ -103,22 +103,29 @@
* input info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for input node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG input info.
*
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for input node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
index 08351d2..8139339 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaList.java
@@ -102,22 +102,29 @@
* list info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeAndUpdateInParent(this, yangPlugin, true);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeAndUpdateInParent(this, yangPlugin, true);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for list node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG list info.
*
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for list node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
index ff48fb4..fc2d9df 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModule.java
@@ -22,11 +22,11 @@
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
@@ -103,23 +103,30 @@
* Generates java code for module.
*
* @param yangPlugin YANG plugin config
- * @throws IOException when fails to generate the source files
+ * @throws TranslatorException when fails to generate the source files
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String modulePkg = getRootPackage(getVersion(), getNameSpace().getUri(), getRevision().getRevDate());
- YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, modulePkg);
+ try {
+ generateCodeOfRootNode(this, yangPlugin, modulePkg);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for module node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG module info.
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
- searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
+ getJavaFileInfo().getPackageFilePath());
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for module node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
index 34c42e8..8624a44 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotification.java
@@ -18,17 +18,25 @@
import java.io.IOException;
+import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNotification;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfAugmentableNode;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
/**
* Represents notification information extended to support java code generation.
@@ -107,11 +115,10 @@
* notification info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
/**
* As part of the notification support the following files needs to be generated.
@@ -122,17 +129,44 @@
* The manager class needs to extend the ListenerRegistry.
*/
+ // Generate subject of the notification(event), this is simple interface
+ // with builder class.
+ try {
+ generateCodeOfAugmentableNode(this, yangPlugin);
+ addNotificationToExtendsList();
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for notification node " + this.getName());
+ }
+ }
- // Generate subject of the notification(event), this is simple interface with builder class.
- generateCodeOfNode(this, yangPlugin);
+ /*Adds current notification info to the extends list so its parents service*/
+ private void addNotificationToExtendsList() {
+ YangNode parent = this.getParent();
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) parent)
+ .getTempJavaCodeFragmentFiles()
+ .getServiceTempFiles().getJavaExtendsListHolder();
+ JavaQualifiedTypeInfo event = new JavaQualifiedTypeInfo();
+
+ String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent)
+ .getJavaFileInfo().getJavaName());
+ event.setClassInfo(parentInfo + EVENT_STRING);
+ event.setPkgInfo(getJavaFileInfo().getPackage());
+ holder.addToExtendsList(event, parent);
+
+ JavaQualifiedTypeInfo eventListener = new JavaQualifiedTypeInfo();
+
+ eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
+ eventListener.setPkgInfo(getJavaFileInfo().getPackage());
+ holder.addToExtendsList(eventListener, parent);
+
}
/**
* Creates a java file using the YANG notification info.
*/
@Override
- public void generateCodeExit()
- throws IOException {
+ public void generateCodeExit() throws TranslatorException {
/**
* As part of the notification support the following files needs to be generated.
* 1) Subject of the notification(event), this is simple interface with builder class.
@@ -141,8 +175,12 @@
*
* The manager class needs to extend the "ListenerRegistry".
*/
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
- | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER
+ | GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for notification node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
index 0c5ddcf..fec436c 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutput.java
@@ -103,23 +103,31 @@
* output info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for output node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG output info.
*
- * @throws IOException IO operation fail
+ * @throws TranslatorException translator operation fail
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code exit for output node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
index d2132f0..d63b887 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpc.java
@@ -71,31 +71,32 @@
* RPC info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operations fails
+ * @throws TranslatorException translator operations fails
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
if (!(this instanceof JavaCodeGeneratorInfo)) {
// TODO:throw exception
}
// Add package information for rpc and create corresponding folder.
- updatePackageInfo((JavaCodeGeneratorInfo) this, yangPlugin);
-
+ try {
+ updatePackageInfo(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to prepare generate code entry for RPC node " + this.getName());
+ }
}
/**
* Creates a java file using the YANG RPC info.
*
- * @throws IOException IO operations fails
+ * @throws TranslatorException translator operations fails
*/
@Override
- public void generateCodeExit()
- throws IOException {
+ public void generateCodeExit() throws TranslatorException {
// Get the parent module/sub-module.
- YangNode parent = getParentNodeInGenCode((YangNode) this);
+ YangNode parent = getParentNodeInGenCode(this);
// Parent should be holder of rpc or notification.
if (!(parent instanceof RpcNotificationContainer)) {
@@ -110,7 +111,8 @@
JavaAttributeInfo javaAttributeInfoOfInput = null;
JavaAttributeInfo javaAttributeInfoOfOutput = null;
- // Get the child input and output node and obtain create java attribute info.
+ // Get the child input and output node and obtain create java attribute
+ // info.
YangNode yangNode = this.getChild();
while (yangNode != null) {
if (yangNode instanceof YangInput) {
@@ -130,10 +132,13 @@
/*
* Add the rpc information to the parent's service temp file.
*/
- ((TempJavaCodeFragmentFilesContainer) parent)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles()
- .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
- ((YangNode) this).getName());
+ try {
+ ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles().getServiceTempFiles()
+ .addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
+ ((YangNode) this).getName());
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for RPC node " + this.getName());
+ }
// No file will be generated during RPC exit.
}
@@ -210,5 +215,5 @@
public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
tempJavaCodeFragmentFiles = fileHandle;
}
-}
+}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
index 570169c..419f15e 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModule.java
@@ -23,11 +23,11 @@
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
+import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfRootNode;
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
/**
@@ -117,24 +117,32 @@
* submodule info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operation fail
+ * @throws TranslatorException when fails to translate
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
String subModulePkg = getRootPackage(getVersion(), getNameSpaceFromModule(getBelongsTo()),
getRevision().getRevDate());
- YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, subModulePkg);
+ try {
+ generateCodeOfRootNode(this, yangPlugin, subModulePkg);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "failed to prepare generate code entry for submodule node " + this.getName());
+ }
+
}
/**
* Creates a java file using the YANG submodule info.
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
- searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
+ searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
+ getJavaFileInfo().getPackageFilePath());
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for submodule node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
index 39b6220..82771d3 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaType.java
@@ -22,6 +22,8 @@
/**
* Represents java information corresponding to the YANG type.
+ *
+ * @param <T> generic parameter for YANG java type
*/
public class YangJavaType<T>
extends YangType<T>
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
index bbec876..3b66693 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDef.java
@@ -103,23 +103,31 @@
* typedef info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operations fails
+ * @throws TranslatorException when fails to translate
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for typedef node " + this.getName());
+ }
+
}
/**
* Create a java file using the YANG typedef info.
*
- * @throws IOException IO operations fails
+ * @throws TranslatorException when fails to translate
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for typedef node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
index 9e46aef..4498204 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnion.java
@@ -18,13 +18,13 @@
import java.io.IOException;
import org.onosproject.yangutils.datamodel.YangUnion;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.utils.YangPluginConfig;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.YangJavaModelUtils.generateCodeOfNode;
/**
@@ -84,10 +84,6 @@
*/
@Override
public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- if (tempFileHandle == null) {
- throw new RuntimeException("Missing temp file hand for current node "
- + getCapitalCase(getJavaFileInfo().getJavaName()));
- }
return tempFileHandle;
}
@@ -106,22 +102,30 @@
* union info.
*
* @param yangPlugin YANG plugin config
- * @throws IOException IO operations fails
+ * @throws TranslatorException when fails to translate
*/
@Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws IOException {
- generateCodeOfNode(this, yangPlugin);
+ public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
+ try {
+ generateCodeOfNode(this, yangPlugin);
+ } catch (IOException e) {
+ throw new TranslatorException(
+ "Failed to prepare generate code entry for union node " + this.getName());
+ }
+
}
/**
* Creates a java file using the YANG union info.
*
- * @throws IOException IO operations fails
+ * @throws TranslatorException when fails to translate
*/
@Override
- public void generateCodeExit()
- throws IOException {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this);
+ public void generateCodeExit() throws TranslatorException {
+ try {
+ getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_UNION_CLASS, this);
+ } catch (IOException e) {
+ throw new TranslatorException("Failed to generate code for union node " + this.getName());
+ }
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
index 9f12346..89e0667 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
@@ -16,6 +16,12 @@
package org.onosproject.yangutils.translator.tojava.utils;
+import org.onosproject.yangutils.datamodel.YangNode;
+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.javamodel.YangJavaNotification;
+
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
@@ -26,17 +32,23 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.getExtendsList;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.isExtendsList;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
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.DIAMOND_CLOSE_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
+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.EXTEND;
import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
+import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
+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;
@@ -71,28 +83,52 @@
* Based on the file type and the YANG name of the file, generate the
* class / interface definition start.
*/
- if ((genFileTypes & INTERFACE_MASK) != 0) {
- return getInterfaceDefinition(yangName);
- } else if ((genFileTypes & BUILDER_CLASS_MASK) != 0) {
+ switch (genFileTypes) {
+ case BUILDER_CLASS_MASK:
return getBuilderClassDefinition(yangName);
- } else if ((genFileTypes & IMPL_CLASS_MASK) != 0) {
+ case IMPL_CLASS_MASK:
return getImplClassDefinition(yangName);
- } else if ((genFileTypes & BUILDER_INTERFACE_MASK) != 0) {
+ case BUILDER_INTERFACE_MASK:
return getBuilderInterfaceDefinition(yangName);
- } else if ((genFileTypes & GENERATE_TYPEDEF_CLASS) != 0) {
+ case GENERATE_TYPEDEF_CLASS:
+ case GENERATE_UNION_CLASS:
return getTypeClassDefinition(yangName);
- } else if ((genFileTypes & GENERATE_UNION_CLASS) != 0) {
- return getTypeClassDefinition(yangName);
- } else if ((genFileTypes & GENERATE_ENUM_CLASS) != 0) {
+ case GENERATE_ENUM_CLASS:
return getEnumClassDefinition(yangName);
- } else if ((genFileTypes & GENERATE_SERVICE_AND_MANAGER) != 0) {
- return getRpcInterfaceDefinition(yangName);
- } else if ((genFileTypes & GENERATE_EVENT_CLASS) != 0) {
- return getEventDefinition(yangName);
- } else if ((genFileTypes & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
+ case GENERATE_EVENT_LISTENER_INTERFACE:
return getEventListenerDefinition(yangName);
+ default:
+ return null;
}
- return null;
+ }
+
+ /**
+ * 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
+ * @param curNode current YANG node
+ * @return class definition
+ */
+ public static String generateClassDefinition(int genFileTypes, String yangName, YangNode curNode) {
+
+ /**
+ * Based on the file type and the YANG name of the file, generate the
+ * class / interface definition start.
+ */
+ switch (genFileTypes) {
+ case INTERFACE_MASK:
+ return getInterfaceDefinition(yangName, curNode);
+ case GENERATE_SERVICE_AND_MANAGER:
+ return getRpcInterfaceDefinition(yangName, curNode);
+ case GENERATE_EVENT_CLASS:
+ String eventName = getCapitalCase(((JavaFileInfoContainer) curNode)
+ .getJavaFileInfo().getJavaName());
+ return getEventDefinition(yangName, eventName);
+ default:
+ return null;
+ }
}
/**
@@ -111,17 +147,25 @@
* @param yangName file name
* @return definition
*/
- private static String getInterfaceDefinition(String yangName) {
- if (!isExtendsList()) {
- return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- }
- String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
- for (String extend : getExtendsList()) {
- def = def + extend + COMMA + SPACE;
- }
- def = trimAtLast(def, COMMA);
+ private static String getInterfaceDefinition(String yangName, YangNode curNode) {
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder();
- return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
+ String def = PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + EXTEND + SPACE;
+ 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;
+ }
+ }
+
+ def = trimAtLast(def, COMMA);
+
+ return def + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+ return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
/**
@@ -169,17 +213,47 @@
}
/**
- * Returns rpc file interface definition.
+ * Returns RPC file interface definition.
*
* @param yangName file name
+ * @param curNode current YANG node
* @return definition
*/
- private static String getRpcInterfaceDefinition(String yangName) {
+ private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) {
+ JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles().getServiceTempFiles().getJavaExtendsListHolder();
+ if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
+ curNode = curNode.getChild();
+ while (curNode != null) {
+ if (curNode instanceof YangJavaNotification) {
+ return getRpcInterfaceDefinitionWhenItExtends(yangName, holder);
+ }
+ curNode = curNode.getNextSibling();
+ }
+ }
if (yangName.contains(SERVICE)) {
return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
}
- return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName + SERVICE
- + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + IMPLEMENTS + SPACE + yangName
+ + SERVICE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+
+ /* Provides class definition when RPC interface needs to extends any event.*/
+ private static String getRpcInterfaceDefinitionWhenItExtends(String yangName,
+ JavaExtendsListHolder holder) {
+
+ if (yangName.contains(SERVICE)) {
+ String[] strArray = yangName.split(SERVICE);
+ return PUBLIC + SPACE + INTERFACE + SPACE + yangName + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + EXTEND + SPACE + LISTENER_SERVICE + DIAMOND_OPEN_BRACKET + strArray[0] + EVENT_STRING + COMMA
+ + SPACE + strArray[0] + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE;
+ }
+ return PUBLIC + SPACE + CLASS + SPACE + yangName + MANAGER + SPACE + NEW_LINE + EIGHT_SPACE_INDENTATION
+ + EXTEND + SPACE + LISTENER_REG + DIAMOND_OPEN_BRACKET + yangName + EVENT_STRING + COMMA + SPACE
+ + yangName + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + SPACE + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + IMPLEMENTS + SPACE + yangName + SERVICE + SPACE + OPEN_CURLY_BRACKET
+ + NEW_LINE;
}
/**
@@ -188,14 +262,9 @@
* @param javaName file name
* @return definition
*/
- private static String getEventDefinition(String javaName) {
+ private static String getEventDefinition(String javaName, String eventName) {
String classDef = PUBLIC + SPACE + CLASS + SPACE + javaName + SPACE + "extends AbstractEvent<"
- + javaName + ".Type, " + javaName;
- if (classDef.length() < 5) {
- throw new RuntimeException("Event class name is error");
- }
- classDef = classDef.substring(0, classDef.length() - 5);
- classDef = classDef + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
+ + javaName + ".Type, " + eventName + ">" + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
return classDef;
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
index 189a329..a116dec 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
@@ -18,7 +18,6 @@
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
-import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
@@ -78,18 +77,6 @@
}
/**
- * Returns based on the file type and the YANG name of the file, generate the class
- * / interface definition start.
- *
- * @param genFileTypes type of file being generated
- * @param yangName YANG name
- * @return corresponding textual java code information
- */
- public static String getJavaClassDefStart(int genFileTypes, String yangName) {
- return generateClassDefinition(genFileTypes, yangName);
- }
-
- /**
* Returns the textual java code for attribute definition in class.
*
* @param javaAttributeTypePkg Package of the attribute type
@@ -128,7 +115,7 @@
* @param type attribute type
* @return list attribute string
*/
- public static String getListAttribute(String type) {
+ private static String getListAttribute(String type) {
return LIST + DIAMOND_OPEN_BRACKET + type + DIAMOND_CLOSE_BRACKET;
}
@@ -138,10 +125,9 @@
* @return attribute of augmented info for generated impl file
*/
public static String getAugmentedInfoAttribute() {
- return FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + getListAttribute(AUGMENTED_INFO) + SPACE
+ getSmallCase(AUGMENTED_INFO) + LIST + SPACE + EQUAL + SPACE + NEW + SPACE + ARRAY_LIST
- + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN
- + NEW_LINE;
+ + DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN;
}
/**
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
new file mode 100644
index 0000000..64e7fe6
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.translator.tojava.utils;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaImportData;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+
+import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.getTempJavaFragement;
+import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
+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.EVENT_LISTENER_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
+import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_REG;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+
+/**
+ * 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 {
+
+ /**
+ * Creates an instance of JavaExtendsListHolder.
+ */
+ public JavaExtendsListHolder() {
+ setExtendedClassStore(new HashMap<>());
+ setExtendsList(new ArrayList<>());
+ }
+
+ private Map<JavaQualifiedTypeInfo, Boolean> extendedClassStore;
+ private List<JavaQualifiedTypeInfo> extendsList;
+
+ /**
+ * Returns extends list.
+ *
+ * @return extends list
+ */
+ public Map<JavaQualifiedTypeInfo, Boolean> getExtendedClassStore() {
+ return extendedClassStore;
+ }
+
+ /**
+ * Sets extends list.
+ *
+ * @param extendsList list of classes need to be extended
+ */
+ private void setExtendedClassStore(Map<JavaQualifiedTypeInfo, Boolean> extendedClass) {
+ this.extendedClassStore = extendedClass;
+ }
+
+ /**
+ * Adds to the extends list.
+ *
+ * @param info java file info
+ * @param node YANG node
+ */
+ public void addToExtendsList(JavaQualifiedTypeInfo info, YangNode node) {
+ JavaFileInfo fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
+
+ if (!fileInfo.getPackage().equals(info.getPkgInfo())) {
+ JavaImportData importData = getTempJavaFragement(node).getJavaImportData();
+ importData.addImportInfo(info);
+ /*true means import should be added*/
+ getExtendedClassStore().put(info, true);
+ }
+ getExtendedClassStore().put(info, false);
+ addToExtendsList(info);
+ }
+
+ /**
+ * Returns extends string for class.
+ *
+ * @param genFileType generated file type
+ * @param className class name
+ * @param isNotificationPresent if notification node is present
+ * @return extends string
+ */
+ public String getExtendsString(int genFileType, String className, boolean isNotificationPresent) {
+ String extend = EXTEND + SPACE;
+ if (genFileType == GENERATE_SERVICE_AND_MANAGER && isNotificationPresent) {
+ extend = extend + LISTENER_REG + DIAMOND_OPEN_BRACKET + className + EVENT_STRING + COMMA + SPACE
+ + className + EVENT_LISTENER_STRING + DIAMOND_CLOSE_BRACKET + NEW_LINE;
+ } else {
+ for (JavaQualifiedTypeInfo info : getExtendsList()) {
+ if (info.getClassInfo().equals(className)) {
+ if (!getExtendedClassStore().get(info)) {
+ return extend + info.getClassInfo();
+ } else {
+ return extend + info.getPkgInfo() + PERIOD + info.getClassInfo();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns extends list.
+ *
+ * @return the extendsList
+ */
+ public List<JavaQualifiedTypeInfo> getExtendsList() {
+ return extendsList;
+ }
+
+ /**
+ * Sets extends info list.
+ *
+ * @param classInfoList the extends List to set
+ */
+ private void setExtendsList(List<JavaQualifiedTypeInfo> classInfoList) {
+ this.extendsList = classInfoList;
+ }
+
+ /**
+ * Adds extends info to list.
+ *
+ * @param classInfo class info
+ */
+ private void addToExtendsList(JavaQualifiedTypeInfo classInfo) {
+ getExtendsList().add(classInfo);
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
index c0cf209..ba06942 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
@@ -24,6 +24,7 @@
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
@@ -74,8 +75,7 @@
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRemoveAugmentationImpl;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
-import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils
- .isHasAugmentationExtended;
+import static org.onosproject.yangutils.translator.tojava.utils.TempJavaCodeFragmentFilesUtils.isAugmentationHolderExtended;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
@@ -102,59 +102,10 @@
*/
public final class JavaFileGenerator {
- /**
- * Flag to check whether generated interface file need to extends any class.
- */
- private static boolean isExtendsList = false;
-
- /**
- * List of classes to be extended by generated interface file.
- */
- private static List<String> extendsList = new ArrayList<>();
-
- /**
- * Creates an instance of java file generator.
- */
private JavaFileGenerator() {
}
/**
- * Returns true if extends list is not empty.
- *
- * @return true or false
- */
- public static boolean isExtendsList() {
- return isExtendsList;
- }
-
- /**
- * Sets the value of is extends list.
- *
- * @param isExtends true or false
- */
- public static void setIsExtendsList(boolean isExtends) {
- isExtendsList = isExtends;
- }
-
- /**
- * Returns list of extended classes.
- *
- * @return list of extended classes
- */
- public static List<String> getExtendsList() {
- return extendsList;
- }
-
- /**
- * Sets the list of extended classes.
- *
- * @param extendList list of extended classes
- */
- public static void setExtendsList(List<String> extendList) {
- extendsList = extendList;
- }
-
- /**
* Returns generated interface file for current node.
*
* @param file file
@@ -171,9 +122,8 @@
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName());
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path);
+ initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode, className);
if (isAttrPresent) {
/**
@@ -343,9 +293,8 @@
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName());
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
+ initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
List<String> methods = new ArrayList<>();
@@ -412,6 +361,17 @@
initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path);
List<String> methods = new ArrayList<>();
+
+ TempJavaCodeFragmentFiles javaCodeFragmentFiles = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles();
+ boolean isAugmentationHolderExtended = isAugmentationHolderExtended(
+ javaCodeFragmentFiles.getBeanTempFiles().getJavaExtendsListHolder().getExtendsList());
+ /**
+ * Add attribute for augmented info's list.
+ */
+ if (isAugmentationHolderExtended) {
+ insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
+ }
if (isAttrPresent) {
/**
* Add attribute strings.
@@ -426,12 +386,6 @@
+ " while impl class file generation");
}
- /**
- * Add attribute for augmented info's list.
- */
- if (isHasAugmentationExtended(getExtendsList())) {
- insertDataIntoJavaFile(file, getAugmentedInfoAttribute());
- }
insertDataIntoJavaFile(file, NEW_LINE);
try {
/**
@@ -471,12 +425,15 @@
insertDataIntoJavaFile(file, NEW_LINE);
}
try {
+
/**
* Constructor.
*/
- methods.add(getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles().getBeanTempFiles())
- + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
+ String constructor = getConstructorStart(className) + getDataFromTempFileHandle(CONSTRUCTOR_IMPL_MASK,
+ ((TempJavaCodeFragmentFilesContainer) curNode).getTempJavaCodeFragmentFiles()
+ .getBeanTempFiles());
+
+ methods.add(constructor + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET);
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " + className
+ " while impl class file generation");
@@ -485,7 +442,7 @@
/**
* Add method for augment info's list.
*/
- if (isHasAugmentationExtended(getExtendsList())) {
+ if (isAugmentationHolderExtended) {
methods.add(getAddAugmentInfoMethodImpl());
methods.add(getAugmentInfoListImpl());
methods.add(getRemoveAugmentationImpl());
@@ -777,7 +734,7 @@
+ getFromStringMethodClose());
} catch (IOException e) {
throw new IOException("No data found in temporary java code fragment files for " +
- getCapitalCase(className) + " while enum class file generation");
+ getCapitalCase(className) + " while enum class file generation");
}
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
@@ -802,9 +759,7 @@
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
String className = getCapitalCase(javaFileInfo.getJavaName()) + SERVICE_METHOD_STRING;
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
-
- initiateJavaFileGeneration(file, className, GENERATE_SERVICE_AND_MANAGER, imports, path);
+ initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports, curNode, className);
List<String> methods = new ArrayList<>();
@@ -853,16 +808,16 @@
* @param imports imports for file
* @throws IOException when fails to generate class file
*/
- public static void generateEventFile(File file, YangNode curNode, List<String> imports)
- throws IOException {
+ public static void generateEventFile(File file, YangNode curNode, List<String> imports) throws IOException {
+ YangNode parent = curNode.getParent();
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_STRING;
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName())
+ + EVENT_STRING;
- initiateJavaFileGeneration(file, className, GENERATE_EVENT_CLASS, imports, path);
-
+ initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode, className);
insertDataIntoJavaFile(file, getEventFileContents(className, javaFileInfo.getJavaName()));
insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
}
@@ -871,7 +826,7 @@
return "\n" +
" public enum Type {\n" +
" /**\n" +
- " * " + eventClassname + "notification.\n" +
+ " * " + getCapitalCase(classname) + " notification.\n" +
" */\n" +
" " + classname.toUpperCase() + "_EVENT\n" +
" }\n" +
@@ -880,9 +835,9 @@
" * Creates " + classname + " event with type and subject.\n" +
" *\n" +
" * @param type event type\n" +
- " * @param subject subject interface\n" +
+ " * @param subject subject " + classname + "\n" +
" */\n" +
- " public " + eventClassname + "(Type type, Interface subject) {\n" +
+ " public " + eventClassname + "(Type type, " + getCapitalCase(classname) + " subject) {\n" +
" super(type, subject);\n" +
" }\n" +
"\n" +
@@ -890,10 +845,11 @@
" * Creates " + classname + " event with type, subject and time.\n" +
" *\n" +
" * @param type event type\n" +
- " * @param subject subject interface\n" +
+ " * @param subject subject " + classname + "\n" +
" * @param time time of event\n" +
" */\n" +
- " public " + eventClassname + "(Type type, Interface subject, long time) {\n" +
+ " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
+ + " subject, long time) {\n" +
" super(type, subject, time);\n" +
" }\n" +
"\n";
@@ -909,10 +865,12 @@
*/
public static void generateEventListenerFile(File file, YangNode curNode, List<String> imports)
throws IOException {
-
+ YangNode parent = curNode.getParent();
JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- String className = getCapitalCase(javaFileInfo.getJavaName()) + EVENT_LISTENER_STRING;
+ String className =
+ getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName())
+ + EVENT_LISTENER_STRING;
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
initiateJavaFileGeneration(file, className, GENERATE_EVENT_LISTENER_INTERFACE, imports, path);
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
index 4f363d8..6ebc453 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
@@ -20,8 +20,10 @@
import java.io.IOException;
import java.util.List;
+import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfo;
+import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
@@ -55,7 +57,7 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
+import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
@@ -226,6 +228,27 @@
}
/**
+ * Initiates generation of file based on generated file type.
+ *
+ * @param file generated file
+ * @param type generated file type
+ * @param imports imports for the file
+ * @param curNode current YANG node
+ * @param className class name
+ * @throws IOException when fails to generate a file
+ */
+ public static void initiateJavaFileGeneration(File file, int type, List<String> imports,
+ YangNode curNode, String className) throws IOException {
+
+ try {
+ file.createNewFile();
+ appendContents(file, type, imports, curNode, className);
+ } catch (IOException e) {
+ throw new IOException("Failed to create " + file.getName() + " class file.");
+ }
+ }
+
+ /**
* Appends all the contents into a generated java file.
*
* @param file generated file
@@ -235,40 +258,76 @@
* @param importsList list of java imports.
* @throws IOException when fails to append contents
*/
- private static void appendContents(File file, String fileName, int type, List<String> importsList,
- String pkg)
+ private static void appendContents(File file, int type, List<String> importsList, YangNode curNode,
+ String className) throws IOException {
+
+ JavaFileInfo javaFileInfo = ((JavaFileInfoContainer) curNode).getJavaFileInfo();
+
+ String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
+ String pkgString = parsePackageString(path, importsList);
+
+ switch (type) {
+ case INTERFACE_MASK:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, type, INTERFACE, curNode, className);
+ break;
+ case GENERATE_SERVICE_AND_MANAGER:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, type, RPC_INTERFACE, curNode, className);
+ break;
+ case GENERATE_EVENT_CLASS:
+ appendHeaderContents(file, pkgString, importsList);
+ write(file, type, EVENT, curNode, className);
+ break;
+ default:
+ break;
+ }
+ }
+
+ /**
+ * Appends all the contents into a generated java file.
+ *
+ * @param file generated file
+ * @param fileName generated file name
+ * @param type generated file type
+ * @param pkg generated file package
+ * @param importsList list of java imports.
+ * @throws IOException when fails to append contents
+ */
+ private static void appendContents(File file, String fileName, int type, List<String> importsList, String pkg)
throws IOException {
String pkgString = parsePackageString(pkg, importsList);
- if ((type & IMPL_CLASS_MASK) != 0) {
+ switch (type) {
+ case IMPL_CLASS_MASK:
write(file, fileName, type, IMPL_CLASS);
- } else if ((type & BUILDER_INTERFACE_MASK) != 0) {
+ break;
+ case BUILDER_INTERFACE_MASK:
write(file, fileName, type, BUILDER_INTERFACE);
- } else if ((type & GENERATE_TYPEDEF_CLASS) != 0) {
+ break;
+ case GENERATE_TYPEDEF_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, IMPL_CLASS);
- } else if ((type & INTERFACE_MASK) != 0) {
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, INTERFACE);
- } else if ((type & BUILDER_CLASS_MASK) != 0) {
+ break;
+ case BUILDER_CLASS_MASK:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, BUILDER_CLASS);
- } else if ((type & GENERATE_UNION_CLASS) != 0) {
+ break;
+ case GENERATE_UNION_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, IMPL_CLASS);
- } else if ((type & GENERATE_ENUM_CLASS) != 0) {
+ break;
+ case GENERATE_ENUM_CLASS:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, ENUM_CLASS);
- } else if ((type & GENERATE_SERVICE_AND_MANAGER) != 0) {
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, RPC_INTERFACE);
- } else if ((type & GENERATE_EVENT_CLASS) != 0) {
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, type, EVENT);
- } else if ((type & GENERATE_EVENT_LISTENER_INTERFACE) != 0) {
+ break;
+ case GENERATE_EVENT_LISTENER_INTERFACE:
appendHeaderContents(file, pkgString, importsList);
write(file, fileName, type, EVENT_LISTENER);
+ break;
+ default:
+ break;
}
}
@@ -333,8 +392,9 @@
* @param javaDocType java doc type
* @throws IOException when fails to write into a file
*/
- private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
+ private static void write(File file, int genType, JavaDocType javaDocType, YangNode curNode, String fileName)
throws IOException {
+
if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
if (!fileName.contains(SERVICE)) {
insertDataIntoJavaFile(file, getJavaDoc(RPC_MANAGER, fileName + MANAGER, false));
@@ -344,7 +404,22 @@
} else {
insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
}
- insertDataIntoJavaFile(file, getJavaClassDefStart(genType, fileName));
+ insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName, curNode));
+ }
+
+ /**
+ * Writes data to the specific generated file.
+ *
+ * @param file generated file
+ * @param fileName file name
+ * @param genType generated file type
+ * @param javaDocType java doc type
+ * @throws IOException when fails to write into a file
+ */
+ private static void write(File file, String fileName, int genType, JavaDocType javaDocType)
+ throws IOException {
+ insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false));
+ insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
}
/**
@@ -354,8 +429,8 @@
* @return enum's attribute
*/
public static String getEnumsValueAttribute(String className) {
- return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className) + SEMI_COLAN
- + NEW_LINE;
+ return NEW_LINE + FOUR_SPACE_INDENTATION + PRIVATE + SPACE + INT + SPACE + getSmallCase(className)
+ + SEMI_COLAN + NEW_LINE;
}
}
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
index 333361f..cd0a98e 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
@@ -19,7 +19,11 @@
import java.util.List;
import java.util.Map;
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
@@ -29,11 +33,13 @@
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
import static org.onosproject.yangutils.utils.UtilConstants.AND;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTABLE;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
import static org.onosproject.yangutils.utils.UtilConstants.CASE;
import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
@@ -64,6 +70,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
import static org.onosproject.yangutils.utils.UtilConstants.INT;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
+import static org.onosproject.yangutils.utils.UtilConstants.LONG;
import static org.onosproject.yangutils.utils.UtilConstants.NEW;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yangutils.utils.UtilConstants.NULL;
@@ -83,6 +90,7 @@
import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
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.SHORT;
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.STATIC;
@@ -241,11 +249,12 @@
* @return getter for attribute
*/
public static String getGetter(String type, String name, int generatedJavaFiles) {
+ String ret = parseTypeForGetter(type);
if ((generatedJavaFiles & GENERATE_SERVICE_AND_MANAGER) != 0) {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + GET_METHOD_PREFIX + getCapitalCase(name)
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE + EIGHT_SPACE_INDENTATION +
- RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+ RETURN + SPACE + ret + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
} else {
return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + type + SPACE + name
+ OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
@@ -255,6 +264,21 @@
}
+ /*Provides string to return for type.*/
+ private static String parseTypeForGetter(String type) {
+ switch (type) {
+ case BYTE:
+ case INT:
+ case SHORT:
+ case LONG:
+ return "0";
+ case BOOLEAN_DATA_TYPE:
+ return FALSE;
+ default:
+ return null;
+ }
+ }
+
/**
* Returns the setter method strings for class file.
*
@@ -524,10 +548,9 @@
outputName = getCapitalCase(outputName);
}
- String method =
- getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
- + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
+ String method = getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + outputName + SPACE + rpcName
+ + OPEN_PARENTHESIS + inputName + SPACE + RPC_INPUT_VAR_NAME + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + YANG_UTILS_TODO + NEW_LINE;
if (!outputName.contentEquals(VOID)) {
method += EIGHT_SPACE_INDENTATION + RETURN + SPACE + NULL + SEMI_COLAN + NEW_LINE;
}
@@ -805,22 +828,6 @@
}
/**
- * Returns implementation of add augmentation method of HasAugmentation class.
- *
- * @return implementation of add augmentation method of HasAugmentation class
- */
- public static String getAddAugmentInfoMethodImpl() {
- String method = FOUR_SPACE_INDENTATION;
- method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
- + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
- + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
- + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
- + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
-
- return method;
- }
-
- /**
* Returns of method's string and java doc for special type.
*
* @param attr attribute info
@@ -884,9 +891,25 @@
}
/**
- * Returns implementation of get augment info list method of HasAugmentation class.
+ * Returns implementation of add augmentation method of AugmentationHolder class.
*
- * @return implementation of get augment info list method of HasAugmentation class
+ * @return implementation of add augmentation method of AugmentationHolder class
+ */
+ public static String getAddAugmentInfoMethodImpl() {
+ String method = FOUR_SPACE_INDENTATION;
+ method = method + getOverRideString() + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING
+ + AUGMENTATION + OPEN_PARENTHESIS + AUGMENTED_INFO + SPACE + VALUE + CLOSE_PARENTHESIS + SPACE
+ + OPEN_CURLY_BRACKET + NEW_LINE + EIGHT_SPACE_INDENTATION + GET_METHOD_PREFIX + AUGMENTED_INFO + LIST
+ + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + ADD_STRING + OPEN_PARENTHESIS + VALUE
+ + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE + FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET;
+
+ return method;
+ }
+
+ /**
+ * Returns implementation of get augment info list method of AugmentationHolder class.
+ *
+ * @return implementation of get augment info list method of AugmentationHolder class
*/
public static String getAugmentInfoListImpl() {
@@ -900,9 +923,9 @@
}
/**
- * Returns implementation of remove augmentation method of HasAugmentation class.
+ * Returns implementation of remove augmentation method of AugmentationHolder class.
*
- * @return implementation of remove augmentation method of HasAugmentation class
+ * @return implementation of remove augmentation method of AugmentationHolder class
*/
public static String getRemoveAugmentationImpl() {
String method = FOUR_SPACE_INDENTATION;
@@ -927,6 +950,36 @@
}
/**
+ * Provides string to be added in augment node's constructor.
+ *
+ * @param curNode current YANG node
+ * @return constructors string
+ */
+ public static String getAugmentsAddToAugmentedMethod(YangNode curNode) {
+
+ if (!(curNode instanceof YangJavaAugment)) {
+ throw new TranslatorException("current node should be of type augment node.");
+ }
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
+
+ String name = targetNodes.get(targetNodes.size() - 1).getName();
+ String captialCase = getCapitalCase(name);
+ String smallCase = getSmallCase(captialCase);
+ return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE
+ + NEW + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE
+ + captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION
+ + OPEN_PARENTHESIS + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+
+ }
+
+ private static String getAugmentsAddToAugmentedMethodStart() {
+ return FOUR_SPACE_INDENTATION + PUBLIC + SPACE + VOID + SPACE + ADD_STRING + AUGMENTABLE + OPEN_PARENTHESIS
+ + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET;
+ }
+
+ /**
* Returns of method for enum class.
*
* @param className class name
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
index e1db371..87ff739 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TempJavaCodeFragmentFilesUtils.java
@@ -21,18 +21,38 @@
import java.util.List;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
+import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaImportDataContainer;
import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
+import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
+import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModule;
import static java.util.Collections.sort;
-import static org.onosproject.yangutils.translator.tojava.JavaImportData.getAugmentedInfoImport;
-import static org.onosproject.yangutils.translator.tojava.JavaImportData.getHasAugmentationImport;
-import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForArrayList;
-import static org.onosproject.yangutils.translator.tojava.JavaImportData.getImportForList;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
+import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
+import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
+import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
+import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
+import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW;
+import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
+import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
+import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.THIS;
import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
/**
@@ -47,20 +67,15 @@
}
/**
- * Adds import for HasAugmentation class.
+ * Adds import for AugmentationHolders class.
*
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
- * @return import for HasAugmentation class
*/
- public static List<String> addHasAugmentationImport(YangNode curNode, List<String> imports,
- boolean operation) {
- if (curNode instanceof JavaImportDataContainer) {
- String thisImport = getHasAugmentationImport();
- performOperationOnImports(imports, thisImport, operation);
- }
- return imports;
+ public static void addAugmentationHoldersImport(YangNode curNode, List<String> imports, boolean operation) {
+ String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentationHolderImport();
+ performOperationOnImports(imports, thisImport, operation);
}
/**
@@ -69,14 +84,113 @@
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
- * @return import for AugmentedInfo class
*/
- public static List<String> addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
- if (curNode instanceof JavaImportDataContainer) {
- String thisImport = getAugmentedInfoImport();
- performOperationOnImports(imports, thisImport, operation);
+ public static void addAugmentedInfoImport(YangNode curNode, List<String> imports, boolean operation) {
+ String thisImport = getTempJavaFragement(curNode).getJavaImportData().getAugmentedInfoImport();
+ performOperationOnImports(imports, thisImport, operation);
+ }
+
+ /**
+ * Returns temp java fragment.
+ *
+ * @param curNode current YANG node
+ * @return temp java fragments
+ */
+ public static TempJavaFragmentFiles getTempJavaFragement(YangNode curNode) {
+ TempJavaCodeFragmentFiles container = ((TempJavaCodeFragmentFilesContainer) curNode)
+ .getTempJavaCodeFragmentFiles();
+ if (container.getBeanTempFiles() != null) {
+ return container.getBeanTempFiles();
}
- return imports;
+ if (container.getEventTempFiles() != null) {
+ return container.getEventTempFiles();
+ }
+ if (container.getEventListenerTempFiles() != null) {
+ return container.getEventListenerTempFiles();
+ }
+ if (container.getServiceTempFiles() != null) {
+ return container.getServiceTempFiles();
+ }
+
+ return null;
+ }
+
+ /**
+ * Updated imports with augmented nodes import.
+ *
+ * @param curNode current YANG node
+ * @param imports list of imports
+ * @param operation to add or to delete
+ */
+ public static void addAugmentedNodesImport(YangNode curNode, List<String> imports, boolean operation) {
+
+ String nodesImport = "";
+
+ if (!(curNode instanceof YangJavaAugment)) {
+ throw new TranslatorException("current node should be of type augment node.");
+ }
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
+ YangNode parent = curNode.getParent();
+ if (parent instanceof YangJavaModule) {
+ // Add impl class import.
+ nodesImport = getAugmendtedNodesImports(parent, targetNodes, true) + SEMI_COLAN + NEW_LINE;
+ performOperationOnImports(imports, nodesImport, operation);
+ // Add builder class import.
+ if (targetNodes.size() > 2) {
+ nodesImport = getAugmendtedNodesImports(parent, targetNodes, false) + SEMI_COLAN + NEW_LINE;
+ performOperationOnImports(imports, nodesImport, operation);
+ }
+ }
+ // TODO: add functionality for submodule and uses.
+ }
+
+ /**
+ * Returns imports for augmented node.
+ *
+ * @param parent parent YANG node
+ * @param targetNodes list of target nodes
+ * @param isImplClass if impl class's import required
+ * @return imports for augmented node
+ */
+ private static String getAugmendtedNodesImports(YangNode parent, List<YangNodeIdentifier> targetNodes,
+ boolean isImplClass) {
+ String pkgInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
+
+ for (int i = 0; i < targetNodes.size() - 1; i++) {
+ pkgInfo = pkgInfo + PERIOD + targetNodes.get(i).getName();
+ }
+ String classInfo = targetNodes.get(targetNodes.size() - 1).getName();
+ if (!isImplClass) {
+ return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER;
+ }
+ return IMPORT + pkgInfo.toLowerCase() + PERIOD + getCapitalCase(classInfo) + BUILDER + PERIOD
+ + getCapitalCase(classInfo) + IMPL;
+ }
+
+ /**
+ * Provides string to be added in augment node's constructor.
+ *
+ * @param curNode current YANG node
+ * @return constructors string
+ */
+ public static String getAugmentsAddToAugmentedClassString(YangNode curNode) {
+
+ if (!(curNode instanceof YangJavaAugment)) {
+ throw new TranslatorException("current node should be of type augment node.");
+ }
+ YangJavaAugment augment = (YangJavaAugment) curNode;
+ List<YangNodeIdentifier> targetNodes = augment.getTargetNode();
+
+ String name = targetNodes.get(targetNodes.size() - 1).getName();
+ String captialCase = getCapitalCase(name);
+ String smallCase = getSmallCase(captialCase);
+ return EIGHT_SPACE_INDENTATION + captialCase + IMPL + SPACE + smallCase + IMPL + SPACE + EQUAL + SPACE + NEW
+ + SPACE + captialCase + BUILDER + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD + NEW + SPACE
+ + captialCase + IMPL + OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE
+ + EIGHT_SPACE_INDENTATION + smallCase + IMPL + PERIOD + ADD_STRING + AUGMENTATION + OPEN_PARENTHESIS
+ + THIS + CLOSE_PARENTHESIS + SEMI_COLAN + NEW_LINE;
+
}
/**
@@ -85,23 +199,38 @@
* @param curNode current YANG node
* @param imports list of imports
* @param operation add or delete import
- * @return import for HasAugmentation class
*/
- public static List<String> addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
- if (curNode instanceof JavaImportDataContainer) {
- String arrayListImport = getImportForArrayList();
- String listImport = getImportForList();
- performOperationOnImports(imports, arrayListImport, operation);
- if (!imports.contains(listImport)) {
- /**
- * List can be there because of attribute also , so no need to remove it and operation will
- * always be add(true).
- */
- performOperationOnImports(imports, listImport, true);
- }
+ public static void addArrayListImport(YangNode curNode, List<String> imports, boolean operation) {
+ String arrayListImport = getTempJavaFragement(curNode).getJavaImportData().getImportForArrayList();
+ String listImport = getTempJavaFragement(curNode).getJavaImportData().getImportForList();
+ performOperationOnImports(imports, arrayListImport, operation);
+ if (!imports.contains(listImport)) {
+ /**
+ * List can be there because of attribute also , so no need to remove it and operation will
+ * always be add(true).
+ */
+ performOperationOnImports(imports, listImport, true);
}
+ }
- return imports;
+ /**
+ * Adds listener's imports.
+ *
+ * @param curNode currentYangNode.
+ * @param imports import list
+ * @param operation add or remove
+ * @param classInfo class info to be added to import list
+ */
+ public static void addListnersImport(YangNode curNode, List<String> imports, boolean operation,
+ String classInfo) {
+ String thisImport = "";
+ if (classInfo.equals(LISTENER_SERVICE)) {
+ thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerServiceImport();
+ performOperationOnImports(imports, thisImport, operation);
+ } else {
+ thisImport = getTempJavaFragement(curNode).getJavaImportData().getListenerRegistryImport();
+ performOperationOnImports(imports, thisImport, operation);
+ }
}
/**
@@ -124,29 +253,16 @@
}
/**
- * Prepares java file generator for extends list.
- *
- * @param extendsList list of classes need to be extended
- */
- public static void prepareJavaFileGeneratorForExtendsList(List<String> extendsList) {
-
- if (extendsList != null && !extendsList.isEmpty()) {
- JavaFileGenerator.setExtendsList(extendsList);
- JavaFileGenerator.setIsExtendsList(true);
- } else {
- JavaFileGenerator.getExtendsList().clear();
- JavaFileGenerator.setIsExtendsList(false);
- }
- }
-
- /**
- * Returns true if HasAugmentation class needs to be extended.
+ * Returns true if AugmentationHolder class needs to be extended.
*
* @param extendsList list of classes need to be extended
* @return true or false
*/
- public static boolean isHasAugmentationExtended(List<String> extendsList) {
- return extendsList != null && extendsList.contains(HAS_AUGMENTATION);
+ public static boolean isAugmentationHolderExtended(List<JavaQualifiedTypeInfo> extendsList) {
+ for (JavaQualifiedTypeInfo info : extendsList) {
+ return info.getClassInfo().equals(AUGMENTATION_HOLDER);
+ }
+ return false;
}
/**
@@ -155,8 +271,11 @@
* @param extendsList list of classes need to be extended
* @return true or false
*/
- public static boolean isAugmentedInfoExtended(List<String> extendsList) {
- return extendsList != null && extendsList.contains(AUGMENTED_INFO);
+ public static boolean isAugmentedInfoExtended(List<JavaQualifiedTypeInfo> extendsList) {
+ for (JavaQualifiedTypeInfo info : extendsList) {
+ return info.getClassInfo().equals(AUGMENTED_INFO);
+ }
+ return false;
}
/**
@@ -190,7 +309,7 @@
JavaQualifiedTypeInfo qualifiedTypeInfo) {
YangNode parent = curNode.getParent();
- String parentsClassInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
+ String parentsClassInfo = getCapitalCase(((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName());
String childsClassInfo = qualifiedTypeInfo.getClassInfo();
if (childsClassInfo.equals(parentsClassInfo)) {
return true;
diff --git a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
index e92b963..0a08db3 100644
--- a/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/translator/tojava/utils/YangJavaModelUtils.java
@@ -20,18 +20,15 @@
import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangAugmentationHolder;
import org.onosproject.yangutils.datamodel.YangCase;
import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangInput;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
import org.onosproject.yangutils.datamodel.YangTypeHolder;
import org.onosproject.yangutils.translator.exception.TranslatorException;
import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
+import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfo;
import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
import org.onosproject.yangutils.translator.tojava.javamodel.JavaCodeGeneratorInfo;
import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumeration;
@@ -40,12 +37,11 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCapitalCase;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCurNodePackage;
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
+import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTATION_HOLDER;
import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.HAS_AUGMENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
+import static org.onosproject.yangutils.utils.UtilConstants.PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG;
/**
* Represents utility class for YANG java model.
@@ -118,14 +114,14 @@
YangPluginConfig yangPluginConfig)
throws IOException {
if (javaCodeGeneratorInfo instanceof RpcNotificationContainer) {
- /**
+ /*
* Module / sub module node code generation.
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getServiceTempFiles().addCurNodeLeavesInfoToTempFiles(
- (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
+ (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangLeavesHolder) {
- /**
+ /*
* Container
* Case
* Grouping
@@ -136,16 +132,16 @@
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.getBeanTempFiles().addCurNodeLeavesInfoToTempFiles(
- (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
+ (YangNode) javaCodeGeneratorInfo, yangPluginConfig);
} else if (javaCodeGeneratorInfo instanceof YangTypeHolder) {
- /**
+ /*
* Typedef
* Union
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles()
.addTypeInfoToTempFiles((YangTypeHolder) javaCodeGeneratorInfo);
} else if (javaCodeGeneratorInfo instanceof YangJavaEnumeration) {
- /**
+ /*
* Enumeration
*/
javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getEnumerationTempFiles()
@@ -189,12 +185,12 @@
throw new TranslatorException("Invalid node for translation");
}
- /**
+ /*
* Generate the Java files corresponding to the current node.
*/
generateCodeOfAugmentableNode(javaCodeGeneratorInfo, yangPlugin);
- /**
+ /*
* Update the current nodes info in its parent nodes generated files.
*/
addCurNodeInfoInParentTempFile((YangNode) javaCodeGeneratorInfo, isMultiInstance);
@@ -216,34 +212,38 @@
generateCodeOfNode(javaCodeGeneratorInfo, yangPlugin);
- /**
+ /*
* For augmentation of nodes.
*/
- if (javaCodeGeneratorInfo instanceof YangContainer
- || javaCodeGeneratorInfo instanceof YangCase
- || javaCodeGeneratorInfo instanceof YangChoice
- || javaCodeGeneratorInfo instanceof YangInput
- || javaCodeGeneratorInfo instanceof YangList
- || javaCodeGeneratorInfo instanceof YangNotification
- || javaCodeGeneratorInfo instanceof YangOutput) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(HAS_AUGMENTATION);
+ if (javaCodeGeneratorInfo instanceof YangAugmentationHolder) {
+ JavaQualifiedTypeInfo augmentationHoldersInfo = new JavaQualifiedTypeInfo();
+ augmentationHoldersInfo.setClassInfo(AUGMENTATION_HOLDER);
+ augmentationHoldersInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(augmentationHoldersInfo, (YangNode) javaCodeGeneratorInfo);
+
} else if (javaCodeGeneratorInfo instanceof YangAugment) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(AUGMENTED_INFO);
+ JavaQualifiedTypeInfo augmentedInfo = new JavaQualifiedTypeInfo();
+ augmentedInfo.setClassInfo(AUGMENTED_INFO);
+ augmentedInfo.setPkgInfo(PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(augmentedInfo, (YangNode) javaCodeGeneratorInfo);
+
}
if (javaCodeGeneratorInfo instanceof YangCase) {
YangNode parent = ((YangCase) javaCodeGeneratorInfo).getParent();
- String curNodeName = ((YangCase) javaCodeGeneratorInfo).getName();
- if (!parent.getName().equals(curNodeName)) {
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(getCapitalCase(getCamelCase(
- parent.getName(), null)));
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
- .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo);
- } else {
- String parentPackage = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
- String caseExtendInfo = parentPackage + PERIOD + parent.getName();
- javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().addToExtendsList(caseExtendInfo);
- }
+ JavaQualifiedTypeInfo parentsInfo = new JavaQualifiedTypeInfo();
+ String parentName = ((JavaFileInfoContainer) parent).getJavaFileInfo().getJavaName();
+ String parentPkg = ((JavaFileInfoContainer) parent).getJavaFileInfo().getPackage();
+ parentsInfo.setClassInfo(parentName);
+ parentsInfo.setPkgInfo(parentPkg);
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles().getJavaExtendsListHolder()
+ .addToExtendsList(parentsInfo, (YangNode) javaCodeGeneratorInfo);
+
+ javaCodeGeneratorInfo.getTempJavaCodeFragmentFiles().getBeanTempFiles()
+ .addParentInfoInCurNodeTempFile((YangNode) javaCodeGeneratorInfo);
+
}
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index b28bc66..278c332 100644
--- a/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -242,6 +242,21 @@
public static final String SPACE = " ";
/**
+ * Static attribute for ListenerRegistry.
+ */
+ public static final String LISTENER_REG = "ListenerRegistry";
+
+ /**
+ * Static attribute for ListenerService.
+ */
+ public static final String LISTENER_SERVICE = "ListenerService";
+
+ /**
+ * Static attribute for listener package.
+ */
+ public static final String LISTENER_PKG = "org.onosproject.event";
+
+ /**
* Static attribute for input string.
*/
public static final String INPUT = "input";
@@ -862,14 +877,15 @@
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
/**
- * Static attribute for HasAugmentation class import package.
+ * Static attribute for AugmentationHolder class import package.
*/
- public static final String HAS_AUGMENTATION_CLASS_IMPORT_PKG = "org.onosproject.yangutils.translator.tojava";
+ public static final String PROVIDED_AUGMENTATION_CLASS_IMPORT_PKG =
+ "org.onosproject.yangutils.translator.tojava";
/**
- * Static attribute for HasAugmentation class import class.
+ * Static attribute for AugmentationHolder class import class.
*/
- public static final String HAS_AUGMENTATION_CLASS_IMPORT_CLASS = "HasAugmentation;\n";
+ public static final String AUGMENTATION_HOLDER_CLASS_IMPORT_CLASS = "AugmentationHolder;\n";
/**
* Static attribute for AugmentedInfo class import package.
@@ -887,9 +903,9 @@
public static final String AUGMENTATION = "Augmentation";
/**
- * Static attribute for HasAugmentation class.
+ * Static attribute for AugmentationHolder class.
*/
- public static final String HAS_AUGMENTATION = "HasAugmentation";
+ public static final String AUGMENTATION_HOLDER = "AugmentationHolder";
/**
* Static attribute for AugmentedInfo class.
@@ -897,6 +913,10 @@
public static final String AUGMENTED_INFO = "AugmentedInfo";
/**
+ * Static attribute for augmentable.
+ */
+ public static final String AUGMENTABLE = "Augmentable";
+ /**
* Static attribute for list.
*/
public static final String LIST = "List";
diff --git a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
index a076fbe..bf166f0 100644
--- a/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ b/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
@@ -158,7 +158,7 @@
}
for (File dir : store) {
- dir.delete();
+ FileUtils.deleteDirectory(dir);
}
}
diff --git a/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentJavaFileNameGenUtilTest.java b/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentListnerUtilTest.java
similarity index 97%
rename from src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentJavaFileNameGenUtilTest.java
rename to src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentListnerUtilTest.java
index ac3658c..3cf6eaa 100644
--- a/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentJavaFileNameGenUtilTest.java
+++ b/src/test/java/org/onosproject/yangutils/parser/impl/parseutils/AugmentListnerUtilTest.java
@@ -21,15 +21,15 @@
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.clearOccurrenceCount;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.createValidNameForAugment;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.getAugmentJavaFileNameList;
-import static org.onosproject.yangutils.parser.impl.parserutils.AugmentJavaFileNameGenUtil.updateNameWhenHasMultipleOuccrrence;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.clearOccurrenceCount;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.createValidNameForAugment;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.getAugmentJavaFileNameList;
+import static org.onosproject.yangutils.parser.impl.parserutils.AugmentListenerUtil.updateNameWhenHasMultipleOuccrrence;
/**
- * Unit test case for augment java file name generator utility.
+ * Unit test case for augment listener utility.
*/
-public class AugmentJavaFileNameGenUtilTest {
+public class AugmentListnerUtilTest {
private static final String TEST1 = "test1Node";
private static final String PARENT_PREFIX = "if";
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
index 8d9cada..301c58a 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ChoiceCaseTranslatorTest.java
@@ -44,7 +44,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/ChoiceCaseTestGenFile/");
- generateJavaCode(node, yangPluginConfig);
+ generateJavaCode(node, yangPluginConfig, "ChoiceCaseTranslator");
deleteDirectory(userDir + "/target/ChoiceCaseTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
index 4dcaa71..39d5205 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGeneratorTest.java
@@ -28,7 +28,6 @@
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
/**
@@ -55,7 +54,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
@@ -98,8 +98,7 @@
*/
@Test
public void generateinterfaceDefinitionTest() {
- String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME);
- assertThat(true, is(interfaceDefinition.equals(INTERFACE_CLASS_DEF)));
+ // TODO: need to add this test case.
}
/**
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
index 2a950fc..2f81a60 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/EnumTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/EnumTestGenFile/");
- generateJavaCode(node, yangPluginConfig);
+ generateJavaCode(node, yangPluginConfig, "EnumTranslator");
deleteDirectory(userDir + "/target/EnumTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
index 1c8a367..fd5c0d3 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGenTest.java
@@ -25,24 +25,18 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getImportText;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefination;
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefClose;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getListAttribute;
import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
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.IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
import static org.onosproject.yangutils.utils.UtilConstants.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.SPACE;
import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
@@ -54,7 +48,6 @@
private static final String PKG_INFO = "org.onosproject.unittest";
private static final String CLASS_INFO = "JavaCodeSnippetGenTest";
- private static final int FILE_GEN_TYPE = INTERFACE_MASK;
private static final String YANG_NAME = "Test";
/**
@@ -68,7 +61,8 @@
* @throws InvocationTargetException when an exception occurs by the method or constructor
*/
@Test
- public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
+ public void callPrivateConstructors()
+ throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {JavaCodeSnippetGen.class };
@@ -94,26 +88,6 @@
}
/**
- * Unit test case for java class definition start.
- */
- @Test
- public void testForJavaClassDefStart() {
- String classDef = getJavaClassDefStart(FILE_GEN_TYPE, YANG_NAME);
- assertThat(true, is(classDef
- .equals(PUBLIC + SPACE + INTERFACE + SPACE + YANG_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
- }
-
- /**
- * Unit test case for list attribute.
- */
- @Test
- public void testForListAttribute() {
- String listAttribute = getListAttribute(STRING_DATA_TYPE);
- assertThat(true,
- is(listAttribute.equals(LIST + DIAMOND_OPEN_BRACKET + STRING_DATA_TYPE + DIAMOND_CLOSE_BRACKET)));
- }
-
- /**
* Unit test case for java class interface definition close.
*/
@Test
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
index f4d8bf8..02ff5d8 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/NotificationTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/NotificationTest/");
- generateJavaCode(node, yangPluginConfig);
+ generateJavaCode(node, yangPluginConfig, "NotificationTest");
deleteDirectory(userDir + "/target/NotificationTest/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
index 9b8077c..8be657b 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/RpcTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(userDir + "/target/RpcTestGenFile/");
- generateJavaCode(node, yangPluginConfig);
+ generateJavaCode(node, yangPluginConfig, "RpcTranslator");
deleteDirectory(userDir + "/target/RpcTestGenFile/");
}
diff --git a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
index 9dcdfdf..9c0c42f 100644
--- a/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
+++ b/src/test/java/org/onosproject/yangutils/translator/tojava/utils/UnionTranslatorTest.java
@@ -46,7 +46,7 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir("target/UnionTestGenFile/");
- generateJavaCode(node, yangPluginConfig);
+ generateJavaCode(node, yangPluginConfig, "UnionTranslator");
deleteDirectory(userDir + "/target/UnionTestGenFile/");
}