Merge "Improved documentation of BindingReflections."
[yangtools.git] / yang / yang-parser-api / src / main / java / org / opendaylight / yangtools / yang / model / parser / api / YangModelParser.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.model.parser.api;
9
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;
13
14 import java.io.File;
15 import java.io.InputStream;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.Set;
19
20 /**
21  * Yang Model Parser interface is designed for parsing yang models and convert
22  * the information to Data Schema Tree.
23  * 
24  */
25 // refactor methods returning input streams, after introducing
26 public interface YangModelParser {
27
28     /**
29      * Parse yangFile file and all yang files found in directory.
30      *
31      * @param yangFile
32      *            file to parse
33      * @param directory
34      *            directory which contains additional yang files
35      * @return Set of Yang Modules
36      */
37     Set<Module> parseYangModels(final File yangFile, final File directory);
38
39     /**
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.
44      * 
45      * @param yangFiles
46      *            yang files to parse
47      * @return Set of Yang Modules
48      */
49     Set<Module> parseYangModels(final List<File> yangFiles);
50
51     /**
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
56      * context.
57      * 
58      * @param yangFiles
59      *            yang files to parse
60      * @param context
61      *            SchemaContext containing already parsed yang models
62      * @return Set of Yang Modules
63      */
64     Set<Module> parseYangModels(final List<File> yangFiles, final SchemaContext context);
65
66     /**
67      * Equivalent to {@link #parseYangModels(List)} that returns parsed modules
68      * mapped to Files from which they were parsed.
69      * 
70      * @param yangFiles
71      *            yang files to parse
72      * @return Map of Yang Modules
73      */
74     Map<File, Module> parseYangModelsMapped(final List<File> yangFiles);
75
76     /**
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.
81      * 
82      * @param yangModelStreams
83      *            yang streams to parse
84      * @return Set of Yang Modules
85      */
86     Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams);
87
88     /**
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
93      * context.
94      * 
95      * @param yangModelStreams
96      *            yang streams to parse
97      * @param context
98      *            SchemaContext containing already parsed yang models
99      * @return Set of Yang Modules
100      */
101     Set<Module> parseYangModelsFromStreams(final List<InputStream> yangModelStreams, final SchemaContext context);
102
103     /**
104      * Equivalent to {@link #parseYangModels(List)} that returns parsed modules
105      * mapped to IputStreams from which they were parsed.
106      * 
107      * @param yangModelStreams
108      *            yang streams to parse
109      * @return Map of Yang Modules
110      */
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);
114
115     /**
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.
122      * 
123      * @param modules
124      *            Set of Yang Modules
125      * @return Schema Context instance constructed from whole Set of Modules.
126      */
127     SchemaContext resolveSchemaContext(final Set<Module> modules);
128 }