2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.md.cluster.datastore.model;
11 import com.google.common.io.Resources;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
19 import org.opendaylight.yangtools.yang.model.api.Module;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
22 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
24 public class SchemaContextHelper {
26 public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
27 public static final String PEOPLE_YANG = "/people.yang";
28 public static final String CARS_YANG = "/cars.yang";
30 public static InputStream getInputStream(final String yangFileName) {
31 return TestModel.class.getResourceAsStream(yangFileName);
34 public static SchemaContext full(){
35 return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
38 public static SchemaContext select(String... schemaFiles){
39 YangParserImpl parser = new YangParserImpl();
40 List<InputStream> streams = new ArrayList<>();
42 for(String schemaFile : schemaFiles){
43 streams.add(getInputStream(schemaFile));
46 Set<Module> modules = parser.parseYangModelsFromStreams(streams);
47 return parser.resolveSchemaContext(modules);
50 public static SchemaContext entityOwners() {
51 YangParserImpl parser = new YangParserImpl();
53 File file = new File("src/main/yang/entity-owners.yang");
54 return parser.parseSources(Arrays.asList(Resources.asByteSource(file.toURI().toURL())));
55 } catch (IOException | YangSyntaxErrorException e) {
56 throw new ExceptionInInitializerError(e);