2 * Copyright (c) 2013 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
8 package org.opendaylight.yangtools.yang.model.parser.api;
10 import org.opendaylight.yangtools.yang.model.api.Module;
11 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
12 import org.opendaylight.yangtools.yang.model.api.type.UnknownTypeDefinition;
15 import java.io.InputStream;
16 import java.util.List;
21 * Yang Model Parser interface is designed for parsing yang models and convert
22 * the information to Data Schema Tree.
25 // refactor methods returning input streams, after introducing
26 public interface YangModelParser {
29 * Parse yangFile file and all yang files found in directory.
34 * directory which contains additional yang files
35 * @return Set of Yang Modules
37 Set<Module> parseYangModels(final File yangFile, final File directory);
40 * Parse one or more Yang model files and return the definitions of Yang
41 * modules defined in *.yang files; <br>
42 * This method SHOULD be used if user need to parse multiple yang models
43 * that are referenced either through import or include statements.
47 * @return Set of Yang Modules
49 Set<Module> parseYangModels(final List<File> yangFiles);
52 * Parse one or more Yang model files and return the definitions of Yang
53 * modules defined in *.yang files. <br>
54 * This method SHOULD be used if user has already parsed context and need to
55 * parse additinal yang models which can have dependencies on models in this
61 * SchemaContext containing already parsed yang models
62 * @return Set of Yang Modules
64 Set<Module> parseYangModels(final List<File> yangFiles, final SchemaContext context);
67 * Equivalent to {@link #parseYangModels(List)} that returns parsed modules
68 * mapped to Files from which they were parsed.
72 * @return Map of Yang Modules
74 Map<File, Module> parseYangModelsMapped(final List<File> yangFiles);
77 * Parse one or more Yang model streams and return the definitions of Yang
78 * modules defined in *.yang files; <br>
79 * This method SHOULD be used if user need to parse multiple yang models
80 * that are referenced either through import or include statements.
82 * @param yangModelStreams
83 * yang streams to parse
84 * @return Set of Yang Modules
86 Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams);
89 * Parse one or more Yang model streams and return the definitions of Yang
90 * modules defined in *.yang files. <br>
91 * This method SHOULD be used if user has already parsed context and need to
92 * parse additinal yang models which can have dependencies on models in this
95 * @param yangModelStreams
96 * yang streams to parse
98 * SchemaContext containing already parsed yang models
99 * @return Set of Yang Modules
101 Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams, final SchemaContext context);
104 * Equivalent to {@link #parseYangModels(List)} that returns parsed modules
105 * mapped to IputStreams from which they were parsed.
107 * @param yangModelStreams
108 * yang streams to parse
109 * @return Map of Yang Modules
111 //TODO: when working with input streams do not swallow IOException, it should be propagated without having to wrap it in a runtime exception
112 //FIXME: it is not defined in which state are the returning streams.
113 Map<InputStream, Module> parseYangModelsFromStreamsMapped(final List<InputStream> yangModelStreams);
116 * Creates {@link SchemaContext} from specified Modules. The modules SHOULD
117 * not contain any unresolved Schema Nodes or Type Definitions. By
118 * unresolved Schema Nodes or Type Definitions we mean that the Module
119 * should not contain ANY Schema Nodes that contains
120 * {@link UnknownTypeDefinition} and all dependencies although via import or
121 * include definitions are resolved.
124 * Set of Yang Modules
125 * @return Schema Context instance constructed from whole Set of Modules.
127 SchemaContext resolveSchemaContext(final Set<Module> modules);