【问题标题】:usage of jyang parser to convert yang files into yin使用 jyang 解析器将 yang 文件转换为 yin
【发布时间】:2015-11-27 16:48:15
【问题描述】:
【问题讨论】:
标签:
java
ietf-netmod-yang
【解决方案1】:
以下是您提供的first link 第 4.3.2 节“编程访问”中的示例,为清楚起见添加了我的 cmets。
public static void main(String[] args) throws Exception {
// Create a FileInputStream using a string with the path to your yang file
FileInputStream yangfile = new FileInputStream(args[0]);
// Pass the yang file input stream to the parser by calling its static constructor
new yang(yangfile);
// Run the parser on the yang file and store the result in spec
YANG_Specification spec = yang.Start();
// Call spec's functions to access it
spec.check();
}
查看源代码,jYang 提供了 4 种不同的静态构造函数,您将希望使用其中的第 2 或第 3 来指定文件的编码:
yang(java.io.InputStream stream);
yang(java.io.InputStream stream, String encoding);
yang(java.io.Reader stream);
yang(yangTokenManager tm);
如果您尝试多次调用 jYang 的构造函数中的任何一个,它们将抛出错误。开发人员通过使用静态状态变量来强制类以静态方式运行,该变量跟踪其构造函数是否已被调用。如果您需要重试解析文件或开始解析新的 yang 文件,则需要使用 ReInit 函数,然后使用 Start 函数。
// One of these 4
yang.ReInit(java.io.InputStream stream);
yang.ReInit(java.io.InputStream stream, String encoding);
yang.ReInit(java.io.Reader stream);
yang.ReInit(yangTokenManager tm);
// Followed by
YANG_Specification spec = yang.Start();