Merge "BUG-576: modified parser to handle augmentation of extension instances."
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / impl / YangParserListenerImpl.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.parser.impl;
9
10 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.checkMissingBody;
11 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.createListKey;
12 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.getConfig;
13 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.getIdentityrefBase;
14 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseConstraints;
15 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseDefault;
16 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseRefine;
17 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseSchemaNodeArgs;
18 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseStatus;
19 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseTypeWithBody;
20 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseUnits;
21 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseUserOrdered;
22 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.parseYinValue;
23 import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.stringFromNode;
24
25 import com.google.common.base.Splitter;
26 import com.google.common.base.Strings;
27 import com.google.common.collect.Iterables;
28 import java.net.URI;
29 import java.text.DateFormat;
30 import java.text.ParseException;
31 import java.text.SimpleDateFormat;
32 import java.util.ArrayList;
33 import java.util.Date;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.TreeMap;
38 import org.antlr.v4.runtime.tree.ParseTree;
39 import org.antlr.v4.runtime.tree.ParseTreeWalker;
40 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser;
41 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Argument_stmtContext;
42 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Base_stmtContext;
43 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Contact_stmtContext;
44 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Container_stmtContext;
45 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Default_stmtContext;
46 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Description_stmtContext;
47 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviate_add_stmtContext;
48 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviate_delete_stmtContext;
49 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviate_not_supported_stmtContext;
50 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Deviate_replace_stmtContext;
51 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Import_stmtContext;
52 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Key_stmtContext;
53 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Leaf_list_stmtContext;
54 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Leaf_stmtContext;
55 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.List_stmtContext;
56 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Module_header_stmtsContext;
57 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Namespace_stmtContext;
58 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Ordered_by_stmtContext;
59 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Organization_stmtContext;
60 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Prefix_stmtContext;
61 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Presence_stmtContext;
62 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Reference_stmtContext;
63 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_date_stmtContext;
64 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_stmtContext;
65 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_stmtsContext;
66 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Status_stmtContext;
67 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Type_body_stmtsContext;
68 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Units_stmtContext;
69 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.When_stmtContext;
70 import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Yang_version_stmtContext;
71 import org.opendaylight.yangtools.antlrv4.code.gen.YangParserBaseListener;
72 import org.opendaylight.yangtools.yang.common.QName;
73 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
74 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
75 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
76 import org.opendaylight.yangtools.yang.model.util.BaseTypes;
77 import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
78 import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
79 import org.opendaylight.yangtools.yang.parser.builder.api.ExtensionBuilder;
80 import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
81 import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
82 import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
83 import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
84 import org.opendaylight.yangtools.yang.parser.builder.impl.AnyXmlBuilder;
85 import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceBuilder;
86 import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceCaseBuilder;
87 import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
88 import org.opendaylight.yangtools.yang.parser.builder.impl.DeviationBuilder;
89 import org.opendaylight.yangtools.yang.parser.builder.impl.FeatureBuilder;
90 import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
91 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
92 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
93 import org.opendaylight.yangtools.yang.parser.builder.impl.ListSchemaNodeBuilder;
94 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
95 import org.opendaylight.yangtools.yang.parser.builder.impl.NotificationBuilder;
96 import org.opendaylight.yangtools.yang.parser.builder.impl.RefineHolderImpl;
97 import org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder;
98 import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
99 import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilderImpl;
100 import org.opendaylight.yangtools.yang.parser.util.YangParseException;
101 import org.slf4j.Logger;
102 import org.slf4j.LoggerFactory;
103
104
105 public final class YangParserListenerImpl extends YangParserBaseListener {
106     private static final Logger LOG = LoggerFactory.getLogger(YangParserListenerImpl.class);
107     private static final Splitter SLASH_SPLITTER = Splitter.on('/').omitEmptyStrings();
108     private static final Splitter COLON_SPLITTER = Splitter.on(':');
109     private static final String AUGMENT_STR = "augment";
110
111     private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
112     private final SchemaPathStack stack = new SchemaPathStack();
113     private final Map<String, TreeMap<Date, URI>> namespaceContext;
114     private final String sourcePath;
115     private QName moduleQName = new QName(null, new Date(0L), null, "dummy");
116     private ModuleBuilder moduleBuilder;
117     private String moduleName;
118     private int augmentOrder;
119     private String yangModelPrefix;
120
121     public YangParserListenerImpl(final Map<String, TreeMap<Date, URI>> namespaceContext, final String sourcePath) {
122         this.namespaceContext = namespaceContext;
123         this.sourcePath = sourcePath;
124     }
125
126     /**
127      * Create a new instance.
128      *
129      * FIXME: the resulting type needs to be extracted, such that we can reuse
130      *        the "BaseListener" aspect, which need not be exposed to the user.
131      *        Maybe factor out a base class into repo.spi?
132      *
133      * @param namespaceContext
134      * @param sourcePath
135      * @param walker
136      * @param tree
137      * @return
138      */
139     public static YangParserListenerImpl create(final Map<String, TreeMap<Date, URI>> namespaceContext,
140             final String sourcePath, final ParseTreeWalker walker, final ParseTree tree) {
141         final YangParserListenerImpl ret = new YangParserListenerImpl(namespaceContext, sourcePath);
142         walker.walk(ret, tree);
143         return ret;
144     }
145
146
147
148     @Override
149     public void enterModule_stmt(final YangParser.Module_stmtContext ctx) {
150         moduleName = stringFromNode(ctx);
151         LOG.trace("entering module {}", moduleName);
152         enterLog("module", moduleName, 0);
153         stack.push();
154
155         moduleBuilder = new ModuleBuilder(moduleName, sourcePath);
156
157         String description = null;
158         String reference = null;
159         for (int i = 0; i < ctx.getChildCount(); i++) {
160             ParseTree child = ctx.getChild(i);
161             if (child instanceof Description_stmtContext) {
162                 description = stringFromNode(child);
163             } else if (child instanceof Reference_stmtContext) {
164                 reference = stringFromNode(child);
165             } else {
166                 if (description != null && reference != null) {
167                     break;
168                 }
169             }
170         }
171         moduleBuilder.setDescription(description);
172         moduleBuilder.setReference(reference);
173     }
174
175     @Override
176     public void exitModule_stmt(final YangParser.Module_stmtContext ctx) {
177         exitLog("module");
178         stack.pop();
179     }
180
181     @Override
182     public void enterSubmodule_stmt(final YangParser.Submodule_stmtContext ctx) {
183         moduleName = stringFromNode(ctx);
184         LOG.trace("entering submodule {}", moduleName);
185         enterLog("submodule", moduleName, 0);
186         stack.push();
187
188         moduleBuilder = new ModuleBuilder(moduleName, true, sourcePath);
189
190         String description = null;
191         String reference = null;
192         for (int i = 0; i < ctx.getChildCount(); i++) {
193             ParseTree child = ctx.getChild(i);
194             if (child instanceof Description_stmtContext) {
195                 description = stringFromNode(child);
196             } else if (child instanceof Reference_stmtContext) {
197                 reference = stringFromNode(child);
198             } else {
199                 if (description != null && reference != null) {
200                     break;
201                 }
202             }
203         }
204         moduleBuilder.setDescription(description);
205         moduleBuilder.setReference(reference);
206     }
207
208     @Override
209     public void exitSubmodule_stmt(final YangParser.Submodule_stmtContext ctx) {
210         exitLog("submodule");
211         stack.pop();
212     }
213
214     @Override
215     public void enterBelongs_to_stmt(final YangParser.Belongs_to_stmtContext ctx) {
216         final String belongsTo = stringFromNode(ctx);
217         TreeMap<Date, URI> context = namespaceContext.get(belongsTo);
218         Map.Entry<Date, URI> entry = context.firstEntry();
219         // TODO
220         // Submodule will contain namespace and revision from module to which it
221         // belongs. If there are multiple modules with same name and different
222         // revisions, it will has revision from the newest one.
223         this.moduleQName = QName.create(entry.getValue(), entry.getKey(), moduleQName.getLocalName());
224         moduleBuilder.setQNameModule(moduleQName.getModule());
225         moduleBuilder.setBelongsTo(belongsTo);
226     }
227
228     @Override
229     public void enterModule_header_stmts(final Module_header_stmtsContext ctx) {
230         enterLog("module_header", "", ctx.getStart().getLine());
231         String yangVersion = null;
232         for (int i = 0; i < ctx.getChildCount(); ++i) {
233             final ParseTree treeNode = ctx.getChild(i);
234             if (treeNode instanceof Namespace_stmtContext) {
235                 final String namespaceStr = stringFromNode(treeNode);
236                 final URI namespace = URI.create(namespaceStr);
237                 this.moduleQName = QName.create(namespace, moduleQName.getRevision(), moduleQName.getLocalName());
238                 moduleBuilder.setQNameModule(moduleQName.getModule());
239                 setLog("namespace", namespaceStr);
240             } else if (treeNode instanceof Prefix_stmtContext) {
241                 yangModelPrefix = stringFromNode(treeNode);
242                 this.moduleQName = QName.create(moduleQName.getModule(), yangModelPrefix, moduleQName.getLocalName());
243                 moduleBuilder.setPrefix(yangModelPrefix);
244                 setLog("prefix", yangModelPrefix);
245             } else if (treeNode instanceof Yang_version_stmtContext) {
246                 yangVersion = stringFromNode(treeNode);
247                 setLog("yang-version", yangVersion);
248             }
249         }
250
251         if (yangVersion == null) {
252             yangVersion = "1";
253         }
254         moduleBuilder.setYangVersion(yangVersion);
255     }
256
257     @Override
258     public void exitModule_header_stmts(final Module_header_stmtsContext ctx) {
259         exitLog("module_header");
260     }
261
262     @Override
263     public void enterMeta_stmts(final YangParser.Meta_stmtsContext ctx) {
264         enterLog("meta_stmt", "", ctx.getStart().getLine());
265         for (int i = 0; i < ctx.getChildCount(); i++) {
266             ParseTree child = ctx.getChild(i);
267             if (child instanceof Organization_stmtContext) {
268                 final String organization = stringFromNode(child);
269                 moduleBuilder.setOrganization(organization);
270                 setLog("organization", organization);
271             } else if (child instanceof Contact_stmtContext) {
272                 final String contact = stringFromNode(child);
273                 moduleBuilder.setContact(contact);
274                 setLog("contact", contact);
275             } else if (child instanceof Description_stmtContext) {
276                 final String description = stringFromNode(child);
277                 moduleBuilder.setDescription(description);
278                 setLog("description", description);
279             } else if (child instanceof Reference_stmtContext) {
280                 final String reference = stringFromNode(child);
281                 moduleBuilder.setReference(reference);
282                 setLog("reference", reference);
283             }
284         }
285     }
286
287     @Override
288     public void exitMeta_stmts(final YangParser.Meta_stmtsContext ctx) {
289         exitLog("meta_stmt");
290     }
291
292     @Override
293     public void enterRevision_stmts(final Revision_stmtsContext ctx) {
294         enterLog("revisions", "", ctx.getStart().getLine());
295         for (int i = 0; i < ctx.getChildCount(); ++i) {
296             final ParseTree treeNode = ctx.getChild(i);
297             if (treeNode instanceof Revision_stmtContext) {
298                 updateRevisionForRevisionStatement(treeNode);
299             }
300         }
301     }
302
303     @Override
304     public void exitRevision_stmts(final Revision_stmtsContext ctx) {
305         exitLog("revisions");
306     }
307
308     private void updateRevisionForRevisionStatement(final ParseTree treeNode) {
309         final String revisionDateStr = stringFromNode(treeNode);
310         try {
311             final Date revisionDate = SIMPLE_DATE_FORMAT.parse(revisionDateStr);
312             if ((revisionDate != null) && (this.moduleQName.getRevision().compareTo(revisionDate) < 0)) {
313                 this.moduleQName = QName.create(moduleQName.getNamespace(), revisionDate, moduleQName.getLocalName());
314                 moduleBuilder.setQNameModule(moduleQName.getModule());
315                 setLog("revision", revisionDate.toString());
316                 for (int i = 0; i < treeNode.getChildCount(); ++i) {
317                     ParseTree child = treeNode.getChild(i);
318                     if (child instanceof Reference_stmtContext) {
319                         moduleBuilder.setReference(stringFromNode(child));
320                     }
321                 }
322             }
323         } catch (ParseException e) {
324             LOG.warn("Failed to parse revision string: {}", revisionDateStr, e);
325         }
326     }
327
328     @Override
329     public void enterImport_stmt(final Import_stmtContext ctx) {
330         final int line = ctx.getStart().getLine();
331         final String importName = stringFromNode(ctx);
332         enterLog("import", importName, line);
333
334         String importPrefix = null;
335         Date importRevision = null;
336
337         for (int i = 0; i < ctx.getChildCount(); ++i) {
338             final ParseTree treeNode = ctx.getChild(i);
339             if (treeNode instanceof Prefix_stmtContext) {
340                 importPrefix = stringFromNode(treeNode);
341             }
342             if (treeNode instanceof Revision_date_stmtContext) {
343                 String importRevisionStr = stringFromNode(treeNode);
344                 try {
345                     importRevision = SIMPLE_DATE_FORMAT.parse(importRevisionStr);
346                 } catch (ParseException e) {
347                     LOG.warn("Failed to parse import revision-date at line {}: {}", line, importRevisionStr, e);
348                 }
349             }
350         }
351         moduleBuilder.addModuleImport(importName, importRevision, importPrefix);
352         LOG.trace("setting import ({}; {}; {})", importName, importRevision, importPrefix);
353     }
354
355     @Override
356     public void exitImport_stmt(final Import_stmtContext ctx) {
357         exitLog("import");
358     }
359
360     @Override
361     public void enterInclude_stmt(YangParser.Include_stmtContext ctx) {
362         final int line = ctx.getStart().getLine();
363         final String includeName = stringFromNode(ctx);
364         enterLog("import", includeName, line);
365
366         Date includeRevision = null;
367         for (int i = 0; i < ctx.getChildCount(); i++) {
368             ParseTree treeNode = ctx.getChild(i);
369             if (treeNode instanceof Revision_date_stmtContext) {
370                 String importRevisionStr = stringFromNode(treeNode);
371                 try {
372                     includeRevision = SIMPLE_DATE_FORMAT.parse(importRevisionStr);
373                 } catch (ParseException e) {
374                     LOG.warn("Failed to parse import revision-date at line {}: {}", line, importRevisionStr, e);
375                 }
376             }
377         }
378         moduleBuilder.addInclude(includeName, includeRevision);
379     }
380
381     @Override public void exitInclude_stmt(YangParser.Include_stmtContext ctx) {
382         exitLog("include");
383     }
384
385     @Override
386     public void enterAugment_stmt(final YangParser.Augment_stmtContext ctx) {
387         final int line = ctx.getStart().getLine();
388         final String augmentPath = stringFromNode(ctx);
389         enterLog(AUGMENT_STR, augmentPath, line);
390         stack.push();
391
392         SchemaPath targetPath = parseXPathString(augmentPath, line);
393         AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath, augmentOrder++);
394
395         for (int i = 0; i < ctx.getChildCount(); i++) {
396             ParseTree child = ctx.getChild(i);
397             if (child instanceof Description_stmtContext) {
398                 builder.setDescription(stringFromNode(child));
399             } else if (child instanceof Reference_stmtContext) {
400                 builder.setReference(stringFromNode(child));
401             } else if (child instanceof Status_stmtContext) {
402                 builder.setStatus(parseStatus((Status_stmtContext) child));
403             } else if (child instanceof When_stmtContext) {
404                 builder.addWhenCondition(stringFromNode(child));
405             }
406         }
407
408         moduleBuilder.enterNode(builder);
409     }
410
411     @Override
412     public void exitAugment_stmt(final YangParser.Augment_stmtContext ctx) {
413         moduleBuilder.exitNode();
414         exitLog(AUGMENT_STR);
415         stack.pop();
416     }
417
418     @Override
419     public void enterExtension_stmt(final YangParser.Extension_stmtContext ctx) {
420         final int line = ctx.getStart().getLine();
421         final String extName = stringFromNode(ctx);
422         enterLog("extension", extName, line);
423         QName qname = QName.create(moduleQName, extName);
424         SchemaPath path = stack.addNodeToPath(qname);
425
426         ExtensionBuilder builder = moduleBuilder.addExtension(qname, line, path);
427         parseSchemaNodeArgs(ctx, builder);
428
429         String argument = null;
430         boolean yin = false;
431         for (int i = 0; i < ctx.getChildCount(); i++) {
432             ParseTree child = ctx.getChild(i);
433             if (child instanceof Argument_stmtContext) {
434                 argument = stringFromNode(child);
435                 yin = parseYinValue((Argument_stmtContext) child);
436                 break;
437             }
438         }
439         builder.setArgument(argument);
440         builder.setYinElement(yin);
441
442         moduleBuilder.enterNode(builder);
443     }
444
445     @Override
446     public void exitExtension_stmt(final YangParser.Extension_stmtContext ctx) {
447         moduleBuilder.exitNode();
448         exitLog("extension", stack.removeNodeFromPath());
449     }
450
451     @Override
452     public void enterTypedef_stmt(final YangParser.Typedef_stmtContext ctx) {
453         final int line = ctx.getStart().getLine();
454         final String typedefName = stringFromNode(ctx);
455         enterLog("typedef", typedefName, line);
456         QName typedefQName = QName.create(moduleQName, typedefName);
457         SchemaPath path = stack.addNodeToPath(typedefQName);
458
459         TypeDefinitionBuilder builder = moduleBuilder.addTypedef(line, typedefQName, path);
460         parseSchemaNodeArgs(ctx, builder);
461         builder.setUnits(parseUnits(ctx));
462         builder.setDefaultValue(parseDefault(ctx));
463
464         moduleBuilder.enterNode(builder);
465     }
466
467     @Override
468     public void exitTypedef_stmt(final YangParser.Typedef_stmtContext ctx) {
469         moduleBuilder.exitNode();
470         exitLog("typedef", stack.removeNodeFromPath());
471     }
472
473     @Override
474     public void enterType_stmt(final YangParser.Type_stmtContext ctx) {
475         final int line = ctx.getStart().getLine();
476         final String typeName = stringFromNode(ctx);
477         enterLog("type", typeName, line);
478
479         final QName typeQName = parseQName(typeName, line);
480
481         TypeDefinition<?> type;
482         Type_body_stmtsContext typeBody = null;
483         for (int i = 0; i < ctx.getChildCount(); i++) {
484             if (ctx.getChild(i) instanceof Type_body_stmtsContext) {
485                 typeBody = (Type_body_stmtsContext) ctx.getChild(i);
486                 break;
487             }
488         }
489
490         // if this is base yang type...
491         if (BaseTypes.isYangBuildInType(typeName)) {
492             if (typeBody == null) {
493                 // check for types which must have body
494                 checkMissingBody(typeName, moduleName, line);
495                 // if there are no constraints, just grab default base yang type
496                 type = BaseTypes.defaultBaseTypeFor(typeName).orNull();
497                 stack.addNodeToPath(type.getQName());
498                 moduleBuilder.setType(type);
499             } else {
500                 QName qname;
501                 switch (typeName) {
502                 case "union":
503                     qname = BaseTypes.UNION_QNAME;
504                     stack.addNodeToPath(qname);
505                     UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(line, moduleQName.getModule());
506                     Builder parent = moduleBuilder.getActualNode();
507                     unionBuilder.setParent(parent);
508                     moduleBuilder.enterNode(unionBuilder);
509                     break;
510                 case "identityref":
511                     qname = BaseTypes.IDENTITYREF_QNAME;
512                     SchemaPath path = stack.addNodeToPath(qname);
513                     moduleBuilder.addIdentityrefType(line, path, getIdentityrefBase(typeBody));
514                     break;
515                 default:
516                     type = parseTypeWithBody(typeName, typeBody, stack.currentSchemaPath(), moduleQName,
517                             moduleBuilder.getActualNode());
518                     moduleBuilder.setType(type);
519                     stack.addNodeToPath(type.getQName());
520                 }
521             }
522         } else {
523             TypeAwareBuilder parent = (TypeAwareBuilder) moduleBuilder.getActualNode();
524             if (typeBody == null) {
525                 parent.setTypeQName(typeQName);
526                 moduleBuilder.markActualNodeDirty();
527             } else {
528                 ParserListenerUtils.parseUnknownTypeWithBody(typeBody, parent, typeQName, moduleBuilder,
529                         moduleQName, stack.currentSchemaPath());
530             }
531             stack.addNodeToPath(QName.create(moduleQName.getModule(), typeQName.getLocalName()));
532         }
533     }
534
535     private QName parseQName(final String qnameString, final int line) {
536         final QName qname;
537         if (qnameString.indexOf(':') == -1) {
538             qname = QName.create(moduleQName.getNamespace(), moduleQName.getRevision(), qnameString);
539         } else {
540             final Iterator<String> split = COLON_SPLITTER.split(qnameString).iterator();
541             final String prefix = split.next();
542             final String name = split.next();
543             if (prefix.equals(moduleBuilder.getPrefix())) {
544                 qname = QName.create(moduleQName.getNamespace(), moduleQName.getRevision(), name);
545             } else {
546                 ModuleImport imp = moduleBuilder.getImport(prefix);
547                 if (imp == null) {
548                     LOG.warn("Error in module {} at line {}: No import found with prefix {}", moduleName, line, prefix);
549                     return QName.create(name);
550                 }
551                 Date revision = imp.getRevision();
552                 TreeMap<Date, URI> namespaces = namespaceContext.get(imp.getModuleName());
553                 URI namespace;
554                 if (revision == null) {
555                     if (namespaces == null) {
556                         throw new YangParseException(moduleName, line, "imported module " + imp.getModuleName()
557                                 + " with prefix " + imp.getPrefix() + " not found.");
558                     }
559                     revision = namespaces.lastEntry().getKey();
560                     namespace = namespaces.lastEntry().getValue();
561                 } else {
562                     namespace = namespaces.get(revision);
563                 }
564                 qname = QName.create(namespace, revision, name);
565             }
566         }
567         return qname;
568     }
569
570     @Override
571     public void exitType_stmt(final YangParser.Type_stmtContext ctx) {
572         final String typeName = stringFromNode(ctx);
573         if ("union".equals(typeName)) {
574             moduleBuilder.exitNode();
575         }
576         exitLog("type", stack.removeNodeFromPath());
577     }
578
579     @Override
580     public void enterGrouping_stmt(final YangParser.Grouping_stmtContext ctx) {
581         final int line = ctx.getStart().getLine();
582         final String groupName = stringFromNode(ctx);
583         enterLog("grouping", groupName, line);
584         QName groupQName = QName.create(moduleQName, groupName);
585         SchemaPath path = stack.addNodeToPath(groupQName);
586
587         GroupingBuilder builder = moduleBuilder.addGrouping(ctx.getStart().getLine(), groupQName, path);
588         parseSchemaNodeArgs(ctx, builder);
589
590         moduleBuilder.enterNode(builder);
591     }
592
593     @Override
594     public void exitGrouping_stmt(final YangParser.Grouping_stmtContext ctx) {
595         moduleBuilder.exitNode();
596         exitLog("grouping", stack.removeNodeFromPath());
597     }
598
599     @Override
600     public void enterContainer_stmt(final Container_stmtContext ctx) {
601         final int line = ctx.getStart().getLine();
602         final String containerName = stringFromNode(ctx);
603         enterLog("container", containerName, line);
604
605         QName containerQName = QName.create(moduleQName, containerName);
606         SchemaPath path = stack.addNodeToPath(containerQName);
607
608         ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(line, containerQName, path);
609         parseSchemaNodeArgs(ctx, builder);
610         parseConstraints(ctx, builder.getConstraints());
611         builder.setConfiguration(getConfig(ctx, builder, moduleName, line));
612
613         for (int i = 0; i < ctx.getChildCount(); ++i) {
614             final ParseTree childNode = ctx.getChild(i);
615             if (childNode instanceof Presence_stmtContext) {
616                 builder.setPresence(true);
617                 break;
618             }
619         }
620
621         moduleBuilder.enterNode(builder);
622     }
623
624     @Override
625     public void exitContainer_stmt(final Container_stmtContext ctx) {
626         moduleBuilder.exitNode();
627         exitLog("container", stack.removeNodeFromPath());
628     }
629
630     @Override
631     public void enterLeaf_stmt(final Leaf_stmtContext ctx) {
632         final int line = ctx.getStart().getLine();
633         final String leafName = stringFromNode(ctx);
634         enterLog("leaf", leafName, line);
635
636         QName leafQName = QName.create(moduleQName, leafName);
637         SchemaPath path = stack.addNodeToPath(leafQName);
638
639         LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(line, leafQName, path);
640         parseSchemaNodeArgs(ctx, builder);
641         parseConstraints(ctx, builder.getConstraints());
642         builder.setConfiguration(getConfig(ctx, builder, moduleName, line));
643
644         String defaultStr = null;
645         String unitsStr = null;
646         for (int i = 0; i < ctx.getChildCount(); i++) {
647             ParseTree child = ctx.getChild(i);
648             if (child instanceof Default_stmtContext) {
649                 defaultStr = stringFromNode(child);
650             } else if (child instanceof Units_stmtContext) {
651                 unitsStr = stringFromNode(child);
652             }
653         }
654         builder.setDefaultStr(defaultStr);
655         builder.setUnits(unitsStr);
656
657         moduleBuilder.enterNode(builder);
658     }
659
660     @Override
661     public void exitLeaf_stmt(final YangParser.Leaf_stmtContext ctx) {
662         moduleBuilder.exitNode();
663         exitLog("leaf", stack.removeNodeFromPath());
664     }
665
666     @Override
667     public void enterUses_stmt(final YangParser.Uses_stmtContext ctx) {
668         final int line = ctx.getStart().getLine();
669         final String groupingPathStr = stringFromNode(ctx);
670         final SchemaPath groupingPath = parseXPathString(groupingPathStr, line);
671         enterLog("uses", groupingPathStr, line);
672
673         UsesNodeBuilder builder = moduleBuilder.addUsesNode(line, groupingPath);
674
675         moduleBuilder.enterNode(builder);
676     }
677
678     @Override
679     public void exitUses_stmt(final YangParser.Uses_stmtContext ctx) {
680         moduleBuilder.exitNode();
681         exitLog("uses");
682     }
683
684     @Override
685     public void enterUses_augment_stmt(final YangParser.Uses_augment_stmtContext ctx) {
686         final int line = ctx.getStart().getLine();
687         final String augmentPath = stringFromNode(ctx);
688         enterLog(AUGMENT_STR, augmentPath, line);
689         stack.push();
690
691         SchemaPath targetPath = parseXPathString(augmentPath, line);
692         AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, targetPath, augmentOrder++);
693
694         for (int i = 0; i < ctx.getChildCount(); i++) {
695             ParseTree child = ctx.getChild(i);
696             if (child instanceof Description_stmtContext) {
697                 builder.setDescription(stringFromNode(child));
698             } else if (child instanceof Reference_stmtContext) {
699                 builder.setReference(stringFromNode(child));
700             } else if (child instanceof Status_stmtContext) {
701                 builder.setStatus(parseStatus((Status_stmtContext) child));
702             } else if (child instanceof When_stmtContext) {
703                 builder.addWhenCondition(stringFromNode(child));
704             }
705         }
706
707         moduleBuilder.enterNode(builder);
708     }
709
710     @Override
711     public void exitUses_augment_stmt(final YangParser.Uses_augment_stmtContext ctx) {
712         moduleBuilder.exitNode();
713         exitLog(AUGMENT_STR);
714         stack.pop();
715     }
716
717     @Override
718     public void enterRefine_stmt(final YangParser.Refine_stmtContext ctx) {
719         final String refineString = stringFromNode(ctx);
720         enterLog("refine", refineString, ctx.getStart().getLine());
721
722         RefineHolderImpl refine = parseRefine(ctx, moduleName);
723         moduleBuilder.addRefine(refine);
724         moduleBuilder.enterNode(refine);
725     }
726
727     @Override
728     public void exitRefine_stmt(final YangParser.Refine_stmtContext ctx) {
729         moduleBuilder.exitNode();
730         exitLog("refine");
731     }
732
733     @Override
734     public void enterLeaf_list_stmt(final Leaf_list_stmtContext ctx) {
735         final int line = ctx.getStart().getLine();
736         final String leafListName = stringFromNode(ctx);
737         enterLog("leaf-list", leafListName, line);
738         QName leafListQName = QName.create(moduleQName, leafListName);
739         SchemaPath path = stack.addNodeToPath(leafListQName);
740
741         LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(line, leafListQName, path);
742         moduleBuilder.enterNode(builder);
743
744         parseSchemaNodeArgs(ctx, builder);
745         parseConstraints(ctx, builder.getConstraints());
746         builder.setConfiguration(getConfig(ctx, builder, moduleName, ctx.getStart().getLine()));
747
748         for (int i = 0; i < ctx.getChildCount(); ++i) {
749             final ParseTree childNode = ctx.getChild(i);
750             if (childNode instanceof Ordered_by_stmtContext) {
751                 final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
752                 final boolean userOrdered = parseUserOrdered(orderedBy);
753                 builder.setUserOrdered(userOrdered);
754                 break;
755             }
756         }
757     }
758
759     @Override
760     public void exitLeaf_list_stmt(final YangParser.Leaf_list_stmtContext ctx) {
761         moduleBuilder.exitNode();
762         exitLog("leaf-list", stack.removeNodeFromPath());
763     }
764
765     @Override
766     public void enterList_stmt(final List_stmtContext ctx) {
767         final int line = ctx.getStart().getLine();
768         final String listName = stringFromNode(ctx);
769         enterLog("list", listName, line);
770
771         QName listQName = QName.create(moduleQName, listName);
772         SchemaPath path = stack.addNodeToPath(listQName);
773
774         ListSchemaNodeBuilder builder = moduleBuilder.addListNode(line, listQName, path);
775         moduleBuilder.enterNode(builder);
776
777         parseSchemaNodeArgs(ctx, builder);
778         parseConstraints(ctx, builder.getConstraints());
779         builder.setConfiguration(getConfig(ctx, builder, moduleName, line));
780
781         for (int i = 0; i < ctx.getChildCount(); ++i) {
782             ParseTree childNode = ctx.getChild(i);
783             if (childNode instanceof Ordered_by_stmtContext) {
784                 final Ordered_by_stmtContext orderedBy = (Ordered_by_stmtContext) childNode;
785                 final boolean userOrdered = parseUserOrdered(orderedBy);
786                 builder.setUserOrdered(userOrdered);
787             } else if (childNode instanceof Key_stmtContext) {
788                 List<String> key = createListKey((Key_stmtContext) childNode);
789                 builder.setKeys(key);
790             }
791         }
792     }
793
794     @Override
795     public void exitList_stmt(final List_stmtContext ctx) {
796         moduleBuilder.exitNode();
797         exitLog("list", stack.removeNodeFromPath());
798     }
799
800     @Override
801     public void enterAnyxml_stmt(final YangParser.Anyxml_stmtContext ctx) {
802         final int line = ctx.getStart().getLine();
803         final String anyXmlName = stringFromNode(ctx);
804         enterLog("anyxml", anyXmlName, line);
805
806         QName anyXmlQName = QName.create(moduleQName, anyXmlName);
807         SchemaPath path = stack.addNodeToPath(anyXmlQName);
808
809         AnyXmlBuilder builder = moduleBuilder.addAnyXml(line, anyXmlQName, path);
810         moduleBuilder.enterNode(builder);
811
812         parseSchemaNodeArgs(ctx, builder);
813         parseConstraints(ctx, builder.getConstraints());
814         builder.setConfiguration(getConfig(ctx, builder, moduleName, line));
815     }
816
817     @Override
818     public void exitAnyxml_stmt(final YangParser.Anyxml_stmtContext ctx) {
819         moduleBuilder.exitNode();
820         exitLog("anyxml", stack.removeNodeFromPath());
821     }
822
823     @Override
824     public void enterChoice_stmt(final YangParser.Choice_stmtContext ctx) {
825         final int line = ctx.getStart().getLine();
826         final String choiceName = stringFromNode(ctx);
827         enterLog("choice", choiceName, line);
828
829         QName choiceQName = QName.create(moduleQName, choiceName);
830         SchemaPath path = stack.addNodeToPath(choiceQName);
831
832         ChoiceBuilder builder = moduleBuilder.addChoice(line, choiceQName, path);
833         moduleBuilder.enterNode(builder);
834
835         parseSchemaNodeArgs(ctx, builder);
836         parseConstraints(ctx, builder.getConstraints());
837         builder.setConfiguration(getConfig(ctx, builder, moduleName, line));
838
839         // set 'default' case
840         for (int i = 0; i < ctx.getChildCount(); i++) {
841             ParseTree child = ctx.getChild(i);
842             if (child instanceof Default_stmtContext) {
843                 String defaultCase = stringFromNode(child);
844                 builder.setDefaultCase(defaultCase);
845                 break;
846             }
847         }
848     }
849
850     @Override
851     public void exitChoice_stmt(final YangParser.Choice_stmtContext ctx) {
852         moduleBuilder.exitNode();
853         exitLog("choice", stack.removeNodeFromPath());
854     }
855
856     @Override
857     public void enterCase_stmt(final YangParser.Case_stmtContext ctx) {
858         final int line = ctx.getStart().getLine();
859         final String caseName = stringFromNode(ctx);
860         enterLog("case", caseName, line);
861
862         QName caseQName = QName.create(moduleQName, caseName);
863         SchemaPath path = stack.addNodeToPath(caseQName);
864
865         ChoiceCaseBuilder builder = moduleBuilder.addCase(line, caseQName, path);
866         moduleBuilder.enterNode(builder);
867
868         parseSchemaNodeArgs(ctx, builder);
869         parseConstraints(ctx, builder.getConstraints());
870     }
871
872     @Override
873     public void exitCase_stmt(final YangParser.Case_stmtContext ctx) {
874         moduleBuilder.exitNode();
875         exitLog("case", stack.removeNodeFromPath());
876     }
877
878     @Override
879     public void enterNotification_stmt(final YangParser.Notification_stmtContext ctx) {
880         final int line = ctx.getStart().getLine();
881         final String notificationName = stringFromNode(ctx);
882         enterLog("notification", notificationName, line);
883
884         QName notificationQName = QName.create(moduleQName, notificationName);
885         SchemaPath path = stack.addNodeToPath(notificationQName);
886
887         NotificationBuilder builder = moduleBuilder.addNotification(line, notificationQName, path);
888         moduleBuilder.enterNode(builder);
889
890         parseSchemaNodeArgs(ctx, builder);
891     }
892
893     @Override
894     public void exitNotification_stmt(final YangParser.Notification_stmtContext ctx) {
895         moduleBuilder.exitNode();
896         exitLog("notification", stack.removeNodeFromPath());
897     }
898
899     // Unknown nodes
900     @Override
901     public void enterIdentifier_stmt(final YangParser.Identifier_stmtContext ctx) {
902         handleUnknownNode(ctx.getStart().getLine(), ctx);
903     }
904
905     @Override
906     public void exitIdentifier_stmt(final YangParser.Identifier_stmtContext ctx) {
907         moduleBuilder.exitNode();
908         exitLog("unknown-node", stack.removeNodeFromPath());
909     }
910
911     @Override public void enterUnknown_statement(final YangParser.Unknown_statementContext ctx) {
912         handleUnknownNode(ctx.getStart().getLine(), ctx);
913     }
914
915     @Override public void exitUnknown_statement(final YangParser.Unknown_statementContext ctx) {
916         moduleBuilder.exitNode();
917         exitLog("unknown-node", stack.removeNodeFromPath());
918     }
919
920     @Override
921     public void enterRpc_stmt(final YangParser.Rpc_stmtContext ctx) {
922         final int line = ctx.getStart().getLine();
923         final String rpcName = stringFromNode(ctx);
924         enterLog("rpc", rpcName, line);
925
926         QName rpcQName = QName.create(moduleQName, rpcName);
927         SchemaPath path = stack.addNodeToPath(rpcQName);
928
929         RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(line, rpcQName, path);
930         moduleBuilder.enterNode(rpcBuilder);
931
932
933         parseSchemaNodeArgs(ctx, rpcBuilder);
934     }
935
936     @Override
937     public void exitRpc_stmt(final YangParser.Rpc_stmtContext ctx) {
938         moduleBuilder.exitNode();
939         exitLog("rpc", stack.removeNodeFromPath());
940     }
941
942     @Override
943     public void enterInput_stmt(final YangParser.Input_stmtContext ctx) {
944         final int line = ctx.getStart().getLine();
945         final String input = "input";
946         enterLog(input, input, line);
947
948         QName rpcQName = QName.create(moduleQName, input);
949         SchemaPath path = stack.addNodeToPath(rpcQName);
950
951         ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(line, rpcQName, path);
952         moduleBuilder.enterNode(builder);
953         builder.setConfiguration(true);
954
955         parseSchemaNodeArgs(ctx, builder);
956         parseConstraints(ctx, builder.getConstraints());
957     }
958
959     @Override
960     public void exitInput_stmt(final YangParser.Input_stmtContext ctx) {
961         moduleBuilder.exitNode();
962         exitLog("input", stack.removeNodeFromPath());
963     }
964
965     @Override
966     public void enterOutput_stmt(final YangParser.Output_stmtContext ctx) {
967         final int line = ctx.getStart().getLine();
968         final String output = "output";
969         enterLog(output, output, line);
970
971         QName rpcQName = QName.create(moduleQName, output);
972         SchemaPath path = stack.addNodeToPath(rpcQName);
973
974         ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(path, rpcQName, line);
975         moduleBuilder.enterNode(builder);
976         builder.setConfiguration(true);
977
978         parseSchemaNodeArgs(ctx, builder);
979         parseConstraints(ctx, builder.getConstraints());
980     }
981
982     @Override
983     public void exitOutput_stmt(final YangParser.Output_stmtContext ctx) {
984         moduleBuilder.exitNode();
985         exitLog("output", stack.removeNodeFromPath());
986     }
987
988     @Override
989     public void enterFeature_stmt(final YangParser.Feature_stmtContext ctx) {
990         final int line = ctx.getStart().getLine();
991         final String featureName = stringFromNode(ctx);
992         enterLog("feature", featureName, line);
993
994         QName featureQName = QName.create(moduleQName, featureName);
995         SchemaPath path = stack.addNodeToPath(featureQName);
996
997         FeatureBuilder featureBuilder = moduleBuilder.addFeature(line, featureQName, path);
998         moduleBuilder.enterNode(featureBuilder);
999
1000         parseSchemaNodeArgs(ctx, featureBuilder);
1001     }
1002
1003     @Override
1004     public void exitFeature_stmt(final YangParser.Feature_stmtContext ctx) {
1005         moduleBuilder.exitNode();
1006         exitLog("feature", stack.removeNodeFromPath());
1007     }
1008
1009     @Override
1010     public void enterDeviation_stmt(final YangParser.Deviation_stmtContext ctx) {
1011         final int line = ctx.getStart().getLine();
1012         final String targetPathStr = stringFromNode(ctx);
1013         if (!targetPathStr.startsWith("/")) {
1014             throw new YangParseException(moduleName, line,
1015                     "Deviation argument string must be an absolute schema node identifier.");
1016         }
1017         enterLog("deviation", targetPathStr, line);
1018
1019         String reference = null;
1020         String deviate = null;
1021
1022         SchemaPath targetPath = parseXPathString(targetPathStr, line);
1023         DeviationBuilder builder = moduleBuilder.addDeviation(line, targetPath);
1024         moduleBuilder.enterNode(builder);
1025
1026         for (int i = 0; i < ctx.getChildCount(); i++) {
1027             ParseTree child = ctx.getChild(i);
1028             if (child instanceof Reference_stmtContext) {
1029                 reference = stringFromNode(child);
1030             } else if (child instanceof Deviate_not_supported_stmtContext) {
1031                 deviate = stringFromNode(child);
1032             } else if (child instanceof Deviate_add_stmtContext) {
1033                 deviate = stringFromNode(child);
1034             } else if (child instanceof Deviate_replace_stmtContext) {
1035                 deviate = stringFromNode(child);
1036             } else if (child instanceof Deviate_delete_stmtContext) {
1037                 deviate = stringFromNode(child);
1038             }
1039         }
1040         builder.setReference(reference);
1041         builder.setDeviate(deviate);
1042     }
1043
1044     public SchemaPath parseXPathString(final String xpathString, final int line) {
1045         final boolean absolute = !xpathString.isEmpty() && xpathString.charAt(0) == '/';
1046
1047         final List<QName> path = new ArrayList<>();
1048         for (String pathElement : SLASH_SPLITTER.split(xpathString)) {
1049             final Iterator<String> it = COLON_SPLITTER.split(pathElement).iterator();
1050             final String s = it.next();
1051             if (it.hasNext()) {
1052                 path.add(parseQName(pathElement, line));
1053             } else {
1054                 path.add(QName.create(moduleQName, s));
1055             }
1056         }
1057         return SchemaPath.create(path, absolute);
1058     }
1059
1060     @Override
1061     public void exitDeviation_stmt(final YangParser.Deviation_stmtContext ctx) {
1062         moduleBuilder.exitNode();
1063         exitLog("deviation");
1064     }
1065
1066     @Override
1067     public void enterIdentity_stmt(final YangParser.Identity_stmtContext ctx) {
1068         final int line = ctx.getStart().getLine();
1069         final String identityName = stringFromNode(ctx);
1070         enterLog("identity", identityName, line);
1071
1072         final QName identityQName = QName.create(moduleQName, identityName);
1073         SchemaPath path = stack.addNodeToPath(identityQName);
1074
1075         IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(identityQName, line, path);
1076         moduleBuilder.enterNode(builder);
1077
1078         parseSchemaNodeArgs(ctx, builder);
1079
1080         for (int i = 0; i < ctx.getChildCount(); i++) {
1081             ParseTree child = ctx.getChild(i);
1082             if (child instanceof Base_stmtContext) {
1083                 String baseIdentityName = stringFromNode(child);
1084                 builder.setBaseIdentityName(baseIdentityName);
1085             }
1086         }
1087     }
1088
1089     @Override
1090     public void exitIdentity_stmt(final YangParser.Identity_stmtContext ctx) {
1091         moduleBuilder.exitNode();
1092         exitLog("identity", stack.removeNodeFromPath());
1093     }
1094
1095     public ModuleBuilder getModuleBuilder() {
1096         return moduleBuilder;
1097     }
1098
1099     private static void enterLog(final String p1, final String p2, final int line) {
1100         LOG.trace("entering {} {} ({})", p1, p2, line);
1101     }
1102
1103     private static void exitLog(final String p1) {
1104         LOG.trace("exiting {}", p1);
1105     }
1106
1107     private static void exitLog(final String p1, final QName p2) {
1108         LOG.trace("exiting {} {}", p1, p2.getLocalName());
1109     }
1110
1111     private static void setLog(final String p1, final String p2) {
1112         LOG.trace("setting {} {}", p1, p2);
1113     }
1114
1115     private void handleUnknownNode(final int line, final ParseTree ctx) {
1116         final String nodeParameter = stringFromNode(ctx);
1117         enterLog("unknown-node", nodeParameter, line);
1118
1119         final String nodeTypeStr = ctx.getChild(0).getText();
1120         QName nodeType = parseQName(nodeTypeStr, line);
1121
1122         QName qname = null;
1123         try {
1124             if (Strings.isNullOrEmpty(nodeParameter)) {
1125                 qname = nodeType;
1126             } else {
1127                 final Iterable<String> splittedName = COLON_SPLITTER.split(nodeParameter);
1128                 final Iterator<String> it = splittedName.iterator();
1129                 if (Iterables.size(splittedName) == 2) {
1130                     qname = parseQName(nodeParameter, line);
1131                 } else {
1132                     qname = QName.create(moduleQName, it.next());
1133                 }
1134             }
1135         } catch (IllegalArgumentException e) {
1136             qname = nodeType;
1137         }
1138
1139         SchemaPath path = stack.addNodeToPath(qname);
1140
1141         UnknownSchemaNodeBuilderImpl builder = moduleBuilder.addUnknownSchemaNode(line, qname, path);
1142         builder.setNodeType(nodeType);
1143         builder.setNodeParameter(nodeParameter);
1144
1145         parseSchemaNodeArgs(ctx, builder);
1146         moduleBuilder.enterNode(builder);
1147     }
1148
1149 }