Vidyashree Rama
Committed by Gerrit Code Review

YANG rpc, input and output listener

Change-Id: Idd9847175c61d9f033cf80213b46e9c9c949849c
...@@ -26,6 +26,9 @@ import org.onosproject.yangutils.datamodel.YangSubModule; ...@@ -26,6 +26,9 @@ import org.onosproject.yangutils.datamodel.YangSubModule;
26 import org.onosproject.yangutils.datamodel.YangTypeDef; 26 import org.onosproject.yangutils.datamodel.YangTypeDef;
27 import org.onosproject.yangutils.datamodel.YangUses; 27 import org.onosproject.yangutils.datamodel.YangUses;
28 import org.onosproject.yangutils.datamodel.YangNotification; 28 import org.onosproject.yangutils.datamodel.YangNotification;
29 +import org.onosproject.yangutils.datamodel.YangRpc;
30 +import org.onosproject.yangutils.datamodel.YangInput;
31 +import org.onosproject.yangutils.datamodel.YangOutput;
29 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment; 32 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugment;
30 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase; 33 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCase;
31 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice; 34 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoice;
...@@ -37,6 +40,9 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule; ...@@ -37,6 +40,9 @@ import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModule;
37 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef; 40 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDef;
38 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses; 41 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUses;
39 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification; 42 import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotification;
43 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpc;
44 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInput;
45 +import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutput;
40 46
41 /** 47 /**
42 * Factory to create data model objects based on the target file type. 48 * Factory to create data model objects based on the target file type.
...@@ -246,4 +252,58 @@ public final class YangDataModelFactory { ...@@ -246,4 +252,58 @@ public final class YangDataModelFactory {
246 } 252 }
247 } 253 }
248 } 254 }
255 +
256 + /**
257 + * Based on the target language generate the inherited data model node.
258 + *
259 + * @param targetLanguage target language in which YANG mapping needs to be
260 + * generated
261 + * @return the corresponding inherited node based on the target language
262 + */
263 + public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
264 + switch (targetLanguage) {
265 + case JAVA_GENERATION: {
266 + return new YangJavaRpc();
267 + }
268 + default: {
269 + throw new RuntimeException("Only YANG to Java is supported.");
270 + }
271 + }
272 + }
273 +
274 + /**
275 + * Based on the target language generate the inherited data model node.
276 + *
277 + * @param targetLanguage target language in which YANG mapping needs to be
278 + * generated
279 + * @return the corresponding inherited node based on the target language
280 + */
281 + public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
282 + switch (targetLanguage) {
283 + case JAVA_GENERATION: {
284 + return new YangJavaInput();
285 + }
286 + default: {
287 + throw new RuntimeException("Only YANG to Java is supported.");
288 + }
289 + }
290 + }
291 +
292 + /**
293 + * Based on the target language generate the inherited data model node.
294 + *
295 + * @param targetLanguage target language in which YANG mapping needs to be
296 + * generated
297 + * @return the corresponding inherited node based on the target language
298 + */
299 + public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
300 + switch (targetLanguage) {
301 + case JAVA_GENERATION: {
302 + return new YangJavaOutput();
303 + }
304 + default: {
305 + throw new RuntimeException("Only YANG to Java is supported.");
306 + }
307 + }
308 + }
249 } 309 }
......
...@@ -1562,6 +1562,22 @@ public interface GeneratedYangListener extends ParseTreeListener { ...@@ -1562,6 +1562,22 @@ public interface GeneratedYangListener extends ParseTreeListener {
1562 1562
1563 /** 1563 /**
1564 * Enter a parse tree produced by GeneratedYangParser for grammar rule 1564 * Enter a parse tree produced by GeneratedYangParser for grammar rule
1565 + * inputStatementBody.
1566 + *
1567 + * @param currentContext current context in the parsed tree
1568 + */
1569 + void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext);
1570 +
1571 + /**
1572 + * Exit a parse tree produced by GeneratedYangParser for grammar rule
1573 + * inputStatementBody.
1574 + *
1575 + * @param currentContext current context in the parsed tree
1576 + */
1577 + void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext currentContext);
1578 +
1579 + /**
1580 + * Enter a parse tree produced by GeneratedYangParser for grammar rule
1565 * outputStatement. 1581 * outputStatement.
1566 * 1582 *
1567 * @param currentContext current context in the parsed tree 1583 * @param currentContext current context in the parsed tree
...@@ -1578,6 +1594,22 @@ public interface GeneratedYangListener extends ParseTreeListener { ...@@ -1578,6 +1594,22 @@ public interface GeneratedYangListener extends ParseTreeListener {
1578 1594
1579 /** 1595 /**
1580 * Enter a parse tree produced by GeneratedYangParser for grammar rule 1596 * Enter a parse tree produced by GeneratedYangParser for grammar rule
1597 + * outputStatementBody.
1598 + *
1599 + * @param currentContext current context in the parsed tree
1600 + */
1601 + void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext);
1602 +
1603 + /**
1604 + * Exit a parse tree produced by GeneratedYangParser for grammar rule
1605 + * outputStatementBody.
1606 + *
1607 + * @param currentContext current context in the parsed tree
1608 + */
1609 + void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext currentContext);
1610 +
1611 + /**
1612 + * Enter a parse tree produced by GeneratedYangParser for grammar rule
1581 * notificationStatement. 1613 * notificationStatement.
1582 * 1614 *
1583 * @param currentContext current context in the parsed tree 1615 * @param currentContext current context in the parsed tree
...@@ -1625,368 +1657,322 @@ public interface GeneratedYangListener extends ParseTreeListener { ...@@ -1625,368 +1657,322 @@ public interface GeneratedYangListener extends ParseTreeListener {
1625 void exitDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext currentContext); 1657 void exitDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext currentContext);
1626 1658
1627 /** 1659 /**
1628 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1660 + * Enter a parse tree produced by GeneratedYangParser for grammar rule deviateAddStatement.
1629 - * deviateAddStatement.
1630 * 1661 *
1631 * @param currentContext current context in the parsed tree 1662 * @param currentContext current context in the parsed tree
1632 */ 1663 */
1633 void enterDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext currentContext); 1664 void enterDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext currentContext);
1634 1665
1635 /** 1666 /**
1636 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1667 + * Exit a parse tree produced by GeneratedYangParser for grammar rule deviateAddStatement.
1637 - * deviateAddStatement.
1638 * 1668 *
1639 * @param currentContext current context in the parsed tree 1669 * @param currentContext current context in the parsed tree
1640 */ 1670 */
1641 void exitDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext currentContext); 1671 void exitDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext currentContext);
1642 1672
1643 /** 1673 /**
1644 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1674 + * Enter a parse tree produced by GeneratedYangParser for grammar rule deviateDeleteStatement.
1645 - * deviateDeleteStatement.
1646 * 1675 *
1647 * @param currentContext current context in the parsed tree 1676 * @param currentContext current context in the parsed tree
1648 */ 1677 */
1649 void enterDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext currentContext); 1678 void enterDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext currentContext);
1650 1679
1651 /** 1680 /**
1652 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1681 + * Exit a parse tree produced by GeneratedYangParser for grammar rule deviateDeleteStatement.
1653 - * deviateDeleteStatement.
1654 * 1682 *
1655 * @param currentContext current context in the parsed tree 1683 * @param currentContext current context in the parsed tree
1656 */ 1684 */
1657 void exitDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext currentContext); 1685 void exitDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext currentContext);
1658 1686
1659 /** 1687 /**
1660 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1688 + * Enter a parse tree produced by GeneratedYangParser for grammar rule deviateReplaceStatement.
1661 - * deviateReplaceStatement.
1662 * 1689 *
1663 * @param currentContext current context in the parsed tree 1690 * @param currentContext current context in the parsed tree
1664 */ 1691 */
1665 void enterDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext currentContext); 1692 void enterDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext currentContext);
1666 1693
1667 /** 1694 /**
1668 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1695 + * Exit a parse tree produced by GeneratedYangParser for grammar rule deviateReplaceStatement.
1669 - * deviateReplaceStatement.
1670 * 1696 *
1671 * @param currentContext current context in the parsed tree 1697 * @param currentContext current context in the parsed tree
1672 */ 1698 */
1673 void exitDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext currentContext); 1699 void exitDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext currentContext);
1674 1700
1675 /** 1701 /**
1676 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1702 + * Enter a parse tree produced by GeneratedYangParser for grammar rule string.
1677 - * string.
1678 * 1703 *
1679 * @param currentContext current context in the parsed tree 1704 * @param currentContext current context in the parsed tree
1680 */ 1705 */
1681 void enterString(GeneratedYangParser.StringContext currentContext); 1706 void enterString(GeneratedYangParser.StringContext currentContext);
1682 1707
1683 /** 1708 /**
1684 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1709 + * Exit a parse tree produced by GeneratedYangParser for grammar rule string.
1685 - * string.
1686 * 1710 *
1687 * @param currentContext current context in the parsed tree 1711 * @param currentContext current context in the parsed tree
1688 */ 1712 */
1689 void exitString(GeneratedYangParser.StringContext currentContext); 1713 void exitString(GeneratedYangParser.StringContext currentContext);
1690 1714
1691 /** 1715 /**
1692 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1716 + * Enter a parse tree produced by GeneratedYangParser for grammar rule identifier.
1693 - * identifier.
1694 * 1717 *
1695 * @param currentContext current context in the parsed tree 1718 * @param currentContext current context in the parsed tree
1696 */ 1719 */
1697 void enterIdentifier(GeneratedYangParser.IdentifierContext currentContext); 1720 void enterIdentifier(GeneratedYangParser.IdentifierContext currentContext);
1698 1721
1699 /** 1722 /**
1700 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1723 + * Exit a parse tree produced by GeneratedYangParser for grammar rule identifier.
1701 - * identifier.
1702 * 1724 *
1703 * @param currentContext current context in the parsed tree 1725 * @param currentContext current context in the parsed tree
1704 */ 1726 */
1705 void exitIdentifier(GeneratedYangParser.IdentifierContext currentContext); 1727 void exitIdentifier(GeneratedYangParser.IdentifierContext currentContext);
1706 1728
1707 /** 1729 /**
1708 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1730 + * Enter a parse tree produced by GeneratedYangParser for grammar rule version.
1709 - * version.
1710 * 1731 *
1711 * @param currentContext current context in the parsed tree 1732 * @param currentContext current context in the parsed tree
1712 */ 1733 */
1713 void enterVersion(GeneratedYangParser.VersionContext currentContext); 1734 void enterVersion(GeneratedYangParser.VersionContext currentContext);
1714 1735
1715 /** 1736 /**
1716 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1737 + * Exit a parse tree produced by GeneratedYangParser for grammar rule version.
1717 - * version.
1718 * 1738 *
1719 * @param currentContext current context in the parsed tree 1739 * @param currentContext current context in the parsed tree
1720 */ 1740 */
1721 void exitVersion(GeneratedYangParser.VersionContext currentContext); 1741 void exitVersion(GeneratedYangParser.VersionContext currentContext);
1722 1742
1723 /** 1743 /**
1724 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1744 + * Enter a parse tree produced by GeneratedYangParser for grammar rule range.
1725 - * range.
1726 * 1745 *
1727 * @param currentContext current context in the parsed tree 1746 * @param currentContext current context in the parsed tree
1728 */ 1747 */
1729 void enterRange(GeneratedYangParser.RangeContext currentContext); 1748 void enterRange(GeneratedYangParser.RangeContext currentContext);
1730 1749
1731 /** 1750 /**
1732 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1751 + * Exit a parse tree produced by GeneratedYangParser for grammar rule range.
1733 - * range.
1734 * 1752 *
1735 * @param currentContext current context in the parsed tree 1753 * @param currentContext current context in the parsed tree
1736 */ 1754 */
1737 void exitRange(GeneratedYangParser.RangeContext currentContext); 1755 void exitRange(GeneratedYangParser.RangeContext currentContext);
1738 1756
1739 /** 1757 /**
1740 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1758 + * Enter a parse tree produced by GeneratedYangParser for grammar rule dateArgumentString.
1741 - * dateArgumentString.
1742 * 1759 *
1743 * @param currentContext current context in the parsed tree 1760 * @param currentContext current context in the parsed tree
1744 */ 1761 */
1745 void enterDateArgumentString(GeneratedYangParser.DateArgumentStringContext currentContext); 1762 void enterDateArgumentString(GeneratedYangParser.DateArgumentStringContext currentContext);
1746 1763
1747 /** 1764 /**
1748 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1765 + * Exit a parse tree produced by GeneratedYangParser for grammar rule dateArgumentString.
1749 - * dateArgumentString.
1750 * 1766 *
1751 * @param currentContext current context in the parsed tree 1767 * @param currentContext current context in the parsed tree
1752 */ 1768 */
1753 void exitDateArgumentString(GeneratedYangParser.DateArgumentStringContext currentContext); 1769 void exitDateArgumentString(GeneratedYangParser.DateArgumentStringContext currentContext);
1754 1770
1755 /** 1771 /**
1756 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1772 + * Enter a parse tree produced by GeneratedYangParser for grammar rule length.
1757 - * length.
1758 * 1773 *
1759 * @param currentContext current context in the parsed tree 1774 * @param currentContext current context in the parsed tree
1760 */ 1775 */
1761 void enterLength(GeneratedYangParser.LengthContext currentContext); 1776 void enterLength(GeneratedYangParser.LengthContext currentContext);
1762 1777
1763 /** 1778 /**
1764 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1779 + * Exit a parse tree produced by GeneratedYangParser for grammar rule length.
1765 - * length.
1766 * 1780 *
1767 * @param currentContext current context in the parsed tree 1781 * @param currentContext current context in the parsed tree
1768 */ 1782 */
1769 void exitLength(GeneratedYangParser.LengthContext currentContext); 1783 void exitLength(GeneratedYangParser.LengthContext currentContext);
1770 1784
1771 /** 1785 /**
1772 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1786 + * Enter a parse tree produced by GeneratedYangParser for grammar rule path.
1773 - * path.
1774 * 1787 *
1775 * @param currentContext current context in the parsed tree 1788 * @param currentContext current context in the parsed tree
1776 */ 1789 */
1777 void enterPath(GeneratedYangParser.PathContext currentContext); 1790 void enterPath(GeneratedYangParser.PathContext currentContext);
1778 1791
1779 /** 1792 /**
1780 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1793 + * Exit a parse tree produced by GeneratedYangParser for grammar rule path.
1781 - * path.
1782 * 1794 *
1783 * @param currentContext current context in the parsed tree 1795 * @param currentContext current context in the parsed tree
1784 */ 1796 */
1785 void exitPath(GeneratedYangParser.PathContext currentContext); 1797 void exitPath(GeneratedYangParser.PathContext currentContext);
1786 1798
1787 /** 1799 /**
1788 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1800 + * Enter a parse tree produced by GeneratedYangParser for grammar rule position.
1789 - * position.
1790 * 1801 *
1791 * @param currentContext current context in the parsed tree 1802 * @param currentContext current context in the parsed tree
1792 */ 1803 */
1793 void enterPosition(GeneratedYangParser.PositionContext currentContext); 1804 void enterPosition(GeneratedYangParser.PositionContext currentContext);
1794 1805
1795 /** 1806 /**
1796 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1807 + * Exit a parse tree produced by GeneratedYangParser for grammar rule position.
1797 - * position.
1798 * 1808 *
1799 * @param currentContext current context in the parsed tree 1809 * @param currentContext current context in the parsed tree
1800 */ 1810 */
1801 void exitPosition(GeneratedYangParser.PositionContext currentContext); 1811 void exitPosition(GeneratedYangParser.PositionContext currentContext);
1802 1812
1803 /** 1813 /**
1804 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1814 + * Enter a parse tree produced by GeneratedYangParser for grammar rule status.
1805 - * status.
1806 * 1815 *
1807 * @param currentContext current context in the parsed tree 1816 * @param currentContext current context in the parsed tree
1808 */ 1817 */
1809 void enterStatus(GeneratedYangParser.StatusContext currentContext); 1818 void enterStatus(GeneratedYangParser.StatusContext currentContext);
1810 1819
1811 /** 1820 /**
1812 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1821 + * Exit a parse tree produced by GeneratedYangParser for grammar rule status.
1813 - * status.
1814 * 1822 *
1815 * @param currentContext current context in the parsed tree 1823 * @param currentContext current context in the parsed tree
1816 */ 1824 */
1817 void exitStatus(GeneratedYangParser.StatusContext currentContext); 1825 void exitStatus(GeneratedYangParser.StatusContext currentContext);
1818 1826
1819 /** 1827 /**
1820 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1828 + * Enter a parse tree produced by GeneratedYangParser for grammar rule config.
1821 - * config.
1822 * 1829 *
1823 * @param currentContext current context in the parsed tree 1830 * @param currentContext current context in the parsed tree
1824 */ 1831 */
1825 void enterConfig(GeneratedYangParser.ConfigContext currentContext); 1832 void enterConfig(GeneratedYangParser.ConfigContext currentContext);
1826 1833
1827 /** 1834 /**
1828 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1835 + * Exit a parse tree produced by GeneratedYangParser for grammar rule config.
1829 - * config.
1830 * 1836 *
1831 * @param currentContext current context in the parsed tree 1837 * @param currentContext current context in the parsed tree
1832 */ 1838 */
1833 void exitConfig(GeneratedYangParser.ConfigContext currentContext); 1839 void exitConfig(GeneratedYangParser.ConfigContext currentContext);
1834 1840
1835 /** 1841 /**
1836 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1842 + * Enter a parse tree produced by GeneratedYangParser for grammar rule mandatory.
1837 - * mandatory.
1838 * 1843 *
1839 * @param currentContext current context in the parsed tree 1844 * @param currentContext current context in the parsed tree
1840 */ 1845 */
1841 void enterMandatory(GeneratedYangParser.MandatoryContext currentContext); 1846 void enterMandatory(GeneratedYangParser.MandatoryContext currentContext);
1842 1847
1843 /** 1848 /**
1844 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1849 + * Exit a parse tree produced by GeneratedYangParser for grammar rule mandatory.
1845 - * mandatory.
1846 * 1850 *
1847 * @param currentContext current context in the parsed tree 1851 * @param currentContext current context in the parsed tree
1848 */ 1852 */
1849 void exitMandatory(GeneratedYangParser.MandatoryContext currentContext); 1853 void exitMandatory(GeneratedYangParser.MandatoryContext currentContext);
1850 1854
1851 /** 1855 /**
1852 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1856 + * Enter a parse tree produced by GeneratedYangParser for grammar rule ordered-by.
1853 - * ordered-by.
1854 * 1857 *
1855 * @param currentContext current context in the parsed tree 1858 * @param currentContext current context in the parsed tree
1856 */ 1859 */
1857 void enterOrderedBy(GeneratedYangParser.OrderedByContext currentContext); 1860 void enterOrderedBy(GeneratedYangParser.OrderedByContext currentContext);
1858 1861
1859 /** 1862 /**
1860 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1863 + * Exit a parse tree produced by GeneratedYangParser for grammar rule ordered-by.
1861 - * ordered-by.
1862 * 1864 *
1863 * @param currentContext current context in the parsed tree 1865 * @param currentContext current context in the parsed tree
1864 */ 1866 */
1865 void exitOrderedBy(GeneratedYangParser.OrderedByContext currentContext); 1867 void exitOrderedBy(GeneratedYangParser.OrderedByContext currentContext);
1866 1868
1867 /** 1869 /**
1868 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1870 + * Enter a parse tree produced by GeneratedYangParser for grammar rule min elements value.
1869 - * min elements value.
1870 * 1871 *
1871 * @param currentContext current context in the parsed tree 1872 * @param currentContext current context in the parsed tree
1872 */ 1873 */
1873 void enterMinValue(GeneratedYangParser.MinValueContext currentContext); 1874 void enterMinValue(GeneratedYangParser.MinValueContext currentContext);
1874 1875
1875 /** 1876 /**
1876 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1877 + * Exit a parse tree produced by GeneratedYangParser for grammar rule min elements value.
1877 - * min elements value.
1878 * 1878 *
1879 * @param currentContext current context in the parsed tree 1879 * @param currentContext current context in the parsed tree
1880 */ 1880 */
1881 void exitMinValue(GeneratedYangParser.MinValueContext currentContext); 1881 void exitMinValue(GeneratedYangParser.MinValueContext currentContext);
1882 1882
1883 /** 1883 /**
1884 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1884 + * Enter a parse tree produced by GeneratedYangParser for grammar rule max elements value.
1885 - * max elements value.
1886 * 1885 *
1887 * @param currentContext current context in the parsed tree 1886 * @param currentContext current context in the parsed tree
1888 */ 1887 */
1889 void enterMaxValue(GeneratedYangParser.MaxValueContext currentContext); 1888 void enterMaxValue(GeneratedYangParser.MaxValueContext currentContext);
1890 1889
1891 /** 1890 /**
1892 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1891 + * Exit a parse tree produced by GeneratedYangParser for grammar rule max elements value.
1893 - * max elements value.
1894 * 1892 *
1895 * @param currentContext current context in the parsed tree 1893 * @param currentContext current context in the parsed tree
1896 */ 1894 */
1897 void exitMaxValue(GeneratedYangParser.MaxValueContext currentContext); 1895 void exitMaxValue(GeneratedYangParser.MaxValueContext currentContext);
1898 1896
1899 /** 1897 /**
1900 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1898 + * Enter a parse tree produced by GeneratedYangParser for grammar rule key.
1901 - * key.
1902 * 1899 *
1903 * @param currentContext current context in the parsed tree 1900 * @param currentContext current context in the parsed tree
1904 */ 1901 */
1905 void enterKey(GeneratedYangParser.KeyContext currentContext); 1902 void enterKey(GeneratedYangParser.KeyContext currentContext);
1906 1903
1907 /** 1904 /**
1908 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1905 + * Exit a parse tree produced by GeneratedYangParser for grammar rule key.
1909 - * key.
1910 * 1906 *
1911 * @param currentContext current context in the parsed tree 1907 * @param currentContext current context in the parsed tree
1912 */ 1908 */
1913 void exitKey(GeneratedYangParser.KeyContext currentContext); 1909 void exitKey(GeneratedYangParser.KeyContext currentContext);
1914 1910
1915 /** 1911 /**
1916 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1912 + * Enter a parse tree produced by GeneratedYangParser for grammar rule unique.
1917 - * unique.
1918 * 1913 *
1919 * @param currentContext current context in the parsed tree 1914 * @param currentContext current context in the parsed tree
1920 */ 1915 */
1921 void enterUnique(GeneratedYangParser.UniqueContext currentContext); 1916 void enterUnique(GeneratedYangParser.UniqueContext currentContext);
1922 1917
1923 /** 1918 /**
1924 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1919 + * Exit a parse tree produced by GeneratedYangParser for grammar rule unique.
1925 - * unique.
1926 * 1920 *
1927 * @param currentContext current context in the parsed tree 1921 * @param currentContext current context in the parsed tree
1928 */ 1922 */
1929 void exitUnique(GeneratedYangParser.UniqueContext currentContext); 1923 void exitUnique(GeneratedYangParser.UniqueContext currentContext);
1930 1924
1931 /** 1925 /**
1932 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1926 + * Enter a parse tree produced by GeneratedYangParser for grammar rule refine.
1933 - * refine.
1934 * 1927 *
1935 * @param currentContext current context in the parsed tree 1928 * @param currentContext current context in the parsed tree
1936 */ 1929 */
1937 void enterRefine(GeneratedYangParser.RefineContext currentContext); 1930 void enterRefine(GeneratedYangParser.RefineContext currentContext);
1938 1931
1939 /** 1932 /**
1940 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1933 + * Exit a parse tree produced by GeneratedYangParser for grammar rule refine.
1941 - * refine.
1942 * 1934 *
1943 * @param currentContext current context in the parsed tree 1935 * @param currentContext current context in the parsed tree
1944 */ 1936 */
1945 void exitRefine(GeneratedYangParser.RefineContext currentContext); 1937 void exitRefine(GeneratedYangParser.RefineContext currentContext);
1946 1938
1947 /** 1939 /**
1948 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1940 + * Enter a parse tree produced by GeneratedYangParser for grammar rule augment.
1949 - * augment.
1950 * 1941 *
1951 * @param currentContext current context in the parsed tree 1942 * @param currentContext current context in the parsed tree
1952 */ 1943 */
1953 void enterAugment(GeneratedYangParser.AugmentContext currentContext); 1944 void enterAugment(GeneratedYangParser.AugmentContext currentContext);
1954 1945
1955 /** 1946 /**
1956 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1947 + * Exit a parse tree produced by GeneratedYangParser for grammar rule augment.
1957 - * augment.
1958 * 1948 *
1959 * @param currentContext current context in the parsed tree 1949 * @param currentContext current context in the parsed tree
1960 */ 1950 */
1961 void exitAugment(GeneratedYangParser.AugmentContext currentContext); 1951 void exitAugment(GeneratedYangParser.AugmentContext currentContext);
1962 1952
1963 /** 1953 /**
1964 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1954 + * Enter a parse tree produced by GeneratedYangParser for grammar rule deviation.
1965 - * deviation.
1966 * 1955 *
1967 * @param currentContext current context in the parsed tree 1956 * @param currentContext current context in the parsed tree
1968 */ 1957 */
1969 void enterDeviation(GeneratedYangParser.DeviationContext currentContext); 1958 void enterDeviation(GeneratedYangParser.DeviationContext currentContext);
1970 1959
1971 /** 1960 /**
1972 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1961 + * Exit a parse tree produced by GeneratedYangParser for grammar rule deviation.
1973 - * deviation.
1974 * 1962 *
1975 * @param currentContext current context in the parsed tree 1963 * @param currentContext current context in the parsed tree
1976 */ 1964 */
1977 void exitDeviation(GeneratedYangParser.DeviationContext currentContext); 1965 void exitDeviation(GeneratedYangParser.DeviationContext currentContext);
1978 1966
1979 /** 1967 /**
1980 - * Enter a parse tree produced by GeneratedYangParser for grammar rule 1968 + * Enter a parse tree produced by GeneratedYangParser for grammar rule yang construct.
1981 - * yang construct.
1982 * 1969 *
1983 * @param currentContext current context in the parsed tree 1970 * @param currentContext current context in the parsed tree
1984 */ 1971 */
1985 void enterYangConstruct(GeneratedYangParser.YangConstructContext currentContext); 1972 void enterYangConstruct(GeneratedYangParser.YangConstructContext currentContext);
1986 1973
1987 /** 1974 /**
1988 - * Exit a parse tree produced by GeneratedYangParser for grammar rule 1975 + * Exit a parse tree produced by GeneratedYangParser for grammar rule yang construct.
1989 - * yang construct.
1990 * 1976 *
1991 * @param currentContext current context in the parsed tree 1977 * @param currentContext current context in the parsed tree
1992 */ 1978 */
......
...@@ -42,6 +42,7 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener; ...@@ -42,6 +42,7 @@ import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
42 import org.onosproject.yangutils.parser.impl.listeners.GroupingListener; 42 import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
43 import org.onosproject.yangutils.parser.impl.listeners.ImportListener; 43 import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
44 import org.onosproject.yangutils.parser.impl.listeners.IncludeListener; 44 import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
45 +import org.onosproject.yangutils.parser.impl.listeners.InputListener;
45 import org.onosproject.yangutils.parser.impl.listeners.KeyListener; 46 import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
46 import org.onosproject.yangutils.parser.impl.listeners.LeafListListener; 47 import org.onosproject.yangutils.parser.impl.listeners.LeafListListener;
47 import org.onosproject.yangutils.parser.impl.listeners.LeafListener; 48 import org.onosproject.yangutils.parser.impl.listeners.LeafListener;
...@@ -53,12 +54,14 @@ import org.onosproject.yangutils.parser.impl.listeners.ModuleListener; ...@@ -53,12 +54,14 @@ import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
53 import org.onosproject.yangutils.parser.impl.listeners.NotificationListener; 54 import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
54 import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener; 55 import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
55 import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener; 56 import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
57 +import org.onosproject.yangutils.parser.impl.listeners.OutputListener;
56 import org.onosproject.yangutils.parser.impl.listeners.PositionListener; 58 import org.onosproject.yangutils.parser.impl.listeners.PositionListener;
57 import org.onosproject.yangutils.parser.impl.listeners.PrefixListener; 59 import org.onosproject.yangutils.parser.impl.listeners.PrefixListener;
58 import org.onosproject.yangutils.parser.impl.listeners.PresenceListener; 60 import org.onosproject.yangutils.parser.impl.listeners.PresenceListener;
59 import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener; 61 import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener;
60 import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener; 62 import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener;
61 import org.onosproject.yangutils.parser.impl.listeners.RevisionListener; 63 import org.onosproject.yangutils.parser.impl.listeners.RevisionListener;
64 +import org.onosproject.yangutils.parser.impl.listeners.RpcListener;
62 import org.onosproject.yangutils.parser.impl.listeners.ShortCaseListener; 65 import org.onosproject.yangutils.parser.impl.listeners.ShortCaseListener;
63 import org.onosproject.yangutils.parser.impl.listeners.StatusListener; 66 import org.onosproject.yangutils.parser.impl.listeners.StatusListener;
64 import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener; 67 import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener;
...@@ -1062,32 +1065,48 @@ public class TreeWalkListener implements GeneratedYangListener { ...@@ -1062,32 +1065,48 @@ public class TreeWalkListener implements GeneratedYangListener {
1062 1065
1063 @Override 1066 @Override
1064 public void enterRpcStatement(GeneratedYangParser.RpcStatementContext ctx) { 1067 public void enterRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
1065 - // TODO: implement the method. 1068 + RpcListener.processRpcEntry(this, ctx);
1066 } 1069 }
1067 1070
1068 @Override 1071 @Override
1069 public void exitRpcStatement(GeneratedYangParser.RpcStatementContext ctx) { 1072 public void exitRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
1070 - // TODO: implement the method. 1073 + RpcListener.processRpcExit(this, ctx);
1071 } 1074 }
1072 1075
1073 @Override 1076 @Override
1074 public void enterInputStatement(GeneratedYangParser.InputStatementContext ctx) { 1077 public void enterInputStatement(GeneratedYangParser.InputStatementContext ctx) {
1075 - // TODO: implement the method. 1078 + InputListener.processInputEntry(this, ctx);
1076 } 1079 }
1077 1080
1078 @Override 1081 @Override
1079 public void exitInputStatement(GeneratedYangParser.InputStatementContext ctx) { 1082 public void exitInputStatement(GeneratedYangParser.InputStatementContext ctx) {
1080 - // TODO: implement the method. 1083 + InputListener.processInputExit(this, ctx);
1084 + }
1085 +
1086 + @Override
1087 + public void enterInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) {
1088 + }
1089 +
1090 + @Override
1091 + public void exitInputStatementBody(GeneratedYangParser.InputStatementBodyContext ctx) {
1081 } 1092 }
1082 1093
1083 @Override 1094 @Override
1084 public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) { 1095 public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
1085 - // TODO: implement the method. 1096 + OutputListener.processOutputEntry(this, ctx);
1086 } 1097 }
1087 1098
1088 @Override 1099 @Override
1089 public void exitOutputStatement(GeneratedYangParser.OutputStatementContext ctx) { 1100 public void exitOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
1090 - // TODO: implement the method. 1101 + OutputListener.processOutputExit(this, ctx);
1102 + }
1103 +
1104 + @Override
1105 + public void enterOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) {
1106 + }
1107 +
1108 + @Override
1109 + public void exitOutputStatementBody(GeneratedYangParser.OutputStatementBodyContext ctx) {
1091 } 1110 }
1092 1111
1093 @Override 1112 @Override
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.onosproject.yangutils.datamodel.YangInput;
20 +import org.onosproject.yangutils.datamodel.YangNode;
21 +import org.onosproject.yangutils.datamodel.YangRpc;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.parser.Parsable;
24 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25 +import org.onosproject.yangutils.parser.exceptions.ParserException;
26 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27 +
28 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
29 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangInputNode;
30 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
39 +import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
40 +
41 +/*
42 + * Reference: RFC6020 and YANG ANTLR Grammar
43 + *
44 + * ABNF grammar as per RFC6020
45 + *
46 + * input-stmt = input-keyword optsep
47 + * "{" stmtsep
48 + * ;; these stmts can appear in any order
49 + * *((typedef-stmt /
50 + * grouping-stmt) stmtsep)
51 + * 1*(data-def-stmt stmtsep)
52 + * "}"
53 + *
54 + * inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE;
55 +
56 + * inputStatementBody : typedefStatement* dataDefStatement+
57 + * | dataDefStatement+ typedefStatement*
58 + * | groupingStatement* dataDefStatement+
59 + * | dataDefStatement+ groupingStatement*;
60 + */
61 +
62 +/**
63 + * Implements listener based call back function corresponding to the "input"
64 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
65 + */
66 +public final class InputListener {
67 +
68 + private static final String INPUT_KEYWORD = "Input";
69 +
70 + /**
71 + * Creates a new input listener.
72 + */
73 + private InputListener() {
74 + }
75 +
76 + /**
77 + * It is called when parser receives an input matching the grammar rule
78 + * (input), performs validation and updates the data model tree.
79 + *
80 + * @param listener listener's object
81 + * @param ctx context object of the grammar rule
82 + */
83 + public static void processInputEntry(TreeWalkListener listener,
84 + GeneratedYangParser.InputStatementContext ctx) {
85 +
86 + // Check for stack to be non empty.
87 + checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY);
88 +
89 + Parsable curData = listener.getParsedDataStack().peek();
90 + if (curData instanceof YangRpc) {
91 +
92 + YangInput yangInput = getYangInputNode(JAVA_GENERATION);
93 + yangInput.setName(((YangRpc) curData).getName() + INPUT_KEYWORD);
94 + YangNode curNode = (YangNode) curData;
95 + try {
96 + curNode.addChild(yangInput);
97 + } catch (DataModelException e) {
98 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
99 + INPUT_DATA, "", ENTRY, e.getMessage()));
100 + }
101 + listener.getParsedDataStack().push(yangInput);
102 + } else {
103 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INPUT_DATA,
104 + "", ENTRY));
105 + }
106 + }
107 +
108 + /**
109 + * It is called when parser exits from grammar rule (input), it perform
110 + * validations and updates the data model tree.
111 + *
112 + * @param listener listener's object
113 + * @param ctx context object of the grammar rule
114 + */
115 + public static void processInputExit(TreeWalkListener listener,
116 + GeneratedYangParser.InputStatementContext ctx) {
117 +
118 + // Check for stack to be non empty.
119 + checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", EXIT);
120 +
121 + if (!(listener.getParsedDataStack().peek() instanceof YangInput)) {
122 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INPUT_DATA,
123 + "", EXIT));
124 + }
125 + listener.getParsedDataStack().pop();
126 + }
127 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.onosproject.yangutils.datamodel.YangNode;
20 +import org.onosproject.yangutils.datamodel.YangOutput;
21 +import org.onosproject.yangutils.datamodel.YangRpc;
22 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
23 +import org.onosproject.yangutils.parser.Parsable;
24 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
25 +import org.onosproject.yangutils.parser.exceptions.ParserException;
26 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
27 +
28 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
29 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangOutputNode;
30 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
36 +import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
37 +
38 +/*
39 + * Reference: RFC6020 and YANG ANTLR Grammar
40 + *
41 + * ABNF grammar as per RFC6020
42 + *
43 + * output-stmt = output-keyword optsep
44 + * "{" stmtsep
45 + * ;; these stmts can appear in any order
46 + * *((typedef-stmt /
47 + * grouping-stmt) stmtsep)
48 + * 1*(data-def-stmt stmtsep)
49 + * "}"
50 + *
51 + * outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE;
52 +
53 + * outputStatementBody : typedefStatement* dataDefStatement+
54 + * | dataDefStatement+ typedefStatement*
55 + * | groupingStatement* dataDefStatement+
56 + * | dataDefStatement+ groupingStatement*;
57 + */
58 +
59 +/**
60 + * Implements listener based call back function corresponding to the "output"
61 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
62 + */
63 +public final class OutputListener {
64 +
65 + private static final String OUTPUT_KEYWORD = "Output";
66 +
67 + /**
68 + * Creates a new output listener.
69 + */
70 + private OutputListener() {
71 + }
72 +
73 + /**
74 + * It is called when parser receives an input matching the grammar rule
75 + * (output), performs validation and updates the data model tree.
76 + *
77 + * @param listener listener's object
78 + * @param ctx context object of the grammar rule
79 + */
80 + public static void processOutputEntry(TreeWalkListener listener,
81 + GeneratedYangParser.OutputStatementContext ctx) {
82 +
83 + // Check for stack to be non empty.
84 + checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY);
85 +
86 + Parsable curData = listener.getParsedDataStack().peek();
87 + if (curData instanceof YangRpc) {
88 +
89 + YangOutput yangOutput = getYangOutputNode(JAVA_GENERATION);
90 + yangOutput.setName(((YangRpc) curData).getName() + OUTPUT_KEYWORD);
91 + YangNode curNode = (YangNode) curData;
92 + try {
93 + curNode.addChild(yangOutput);
94 + } catch (DataModelException e) {
95 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
96 + OUTPUT_DATA, "", ENTRY, e.getMessage()));
97 + }
98 + listener.getParsedDataStack().push(yangOutput);
99 + } else {
100 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, OUTPUT_DATA,
101 + "", ENTRY));
102 + }
103 + }
104 +
105 + /**
106 + * It is called when parser exits from grammar rule (output), it perform
107 + * validations and updates the data model tree.
108 + *
109 + * @param listener listener's object
110 + * @param ctx context object of the grammar rule
111 + */
112 + public static void processOutputExit(TreeWalkListener listener,
113 + GeneratedYangParser.OutputStatementContext ctx) {
114 +
115 + // Check for stack to be non empty.
116 + checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", EXIT);
117 +
118 + if (!(listener.getParsedDataStack().peek() instanceof YangOutput)) {
119 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, OUTPUT_DATA,
120 + "", EXIT));
121 + }
122 + listener.getParsedDataStack().pop();
123 + }
124 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import org.onosproject.yangutils.datamodel.YangNode;
20 +import org.onosproject.yangutils.datamodel.YangRpc;
21 +import org.onosproject.yangutils.datamodel.YangModule;
22 +import org.onosproject.yangutils.datamodel.YangSubModule;
23 +import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
24 +import org.onosproject.yangutils.parser.Parsable;
25 +import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
26 +import org.onosproject.yangutils.parser.exceptions.ParserException;
27 +import org.onosproject.yangutils.parser.impl.TreeWalkListener;
28 +
29 +import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
30 +import static org.onosproject.yangutils.datamodel.utils.YangDataModelFactory.getYangRpcNode;
31 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
32 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
33 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
34 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
35 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
36 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
37 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
38 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
39 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
40 +import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateMutuallyExclusiveChilds;
41 +import static org.onosproject.yangutils.utils.YangConstructType.RPC_DATA;
42 +import static org.onosproject.yangutils.utils.YangConstructType.INPUT_DATA;
43 +import static org.onosproject.yangutils.utils.YangConstructType.OUTPUT_DATA;
44 +import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
45 +import static org.onosproject.yangutils.utils.YangConstructType.GROUPING_DATA;
46 +import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
47 +import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
48 +import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
49 +
50 +/*
51 + * Reference: RFC6020 and YANG ANTLR Grammar
52 + *
53 + * ABNF grammar as per RFC6020
54 + * rpc-stmt = rpc-keyword sep identifier-arg-str optsep
55 + * (";" /
56 + * "{" stmtsep
57 + * ;; these stmts can appear in any order
58 + * *(if-feature-stmt stmtsep)
59 + * [status-stmt stmtsep]
60 + * [description-stmt stmtsep]
61 + * [reference-stmt stmtsep]
62 + * *((typedef-stmt /
63 + * grouping-stmt) stmtsep)
64 + * [input-stmt stmtsep]
65 + * [output-stmt stmtsep]
66 + * "}")
67 + *
68 + * ANTLR grammar rule
69 + * rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
70 + * | descriptionStatement | referenceStatement | typedefStatement | groupingStatement | inputStatement
71 + * | outputStatement)* RIGHT_CURLY_BRACE);
72 + */
73 +
74 +/**
75 + * Implements listener based call back function corresponding to the "rpc"
76 + * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
77 + */
78 +public final class RpcListener {
79 +
80 + /**
81 + * Creates a new rpc listener.
82 + */
83 + private RpcListener() {
84 + }
85 +
86 + /**
87 + * It is called when parser receives an input matching the grammar rule
88 + * (rpc), performs validation and updates the data model tree.
89 + *
90 + * @param listener listener's object
91 + * @param ctx context object of the grammar rule
92 + */
93 + public static void processRpcEntry(TreeWalkListener listener,
94 + GeneratedYangParser.RpcStatementContext ctx) {
95 +
96 + // Check for stack to be non empty.
97 + checkStackIsNotEmpty(listener, MISSING_HOLDER, RPC_DATA, ctx.identifier().getText(), ENTRY);
98 +
99 + String identifier = getValidIdentifier(ctx.identifier().getText(), RPC_DATA, ctx);
100 +
101 + // Validate sub statement cardinality.
102 + validateSubStatementsCardinality(ctx);
103 +
104 + // Check for identifier collision
105 + int line = ctx.getStart().getLine();
106 + int charPositionInLine = ctx.getStart().getCharPositionInLine();
107 + detectCollidingChildUtil(listener, line, charPositionInLine, identifier, RPC_DATA);
108 +
109 + Parsable curData = listener.getParsedDataStack().peek();
110 + if (curData instanceof YangModule || curData instanceof YangSubModule) {
111 +
112 + YangNode curNode = (YangNode) curData;
113 + YangRpc yangRpc = getYangRpcNode(JAVA_GENERATION);
114 + yangRpc.setName(identifier);
115 + try {
116 + curNode.addChild(yangRpc);
117 + } catch (DataModelException e) {
118 + throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
119 + RPC_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
120 + }
121 + listener.getParsedDataStack().push(yangRpc);
122 + } else {
123 + throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RPC_DATA,
124 + ctx.identifier().getText(), ENTRY));
125 + }
126 + }
127 +
128 + /**
129 + * It is called when parser exits from grammar rule (rpc), it perform
130 + * validations and updates the data model tree.
131 + *
132 + * @param listener listener's object
133 + * @param ctx context object of the grammar rule
134 + */
135 + public static void processRpcExit(TreeWalkListener listener,
136 + GeneratedYangParser.RpcStatementContext ctx) {
137 +
138 + //Check for stack to be non empty.
139 + checkStackIsNotEmpty(listener, MISSING_HOLDER, RPC_DATA, ctx.identifier().getText(), EXIT);
140 +
141 + if (!(listener.getParsedDataStack().peek() instanceof YangRpc)) {
142 + throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, RPC_DATA,
143 + ctx.identifier().getText(), EXIT));
144 + }
145 + listener.getParsedDataStack().pop();
146 + }
147 +
148 + /**
149 + * Validates the cardinality of rpc sub-statements as per grammar.
150 + *
151 + * @param ctx context object of the grammar rule
152 + */
153 + private static void validateSubStatementsCardinality(GeneratedYangParser.RpcStatementContext ctx) {
154 +
155 + validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, RPC_DATA, ctx.identifier().getText());
156 + validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, RPC_DATA, ctx.identifier().getText());
157 + validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText());
158 + validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText());
159 + validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText());
160 + validateMutuallyExclusiveChilds(ctx.typedefStatement(), TYPEDEF_DATA, ctx.groupingStatement(), GROUPING_DATA,
161 + RPC_DATA, ctx.identifier().getText());
162 + }
163 +
164 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.translator.tojava.javamodel;
18 +
19 +import java.io.IOException;
20 +import org.onosproject.yangutils.datamodel.YangRpc;
21 +import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
22 +
23 +/**
24 + * Rpc information extended to support java code generation.
25 + */
26 +public class YangJavaRpc extends YangRpc implements JavaCodeGenerator {
27 +
28 + /**
29 + * Creates an instance of java Rpc.
30 + */
31 + public YangJavaRpc() {
32 + }
33 +
34 + /**
35 + * Prepare the information for java code generation corresponding to YANG
36 + * rpc info.
37 + *
38 + * @param codeGenDir code generation directory
39 + * @throws IOException IO operation fail
40 + */
41 + @Override
42 + public void generateCodeEntry(String codeGenDir) throws IOException {
43 + // TODO
44 + }
45 +
46 + /**
47 + * Create a java file using the YANG rpc info.
48 + *
49 + * @throws IOException IO operation fail
50 + */
51 + @Override
52 + public void generateCodeExit() throws IOException {
53 + // TODO
54 + }
55 +}
...@@ -1085,7 +1085,6 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1085,7 +1085,6 @@ package org.onosproject.yangutils.parser.antlrgencode;
1085 * [input-stmt stmtsep] 1085 * [input-stmt stmtsep]
1086 * [output-stmt stmtsep] 1086 * [output-stmt stmtsep]
1087 * "}") 1087 * "}")
1088 - * TODO : 0..1 occurance to be checked in listener
1089 */ 1088 */
1090 rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement | descriptionStatement 1089 rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement | descriptionStatement
1091 | referenceStatement | typedefStatement | groupingStatement | inputStatement | outputStatement)* RIGHT_CURLY_BRACE); 1090 | referenceStatement | typedefStatement | groupingStatement | inputStatement | outputStatement)* RIGHT_CURLY_BRACE);
...@@ -1099,9 +1098,12 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1099,9 +1098,12 @@ package org.onosproject.yangutils.parser.antlrgencode;
1099 * 1*(data-def-stmt stmtsep) 1098 * 1*(data-def-stmt stmtsep)
1100 * "}" 1099 * "}"
1101 */ 1100 */
1102 - inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE 1101 + inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE;
1103 - ((typedefStatement | groupingStatement)* | dataDefStatement+) 1102 +
1104 - | (dataDefStatement+ | (typedefStatement | groupingStatement)*)RIGHT_CURLY_BRACE; 1103 + inputStatementBody : typedefStatement* dataDefStatement+
1104 + | dataDefStatement+ typedefStatement*
1105 + | groupingStatement* dataDefStatement+
1106 + | dataDefStatement+ groupingStatement*;
1105 1107
1106 /** 1108 /**
1107 * output-stmt = output-keyword optsep 1109 * output-stmt = output-keyword optsep
...@@ -1112,9 +1114,12 @@ package org.onosproject.yangutils.parser.antlrgencode; ...@@ -1112,9 +1114,12 @@ package org.onosproject.yangutils.parser.antlrgencode;
1112 * 1*(data-def-stmt stmtsep) 1114 * 1*(data-def-stmt stmtsep)
1113 * "}" 1115 * "}"
1114 */ 1116 */
1115 - outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE 1117 + outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE;
1116 - ((typedefStatement | groupingStatement)* | dataDefStatement+) 1118 +
1117 - | (dataDefStatement+ | (typedefStatement | groupingStatement)*)RIGHT_CURLY_BRACE; 1119 + outputStatementBody : typedefStatement* dataDefStatement+
1120 + | dataDefStatement+ typedefStatement*
1121 + | groupingStatement* dataDefStatement+
1122 + | dataDefStatement+ groupingStatement*;
1118 1123
1119 /** 1124 /**
1120 * notification-stmt = notification-keyword sep 1125 * notification-stmt = notification-keyword sep
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import java.io.IOException;
20 +import java.util.ListIterator;
21 +
22 +import org.junit.Test;
23 +import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNodeType;
26 +import org.onosproject.yangutils.datamodel.YangRpc;
27 +import org.onosproject.yangutils.datamodel.YangInput;
28 +import org.onosproject.yangutils.datamodel.YangLeaf;
29 +import org.onosproject.yangutils.datamodel.YangList;
30 +import org.onosproject.yangutils.datamodel.YangContainer;
31 +import org.onosproject.yangutils.datamodel.YangTypeDef;
32 +import org.onosproject.yangutils.datamodel.YangStatusType;
33 +import org.onosproject.yangutils.datamodel.YangDataTypes;
34 +import org.onosproject.yangutils.parser.exceptions.ParserException;
35 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
36 +
37 +import static org.hamcrest.core.Is.is;
38 +import static org.junit.Assert.assertThat;
39 +
40 +/**
41 + * Test cases for testing Input listener functionality.
42 + */
43 +public class InputListenerTest {
44 +
45 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
46 +
47 + /**
48 + * Checks input statements with data definition statements as sub-statements.
49 + */
50 + @Test
51 + public void processInputStatementWithDataDefinition() throws IOException, ParserException {
52 +
53 + YangNode node = manager.getDataModel("src/test/resources/InputStatementWithDataDefinition.yang");
54 +
55 + assertThat((node instanceof YangModule), is(true));
56 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
57 + YangModule yangNode = (YangModule) node;
58 + assertThat(yangNode.getName(), is("rock"));
59 +
60 + YangRpc yangRpc = (YangRpc) yangNode.getChild();
61 + assertThat(yangRpc.getName(), is("activate-software-image"));
62 +
63 + YangInput yangInput = (YangInput) yangRpc.getChild();
64 + assertThat(yangInput.getName(), is("activate-software-imageInput"));
65 + ListIterator<YangLeaf> leafIterator = yangInput.getListOfLeaf().listIterator();
66 + YangLeaf leafInfo = leafIterator.next();
67 +
68 + assertThat(leafInfo.getLeafName(), is("image-name"));
69 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
70 +
71 + YangList yangList = (YangList) yangInput.getChild();
72 + assertThat(yangList.getName(), is("ospf"));
73 + assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
74 + assertThat(yangList.isConfig(), is(true));
75 + assertThat(yangList.getMaxElements(), is(10));
76 + assertThat(yangList.getMinElements(), is(3));
77 + leafIterator = yangList.getListOfLeaf().listIterator();
78 + leafInfo = leafIterator.next();
79 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
80 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
81 +
82 + YangContainer yangContainer = (YangContainer) yangList.getNextSibling();
83 + assertThat(yangContainer.getName(), is("isis"));
84 +
85 + leafIterator = yangContainer.getListOfLeaf().listIterator();
86 + leafInfo = leafIterator.next();
87 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
88 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
89 + }
90 +
91 + /**
92 + * Checks input statements with type-def statement as sub-statements.
93 + */
94 + @Test
95 + public void processInputStatementWithTypedef() throws IOException, ParserException {
96 +
97 + YangNode node = manager.getDataModel("src/test/resources/InputStatementWithTypedef.yang");
98 + YangModule yangNode = (YangModule) node;
99 + assertThat(yangNode.getName(), is("rock"));
100 +
101 + YangRpc yangRpc = (YangRpc) yangNode.getChild();
102 + assertThat(yangRpc.getName(), is("activate-software-image"));
103 +
104 + YangInput yangInput = (YangInput) yangRpc.getChild();
105 + assertThat(yangInput.getName(), is("activate-software-imageInput"));
106 + YangTypeDef typeDef = (YangTypeDef) yangInput.getChild();
107 + assertThat(typeDef.getName(), is("my-type"));
108 + assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
109 + assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
110 + }
111 +}
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import java.io.IOException;
20 +import java.util.ListIterator;
21 +import org.junit.Test;
22 +
23 +import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangNode;
25 +import org.onosproject.yangutils.datamodel.YangNodeType;
26 +import org.onosproject.yangutils.datamodel.YangRpc;
27 +import org.onosproject.yangutils.datamodel.YangOutput;
28 +import org.onosproject.yangutils.datamodel.YangLeaf;
29 +import org.onosproject.yangutils.datamodel.YangList;
30 +import org.onosproject.yangutils.datamodel.YangContainer;
31 +import org.onosproject.yangutils.datamodel.YangTypeDef;
32 +import org.onosproject.yangutils.datamodel.YangStatusType;
33 +import org.onosproject.yangutils.datamodel.YangDataTypes;
34 +import org.onosproject.yangutils.parser.exceptions.ParserException;
35 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
36 +
37 +import static org.hamcrest.core.Is.is;
38 +import static org.junit.Assert.assertThat;
39 +
40 +/**
41 + * Test cases for testing output listener functionality.
42 + */
43 +public class OutputListenerTest {
44 +
45 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
46 +
47 + /**
48 + * Checks output statements with data definition statements as sub-statements.
49 + */
50 + @Test
51 + public void processOutputStatementWithDataDefinition() throws IOException, ParserException {
52 +
53 + YangNode node = manager.getDataModel("src/test/resources/OutputStatementWithDataDefinition.yang");
54 +
55 + assertThat((node instanceof YangModule), is(true));
56 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
57 + YangModule yangNode = (YangModule) node;
58 + assertThat(yangNode.getName(), is("rock"));
59 +
60 + YangRpc yangRpc = (YangRpc) yangNode.getChild();
61 + assertThat(yangRpc.getName(), is("activate-software-image"));
62 +
63 + YangOutput yangOutput = (YangOutput) yangRpc.getChild();
64 + assertThat(yangOutput.getName(), is("activate-software-imageOutput"));
65 + ListIterator<YangLeaf> leafIterator = yangOutput.getListOfLeaf().listIterator();
66 + YangLeaf leafInfo = leafIterator.next();
67 +
68 + assertThat(leafInfo.getLeafName(), is("image-name"));
69 + assertThat(leafInfo.getDataType().getDataTypeName(), is("string"));
70 +
71 + YangList yangList = (YangList) yangOutput.getChild();
72 + assertThat(yangList.getName(), is("ospf"));
73 + assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
74 + assertThat(yangList.isConfig(), is(true));
75 + assertThat(yangList.getMaxElements(), is(10));
76 + assertThat(yangList.getMinElements(), is(3));
77 + leafIterator = yangList.getListOfLeaf().listIterator();
78 + leafInfo = leafIterator.next();
79 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
80 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
81 +
82 + YangContainer yangContainer = (YangContainer) yangList.getNextSibling();
83 + assertThat(yangContainer.getName(), is("isis"));
84 +
85 + leafIterator = yangContainer.getListOfLeaf().listIterator();
86 + leafInfo = leafIterator.next();
87 + assertThat(leafInfo.getLeafName(), is("invalid-interval"));
88 + assertThat(leafInfo.getDataType().getDataTypeName(), is("uint16"));
89 + }
90 +
91 + /**
92 + * Checks output statements with type-def statement as sub-statements.
93 + */
94 + @Test
95 + public void processOutputStatementWithTypedef() throws IOException, ParserException {
96 +
97 + YangNode node = manager.getDataModel("src/test/resources/OutputStatementWithTypedef.yang");
98 + YangModule yangNode = (YangModule) node;
99 + assertThat(yangNode.getName(), is("rock"));
100 +
101 + YangRpc yangRpc = (YangRpc) yangNode.getChild();
102 + assertThat(yangRpc.getName(), is("activate-software-image"));
103 +
104 + YangOutput yangOutput = (YangOutput) yangRpc.getChild();
105 + assertThat(yangOutput.getName(), is("activate-software-imageOutput"));
106 + YangTypeDef typeDef = (YangTypeDef) yangOutput.getChild();
107 + assertThat(typeDef.getName(), is("my-type"));
108 + assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
109 + assertThat(typeDef.getName(), is("my-type"));
110 + assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
111 + assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
112 + }
113 +}
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +
17 +package org.onosproject.yangutils.parser.impl.listeners;
18 +
19 +import java.io.IOException;
20 +
21 +import org.junit.Test;
22 +import org.onosproject.yangutils.datamodel.YangNode;
23 +import org.onosproject.yangutils.datamodel.YangModule;
24 +import org.onosproject.yangutils.datamodel.YangRpc;
25 +import org.onosproject.yangutils.datamodel.YangTypeDef;
26 +import org.onosproject.yangutils.datamodel.YangStatusType;
27 +import org.onosproject.yangutils.datamodel.YangNodeType;
28 +import org.onosproject.yangutils.datamodel.YangDataTypes;
29 +import org.onosproject.yangutils.parser.exceptions.ParserException;
30 +import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
31 +
32 +import static org.hamcrest.core.Is.is;
33 +import static org.junit.Assert.assertThat;
34 +
35 +/**
36 + * Test cases for testing Rpc listener functionality.
37 + */
38 +public class RpcListenerTest {
39 +
40 + private final YangUtilsParserManager manager = new YangUtilsParserManager();
41 +
42 + /**
43 + * Checks valid rpc statements.
44 + */
45 + @Test
46 + public void processValidRpcStatement() throws IOException, ParserException {
47 +
48 + YangNode node = manager.getDataModel("src/test/resources/ValidRpcStatement.yang");
49 +
50 + assertThat((node instanceof YangModule), is(true));
51 + assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
52 + YangModule yangNode = (YangModule) node;
53 + assertThat(yangNode.getName(), is("rock"));
54 +
55 + YangRpc yangRpc = (YangRpc) yangNode.getChild();
56 + assertThat(yangRpc.getName(), is("rock-the-house"));
57 + assertThat(yangRpc.getDescription(), is("\"description\""));
58 + assertThat(yangRpc.getReference(), is("\"reference\""));
59 + assertThat(yangRpc.getStatus(), is(YangStatusType.CURRENT));
60 +
61 + YangTypeDef typeDef = (YangTypeDef) yangRpc.getChild();
62 + assertThat(typeDef.getName(), is("my-type"));
63 + assertThat(typeDef.getStatus(), is(YangStatusType.DEPRECATED));
64 + assertThat(typeDef.getDataType().getDataType(), is(YangDataTypes.INT32));
65 + }
66 +}
1 +module rock {
2 + namespace "http://example.net/rock";
3 + prefix "rock";
4 +
5 + rpc activate-software-image {
6 + description "description";
7 + input {
8 + leaf image-name {
9 + type string;
10 + }
11 + list ospf {
12 + key "invalid-interval";
13 + config true;
14 + max-elements 10;
15 + min-elements 3;
16 + leaf invalid-interval {
17 + type uint16;
18 + }
19 + }
20 + container isis {
21 + config true;
22 + leaf invalid-interval {
23 + type uint16;
24 + }
25 + }
26 + }
27 + }
28 +}
1 +module rock {
2 + namespace "http://example.net/rock";
3 + prefix "rock";
4 +
5 + rpc activate-software-image {
6 + description "description";
7 + input {
8 + leaf image-name {
9 + type string;
10 + }
11 + typedef my-type {
12 + status deprecated;
13 + type int32;
14 + }
15 + }
16 + }
17 +}
1 +module rock {
2 + namespace "http://example.net/rock";
3 + prefix "rock";
4 +
5 + rpc activate-software-image {
6 + description "description";
7 + output {
8 + leaf image-name {
9 + type string;
10 + }
11 + list ospf {
12 + key "invalid-interval";
13 + config true;
14 + max-elements 10;
15 + min-elements 3;
16 + leaf invalid-interval {
17 + type uint16;
18 + }
19 + }
20 + container isis {
21 + config true;
22 + leaf invalid-interval {
23 + type uint16;
24 + }
25 + }
26 + }
27 + }
28 +}
1 +module rock {
2 + namespace "http://example.net/rock";
3 + prefix "rock";
4 +
5 + rpc activate-software-image {
6 + description "description";
7 + output {
8 + leaf image-name {
9 + type string;
10 + }
11 + typedef my-type {
12 + status deprecated;
13 + type int32;
14 + }
15 + }
16 + }
17 +}
1 +module rock {
2 + namespace "http://example.net/rock";
3 + prefix "rock";
4 +
5 + rpc rock-the-house {
6 + description "description";
7 + status current;
8 + reference "reference";
9 + typedef my-type {
10 + status deprecated;
11 + type int32;
12 + }
13 + input {
14 + leaf zip-code {
15 + type string;
16 + }
17 + }
18 + output {
19 + leaf status {
20 + type string;
21 + }
22 + }
23 + }
24 +}