import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.controller.yang.model.api.ChoiceNode;
import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataNodeContainer;
import org.opendaylight.controller.yang.model.api.DataSchemaNode;
import org.opendaylight.controller.yang.model.api.GroupingDefinition;
import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
import org.opendaylight.controller.yang.model.api.ListSchemaNode;
import org.opendaylight.controller.yang.model.api.Module;
import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
import org.opendaylight.controller.yang.model.api.SchemaPath;
import org.opendaylight.controller.yang.model.api.TypeDefinition;
import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.DeviationBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
import org.opendaylight.controller.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
import org.opendaylight.controller.yang.parser.builder.impl.IdentityrefTypeBuilder;
}
}
resolveAugments(modules);
+ resolveDeviations(modules);
// build
// LinkedHashMap MUST be used otherwise the values will not maintain
}
}
resolveAugmentsWithContext(modules, context);
+ resolveDeviationsWithContext(modules, context);
// build
// LinkedHashMap MUST be used otherwise the values will not maintain
* current module
*/
private void resolveDirtyNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- final Map<List<String>, TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
+ final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
if (!dirtyNodes.isEmpty()) {
- for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes.entrySet()) {
- final TypeAwareBuilder nodeToResolve = entry.getValue();
-
+ for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
if (nodeToResolve instanceof UnionTypeBuilder) {
// special handling for union types
resolveTypeUnion((UnionTypeBuilder) nodeToResolve, modules, module);
private void resolveDirtyNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module, SchemaContext context) {
- final Map<List<String>, TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
+ final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
if (!dirtyNodes.isEmpty()) {
- for (Map.Entry<List<String>, TypeAwareBuilder> entry : dirtyNodes.entrySet()) {
- final TypeAwareBuilder nodeToResolve = entry.getValue();
-
+ for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
if (nodeToResolve instanceof UnionTypeBuilder) {
// special handling for union types
resolveTypeUnionWithContext((UnionTypeBuilder) nodeToResolve, modules, module, context);
DataNodeContainerBuilder parent = usesNode.getParent();
SchemaPath parentPath = parent.getPath();
for (DataSchemaNodeBuilder child : targetGrouping.getChildNodeBuilders()) {
- // if node is refined, take it from refined nodes and continue
- SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
- if (refined != null) {
- refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
- parent.addChildNode((DataSchemaNodeBuilder) refined);
- continue;
- }
+ if (child != null) {
+ // if node is refined, take it from refined nodes and continue
+ SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+ if (refined != null) {
+ refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+ parent.addChildNode((DataSchemaNodeBuilder) refined);
+ continue;
+ }
- DataSchemaNodeBuilder newChild = null;
- if (child instanceof AnyXmlBuilder) {
- newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
- } else if (child instanceof ChoiceBuilder) {
- newChild = new ChoiceBuilder((ChoiceBuilder) child);
- } else if (child instanceof ContainerSchemaNodeBuilder) {
- newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
- } else if (child instanceof LeafListSchemaNodeBuilder) {
- newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
- } else if (child instanceof LeafSchemaNodeBuilder) {
- newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
- } else if (child instanceof ListSchemaNodeBuilder) {
- newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
- }
+ DataSchemaNodeBuilder newChild = null;
+ if (child instanceof AnyXmlBuilder) {
+ newChild = new AnyXmlBuilder((AnyXmlBuilder) child);
+ } else if (child instanceof ChoiceBuilder) {
+ newChild = new ChoiceBuilder((ChoiceBuilder) child);
+ } else if (child instanceof ContainerSchemaNodeBuilder) {
+ newChild = new ContainerSchemaNodeBuilder((ContainerSchemaNodeBuilder) child);
+ } else if (child instanceof LeafListSchemaNodeBuilder) {
+ newChild = new LeafListSchemaNodeBuilder((LeafListSchemaNodeBuilder) child);
+ } else if (child instanceof LeafSchemaNodeBuilder) {
+ newChild = new LeafSchemaNodeBuilder((LeafSchemaNodeBuilder) child);
+ } else if (child instanceof ListSchemaNodeBuilder) {
+ newChild = new ListSchemaNodeBuilder((ListSchemaNodeBuilder) child);
+ }
+
+ if (newChild == null) {
+ throw new YangParseException(usesNode.getLine(),
+ "Unknown member of target grouping while resolving uses node.");
+ }
- if (newChild instanceof GroupingMember) {
- ((GroupingMember) newChild).setAddedByUses(true);
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+
+ newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+ parent.addChildNode(newChild);
}
- newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
- parent.addChildNode(newChild);
}
for (GroupingBuilder g : targetGrouping.getGroupingBuilders()) {
GroupingBuilder newGrouping = new GroupingBuilderImpl(g);
DataNodeContainerBuilder parent = usesNode.getParent();
SchemaPath parentPath = parent.getPath();
for (DataSchemaNode child : targetGrouping.getChildNodes()) {
- // if node is refined, take it from refined nodes and continue
- SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
- if (refined != null) {
- refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
- parent.addChildNode((DataSchemaNodeBuilder) refined);
- continue;
- }
+ if (child != null) {
+ // if node is refined, take it from refined nodes and continue
+ SchemaNodeBuilder refined = getRefined(child.getQName(), refineNodes);
+ if (refined != null) {
+ refined.setPath(createSchemaPath(parentPath, refined.getQName().getLocalName()));
+ parent.addChildNode((DataSchemaNodeBuilder) refined);
+ continue;
+ }
- DataSchemaNodeBuilder newChild = null;
- if (child instanceof AnyXmlSchemaNode) {
- newChild = createAnyXml((AnyXmlSchemaNode) child, line);
- } else if (child instanceof ChoiceNode) {
- newChild = createChoice((ChoiceNode) child, line);
- } else if (child instanceof ContainerSchemaNode) {
- newChild = createContainer((ContainerSchemaNode) child, line);
- } else if (child instanceof LeafListSchemaNode) {
- newChild = createLeafList((LeafListSchemaNode) child, line);
- } else if (child instanceof LeafSchemaNode) {
- newChild = createLeafBuilder((LeafSchemaNode) child, line);
- } else if (child instanceof ListSchemaNode) {
- newChild = createList((ListSchemaNode) child, line);
- }
+ DataSchemaNodeBuilder newChild = null;
+ if (child instanceof AnyXmlSchemaNode) {
+ newChild = createAnyXml((AnyXmlSchemaNode) child, line);
+ } else if (child instanceof ChoiceNode) {
+ newChild = createChoice((ChoiceNode) child, line);
+ } else if (child instanceof ContainerSchemaNode) {
+ newChild = createContainer((ContainerSchemaNode) child, line);
+ } else if (child instanceof LeafListSchemaNode) {
+ newChild = createLeafList((LeafListSchemaNode) child, line);
+ } else if (child instanceof LeafSchemaNode) {
+ newChild = createLeafBuilder((LeafSchemaNode) child, line);
+ } else if (child instanceof ListSchemaNode) {
+ newChild = createList((ListSchemaNode) child, line);
+ }
+
+ if (newChild == null) {
+ throw new YangParseException(usesNode.getLine(),
+ "Unknown member of target grouping while resolving uses node.");
+ }
- if (newChild instanceof GroupingMember) {
- ((GroupingMember) newChild).setAddedByUses(true);
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+ newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
+ parent.addChildNode(newChild);
}
- newChild.setPath(createSchemaPath(parentPath, newChild.getQName().getLocalName()));
- parent.addChildNode(newChild);
}
for (GroupingDefinition g : targetGrouping.getGroupings()) {
GroupingBuilder newGrouping = createGrouping(g, line);
}
private void resolveUnknownNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- for (UnknownSchemaNodeBuilder usnb : module.getUnknownNodes()) {
+ for (UnknownSchemaNodeBuilder usnb : module.getAllUnknownNodes()) {
QName nodeType = usnb.getNodeType();
if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
try {
}
private void resolveUnknownNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder module, SchemaContext context) {
- for (UnknownSchemaNodeBuilder unknownNodeBuilder : module.getUnknownNodes()) {
+ final ModuleBuilder module, final SchemaContext context) {
+ for (UnknownSchemaNodeBuilder unknownNodeBuilder : module.getAllUnknownNodes()) {
QName nodeType = unknownNodeBuilder.getNodeType();
if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
try {
}
}
+ private void resolveDeviations(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ ModuleBuilder b = inner.getValue();
+ resolveDeviation(modules, b);
+ }
+ }
+ }
+
+ private void resolveDeviation(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+ for (DeviationBuilder dev : module.getDeviations()) {
+ int line = dev.getLine();
+ SchemaPath targetPath = dev.getTargetPath();
+ List<QName> path = targetPath.getPath();
+ QName q0 = path.get(0);
+ String prefix = q0.getPrefix();
+ if (prefix == null) {
+ prefix = module.getPrefix();
+ }
+
+ ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module, prefix, line);
+ processDeviation(dev, dependentModuleBuilder, path, module);
+ }
+ }
+
+ private void resolveDeviationsWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final SchemaContext context) {
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ ModuleBuilder b = inner.getValue();
+ resolveDeviationWithContext(modules, b, context);
+ }
+ }
+ }
+
+ private void resolveDeviationWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+ final ModuleBuilder module, final SchemaContext context) {
+ for (DeviationBuilder dev : module.getDeviations()) {
+ int line = dev.getLine();
+ SchemaPath targetPath = dev.getTargetPath();
+ List<QName> path = targetPath.getPath();
+ QName q0 = path.get(0);
+ String prefix = q0.getPrefix();
+ if (prefix == null) {
+ prefix = module.getPrefix();
+ }
+ String name = null;
+
+ ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module, prefix, line);
+ if (dependentModuleBuilder == null) {
+ Module dependentModule = findModuleFromContext(context, module, prefix, line);
+ Object currentParent = dependentModule;
+
+ for (int i = 0; i < path.size(); i++) {
+ if (currentParent == null) {
+ throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+ }
+ QName q = path.get(i);
+ name = q.getLocalName();
+ if (currentParent instanceof DataNodeContainer) {
+ currentParent = ((DataNodeContainer) currentParent).getDataChildByName(name);
+ }
+ }
+
+ if (currentParent == null) {
+ throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+ }
+ if (currentParent instanceof SchemaNode) {
+ dev.setTargetPath(((SchemaNode) currentParent).getPath());
+ }
+
+ } else {
+ processDeviation(dev, dependentModuleBuilder, path, module);
+ }
+ }
+ }
+
+ /**
+ * Correct deviation target path in deviation builder.
+ *
+ * @param dev
+ * deviation
+ * @param dependentModuleBuilder
+ * module containing deviation target
+ * @param path
+ * current deviation target path
+ * @param module
+ * current module
+ */
+ private void processDeviation(final DeviationBuilder dev, final ModuleBuilder dependentModuleBuilder,
+ final List<QName> path, final ModuleBuilder module) {
+ final int line = dev.getLine();
+ Builder currentParent = dependentModuleBuilder;
+
+ for (int i = 0; i < path.size(); i++) {
+ if (currentParent == null) {
+ throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+ }
+ QName q = path.get(i);
+ String name = q.getLocalName();
+ if (currentParent instanceof DataNodeContainerBuilder) {
+ currentParent = ((DataNodeContainerBuilder) currentParent).getDataChildByName(name);
+ }
+ }
+
+ if (currentParent == null || !(currentParent instanceof SchemaNodeBuilder)) {
+ throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+ }
+ dev.setTargetPath(((SchemaNodeBuilder) currentParent).getPath());
+ }
+
}