* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.md.cluster.datastore.model;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
-public class SchemaContextHelper {
+public final class SchemaContextHelper {
public static final String ODL_DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
public static final String PEOPLE_YANG = "/people.yang";
public static final String CARS_YANG = "/cars.yang";
- public static InputStream getInputStream(final String yangFileName) {
- return TestModel.class.getResourceAsStream(yangFileName);
- }
+ private static volatile EffectiveModelContext FULL;
+
+ private SchemaContextHelper() {
- public static SchemaContext full(){
- return select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
}
- public static SchemaContext select(String... schemaFiles){
- YangParserImpl parser = new YangParserImpl();
- List<InputStream> streams = new ArrayList<>();
+ public static InputStream getInputStream(final String yangFileName) {
+ return SchemaContextHelper.class.getResourceAsStream(yangFileName);
+ }
- for(String schemaFile : schemaFiles){
- streams.add(getInputStream(schemaFile));
+ public static EffectiveModelContext full() {
+ EffectiveModelContext ret = FULL;
+ if (ret == null) {
+ synchronized (SchemaContextHelper.class) {
+ ret = FULL;
+ if (ret == null) {
+ ret = FULL = select(ODL_DATASTORE_TEST_YANG, PEOPLE_YANG, CARS_YANG);
+ }
+ }
}
- Set<Module> modules = parser.parseYangModelsFromStreams(streams);
- return parser.resolveSchemaContext(modules);
+ return ret;
}
+ public static EffectiveModelContext select(final String... schemaFiles) {
+ return YangParserTestUtils.parseYangResources(SchemaContextHelper.class, schemaFiles);
+ }
}