import org.opendaylight.controller.yang.common.QName;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.ModuleImport;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
return parser.parseYangModels(testFiles);
}
- public static Set<Module> loadModules(String... pathToYangFile) throws IOException {
- YangModelParser parser = new YangParserImpl();
- List<InputStream> input = new ArrayList<InputStream>();
- for(String path : pathToYangFile) {
- input.add(TestUtils.class.getResourceAsStream(path));
- }
- Set<Module> modules = new HashSet<Module>(
+ public static Set<Module> loadModules(List<InputStream> input) throws IOException {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = new HashSet<Module>(
parser.parseYangModelsFromStreams(input));
for(InputStream stream : input) {
stream.close();
return modules;
}
- public static Module loadModule(String pathToYangFile) throws IOException {
- YangModelParser parser = new YangParserImpl();
- InputStream stream = TestUtils.class.getResourceAsStream(pathToYangFile);
- List<InputStream> input = Collections.singletonList(stream);
- Set<Module> modules = new HashSet<Module>(
+ public static Module loadModule(final InputStream stream) throws
+ IOException {
+ final YangModelParser parser = new YangParserImpl();
+ final List<InputStream> input = Collections.singletonList(stream);
+ final Set<Module> modules = new HashSet<Module>(
parser.parseYangModelsFromStreams(input));
stream.close();
return modules.iterator().next();
}
+ public static Module loadModuleWithContext(final InputStream stream, final SchemaContext context) throws IOException {
+ final YangModelParser parser = new YangParserImpl();
+ final List<InputStream> input = Collections.singletonList(stream);
+ final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+ stream.close();
+ return modules.iterator().next();
+ }
+
+ public static Set<Module> loadModulesWithContext(final List<InputStream> input, final SchemaContext context) throws IOException {
+ final YangModelParser parser = new YangParserImpl();
+ final Set<Module> modules = new HashSet<Module>(parser.parseYangModelsFromStreams(input, context));
+ for(InputStream is : input) {
+ if(is != null) {
+ is.close();
+ }
+ }
+ return modules;
+ }
+
public static Module findModule(Set<Module> modules, String moduleName) {
Module result = null;
for (Module module : modules) {