/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
package org.opendaylight.yangtools.yang.model.util;\r
\r
import java.util.Collections;\r
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;\r
\r
/**\r
- * The <code>default</code> implementation of Identityref Type Definition interface.\r
+ * The <code>default</code> implementation of Identityref Type Definition\r
+ * interface.\r
*\r
* @see IdentityrefTypeDefinition\r
*/\r
return baseType;\r
}\r
\r
+ @Override\r
+ public String toString() {\r
+ return "identityref " + identity.getLocalName();\r
+ }\r
+\r
}\r
*/\r
package org.opendaylight.yangtools.yang.model.util;\r
\r
-import java.net.URI;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
import java.util.HashSet;\r
-import java.util.List;\r
import java.util.Set;\r
\r
-import org.opendaylight.yangtools.yang.common.QName;\r
import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
\r
return baseYangTypes.contains(type);\r
}\r
\r
- public static TypeDefinition<?> javaTypeForBaseYangType(\r
- List<String> actualPath, URI namespace, Date revision,\r
- String typeName) {\r
+ public static TypeDefinition<?> javaTypeForBaseYangType(SchemaPath path, String typeName) {\r
TypeDefinition<?> type = null;\r
\r
- SchemaPath path = createSchemaPath(actualPath, namespace, revision, typeName);\r
if (typeName.startsWith("int")) {\r
if ("int8".equals(typeName)) {\r
type = new Int8(path);\r
return type;\r
}\r
\r
- private static SchemaPath createSchemaPath(List<String> actualPath, URI namespace, Date revision, String typeName) {\r
- List<String> correctPath = new ArrayList<String>(actualPath);\r
- // remove module name\r
- correctPath.remove(0);\r
-\r
- List<QName> path = new ArrayList<QName>();\r
- for(String element : correctPath) {\r
- path.add(new QName(namespace, revision, element));\r
- }\r
- // add type qname\r
- QName typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);\r
- path.add(typeQName);\r
- return new SchemaPath(path, true);\r
- }\r
-\r
}\r
import java.util.List;
import java.util.Set;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
void setGroupingPath(SchemaPath groupingPath);
+ GroupingDefinition getGroupingDefinition();
+
+ void setGroupingDefinition(GroupingDefinition groupingDefinition);
+
+ GroupingBuilder getGroupingBuilder();
+
+ void setGrouping(GroupingBuilder grouping);
+
Set<AugmentationSchemaBuilder> getAugmentations();
void addAugment(AugmentationSchemaBuilder builder);
UsesNode build();
- Set<DataSchemaNodeBuilder> getFinalChildren();
-
Set<DataSchemaNodeBuilder> getTargetChildren();
void setTargetChildren(Set<DataSchemaNodeBuilder> targetChildren);
- Set<GroupingBuilder> getFinalGroupings();
-
Set<GroupingBuilder> getTargetGroupings();
void setTargetGroupings(Set<GroupingBuilder> targetGroupings);
- Set<TypeDefinitionBuilder> getFinalTypedefs();
-
Set<TypeDefinitionBuilder> getTargetTypedefs();
void setTargetTypedefs(Set<TypeDefinitionBuilder> targetTypedefs);
- List<UnknownSchemaNodeBuilder> getFinalUnknownNodes();
-
List<UnknownSchemaNodeBuilder> getTargetUnknownNodes();
void setTargetUnknownNodes(List<UnknownSchemaNodeBuilder> targetUnknownNodes);
- List<UsesNodeBuilder> getTargetGroupingUses();
+ boolean isDataCollected();
+
+ void setDataCollected(boolean dataCollected);
- boolean isLoadDone();
+ boolean isParentUpdated();
- void setLoadDone(boolean loadDone);
+ void setParentUpdated(boolean parentUpdated);
}
return instance;
}
- public boolean allUsesLoadDone() {
+ public boolean isAllUsesDataCollected() {
for(UsesNodeBuilder usesNode : allUsesNodes) {
- if(!usesNode.isLoadDone()) {
+ if(!usesNode.isDataCollected()) {
return false;
}
}
return builder;
}
- public IdentitySchemaNodeBuilder addIdentity(final QName qname, final List<String> parentPath, final int line) {
+ public IdentitySchemaNodeBuilder addIdentity(final QName qname, final int line) {
Builder parent = getActualNode();
if (!(parent.equals(this))) {
throw new YangParseException(name, line, "identity can be defined only in module or submodule");
@Override
public String toString() {
- final StringBuilder result = new StringBuilder("TypedefBuilder[" + qname.getLocalName());
- result.append(", type=");
- if (type == null) {
- result.append(typedef);
- } else {
- result.append(type);
- }
- result.append("]");
- return result.toString();
+ return "typedef " + qname.getLocalName();
}
}
}
public List<TypeDefinitionBuilder> getTypedefs() {
- return Collections.unmodifiableList(typedefs);
+ return typedefs;
}
@Override
@Override
public String toString() {
final StringBuilder result = new StringBuilder(UnionTypeBuilder.class.getSimpleName() + "[");
- result.append(", types=" + types);
+ result.append("types=" + types);
result.append(", typedefs=" + typedefs);
result.append("]");
return result.toString();
import java.util.Set;\r
\r
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;\r
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;\r
import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
import org.opendaylight.yangtools.yang.model.api.SchemaPath;\r
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;\r
private DataNodeContainerBuilder parent;\r
private final String groupingName;\r
private SchemaPath groupingPath;\r
+ private GroupingDefinition groupingDefinition;\r
+ private GroupingBuilder groupingBuilder;\r
private boolean augmenting;\r
private boolean addedByUses;\r
private final Set<AugmentationSchemaBuilder> addedAugments = new HashSet<AugmentationSchemaBuilder>();\r
private final List<SchemaNodeBuilder> refineBuilders = new ArrayList<SchemaNodeBuilder>();\r
private final List<RefineHolder> refines = new ArrayList<RefineHolder>();\r
\r
- private final Set<DataSchemaNodeBuilder> finalChildren = new HashSet<>();\r
- private Set<DataSchemaNodeBuilder> targetChildren;\r
+ private Set<DataSchemaNodeBuilder> targetChildren = new HashSet<>();\r
+ private Set<GroupingBuilder> targetGroupings = new HashSet<>();\r
+ private Set<TypeDefinitionBuilder> targetTypedefs = new HashSet<>();\r
+ private List<UnknownSchemaNodeBuilder> targetUnknownNodes = new ArrayList<>();\r
\r
- private final Set<GroupingBuilder> finalGroupings = new HashSet<>();\r
- private Set<GroupingBuilder> targetGroupings;\r
+ private boolean dataCollected;\r
+ private boolean parentUpdated;\r
\r
- private final Set<TypeDefinitionBuilder> finalTypedefs = new HashSet<>();\r
- private Set<TypeDefinitionBuilder> targetTypedefs;\r
-\r
- private final List<UnknownSchemaNodeBuilder> finalUnknownNodes = new ArrayList<>();\r
- private List<UnknownSchemaNodeBuilder> targetUnknownNodes;\r
-\r
- private final List<UsesNodeBuilder> targetGroupingUses = new ArrayList<>();\r
+ @Override\r
+ public boolean isDataCollected() {\r
+ return dataCollected;\r
+ }\r
\r
- boolean loadDone;\r
+ @Override\r
+ public void setDataCollected(boolean dataCollected) {\r
+ this.dataCollected = dataCollected;\r
+ }\r
\r
- public boolean isLoadDone() {\r
- return loadDone;\r
+ @Override\r
+ public boolean isParentUpdated() {\r
+ return parentUpdated;\r
}\r
\r
- public void setLoadDone(boolean loadDone) {\r
- this.loadDone = loadDone;\r
+ @Override\r
+ public void setParentUpdated(boolean parentUpdated) {\r
+ this.parentUpdated = parentUpdated;\r
}\r
\r
public UsesNodeBuilderImpl(final String moduleName, final int line, final String groupingName) {\r
this.groupingPath = groupingPath;\r
}\r
\r
+ @Override\r
+ public GroupingDefinition getGroupingDefinition() {\r
+ return groupingDefinition;\r
+ }\r
+\r
+ @Override\r
+ public void setGroupingDefinition(GroupingDefinition groupingDefinition) {\r
+ this.groupingDefinition = groupingDefinition;\r
+ }\r
+\r
+ @Override\r
+ public GroupingBuilder getGroupingBuilder() {\r
+ return groupingBuilder;\r
+ }\r
+\r
+ @Override\r
+ public void setGrouping(GroupingBuilder grouping) {\r
+ this.groupingBuilder = grouping;\r
+ }\r
+\r
@Override\r
public String getGroupingName() {\r
return groupingName;\r
refines.add(refine);\r
}\r
\r
- @Override\r
- public Set<DataSchemaNodeBuilder> getFinalChildren() {\r
- return finalChildren;\r
- }\r
-\r
@Override\r
public Set<DataSchemaNodeBuilder> getTargetChildren() {\r
return targetChildren;\r
this.targetChildren = targetChildren;\r
}\r
\r
- @Override\r
- public Set<GroupingBuilder> getFinalGroupings() {\r
- return finalGroupings;\r
- }\r
-\r
@Override\r
public Set<GroupingBuilder> getTargetGroupings() {\r
return targetGroupings;\r
this.targetGroupings = targetGroupings;\r
}\r
\r
- @Override\r
- public Set<TypeDefinitionBuilder> getFinalTypedefs() {\r
- return finalTypedefs;\r
- }\r
-\r
@Override\r
public Set<TypeDefinitionBuilder> getTargetTypedefs() {\r
return targetTypedefs;\r
this.targetTypedefs = targetTypedefs;\r
}\r
\r
- @Override\r
- public List<UnknownSchemaNodeBuilder> getFinalUnknownNodes() {\r
- return finalUnknownNodes;\r
- }\r
-\r
@Override\r
public List<UnknownSchemaNodeBuilder> getTargetUnknownNodes() {\r
return targetUnknownNodes;\r
this.targetUnknownNodes = targetUnknownNodes;\r
}\r
\r
- @Override\r
- public List<UsesNodeBuilder> getTargetGroupingUses() {\r
- return targetGroupingUses;\r
- }\r
-\r
@Override\r
public int hashCode() {\r
final int prime = 31;\r
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import org.opendaylight.yangtools.antlrv4.code.gen.YangLexer;
import org.opendaylight.yangtools.antlrv4.code.gen.YangParser;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingMember;
import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.CopyUtils;
import org.opendaylight.yangtools.yang.parser.util.GroupingUtils;
import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
import org.opendaylight.yangtools.yang.parser.util.ParserUtils;
}
private Map<ModuleBuilder, Module> build(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+ findUsesTargets(modules, null);
+
// fix unresolved nodes
for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
fixUnresolvedNodes(modules, moduleBuilder);
}
}
+
+ finishResolveDirtyNodes(modules);
resolveAugments(modules);
- finishResolvingUses(modules);
+ resolveUses(modules);
resolveDeviations(modules);
// build
private Map<ModuleBuilder, Module> buildWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
SchemaContext context) {
+ findUsesTargets(modules, context);
+
// fix unresolved nodes
for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
fixUnresolvedNodesWithContext(modules, moduleBuilder, context);
}
}
+ // TODO finishResolveDirtyNodesWithContext(modules, context)
resolveAugmentsWithContext(modules, context);
+ resolveUsesWithContext(modules, context);
resolveDeviationsWithContext(modules, context);
// build
private void fixUnresolvedNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder builder) {
resolveDirtyNodes(modules, builder);
resolveIdentities(modules, builder);
- resolveUsesNodes(modules, builder);
resolveUnknownNodes(modules, builder);
}
final ModuleBuilder builder, final SchemaContext context) {
resolveDirtyNodesWithContext(modules, builder, context);
resolveIdentitiesWithContext(modules, builder, context);
- resolveUsesNodesWithContext(modules, builder, context);
resolveUnknownNodesWithContext(modules, builder, context);
}
}
}
+ private void finishResolveDirtyNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+ final Set<TypeAwareBuilder> dirtyNodes = new HashSet<>();
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ dirtyNodes.addAll(inner.getValue().getDirtyNodes());
+ }
+ }
+
+ if (!dirtyNodes.isEmpty()) {
+ for (TypeAwareBuilder nodeToResolve : dirtyNodes) {
+ if (nodeToResolve instanceof UnionTypeBuilder) {
+ List<TypeDefinitionBuilder> newTypes = new ArrayList<>();
+ List<TypeDefinitionBuilder> oldTypes = ((UnionTypeBuilder) nodeToResolve).getTypedefs();
+ for (TypeDefinitionBuilder tdb : oldTypes) {
+ TypeDefinitionBuilder newType = CopyUtils.copy(tdb, nodeToResolve, false);
+ ParserUtils.correctTypeAwareNodePath(newType);
+ newTypes.add(newType);
+ }
+ oldTypes.clear();
+ oldTypes.addAll(newTypes);
+ } else if (nodeToResolve.getType() instanceof IdentityrefType) {
+ TypeDefinition<?> idRef = ParserUtils.createCorrectTypeDefinition(nodeToResolve.getPath(),
+ nodeToResolve.getType());
+ nodeToResolve.setType(idRef);
+ } else {
+ TypeDefinitionBuilder tdb = CopyUtils.copy(nodeToResolve.getTypedef(), nodeToResolve, false);
+ ParserUtils.correctTypeAwareNodePath(tdb);
+ nodeToResolve.setTypedef(tdb);
+ }
+ }
+ }
+ }
+
private void resolveDirtyNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
final ModuleBuilder module, SchemaContext context) {
final Set<TypeAwareBuilder> dirtyNodes = module.getDirtyNodes();
ModuleBuilder module = getParentModule(augmentBuilder);
List<QName> path = augmentBuilder.getTargetPath().getPath();
Builder augmentParent = augmentBuilder.getParent();
- boolean isUsesAugment = false;
Builder firstNodeParent = null;
if (augmentParent instanceof ModuleBuilder) {
}
firstNodeParent = findDependentModuleBuilder(modules, module, prefix, line);
} else if (augmentParent instanceof UsesNodeBuilder) {
- // if augment is defined under uses, parent of first node is uses
- // parent
- isUsesAugment = true;
firstNodeParent = augmentParent.getParent();
} else {
// augment can be defined only under module or uses
"Failed to parse augment: Unresolved parent of augment: " + augmentParent);
}
- return processAugmentation(augmentBuilder, firstNodeParent, path, isUsesAugment);
+ return processAugmentation(augmentBuilder, firstNodeParent, path);
}
/**
}
Builder augmentParent = augmentBuilder.getParent();
Builder currentParent = null;
- boolean isUsesAugment = false;
if (augmentParent instanceof ModuleBuilder) {
// if augment is defined under module, first parent is target module
currentParent = findDependentModuleBuilder(modules, module, prefix, line);
} else if (augmentParent instanceof UsesNodeBuilder) {
- // if augment is defined under uses, first parent is uses parent
- isUsesAugment = true;
currentParent = augmentParent.getParent();
} else {
// augment can be defined only under module or uses
if (currentParent == null) {
return processAugmentationOnContext(augmentBuilder, path, module, prefix, context);
} else {
- return processAugmentation(augmentBuilder, currentParent, path, isUsesAugment);
+ return processAugmentation(augmentBuilder, currentParent, path);
}
}
}
/**
- * Go through uses statements defined in current module and resolve their
- * refine statements.
+ * Find target grouping for all uses nodes.
*
* @param modules
- * all modules
- * @param module
- * module being resolved
+ * all loaded modules
*/
- private void resolveUsesNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
- final List<UsesNodeBuilder> allModuleUses = module.getAllUsesNodes();
- List<UsesNodeBuilder> collection = new ArrayList<>(module.getAllUsesNodes());
- boolean usesDataLoaded = module.allUsesLoadDone();
- while (!usesDataLoaded) {
- for (UsesNodeBuilder usesNode : collection) {
- if (!usesNode.isLoadDone()) {
- final GroupingBuilder targetGrouping = GroupingUtils.getTargetGroupingFromModules(usesNode,
- modules, module);
- usesNode.setGroupingPath(targetGrouping.getPath());
- // load uses target nodes in uses
- GroupingUtils.loadTargetGroupingData(usesNode, targetGrouping);
- }
+ private void findUsesTargets(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final SchemaContext context) {
+ final List<UsesNodeBuilder> allUses = new ArrayList<>();
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ allUses.addAll(inner.getValue().getAllUsesNodes());
}
- collection = new ArrayList<>(module.getAllUsesNodes());
- usesDataLoaded = module.allUsesLoadDone();
}
-
- for (UsesNodeBuilder usesNode : allModuleUses) {
- final GroupingBuilder targetGrouping = GroupingUtils
- .getTargetGroupingFromModules(usesNode, modules, module);
- // load uses target uses nodes in uses
- GroupingUtils.loadTargetGroupingUses(usesNode, targetGrouping);
+ for (UsesNodeBuilder usesNode : allUses) {
+ ModuleBuilder module = ParserUtils.getParentModule(usesNode);
+ final GroupingBuilder targetGroupingBuilder = GroupingUtils.getTargetGroupingFromModules(usesNode, modules,
+ module);
+ if (targetGroupingBuilder == null) {
+ if (context == null) {
+ throw new YangParseException(module.getName(), usesNode.getLine(), "Referenced grouping '"
+ + usesNode.getGroupingName() + "' not found.");
+ } else {
+ GroupingDefinition targetGroupingDefinition = GroupingUtils.getTargetGroupingFromContext(usesNode,
+ module, context);
+ usesNode.setGroupingDefinition(targetGroupingDefinition);
+ usesNode.setGroupingPath(targetGroupingDefinition.getPath());
+ }
+ } else {
+ usesNode.setGrouping(targetGroupingBuilder);
+ usesNode.setGroupingPath(targetGroupingBuilder.getPath());
+ }
}
}
- private void finishResolvingUses(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
- final List<UsesNodeBuilder> alluses = new ArrayList<>();
+ /**
+ * Copy data from uses target, update uses parent and perform refinement.
+ * Augmentations have to be resolved already.
+ *
+ * @param modules
+ * all loaded modules
+ */
+ private void resolveUses(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()) {
- alluses.addAll(inner.getValue().getAllUsesNodes());
+ ModuleBuilder module = inner.getValue();
+ List<UsesNodeBuilder> usesNodes = null;
+ boolean dataCollected = module.isAllUsesDataCollected();
+
+ while (!dataCollected) {
+ usesNodes = new ArrayList<>(module.getAllUsesNodes());
+ for (UsesNodeBuilder usesNode : usesNodes) {
+ if (!usesNode.isDataCollected()) {
+ GroupingUtils.collectUsesData(usesNode);
+ }
+ }
+ dataCollected = module.isAllUsesDataCollected();
+ }
}
}
- for (UsesNodeBuilder usesNode : alluses) {
- ParserUtils.processUsesNode(usesNode);
+
+ // new cycle is must because in collecting data process new uses could
+ // be created
+ final List<UsesNodeBuilder> allModulesUses = new ArrayList<>();
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ allModulesUses.addAll(inner.getValue().getAllUsesNodes());
+ }
}
- for (UsesNodeBuilder usesNode : alluses) {
- ParserUtils.performRefine(usesNode);
- ParserUtils.updateUsesParent(usesNode, usesNode.getParent());
+
+ for (UsesNodeBuilder usesNode : allModulesUses) {
+ GroupingUtils.updateUsesParent(usesNode);
+ GroupingUtils.performRefine(usesNode);
}
- for (UsesNodeBuilder usesNode : alluses) {
- ParserUtils.fixUsesNodesPath(usesNode);
+ for (UsesNodeBuilder usesNode : allModulesUses) {
+ GroupingUtils.fixUsesNodesPath(usesNode);
}
}
/**
- * Tries to search target grouping in given modules and resolve refine
- * nodes. If grouping is not found in modules, method tries to find it in
- * modules from context.
*
* @param modules
* all loaded modules
- * @param module
- * current module
* @param context
* SchemaContext containing already resolved modules
*/
- private void resolveUsesNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
- final ModuleBuilder module, final SchemaContext context) {
- final List<UsesNodeBuilder> allModuleUses = module.getAllUsesNodes();
- for (UsesNodeBuilder usesNode : allModuleUses) {
- // process uses operation
- final GroupingBuilder targetGrouping = GroupingUtils
- .getTargetGroupingFromModules(usesNode, modules, module);
- if (targetGrouping == null) {
- // TODO implement
- } else {
- usesNode.setGroupingPath(targetGrouping.getPath());
- GroupingUtils.loadTargetGroupingData(usesNode, targetGrouping);
- }
- }
- for (UsesNodeBuilder usesNode : allModuleUses) {
- final GroupingBuilder targetGrouping = GroupingUtils
- .getTargetGroupingFromModules(usesNode, modules, module);
- if (targetGrouping == null) {
- // TODO implement
- } else {
- GroupingUtils.loadTargetGroupingUses(usesNode, targetGrouping);
+ private void resolveUsesWithContext(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 module = inner.getValue();
+ List<UsesNodeBuilder> usesNodes = null;
+ boolean dataCollected = module.isAllUsesDataCollected();
+
+ while (!dataCollected) {
+ usesNodes = new ArrayList<>(module.getAllUsesNodes());
+ for (UsesNodeBuilder usesNode : usesNodes) {
+ if (!usesNode.isDataCollected()) {
+ if (usesNode.getGroupingBuilder() == null) {
+ GroupingUtils.collectUsesDataFromContext(usesNode);
+ } else {
+ GroupingUtils.collectUsesData(usesNode);
+ }
+ }
+ }
+ dataCollected = module.isAllUsesDataCollected();
+ }
}
}
- }
- // TODO use in implementation
- private void processUsesNode(final UsesNodeBuilder usesNode, final GroupingDefinition targetGrouping) {
- final String moduleName = usesNode.getModuleName();
- final int line = usesNode.getLine();
- DataNodeContainerBuilder parent = usesNode.getParent();
- URI namespace = null;
- Date revision = null;
- String prefix = null;
- if (parent instanceof ModuleBuilder) {
- ModuleBuilder m = (ModuleBuilder) parent;
- namespace = m.getNamespace();
- revision = m.getRevision();
- prefix = m.getPrefix();
- } else {
- QName parentQName = parent.getQName();
- namespace = parentQName.getNamespace();
- revision = parentQName.getRevision();
- prefix = parentQName.getPrefix();
- }
- SchemaPath parentPath = parent.getPath();
-
- final Set<DataSchemaNodeBuilder> newChildren = new HashSet<>();
- for (DataSchemaNode child : targetGrouping.getChildNodes()) {
- if (child != null) {
- DataSchemaNodeBuilder newChild = null;
- QName newQName = new QName(namespace, revision, prefix, child.getQName().getLocalName());
- if (child instanceof AnyXmlSchemaNode) {
- newChild = createAnyXml((AnyXmlSchemaNode) child, newQName, moduleName, line);
- } else if (child instanceof ChoiceNode) {
- newChild = createChoice((ChoiceNode) child, newQName, moduleName, line);
- } else if (child instanceof ContainerSchemaNode) {
- newChild = createContainer((ContainerSchemaNode) child, newQName, moduleName, line);
- } else if (child instanceof LeafListSchemaNode) {
- newChild = createLeafList((LeafListSchemaNode) child, newQName, moduleName, line);
- } else if (child instanceof LeafSchemaNode) {
- newChild = createLeafBuilder((LeafSchemaNode) child, newQName, moduleName, line);
- } else if (child instanceof ListSchemaNode) {
- newChild = createList((ListSchemaNode) child, newQName, moduleName, line);
- }
-
- if (newChild == null) {
- throw new YangParseException(moduleName, line,
- "Unknown member of target grouping while resolving uses node.");
- }
- if (newChild instanceof GroupingMember) {
- ((GroupingMember) newChild).setAddedByUses(true);
- }
-
- newChild.setPath(createSchemaPath(parentPath, newQName));
- newChildren.add(newChild);
+ // new cycle is must because in collecting data process new uses could
+ // be created
+ final List<UsesNodeBuilder> allModulesUses = new ArrayList<>();
+ for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+ allModulesUses.addAll(inner.getValue().getAllUsesNodes());
}
}
- usesNode.getFinalChildren().addAll(newChildren);
-
- final Set<GroupingBuilder> newGroupings = new HashSet<>();
- for (GroupingDefinition g : targetGrouping.getGroupings()) {
- QName newQName = new QName(namespace, revision, prefix, g.getQName().getLocalName());
- GroupingBuilder newGrouping = createGrouping(g, newQName, moduleName, line);
- newGrouping.setAddedByUses(true);
- newGrouping.setPath(createSchemaPath(parentPath, newQName));
- newGroupings.add(newGrouping);
- }
- usesNode.getFinalGroupings().addAll(newGroupings);
-
- final Set<TypeDefinitionBuilder> newTypedefs = new HashSet<>();
- for (TypeDefinition<?> td : targetGrouping.getTypeDefinitions()) {
- QName newQName = new QName(namespace, revision, prefix, td.getQName().getLocalName());
- TypeDefinitionBuilder newType = createTypedef((ExtendedType) td, newQName, moduleName, line);
- newType.setAddedByUses(true);
- newType.setPath(createSchemaPath(parentPath, newQName));
- newTypedefs.add(newType);
+
+ for (UsesNodeBuilder usesNode : allModulesUses) {
+ GroupingUtils.updateUsesParent(usesNode);
+ GroupingUtils.performRefine(usesNode);
}
- usesNode.getFinalTypedefs().addAll(newTypedefs);
-
- final List<UnknownSchemaNodeBuilder> newUnknownNodes = new ArrayList<>();
- for (UnknownSchemaNode un : targetGrouping.getUnknownSchemaNodes()) {
- QName newQName = new QName(namespace, revision, prefix, un.getQName().getLocalName());
- UnknownSchemaNodeBuilder newNode = createUnknownSchemaNode(un, newQName, moduleName, line);
- newNode.setAddedByUses(true);
- newNode.setPath(createSchemaPath(parentPath, newQName));
- newUnknownNodes.add(newNode);
+ for (UsesNodeBuilder usesNode : allModulesUses) {
+ GroupingUtils.fixUsesNodesPath(usesNode);
}
- usesNode.getFinalUnknownNodes().addAll(newUnknownNodes);
}
private void resolveUnknownNodes(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.YangTypesConverter;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
private Date revision = new Date(0L);
public final static DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
- private final Stack<String> actualPath = new Stack<String>();
+ private final Stack<Stack<QName>> actualPath = new Stack<>();
+
+ private void addNodeToPath(QName name) {
+ actualPath.peek().push(name);
+ }
+
+ private QName removeNodeFromPath() {
+ return actualPath.peek().pop();
+ }
@Override
public void enterModule_stmt(YangParser.Module_stmtContext ctx) {
moduleName = stringFromNode(ctx);
- logger.debug("enter module " + moduleName);
- actualPath.push(moduleName);
+ logger.debug("entering module " + moduleName);
+ enterLog("module", moduleName, 0);
+ actualPath.push(new Stack<QName>());
+
moduleBuilder = new ModuleBuilder(moduleName);
String description = null;
String reference = null;
-
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof Description_stmtContext) {
@Override
public void exitModule_stmt(YangParser.Module_stmtContext ctx) {
- exitLog("module", actualPath.pop());
+ exitLog("module", "");
+ actualPath.pop();
}
@Override
final int line = ctx.getStart().getLine();
final String augmentPath = stringFromNode(ctx);
enterLog("augment", augmentPath, line);
+ actualPath.push(new Stack<QName>());
AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath);
}
moduleBuilder.enterNode(builder);
- actualPath.push(augmentPath);
}
@Override
public void exitAugment_stmt(YangParser.Augment_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("augment", actualPath.pop());
+ exitLog("augment", "");
+ actualPath.pop();
}
@Override
final int line = ctx.getStart().getLine();
final String extName = stringFromNode(ctx);
enterLog("extension", extName, line);
-
QName qname = new QName(namespace, revision, yangModelPrefix, extName);
+ addNodeToPath(qname);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+
ExtensionBuilder builder = moduleBuilder.addExtension(qname, line);
+ builder.setPath(path);
parseSchemaNodeArgs(ctx, builder);
String argument = null;
builder.setYinElement(yin);
moduleBuilder.enterNode(builder);
- actualPath.push(extName);
}
@Override
public void exitExtension_stmt(YangParser.Extension_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("extension", actualPath.pop());
+ exitLog("extension", removeNodeFromPath());
}
@Override
final int line = ctx.getStart().getLine();
final String typedefName = stringFromNode(ctx);
enterLog("typedef", typedefName, line);
-
QName typedefQName = new QName(namespace, revision, yangModelPrefix, typedefName);
- TypeDefinitionBuilder builder = moduleBuilder.addTypedef(line, typedefQName);
- moduleBuilder.enterNode(builder);
- actualPath.push(typedefName);
+ addNodeToPath(typedefQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
+ TypeDefinitionBuilder builder = moduleBuilder.addTypedef(line, typedefQName);
+ builder.setPath(path);
parseSchemaNodeArgs(ctx, builder);
builder.setUnits(parseUnits(ctx));
builder.setDefaultValue(parseDefault(ctx));
+
+ moduleBuilder.enterNode(builder);
}
@Override
public void exitTypedef_stmt(YangParser.Typedef_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("typedef", actualPath.pop());
+ exitLog("typedef", removeNodeFromPath());
}
@Override
// check for types which must have body
checkMissingBody(typeName, moduleName, line);
// if there are no constraints, just grab default base yang type
- type = YangTypesConverter.javaTypeForBaseYangType(actualPath, namespace, revision, typeName);
+ QName qname = BaseTypes.constructQName(typeName);
+ addNodeToPath(qname);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+ type = YangTypesConverter.javaTypeForBaseYangType(path, typeName);
moduleBuilder.setType(type);
} else {
if ("union".equals(typeName)) {
- SchemaPath p = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, typeName);
+ QName qname = BaseTypes.constructQName("union");
+ addNodeToPath(qname);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
UnionTypeBuilder unionBuilder = moduleBuilder.addUnionType(line, namespace, revision);
moduleBuilder.enterNode(unionBuilder);
- unionBuilder.setPath(p);
+ unionBuilder.setPath(path);
} else if ("identityref".equals(typeName)) {
- SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, typeName);
+ QName qname = BaseTypes.constructQName("identityref");
+ addNodeToPath(qname);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
moduleBuilder.addIdentityrefType(line, path, getIdentityrefBase(typeBody));
} else {
- type = parseTypeWithBody(typeName, typeBody, actualPath, namespace, revision, yangModelPrefix,
- moduleBuilder.getActualNode());
+ type = parseTypeWithBody(typeName, typeBody, actualPath.peek(), namespace, revision, yangModelPrefix, moduleBuilder.getActualNode());
moduleBuilder.setType(type);
+ addNodeToPath(type.getQName());
}
}
} else {
- type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath, namespace, revision, yangModelPrefix,
+ type = parseUnknownTypeWithBody(typeQName, typeBody, actualPath.peek(), namespace, revision, yangModelPrefix,
moduleBuilder.getActualNode());
// add parent node of this type statement to dirty nodes
moduleBuilder.markActualNodeDirty();
moduleBuilder.setType(type);
+ addNodeToPath(type.getQName());
}
- actualPath.push(typeName);
}
private QName parseQName(String typeName) {
if ("union".equals(typeName)) {
moduleBuilder.exitNode();
}
- exitLog("type", actualPath.pop());
+ exitLog("type", removeNodeFromPath());
}
@Override
final int line = ctx.getStart().getLine();
final String groupName = stringFromNode(ctx);
enterLog("grouping", groupName, line);
-
QName groupQName = new QName(namespace, revision, yangModelPrefix, groupName);
- GroupingBuilder builder = moduleBuilder.addGrouping(ctx.getStart().getLine(), groupQName);
- moduleBuilder.enterNode(builder);
- actualPath.push(groupName);
+ addNodeToPath(groupQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
+ GroupingBuilder builder = moduleBuilder.addGrouping(ctx.getStart().getLine(), groupQName);
+ builder.setPath(path);
parseSchemaNodeArgs(ctx, builder);
+
+ moduleBuilder.enterNode(builder);
}
@Override
public void exitGrouping_stmt(YangParser.Grouping_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("grouping", actualPath.pop());
+ exitLog("grouping", removeNodeFromPath());
}
@Override
enterLog("container", containerName, line);
QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName);
- SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, containerName);
+ addNodeToPath(containerQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
ContainerSchemaNodeBuilder builder = moduleBuilder.addContainerNode(line, containerQName, path);
- moduleBuilder.enterNode(builder);
- actualPath.push(containerName);
-
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
break;
}
}
+
+ moduleBuilder.enterNode(builder);
}
@Override
public void exitContainer_stmt(Container_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("container", actualPath.pop());
+ exitLog("container", removeNodeFromPath());
}
@Override
enterLog("leaf", leafName, line);
QName leafQName = new QName(namespace, revision, yangModelPrefix, leafName);
- SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafName);
-
- LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(line, leafQName, schemaPath);
- moduleBuilder.enterNode(builder);
- actualPath.push(leafName);
+ addNodeToPath(leafQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+ LeafSchemaNodeBuilder builder = moduleBuilder.addLeafNode(line, leafQName, path);
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
}
builder.setDefaultStr(defaultStr);
builder.setUnits(unitsStr);
+
+ moduleBuilder.enterNode(builder);
}
@Override
public void exitLeaf_stmt(YangParser.Leaf_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("leaf", actualPath.pop());
+ exitLog("leaf", removeNodeFromPath());
}
@Override
UsesNodeBuilder builder = moduleBuilder.addUsesNode(line, groupingPathStr);
moduleBuilder.enterNode(builder);
- actualPath.push(groupingPathStr);
}
@Override
public void exitUses_stmt(YangParser.Uses_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("uses", actualPath.pop());
+ exitLog("uses", "");
}
- @Override public void enterUses_augment_stmt(YangParser.Uses_augment_stmtContext ctx) {
+ @Override
+ public void enterUses_augment_stmt(YangParser.Uses_augment_stmtContext ctx) {
+ actualPath.push(new Stack<QName>());
final int line = ctx.getStart().getLine();
final String augmentPath = stringFromNode(ctx);
enterLog("augment", augmentPath, line);
}
moduleBuilder.enterNode(builder);
- actualPath.push(augmentPath);
}
- @Override public void exitUses_augment_stmt(YangParser.Uses_augment_stmtContext ctx) {
+ @Override
+ public void exitUses_augment_stmt(YangParser.Uses_augment_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("augment", actualPath.pop());
+ exitLog("augment", "");
+ actualPath.pop();
}
@Override
RefineHolder refine = parseRefine(ctx, moduleName);
moduleBuilder.addRefine(refine);
moduleBuilder.enterNode(refine);
- actualPath.push(refineString);
}
@Override
public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("refine", actualPath.pop());
+ exitLog("refine", "");
}
@Override
final int line = ctx.getStart().getLine();
final String leafListName = stringFromNode(ctx);
enterLog("leaf-list", leafListName, line);
-
QName leafListQName = new QName(namespace, revision, yangModelPrefix, leafListName);
- SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, leafListName);
+ addNodeToPath(leafListQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
- LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(line, leafListQName, schemaPath);
+ LeafListSchemaNodeBuilder builder = moduleBuilder.addLeafListNode(line, leafListQName, path);
moduleBuilder.enterNode(builder);
- actualPath.push(leafListName);
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
@Override
public void exitLeaf_list_stmt(YangParser.Leaf_list_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("leaf-list", actualPath.pop());
+ exitLog("leaf-list", removeNodeFromPath());
}
@Override
enterLog("list", listName, line);
QName listQName = new QName(namespace, revision, yangModelPrefix, listName);
- SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, listName);
+ addNodeToPath(listQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
- ListSchemaNodeBuilder builder = moduleBuilder.addListNode(line, listQName, schemaPath);
+ ListSchemaNodeBuilder builder = moduleBuilder.addListNode(line, listQName, path);
moduleBuilder.enterNode(builder);
- actualPath.push(listName);
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
@Override
public void exitList_stmt(List_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("list", actualPath.pop());
+ exitLog("list", removeNodeFromPath());
}
@Override
enterLog("anyxml", anyXmlName, line);
QName anyXmlQName = new QName(namespace, revision, yangModelPrefix, anyXmlName);
- SchemaPath schemaPath = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, anyXmlName);
+ addNodeToPath(anyXmlQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
- AnyXmlBuilder builder = moduleBuilder.addAnyXml(line, anyXmlQName, schemaPath);
+ AnyXmlBuilder builder = moduleBuilder.addAnyXml(line, anyXmlQName, path);
moduleBuilder.enterNode(builder);
- actualPath.push(anyXmlName);
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
@Override
public void exitAnyxml_stmt(YangParser.Anyxml_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("anyxml", actualPath.pop());
+ exitLog("anyxml", removeNodeFromPath());
}
@Override
enterLog("choice", choiceName, line);
QName choiceQName = new QName(namespace, revision, yangModelPrefix, choiceName);
+ addNodeToPath(choiceQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
ChoiceBuilder builder = moduleBuilder.addChoice(line, choiceQName);
+ builder.setPath(path);
moduleBuilder.enterNode(builder);
- actualPath.push(choiceName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
builder.setConfiguration(getConfig(ctx, moduleBuilder.getActualParent(), moduleName, line));
@Override
public void exitChoice_stmt(YangParser.Choice_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("choice", actualPath.pop());
+ exitLog("choice", removeNodeFromPath());
}
@Override
enterLog("case", caseName, line);
QName caseQName = new QName(namespace, revision, yangModelPrefix, caseName);
+ addNodeToPath(caseQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+
ChoiceCaseBuilder builder = moduleBuilder.addCase(line, caseQName);
+ builder.setPath(path);
moduleBuilder.enterNode(builder);
- actualPath.push(caseName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
}
@Override
public void exitCase_stmt(YangParser.Case_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("case", actualPath.pop());
+ exitLog("case", removeNodeFromPath());
}
@Override
enterLog("notification", notificationName, line);
QName notificationQName = new QName(namespace, revision, yangModelPrefix, notificationName);
+ addNodeToPath(notificationQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+
NotificationBuilder builder = moduleBuilder.addNotification(line, notificationQName);
+ builder.setPath(path);
moduleBuilder.enterNode(builder);
- actualPath.push(notificationName);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
}
@Override
public void exitNotification_stmt(YangParser.Notification_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("notification", actualPath.pop());
+ exitLog("notification", removeNodeFromPath());
}
// Unknown nodes
UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode(line, qname);
builder.setNodeType(nodeType);
builder.setNodeParameter(nodeParameter);
- actualPath.push(nodeParameter);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
+ addNodeToPath(new QName(namespace, revision, yangModelPrefix, nodeParameter));
+
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+ builder.setPath(path);
+
parseSchemaNodeArgs(ctx, builder);
moduleBuilder.enterNode(builder);
}
@Override
public void exitIdentifier_stmt(YangParser.Identifier_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("unknown-node", actualPath.pop());
+ exitLog("unknown-node", removeNodeFromPath());
}
@Override
QName rpcQName = new QName(namespace, revision, yangModelPrefix, rpcName);
RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(line, rpcQName);
moduleBuilder.enterNode(rpcBuilder);
- actualPath.push(rpcName);
+ addNodeToPath(rpcQName);
+
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+ rpcBuilder.setPath(path);
- rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, rpcBuilder);
}
@Override
public void exitRpc_stmt(YangParser.Rpc_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("rpc", actualPath.pop());
+ exitLog("rpc", removeNodeFromPath());
}
@Override
enterLog(input, input, line);
QName rpcQName = new QName(namespace, revision, yangModelPrefix, input);
- SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, input);
+ addNodeToPath(rpcQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcInput(line, rpcQName, path);
moduleBuilder.enterNode(builder);
- actualPath.push(input);
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
@Override
public void exitInput_stmt(YangParser.Input_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("input", actualPath.pop());
+ exitLog("input", removeNodeFromPath());
}
@Override
enterLog(output, output, line);
QName rpcQName = new QName(namespace, revision, yangModelPrefix, output);
- SchemaPath path = createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix, output);
+ addNodeToPath(rpcQName);
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
ContainerSchemaNodeBuilder builder = moduleBuilder.addRpcOutput(path, rpcQName, line);
moduleBuilder.enterNode(builder);
- actualPath.push(output);
parseSchemaNodeArgs(ctx, builder);
parseConstraints(ctx, builder.getConstraints());
@Override
public void exitOutput_stmt(YangParser.Output_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("output", actualPath.pop());
+ exitLog("output", removeNodeFromPath());
}
@Override
QName featureQName = new QName(namespace, revision, yangModelPrefix, featureName);
FeatureBuilder featureBuilder = moduleBuilder.addFeature(line, featureQName);
moduleBuilder.enterNode(featureBuilder);
- actualPath.push(featureName);
+ addNodeToPath(featureQName);
- featureBuilder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+ featureBuilder.setPath(path);
parseSchemaNodeArgs(ctx, featureBuilder);
}
@Override
public void exitFeature_stmt(YangParser.Feature_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("feature", actualPath.pop());
+ exitLog("feature", removeNodeFromPath());
}
@Override
String deviate = null;
DeviationBuilder builder = moduleBuilder.addDeviation(line, targetPath);
moduleBuilder.enterNode(builder);
- actualPath.push(targetPath);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
@Override
public void exitDeviation_stmt(YangParser.Deviation_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("deviation", actualPath.pop());
+ exitLog("deviation", "");
}
@Override
enterLog("identity", identityName, line);
final QName identityQName = new QName(namespace, revision, yangModelPrefix, identityName);
- IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(identityQName, actualPath, line);
+ IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity(identityQName, line);
moduleBuilder.enterNode(builder);
- actualPath.push(identityName);
+ addNodeToPath(identityQName);
+
+ SchemaPath path = createActualSchemaPath(actualPath.peek());
+ builder.setPath(path);
- builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
parseSchemaNodeArgs(ctx, builder);
for (int i = 0; i < ctx.getChildCount(); i++) {
@Override
public void exitIdentity_stmt(YangParser.Identity_stmtContext ctx) {
moduleBuilder.exitNode();
- exitLog("identity", actualPath.pop());
+ exitLog("identity", removeNodeFromPath());
}
public ModuleBuilder getModuleBuilder() {
logger.trace("exiting {} {}", p1, p2);
}
+ private void exitLog(String p1, QName p2) {
+ logger.trace("exiting {} {}", p1, p2.getLocalName());
+ }
+
private void setLog(String p1, String p2) {
logger.trace("setting {} {}", p1, p2);
}
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- AnyXmlBuilder c = new AnyXmlBuilder(newParent.getModuleName(), newParent.getLine(), newQName, newSchemaPath);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAugmenting(old.isAugmenting());
- c.setAddedByUses(old.isAddedByUses());
- c.setConfiguration(old.isConfiguration());
+ AnyXmlBuilder copy = new AnyXmlBuilder(newParent.getModuleName(), newParent.getLine(), newQName, newSchemaPath);
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setConfiguration(old.isConfiguration());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
- return c;
+ return copy;
}
private static ChoiceBuilder copy(ChoiceBuilder old, Builder newParent, boolean updateQName) {
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- ChoiceBuilder c = new ChoiceBuilder(newParent.getModuleName(), newParent.getLine(), newQName);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAugmenting(old.isAugmenting());
- c.setAddedByUses(old.isAddedByUses());
- c.setConfiguration(old.isConfiguration());
+ ChoiceBuilder copy = new ChoiceBuilder(newParent.getModuleName(), newParent.getLine(), newQName);
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setConfiguration(old.isConfiguration());
for (ChoiceCaseBuilder childNode : old.getCases()) {
- c.addCase(copy(childNode, c, updateQName));
+ copy.addCase(copy(childNode, copy, updateQName));
}
for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- c.addAugmentation(copyAugment(augment, c));
+ copy.addAugmentation(copyAugment(augment, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
- return c;
+ return copy;
}
private static ChoiceCaseBuilder copy(ChoiceCaseBuilder old, Builder newParent, boolean updateQName) {
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- ChoiceCaseBuilder c = new ChoiceCaseBuilder(newParent.getModuleName(), newParent.getLine(), newQName);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAugmenting(old.isAugmenting());
- c.getChildNodes().addAll(old.getChildNodes());
+ ChoiceCaseBuilder copy = new ChoiceCaseBuilder(newParent.getModuleName(), newParent.getLine(), newQName);
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAugmenting(old.isAugmenting());
+ copy.getChildNodes().addAll(old.getChildNodes());
for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
- c.addChildNode(copy(childNode, c, updateQName));
+ copy.addChildNode(copy(childNode, copy, updateQName));
}
- c.getGroupings().addAll(old.getGroupings());
+ copy.getGroupings().addAll(old.getGroupings());
for (GroupingBuilder grouping : old.getGroupingBuilders()) {
- c.addGrouping(copy(grouping, c, updateQName));
+ copy.addGrouping(copy(grouping, copy, updateQName));
}
for (TypeDefinitionBuilder tdb : old.getTypeDefinitionBuilders()) {
- c.addTypedef(copy(tdb, c, updateQName));
+ copy.addTypedef(copy(tdb, copy, updateQName));
}
for (UsesNodeBuilder oldUses : old.getUsesNodes()) {
- c.addUsesNode(copyUses(oldUses, c));
+ copy.addUsesNode(copyUses(oldUses, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
- return c;
+ return copy;
}
private static ContainerSchemaNodeBuilder copy(ContainerSchemaNodeBuilder old, Builder newParent,
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- ContainerSchemaNodeBuilder c = new ContainerSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
+ ContainerSchemaNodeBuilder copy = new ContainerSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
newQName, newSchemaPath);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setPresence(old.isPresence());
- c.setAugmenting(old.isAugmenting());
- c.setAddedByUses(old.isAddedByUses());
- c.setConfiguration(old.isConfiguration());
- c.setChildNodes(old.getChildNodes());
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setPresence(old.isPresence());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setConfiguration(old.isConfiguration());
+ copy.setChildNodes(old.getChildNodes());
for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
- c.addChildNode(copy(childNode, c, updateQName));
+ copy.addChildNode(copy(childNode, copy, updateQName));
}
- c.getGroupings().addAll(old.getGroupings());
+ copy.getGroupings().addAll(old.getGroupings());
for (GroupingBuilder grouping : old.getGroupingBuilders()) {
- c.addGrouping(copy(grouping, c, updateQName));
+ copy.addGrouping(copy(grouping, copy, updateQName));
}
for (TypeDefinitionBuilder tdb : old.getTypeDefinitionBuilders()) {
- c.addTypedef(copy(tdb, c, updateQName));
+ copy.addTypedef(copy(tdb, copy, updateQName));
}
for (UsesNodeBuilder oldUses : old.getUsesNodes()) {
- c.addUsesNode(copyUses(oldUses, c));
+ copy.addUsesNode(copyUses(oldUses, copy));
}
for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- c.addAugmentation(copyAugment(augment, c));
+ copy.addAugmentation(copyAugment(augment, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
- return c;
+ return copy;
}
private static LeafSchemaNodeBuilder copy(LeafSchemaNodeBuilder old, Builder newParent, boolean updateQName) {
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- LeafSchemaNodeBuilder c = new LeafSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(), newQName,
+ LeafSchemaNodeBuilder copy = new LeafSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(), newQName,
newSchemaPath);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAugmenting(old.isAugmenting());
- c.setAddedByUses(old.isAddedByUses());
- c.setConfiguration(old.isConfiguration());
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setConfiguration(old.isConfiguration());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
if (old.getType() == null) {
- c.setTypedef(copy(old.getTypedef(), c, updateQName));
+ copy.setTypedef(copy(old.getTypedef(), copy, updateQName));
} else {
- c.setType(old.getType());
+ copy.setType(ParserUtils.createCorrectTypeDefinition(copy.getPath(), old.getType()));
}
- c.setDefaultStr(old.getDefaultStr());
- c.setUnits(old.getUnits());
+ copy.setDefaultStr(old.getDefaultStr());
+ copy.setUnits(old.getUnits());
- return c;
+ return copy;
}
public static LeafListSchemaNodeBuilder copy(LeafListSchemaNodeBuilder old, Builder newParent, boolean updateQName) {
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- LeafListSchemaNodeBuilder c = new LeafListSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
+ LeafListSchemaNodeBuilder copy = new LeafListSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
newQName, newSchemaPath);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAugmenting(old.isAugmenting());
- c.setAddedByUses(old.isAddedByUses());
- c.setConfiguration(old.isConfiguration());
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setConfiguration(old.isConfiguration());
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
if (old.getType() == null) {
- c.setTypedef(copy(old.getTypedef(), c, updateQName));
+ copy.setTypedef(copy(old.getTypedef(), copy, updateQName));
} else {
- c.setType(old.getType());
+ copy.setType(ParserUtils.createCorrectTypeDefinition(copy.getPath(), old.getType()));
}
- c.setUserOrdered(old.isUserOrdered());
+ copy.setUserOrdered(old.isUserOrdered());
- return c;
+ return copy;
}
private static ListSchemaNodeBuilder copy(ListSchemaNodeBuilder old, Builder newParent, boolean updateQName) {
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- ListSchemaNodeBuilder c = new ListSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(), newQName,
+ ListSchemaNodeBuilder copy = new ListSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(), newQName,
newSchemaPath);
- copyConstraints(c.getConstraints(), old.getConstraints());
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAugmenting(old.isAugmenting());
- c.setAddedByUses(old.isAddedByUses());
- c.setConfiguration(old.isConfiguration());
- c.setChildNodes(old.getChildNodes());
+ copyConstraints(copy.getConstraints(), old.getConstraints());
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setConfiguration(old.isConfiguration());
+ copy.setChildNodes(old.getChildNodes());
for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
- c.addChildNode(copy(childNode, c, updateQName));
+ copy.addChildNode(copy(childNode, copy, updateQName));
}
- c.getGroupings().addAll(old.getGroupings());
+ copy.getGroupings().addAll(old.getGroupings());
for (GroupingBuilder grouping : old.getGroupingBuilders()) {
- c.addGrouping(copy(grouping, c, updateQName));
+ copy.addGrouping(copy(grouping, copy, updateQName));
}
for (TypeDefinitionBuilder tdb : old.getTypeDefinitionBuilders()) {
- c.addTypedef(copy(tdb, c, updateQName));
+ copy.addTypedef(copy(tdb, copy, updateQName));
}
for (UsesNodeBuilder oldUses : old.getUsesNodes()) {
- c.addUsesNode(copyUses(oldUses, c));
+ copy.addUsesNode(copyUses(oldUses, copy));
}
for (AugmentationSchemaBuilder augment : old.getAugmentations()) {
- c.addAugmentation(copyAugment(augment, c));
+ copy.addAugmentation(copyAugment(augment, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
- c.setUserOrdered(old.isUserOrdered());
- c.setKeyDefinition(old.getKeyDefinition());
+ copy.setUserOrdered(old.isUserOrdered());
+ copy.setKeyDefinition(old.getKeyDefinition());
- return c;
+ return copy;
}
- static GroupingBuilder copy(GroupingBuilder old, Builder newParent, boolean updateQName) {
+ public static GroupingBuilder copy(GroupingBuilder old, Builder newParent, boolean updateQName) {
DataBean data = getdata(old, newParent, updateQName);
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
- GroupingBuilderImpl c = new GroupingBuilderImpl(newParent.getModuleName(), newParent.getLine(), newQName);
- c.setParent(newParent);
- c.setPath(newSchemaPath);
- c.setDescription(old.getDescription());
- c.setReference(old.getReference());
- c.setStatus(old.getStatus());
- c.setAddedByUses(old.isAddedByUses());
- c.setChildNodes(old.getChildNodes());
+ GroupingBuilderImpl copy = new GroupingBuilderImpl(newParent.getModuleName(), newParent.getLine(), newQName);
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setChildNodes(old.getChildNodes());
for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
- c.addChildNode(copy(childNode, c, updateQName));
+ copy.addChildNode(copy(childNode, copy, updateQName));
}
- c.getGroupings().addAll(old.getGroupings());
+ copy.getGroupings().addAll(old.getGroupings());
for (GroupingBuilder grouping : old.getGroupingBuilders()) {
- c.addGrouping(copy(grouping, c, updateQName));
+ copy.addGrouping(copy(grouping, copy, updateQName));
}
for (TypeDefinitionBuilder tdb : old.getTypeDefinitionBuilders()) {
- c.addTypedef(copy(tdb, c, updateQName));
+ copy.addTypedef(copy(tdb, copy, updateQName));
}
for (UsesNodeBuilder oldUses : old.getUsesNodes()) {
- c.addUsesNode(copyUses(oldUses, c));
+ copy.addUsesNode(copyUses(oldUses, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- c.addUnknownNodeBuilder((copy(un, c, updateQName)));
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
}
- return c;
+ return copy;
+ }
+
+ public static GroupingBuilder copyGroupingWithoutDeep(GroupingBuilder old, Builder newParent, boolean updateQName) {
+ DataBean data = getdata(old, newParent, updateQName);
+ QName newQName = data.qname;
+ SchemaPath newSchemaPath = data.schemaPath;
+
+ GroupingBuilderImpl copy = new GroupingBuilderImpl(newParent.getModuleName(), newParent.getLine(), newQName);
+ copy.setParent(newParent);
+ copy.setPath(newSchemaPath);
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.setChildNodes(old.getChildNodes());
+ for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
+ copy.addChildNode(copy(childNode, copy, updateQName));
+ }
+ copy.getGroupings().addAll(old.getGroupings());
+ for (GroupingBuilder grouping : old.getGroupingBuilders()) {
+ copy.addGrouping(copy(grouping, copy, updateQName));
+ }
+ for (TypeDefinitionBuilder tdb : old.getTypeDefinitionBuilders()) {
+ copy.addTypedef(copy(tdb, copy, updateQName));
+ }
+ for (UsesNodeBuilder oldUses : old.getUsesNodes()) {
+ copy.addUsesNode(copyUses(oldUses, copy));
+
+ }
+ for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
+ copy.addUnknownNodeBuilder((copy(un, copy, updateQName)));
+ }
+
+ return copy;
}
- static TypeDefinitionBuilder copy(TypeDefinitionBuilder old, Builder newParent, boolean updateQName) {
+ public static TypeDefinitionBuilder copy(TypeDefinitionBuilder old, Builder newParent, boolean updateQName) {
DataBean data = getdata(old, newParent, updateQName);
QName newQName = data.qname;
SchemaPath newSchemaPath = data.schemaPath;
TypeDefinitionBuilder type = null;
if (old instanceof UnionTypeBuilder) {
+ UnionTypeBuilder oldUnion = (UnionTypeBuilder)old;
type = new UnionTypeBuilder(newParent.getModuleName(), newParent.getLine());
+ type.setParent(newParent);
+ type.setPath(newSchemaPath);
+ for(TypeDefinition<?> td : oldUnion.getTypes()) {
+ type.setType(ParserUtils.createCorrectTypeDefinition(type.getPath(), td));
+ }
+ for(TypeDefinitionBuilder tdb : oldUnion.getTypedefs()) {
+ type.setTypedef(copy(tdb, type, updateQName));
+ }
} else if (old instanceof IdentityrefTypeBuilder) {
type = new IdentityrefTypeBuilder(newParent.getModuleName(), newParent.getLine(),
((IdentityrefTypeBuilder) old).getBaseString(), newSchemaPath);
+ type.setParent(newParent);
+ type.setPath(newSchemaPath);
} else {
type = new TypeDefinitionBuilderImpl(old.getModuleName(), newParent.getLine(), newQName);
type.setParent(newParent);
if (old.getType() == null) {
type.setTypedef(copy(old.getTypedef(), type, updateQName));
} else {
- type.setType(old.getType());
+ type.setType(ParserUtils.createCorrectTypeDefinition(type.getPath(), old.getType()));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
}
static UsesNodeBuilder copyUses(UsesNodeBuilder old, Builder newParent) {
- UsesNodeBuilder u = new UsesNodeBuilderImpl(newParent.getModuleName(), newParent.getLine(),
+ UsesNodeBuilder copy = new UsesNodeBuilderImpl(newParent.getModuleName(), newParent.getLine(),
old.getGroupingName());
- u.setParent(newParent);
- u.setGroupingPath(old.getGroupingPath());
- u.setAugmenting(old.isAugmenting());
- u.setAddedByUses(old.isAddedByUses());
- u.getAugmentations().addAll(old.getAugmentations());
- u.getRefineNodes().addAll(old.getRefineNodes());
- u.getRefines().addAll(old.getRefines());
- u.getFinalChildren().addAll(old.getFinalChildren());
- u.getFinalGroupings().addAll(old.getFinalGroupings());
- u.getFinalTypedefs().addAll(old.getFinalTypedefs());
- u.getFinalUnknownNodes().addAll(old.getFinalUnknownNodes());
-
- Set<DataSchemaNodeBuilder> oldChildren = old.getTargetChildren();
- Set<DataSchemaNodeBuilder> newChildren = new HashSet<>();
- if (oldChildren != null) {
- for (DataSchemaNodeBuilder child : old.getTargetChildren()) {
- newChildren.add(CopyUtils.copy(child, newParent, true));
- }
- }
- u.setTargetChildren(newChildren);
-
- Set<TypeDefinitionBuilder> oldTypedefs = old.getTargetTypedefs();
- Set<TypeDefinitionBuilder> newTypedefs = new HashSet<>();
- if (oldTypedefs != null) {
- for (TypeDefinitionBuilder typedef : old.getTargetTypedefs()) {
- newTypedefs.add(CopyUtils.copy(typedef, newParent, true));
- }
- }
- u.setTargetTypedefs(newTypedefs);
-
- Set<GroupingBuilder> oldGroupings = old.getTargetGroupings();
- Set<GroupingBuilder> newGroupings = new HashSet<>();
- if (oldGroupings != null) {
- for (GroupingBuilder grouping : old.getTargetGroupings()) {
- newGroupings.add(copy(grouping, newParent, true));
- }
- }
- u.setTargetGroupings(newGroupings);
-
- List<UnknownSchemaNodeBuilder> oldUN = old.getTargetUnknownNodes();
- List<UnknownSchemaNodeBuilder> newUN = new ArrayList<>();
- if (oldUN != null) {
- for (UnknownSchemaNodeBuilder un : oldUN) {
- newUN.add(copy(un, newParent, true));
- }
- }
- u.setTargetUnknownNodes(newUN);
-
- for (UsesNodeBuilder uses : old.getTargetGroupingUses()) {
- u.getTargetGroupingUses().add(copyUses(uses, uses.getParent()));
- }
+ copy.setParent(newParent);
+ copy.setGroupingPath(old.getGroupingPath());
+ // TODO grouping vs grouping path?
+ copy.setGrouping(old.getGroupingBuilder());
+ copy.setAugmenting(old.isAugmenting());
+ copy.setAddedByUses(old.isAddedByUses());
+ copy.getAugmentations().addAll(old.getAugmentations());
+ copy.getRefineNodes().addAll(old.getRefineNodes());
+ copy.getRefines().addAll(old.getRefines());
+
+ copy.setTargetChildren(old.getTargetChildren());
+ copy.setTargetTypedefs(old.getTargetTypedefs());
+ copy.setTargetGroupings(old.getTargetGroupings());
+ copy.setTargetUnknownNodes(old.getTargetUnknownNodes());
// add new uses to collection of uses in module
ModuleBuilder module = ParserUtils.getParentModule(newParent);
- module.addUsesNode(u);
+ module.addUsesNode(copy);
- return u;
+ return copy;
}
private static AugmentationSchemaBuilder copyAugment(AugmentationSchemaBuilder old, Builder newParent) {
- AugmentationSchemaBuilderImpl a = new AugmentationSchemaBuilderImpl(newParent.getModuleName(),
+ AugmentationSchemaBuilderImpl copy = new AugmentationSchemaBuilderImpl(newParent.getModuleName(),
newParent.getLine(), old.getTargetPathAsString());
- a.setParent(newParent);
+ copy.setParent(newParent);
- a.setDescription(old.getDescription());
- a.setReference(old.getReference());
- a.setStatus(old.getStatus());
- a.addWhenCondition(old.getWhenCondition());
- a.setChildNodes(old.getChildNodes());
+ copy.setDescription(old.getDescription());
+ copy.setReference(old.getReference());
+ copy.setStatus(old.getStatus());
+ copy.addWhenCondition(old.getWhenCondition());
+ copy.setChildNodes(old.getChildNodes());
for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
- a.addChildNode(copy(childNode, a, false));
+ copy.addChildNode(copy(childNode, copy, false));
}
for (UsesNodeBuilder oldUses : old.getUsesNodes()) {
- a.addUsesNode(copyUses(oldUses, a));
+ copy.addUsesNode(copyUses(oldUses, copy));
}
for (UnknownSchemaNodeBuilder un : old.getUnknownNodeBuilders()) {
- a.addUnknownNodeBuilder((copy(un, a, false)));
+ copy.addUnknownNodeBuilder((copy(un, copy, false)));
}
- return a;
+ return copy;
}
static UnknownSchemaNodeBuilder copy(UnknownSchemaNodeBuilder old, Builder newParent, boolean updateQName) {
newPath = new ArrayList<>(parent.getPath().getPath());
newPath.add(newQName);
} else {
+ if(old == null) {
+ System.out.println();
+ }
newQName = old.getQName();
newPath = new ArrayList<>(parent.getPath().getPath());
newPath.add(newQName);
}
}
+
+ /**
+ * Create AnyXmlBuilder from given AnyXmlSchemaNode.
+ *
+ * @param anyxml
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return anyxml builder based on given anyxml node
+ */
+ public static AnyXmlBuilder createAnyXml(AnyXmlSchemaNode anyxml, QName qname, String moduleName, int line) {
+ final AnyXmlBuilder builder = new AnyXmlBuilder(moduleName, line, qname, anyxml.getPath());
+ convertDataSchemaNode(anyxml, builder);
+ builder.setConfiguration(anyxml.isConfiguration());
+ builder.setUnknownNodes(anyxml.getUnknownSchemaNodes());
+ return builder;
+ }
+
+ /**
+ * Create GroupingBuilder from given GroupingDefinition.
+ *
+ * @param grouping
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return grouping builder based on given grouping node
+ */
+ public static GroupingBuilder createGrouping(GroupingDefinition grouping, QName qname, String moduleName, int line) {
+ final GroupingBuilderImpl builder = new GroupingBuilderImpl(moduleName, line, qname);
+ builder.setPath(grouping.getPath());
+ builder.setChildNodes(grouping.getChildNodes());
+ builder.setGroupings(grouping.getGroupings());
+ builder.setTypedefs(grouping.getTypeDefinitions());
+ builder.setUsesnodes(grouping.getUses());
+ builder.setUnknownNodes(grouping.getUnknownSchemaNodes());
+ builder.setDescription(grouping.getDescription());
+ builder.setReference(grouping.getReference());
+ builder.setStatus(grouping.getStatus());
+ return builder;
+ }
+
+ /**
+ * Create TypeDefinitionBuilder from given ExtendedType.
+ *
+ * @param typedef
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return typedef builder based on given typedef node
+ */
+ public static TypeDefinitionBuilder createTypedef(ExtendedType typedef, QName qname, String moduleName, int line) {
+ final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(moduleName, line, qname);
+ builder.setPath(typedef.getPath());
+ builder.setDefaultValue(typedef.getDefaultValue());
+ builder.setUnits(typedef.getUnits());
+ builder.setDescription(typedef.getDescription());
+ builder.setReference(typedef.getReference());
+ builder.setStatus(typedef.getStatus());
+ builder.setRanges(typedef.getRanges());
+ builder.setLengths(typedef.getLengths());
+ builder.setPatterns(typedef.getPatterns());
+ builder.setFractionDigits(typedef.getFractionDigits());
+ final TypeDefinition<?> type = typedef.getBaseType();
+ builder.setType(type);
+ builder.setUnits(typedef.getUnits());
+ builder.setUnknownNodes(typedef.getUnknownSchemaNodes());
+ return builder;
+ }
+
+ /**
+ * Create UnknownSchemaNodeBuilder from given UnknownSchemaNode.
+ *
+ * @param unknownNode
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return unknown node builder based on given unknown node
+ */
+ public static UnknownSchemaNodeBuilder createUnknownSchemaNode(UnknownSchemaNode unknownNode, QName qname,
+ String moduleName, int line) {
+ final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(moduleName, line, qname);
+ builder.setPath(unknownNode.getPath());
+ builder.setUnknownNodes(unknownNode.getUnknownSchemaNodes());
+ builder.setDescription(unknownNode.getDescription());
+ builder.setReference(unknownNode.getReference());
+ builder.setStatus(unknownNode.getStatus());
+ builder.setAddedByUses(unknownNode.isAddedByUses());
+ builder.setNodeType(unknownNode.getNodeType());
+ builder.setNodeParameter(unknownNode.getNodeParameter());
+ return builder;
+ }
+
+
+ /**
+ * Create LeafSchemaNodeBuilder from given LeafSchemaNode.
+ *
+ * @param leaf
+ * leaf from which to create builder
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * line in module
+ * @return leaf builder based on given leaf node
+ */
+ public static LeafSchemaNodeBuilder createLeafBuilder(LeafSchemaNode leaf, QName qname, String moduleName, int line) {
+ final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(moduleName, line, qname, leaf.getPath());
+ convertDataSchemaNode(leaf, builder);
+ builder.setConfiguration(leaf.isConfiguration());
+ final TypeDefinition<?> type = leaf.getType();
+ builder.setType(type);
+ builder.setPath(leaf.getPath());
+ builder.setUnknownNodes(leaf.getUnknownSchemaNodes());
+ builder.setDefaultStr(leaf.getDefault());
+ builder.setUnits(leaf.getUnits());
+ return builder;
+ }
+
+ /**
+ * Create ContainerSchemaNodeBuilder from given ContainerSchemaNode.
+ *
+ * @param container
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return container builder based on given container node
+ */
+ public static ContainerSchemaNodeBuilder createContainer(ContainerSchemaNode container, QName qname,
+ String moduleName, int line) {
+ final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(moduleName, line, qname,
+ container.getPath());
+ convertDataSchemaNode(container, builder);
+ builder.setConfiguration(container.isConfiguration());
+ builder.setUnknownNodes(container.getUnknownSchemaNodes());
+ builder.setChildNodes(container.getChildNodes());
+ builder.setGroupings(container.getGroupings());
+ builder.setTypedefs(container.getTypeDefinitions());
+ builder.setAugmentations(container.getAvailableAugmentations());
+ builder.setUsesnodes(container.getUses());
+ builder.setPresence(container.isPresenceContainer());
+ return builder;
+ }
+
+ /**
+ * Create ListSchemaNodeBuilder from given ListSchemaNode.
+ *
+ * @param list
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return list builder based on given list node
+ */
+ public static ListSchemaNodeBuilder createList(ListSchemaNode list, QName qname, String moduleName, int line) {
+ ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(moduleName, line, qname, list.getPath());
+ convertDataSchemaNode(list, builder);
+ builder.setConfiguration(list.isConfiguration());
+ builder.setUnknownNodes(list.getUnknownSchemaNodes());
+ builder.setTypedefs(list.getTypeDefinitions());
+ builder.setChildNodes(list.getChildNodes());
+ builder.setGroupings(list.getGroupings());
+ builder.setAugmentations(list.getAvailableAugmentations());
+ builder.setUsesnodes(list.getUses());
+ builder.setUserOrdered(builder.isUserOrdered());
+ return builder;
+ }
+
+ /**
+ * Create LeafListSchemaNodeBuilder from given LeafListSchemaNode.
+ *
+ * @param leafList
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return leaf-list builder based on given leaf-list node
+ */
+ public static LeafListSchemaNodeBuilder createLeafList(LeafListSchemaNode leafList, QName qname, String moduleName,
+ int line) {
+ final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(moduleName, line, qname,
+ leafList.getPath());
+ convertDataSchemaNode(leafList, builder);
+ builder.setConfiguration(leafList.isConfiguration());
+ builder.setType(leafList.getType());
+ builder.setUnknownNodes(leafList.getUnknownSchemaNodes());
+ builder.setUserOrdered(leafList.isUserOrdered());
+ return builder;
+ }
+
+ /**
+ * Create ChoiceBuilder from given ChoiceNode.
+ *
+ * @param choice
+ * @param qname
+ * @param moduleName
+ * current module name
+ * @param line
+ * current line in module
+ * @return choice builder based on given choice node
+ */
+ public static ChoiceBuilder createChoice(ChoiceNode choice, QName qname, String moduleName, int line) {
+ final ChoiceBuilder builder = new ChoiceBuilder(moduleName, line, qname);
+ convertDataSchemaNode(choice, builder);
+ builder.setConfiguration(choice.isConfiguration());
+ builder.setCases(choice.getCases());
+ builder.setUnknownNodes(choice.getUnknownSchemaNodes());
+ builder.setDefaultCase(choice.getDefaultCase());
+ return builder;
+ }
+
+
+ /**
+ * Set DataSchemaNode arguments to builder object
+ *
+ * @param node
+ * node from which arguments should be read
+ * @param builder
+ * builder to which arguments should be set
+ */
+ private static void convertDataSchemaNode(DataSchemaNode node, DataSchemaNodeBuilder builder) {
+ builder.setPath(node.getPath());
+ builder.setDescription(node.getDescription());
+ builder.setReference(node.getReference());
+ builder.setStatus(node.getStatus());
+ builder.setAugmenting(node.isAugmenting());
+ copyConstraintsFromDefinition(node.getConstraints(), builder.getConstraints());
+ }
+
+ /**
+ * Copy constraints from constraints definition to constraints builder.
+ *
+ * @param nodeConstraints
+ * definition from which constraints will be copied
+ * @param constraints
+ * builder to which constraints will be added
+ */
+ private static void copyConstraintsFromDefinition(final ConstraintDefinition nodeConstraints,
+ final ConstraintsBuilder constraints) {
+ final RevisionAwareXPath when = nodeConstraints.getWhenCondition();
+ final Set<MustDefinition> must = nodeConstraints.getMustConstraints();
+
+ if (when != null) {
+ constraints.addWhenCondition(when.toString());
+ }
+ if (must != null) {
+ for (MustDefinition md : must) {
+ constraints.addMustDefinition(md);
+ }
+ }
+ constraints.setMandatory(nodeConstraints.isMandatory());
+ constraints.setMinElements(nodeConstraints.getMinElements());
+ constraints.setMaxElements(nodeConstraints.getMaxElements());
+ }
+
}
*/
package org.opendaylight.yangtools.yang.parser.util;
+import static org.opendaylight.yangtools.yang.parser.util.ParserUtils.createSchemaPath;
+
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.Set;
import java.util.TreeMap;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
}
/**
- * Copy target grouping data to given uses node.
- * <p>
- * Copy all data-schema-nodes, groupings, typedefs and unknown nodes from
- * target grouping to uses node.
- * </p>
+ * Add nodes defined in uses target grouping to uses parent.
*
* @param usesNode
- * @param targetGrouping
*/
- public static void loadTargetGroupingData(final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
+ public static void updateUsesParent(UsesNodeBuilder usesNode) {
+ DataNodeContainerBuilder parent = usesNode.getParent();
+
// child nodes
- Set<DataSchemaNodeBuilder> targetChildren = new HashSet<>();
- for (DataSchemaNodeBuilder targetChild : targetGrouping.getChildNodeBuilders()) {
- targetChildren.add(CopyUtils.copy(targetChild, usesNode.getParent(), true));
+ for (DataSchemaNodeBuilder child : usesNode.getTargetChildren()) {
+ if (child instanceof GroupingMember) {
+ ((GroupingMember) child).setAddedByUses(true);
+ }
+ parent.addChildNode(child);
}
- usesNode.setTargetChildren(targetChildren);
// groupings
- Set<GroupingBuilder> targetGroupingGroupings = new HashSet<>();
- for (GroupingBuilder targetGroupingGrouping : targetGrouping.getGroupingBuilders()) {
- targetGroupingGroupings.add(CopyUtils.copy(targetGroupingGrouping, usesNode.getParent(), true));
+ for (GroupingBuilder gb : usesNode.getTargetGroupings()) {
+ gb.setAddedByUses(true);
+ parent.addGrouping(gb);
}
- usesNode.setTargetGroupings(targetGroupingGroupings);
// typedefs
- Set<TypeDefinitionBuilder> targetGroupingTypedefs = new HashSet<>();
- for(TypeDefinitionBuilder targetGroupingTypedef : targetGrouping.getTypeDefinitionBuilders()) {
- targetGroupingTypedefs.add(CopyUtils.copy(targetGroupingTypedef, usesNode.getParent(), true));
+ for (TypeDefinitionBuilder tdb : usesNode.getTargetTypedefs()) {
+ tdb.setAddedByUses(true);
+ parent.addTypedef(tdb);
}
- usesNode.setTargetTypedefs(targetGroupingTypedefs);
// unknown nodes
- List<UnknownSchemaNodeBuilder> targetGroupingUNs = new ArrayList<>();
- for(UnknownSchemaNodeBuilder targetGroupingUN : targetGrouping.getUnknownNodeBuilders()) {
- targetGroupingUNs.add(CopyUtils.copy(targetGroupingUN, usesNode.getParent(), true));
+ for (UnknownSchemaNodeBuilder un : usesNode.getTargetUnknownNodes()) {
+ un.setAddedByUses(true);
+ parent.addUnknownNodeBuilder(un);
}
- usesNode.setTargetUnknownNodes(targetGroupingUNs);
+ }
- usesNode.setLoadDone(true);
+ public static void collectUsesData(UsesNodeBuilder usesNode) {
+ usesNode.setTargetChildren(collectUsesChildNodes(usesNode));
+ usesNode.setTargetTypedefs(collectUsesTypedefs(usesNode));
+ usesNode.setTargetGroupings(collectUsesGroupings(usesNode));
+ usesNode.setTargetUnknownNodes(collectUsesUnknownNodes(usesNode));
+ usesNode.setDataCollected(true);
}
- /**
- * Copy all data from target grouping which were added by uses.
- * <p>
- * Traverse uses statements in target grouping and copy all
- * data-schema-nodes, groupings, typedefs and unknown nodes to current uses
- * node.
- * </p>
- *
- * @param usesNode
- * @param targetGrouping
- */
- public static void loadTargetGroupingUses(final UsesNodeBuilder usesNode, final GroupingBuilder targetGrouping) {
- usesNode.getTargetGroupingUses().addAll(targetGrouping.getUsesNodes());
+ private static Set<DataSchemaNodeBuilder> collectUsesChildNodes(UsesNodeBuilder usesNode) {
+ final GroupingBuilder target = usesNode.getGroupingBuilder();
+ Set<DataSchemaNodeBuilder> childNodes = target.getChildNodeBuilders();
+ Set<DataSchemaNodeBuilder> copies = new HashSet<>();
+ for (DataSchemaNodeBuilder childNode : childNodes) {
+ copies.add(CopyUtils.copy(childNode, usesNode.getParent(), true));
+ }
+ for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
+ copies.addAll(collectUsesChildNodes(targetUses));
+ }
+ return copies;
}
- /**
- * Create copy of collection of given nodes with new schema path.
- *
- * @param nodes
- * nodes to copy
- * @param parentPath
- * schema path of parent node
- * @param namespace
- * new namespace of node qname
- * @param revision
- * new revision of node qname
- * @param prefix
- * new prefix of node qname
- * @param moduleName
- * current yang module name
- * @param line
- * current line in yang module
- * @return collection of new nodes with corrected path
- */
- public static Set<DataSchemaNodeBuilder> copyUsesTargetNodesWithNewPath(UsesNodeBuilder usesNode, Builder parent) {
- Set<DataSchemaNodeBuilder> newNodes = new HashSet<>();
+ private static Set<TypeDefinitionBuilder> collectUsesTypedefs(UsesNodeBuilder usesNode) {
+ final GroupingBuilder target = usesNode.getGroupingBuilder();
+ Set<TypeDefinitionBuilder> typedefs = target.getTypeDefinitionBuilders();
+ Set<TypeDefinitionBuilder> copies = new HashSet<>();
+ for (TypeDefinitionBuilder typedef : typedefs) {
+ copies.add(CopyUtils.copy(typedef, usesNode.getParent(), true));
+ }
+ for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
+ copies.addAll(collectUsesTypedefs(targetUses));
+ }
+ return copies;
+ }
- for (DataSchemaNodeBuilder node : usesNode.getTargetChildren()) {
- if (node != null) {
- if (node instanceof GroupingMember) {
- ((GroupingMember) node).setAddedByUses(true);
- }
- newNodes.add(node);
- }
+ private static Set<GroupingBuilder> collectUsesGroupings(UsesNodeBuilder usesNode) {
+ final GroupingBuilder target = usesNode.getGroupingBuilder();
+ Set<GroupingBuilder> groupings = target.getGroupingBuilders();
+ Set<GroupingBuilder> copies = new HashSet<>();
+ for (GroupingBuilder grouping : groupings) {
+ copies.add(CopyUtils.copy(grouping, usesNode.getParent(), true));
+ }
+ for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
+ copies.addAll(collectUsesGroupings(targetUses));
}
+ return copies;
+ }
- return newNodes;
+ private static List<UnknownSchemaNodeBuilder> collectUsesUnknownNodes(UsesNodeBuilder usesNode) {
+ final GroupingBuilder target = usesNode.getGroupingBuilder();
+ List<UnknownSchemaNodeBuilder> unknownNodes = target.getUnknownNodeBuilders();
+ List<UnknownSchemaNodeBuilder> copies = new ArrayList<>();
+ for (UnknownSchemaNodeBuilder unknownNode : unknownNodes) {
+ copies.add(CopyUtils.copy(unknownNode, usesNode.getParent(), true));
+ }
+ for (UsesNodeBuilder targetUses : target.getUsesNodes()) {
+ copies.addAll(collectUsesUnknownNodes(targetUses));
+ }
+ return copies;
}
- /**
- * Create copy of collection of given groupings with new schema path.
- *
- * @param groupings
- * groupings to copy
- * @param parentPath
- * schema path of parent node
- * @param namespace
- * new namespace of node qname
- * @param revision
- * new revision of node qname
- * @param prefix
- * new prefix of node qname
- * @return collection of new groupings with corrected path
- */
- public static Set<GroupingBuilder> copyUsesTargetGroupingsWithNewPath(UsesNodeBuilder usesNode,
- SchemaPath parentPath, URI namespace, Date revision, String prefix) {
- Set<GroupingBuilder> newGroupings = new HashSet<>();
- for (GroupingBuilder node : usesNode.getTargetGroupings()) {
- if (node != null) {
- if (node instanceof GroupingMember) {
- ((GroupingMember) node).setAddedByUses(true);
+ public static void collectUsesDataFromContext(UsesNodeBuilder usesNode) {
+ DataNodeContainerBuilder parent = usesNode.getParent();
+ URI namespace = parent.getQName().getNamespace();
+ Date revision = parent.getQName().getRevision();
+ String prefix = parent.getQName().getPrefix();
+ String moduleName = parent.getModuleName();
+ int line = parent.getLine();
+
+ // child nodes
+ final Set<DataSchemaNodeBuilder> newChildren = new HashSet<>();
+ for (DataSchemaNode child : usesNode.getGroupingDefinition().getChildNodes()) {
+ if (child != null) {
+ DataSchemaNodeBuilder newChild = null;
+ QName newQName = new QName(namespace, revision, prefix, child.getQName().getLocalName());
+ if (child instanceof AnyXmlSchemaNode) {
+ newChild = CopyUtils.createAnyXml((AnyXmlSchemaNode) child, newQName, moduleName, line);
+ } else if (child instanceof ChoiceNode) {
+ newChild = CopyUtils.createChoice((ChoiceNode) child, newQName, moduleName, line);
+ } else if (child instanceof ContainerSchemaNode) {
+ newChild = CopyUtils.createContainer((ContainerSchemaNode) child, newQName, moduleName, line);
+ } else if (child instanceof LeafListSchemaNode) {
+ newChild = CopyUtils.createLeafList((LeafListSchemaNode) child, newQName, moduleName, line);
+ } else if (child instanceof LeafSchemaNode) {
+ newChild = CopyUtils.createLeafBuilder((LeafSchemaNode) child, newQName, moduleName, line);
+ } else if (child instanceof ListSchemaNode) {
+ newChild = CopyUtils.createList((ListSchemaNode) child, newQName, moduleName, line);
+ }
+
+ if (newChild == null) {
+ throw new YangParseException(moduleName, line,
+ "Unknown member of target grouping while resolving uses node.");
+ }
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
}
- newGroupings.add(node);
+
+ newChild.setPath(createSchemaPath(parent.getPath(), newQName));
+ newChildren.add(newChild);
}
}
+ usesNode.setTargetChildren(newChildren);
+
+ // groupings
+ final Set<GroupingBuilder> newGroupings = new HashSet<>();
+ for (GroupingDefinition g : usesNode.getGroupingDefinition().getGroupings()) {
+ QName newQName = new QName(namespace, revision, prefix, g.getQName().getLocalName());
+ GroupingBuilder newGrouping = CopyUtils.createGrouping(g, newQName, moduleName, line);
+ newGrouping.setAddedByUses(true);
+ newGrouping.setPath(createSchemaPath(parent.getPath(), newQName));
+ newGroupings.add(newGrouping);
+ }
+ usesNode.setTargetGroupings(newGroupings);
+
+ // typedefs
+ final Set<TypeDefinitionBuilder> newTypedefs = new HashSet<>();
+ for (TypeDefinition<?> td : usesNode.getGroupingDefinition().getTypeDefinitions()) {
+ QName newQName = new QName(namespace, revision, prefix, td.getQName().getLocalName());
+ TypeDefinitionBuilder newType = CopyUtils.createTypedef((ExtendedType) td, newQName, moduleName, line);
+ newType.setAddedByUses(true);
+ newType.setPath(createSchemaPath(parent.getPath(), newQName));
+ newTypedefs.add(newType);
+ }
+ usesNode.setTargetTypedefs(newTypedefs);
+
+ // unknown nodes
+ final List<UnknownSchemaNodeBuilder> newUnknownNodes = new ArrayList<>();
+ for (UnknownSchemaNode un : usesNode.getGroupingDefinition().getUnknownSchemaNodes()) {
+ QName newQName = new QName(namespace, revision, prefix, un.getQName().getLocalName());
+ UnknownSchemaNodeBuilder newNode = CopyUtils.createUnknownSchemaNode(un, newQName, moduleName, line);
+ newNode.setAddedByUses(true);
+ newNode.setPath(createSchemaPath(parent.getPath(), newQName));
+ newUnknownNodes.add(newNode);
+ }
+ usesNode.setTargetUnknownNodes(newUnknownNodes);
- return newGroupings;
+ usesNode.setDataCollected(true);
}
- /**
- * Create copy of collection of given typedefs with new schema path.
- *
- * @param typedefs
- * typedefs to copy
- * @param parentPath
- * schema path of parent node
- * @param namespace
- * new namespace of node qname
- * @param revision
- * new revision of node qname
- * @param prefix
- * new prefix of node qname
- * @return collection of new typedefs with corrected path
- */
- public static Set<TypeDefinitionBuilder> copyUsesTargetTypedefsWithNewPath(UsesNodeBuilder usesNode,
- SchemaPath parentPath, URI namespace, Date revision, String prefix) {
- Set<TypeDefinitionBuilder> newTypedefs = new HashSet<>();
-
- for (TypeDefinitionBuilder node : usesNode.getTargetTypedefs()) {
- if (node != null) {
- if (node instanceof GroupingMember) {
- ((GroupingMember) node).setAddedByUses(true);
+ public static void fixUsesNodesPath(UsesNodeBuilder usesNode) {
+ DataNodeContainerBuilder parent = usesNode.getParent();
+
+ // child nodes
+ Set<DataSchemaNodeBuilder> currentChildNodes = parent.getChildNodeBuilders();
+ Set<DataSchemaNodeBuilder> toRemove = new HashSet<>();
+ Set<DataSchemaNodeBuilder> toAdd = new HashSet<>();
+ for (DataSchemaNodeBuilder child : currentChildNodes) {
+ if (child instanceof GroupingMember) {
+ GroupingMember gm = (GroupingMember) child;
+ if (gm.isAddedByUses()) {
+ toRemove.add(child);
+ DataSchemaNodeBuilder copy = CopyUtils.copy(child, parent, true);
+ ParserUtils.correctNodePath(copy, parent.getPath());
+ toAdd.add(copy);
}
- newTypedefs.add(node);
}
}
+ currentChildNodes.removeAll(toRemove);
+ currentChildNodes.addAll(toAdd);
- return newTypedefs;
+ // groupings
+ Set<GroupingBuilder> currentGroupings = parent.getGroupingBuilders();
+ Set<GroupingBuilder> toRemoveG = new HashSet<>();
+ Set<GroupingBuilder> toAddG = new HashSet<>();
+ for (GroupingBuilder child : currentGroupings) {
+ if (child.isAddedByUses()) {
+ toRemoveG.add(child);
+ GroupingBuilder copy = CopyUtils.copy(child, parent, true);
+ ParserUtils.correctNodePath(copy, parent.getPath());
+ toAddG.add(copy);
+ }
+
+ }
+ currentGroupings.removeAll(toRemoveG);
+ currentGroupings.addAll(toAddG);
+
+ // typedefs
+ Set<TypeDefinitionBuilder> currentTypedefs = parent.getTypeDefinitionBuilders();
+ Set<TypeDefinitionBuilder> toRemoveTD = new HashSet<>();
+ Set<TypeDefinitionBuilder> toAddTD = new HashSet<>();
+ for (TypeDefinitionBuilder child : currentTypedefs) {
+ if (child.isAddedByUses()) {
+ toRemoveTD.add(child);
+ TypeDefinitionBuilder copy = CopyUtils.copy(child, parent, true);
+ ParserUtils.correctNodePath(copy, parent.getPath());
+ toAddTD.add(copy);
+ }
+
+ }
+ currentTypedefs.removeAll(toRemoveTD);
+ currentTypedefs.addAll(toAddTD);
+
+ // unknown nodes
+ List<UnknownSchemaNodeBuilder> currentUN = parent.getUnknownNodeBuilders();
+ List<UnknownSchemaNodeBuilder> toRemoveUN = new ArrayList<>();
+ List<UnknownSchemaNodeBuilder> toAddUN = new ArrayList<>();
+ for (UnknownSchemaNodeBuilder un : currentUN) {
+ if (un.isAddedByUses()) {
+ toRemoveUN.add(un);
+ UnknownSchemaNodeBuilder copy = CopyUtils.copy(un, parent, true);
+ ParserUtils.correctNodePath(copy, parent.getPath());
+ toAddUN.add(copy);
+ }
+ }
+ currentUN.removeAll(toRemoveUN);
+ currentUN.addAll(toAddUN);
}
/**
- * Create copy of collection of given unknown nodes with new schema path.
+ * Perform refinement of uses target grouping nodes. Uses process has to be
+ * already performed.
*
* @param usesNode
- * @param parentPath
- * schema path of parent node
- * @param namespace
- * new namespace of node qname
- * @param revision
- * new revision of node qname
- * @param prefix
- * new prefix of node qname
- * @return collection of new unknownNodes with corrected path
*/
- public static List<UnknownSchemaNodeBuilder> copyUsesTargetUnknownNodesWithNewPath(UsesNodeBuilder usesNode,
- SchemaPath parentPath, URI namespace, Date revision, String prefix) {
- List<UnknownSchemaNodeBuilder> newUnknownNodes = new ArrayList<>();
-
- for (UnknownSchemaNodeBuilder node : usesNode.getTargetUnknownNodes()) {
- if (node != null) {
- node.setAddedByUses(true);
- newUnknownNodes.add(node);
+ public static void performRefine(UsesNodeBuilder usesNode) {
+ for (RefineHolder refine : usesNode.getRefines()) {
+ DataSchemaNodeBuilder nodeToRefine = null;
+ for (DataSchemaNodeBuilder dataNode : usesNode.getParent().getChildNodeBuilders()) {
+ if (refine.getName().equals(dataNode.getQName().getLocalName())) {
+ nodeToRefine = dataNode;
+ break;
+ }
+ }
+ if (nodeToRefine == null) {
+ throw new YangParseException(refine.getModuleName(), refine.getLine(), "Refine target node '"
+ + refine.getName() + "' not found");
}
+ RefineUtils.performRefine(nodeToRefine, refine);
+ usesNode.addRefineNode(nodeToRefine);
}
-
- return newUnknownNodes;
}
}
}
/**
- * Create SchemaPath from actualPath and names.
+ * Create SchemaPath from actualPath and new node name.
*
* @param actualPath
* current position in model
- * @param namespace
- * @param revision
- * @param prefix
- * @param names
- * @return SchemaPath object.
+ * @return SchemaPath object
*/
- public static SchemaPath createActualSchemaPath(final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix, final String... names) {
- final List<QName> path = new ArrayList<QName>();
- QName qname;
- // start from index 1 - module name omited
- for (int i = 1; i < actualPath.size(); i++) {
- qname = new QName(namespace, revision, prefix, actualPath.get(i));
- path.add(qname);
- }
- for (String name : names) {
- qname = new QName(namespace, revision, prefix, name);
- path.add(qname);
- }
+ public static SchemaPath createActualSchemaPath(final Stack<QName> actualPath) {
+ final List<QName> path = new ArrayList<QName>(actualPath);
return new SchemaPath(path, true);
}
* type body context to parse
* @param path
* actual position in YANG model
- * @param moduleName current module name
- * @param namespace
- * @param revision
- * @param prefix
+ * @param moduleName
+ * current module name
* @return List of EnumPair object parsed from given context
*/
private static List<EnumTypeDefinition.EnumPair> getEnumConstants(final Type_body_stmtsContext ctx,
- final List<String> path, final String moduleName, final URI namespace, final Date revision, final String prefix) {
+ final Stack<QName> path, final String moduleName) {
List<EnumTypeDefinition.EnumPair> enumConstants = new ArrayList<EnumTypeDefinition.EnumPair>();
for (int i = 0; i < ctx.getChildCount(); i++) {
for (int j = 0; j < enumSpecChild.getChildCount(); j++) {
ParseTree enumChild = enumSpecChild.getChild(j);
if (enumChild instanceof Enum_stmtContext) {
- EnumPair enumPair = createEnumPair((Enum_stmtContext) enumChild, highestValue, path, moduleName, namespace,
- revision, prefix);
+ EnumPair enumPair = createEnumPair((Enum_stmtContext) enumChild, highestValue, path, moduleName);
if (enumPair.getValue() > highestValue) {
highestValue = enumPair.getValue();
}
* actual position in YANG model
* @param moduleName
* current module name
- * @param namespace
- * @param revision
- * @param prefix
* @return EnumPair object parsed from given context
*/
private static EnumTypeDefinition.EnumPair createEnumPair(final Enum_stmtContext ctx, final int highestValue,
- final List<String> path, final String moduleName, final URI namespace, final Date revision,
- final String prefix) {
+ final Stack<QName> actualPath, final String moduleName) {
final String name = stringFromNode(ctx);
- final QName qname = new QName(namespace, revision, prefix, name);
+ SchemaPath path = createTypePath(actualPath, name);
Integer value = null;
String description = null;
String reference = null;
Status status = null;
- List<String> enumPairPath = new ArrayList<String>(path);
- enumPairPath.add(name);
-
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof Value_stmtContext) {
}
EnumPairImpl result = new EnumPairImpl();
- result.qname = qname;
- result.path = createActualSchemaPath(enumPairPath, namespace, revision, prefix);
+ result.qname = path.getPath().get(path.getPath().size() - 1);
+ result.path = path;
result.description = description;
result.reference = reference;
result.status = status;
*
* @param ctx
* type body context to parse
+ * @param moduleName
* @return List of RangeConstraint created from this context
*/
private static List<RangeConstraint> getRangeConstraints(final Type_body_stmtsContext ctx, final String moduleName) {
*
* @param ctx
* range context to parse
+ * @param moduleName
* @return List of RangeConstraints parsed from this context
*/
private static List<RangeConstraint> parseRangeConstraints(final Range_stmtContext ctx, final String moduleName) {
*
* @param ctx
* type body context to parse
+ * @param moduleName
* @return List of LengthConstraint created from this context
*/
private static List<LengthConstraint> getLengthConstraints(final Type_body_stmtsContext ctx, final String moduleName) {
*
* @param ctx
* length context to parse
+ * @param moduleName
* @return List of LengthConstraints parsed from this context
*/
private static List<LengthConstraint> parseLengthConstraints(final Length_stmtContext ctx, final String moduleName) {
/**
* @param value
* value to parse
+ * @param moduleName name of current module
+ * @param line current line in module
* @return wrapper object of primitive java type or UnknownBoundaryNumber if
* type is one of special YANG values 'min' or 'max'
*/
* type body context to parse
* @param actualPath
* current position in YANG model
- * @param moduleName current module name
- * @param namespace
- * @param revision
- * @param prefix
+ * @param moduleName
+ * current module name
* @return List of Bit objects created from this context
*/
- private static List<BitsTypeDefinition.Bit> getBits(Type_body_stmtsContext ctx, List<String> actualPath,
- String moduleName, URI namespace, Date revision, String prefix) {
+ private static List<BitsTypeDefinition.Bit> getBits(Type_body_stmtsContext ctx, Stack<QName> actualPath,
+ String moduleName) {
final List<BitsTypeDefinition.Bit> bits = new ArrayList<BitsTypeDefinition.Bit>();
for (int j = 0; j < ctx.getChildCount(); j++) {
ParseTree bitsSpecChild = ctx.getChild(j);
for (int k = 0; k < bitsSpecChild.getChildCount(); k++) {
ParseTree bitChild = bitsSpecChild.getChild(k);
if (bitChild instanceof Bit_stmtContext) {
- Bit bit = parseBit((Bit_stmtContext) bitChild, highestPosition, actualPath, moduleName, namespace,
- revision, prefix);
+ Bit bit = parseBit((Bit_stmtContext) bitChild, highestPosition, actualPath, moduleName);
if (bit.getPosition() > highestPosition) {
highestPosition = bit.getPosition();
}
* current highest position in bits type
* @param actualPath
* current position in YANG model
- * @param moduleName current module name
- * @param namespace
- * @param revision
- * @param prefix
+ * @param moduleName
+ * current module name
* @return Bit object parsed from this context
*/
private static BitsTypeDefinition.Bit parseBit(final Bit_stmtContext ctx, long highestPosition,
- List<String> actualPath, final String moduleName, final URI namespace, final Date revision, final String prefix) {
+ Stack<QName> actualPath, final String moduleName) {
String name = stringFromNode(ctx);
- final QName qname = new QName(namespace, revision, prefix, name);
Long position = null;
String description = null;
String reference = null;
Status status = Status.CURRENT;
- Stack<String> bitPath = new Stack<String>();
- bitPath.addAll(actualPath);
- bitPath.add(name);
-
- SchemaPath schemaPath = createActualSchemaPath(bitPath, namespace, revision, prefix);
+ SchemaPath schemaPath = createBaseTypePath(actualPath, name);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
}
final List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
- return new BitImpl(position, qname, schemaPath, description, reference, status, unknownNodes);
+ return new BitImpl(position, schemaPath.getPath().get(schemaPath.getPath().size() - 1), schemaPath,
+ description, reference, status, unknownNodes);
}
/**
*
* @param ctx
* config context to parse
- * @param moduleName current module name
+ * @param moduleName
+ * current module name
* @return true if given context contains string 'true', false otherwise
*/
private static Boolean parseConfig(final Config_stmtContext ctx, final String moduleName) {
* @return UnknownType object with constraints from parsed type body
*/
public static TypeDefinition<?> parseUnknownTypeWithBody(final QName typedefQName,
- final Type_body_stmtsContext ctx, final List<String> actualPath, final URI namespace, final Date revision,
+ final Type_body_stmtsContext ctx, final Stack<QName> actualPath, final URI namespace, final Date revision,
final String prefix, final Builder parent) {
String moduleName = parent.getModuleName();
String typeName = typedefQName.getLocalName();
TypeDefinition<?> baseType = unknownType.build();
TypeDefinition<?> result = null;
QName qname = new QName(namespace, revision, prefix, typeName);
- SchemaPath schemaPath = createTypeSchemaPath(actualPath, namespace, revision, prefix, typeName, false,
- false);
+ SchemaPath schemaPath = createTypePath(actualPath, typeName);
ExtendedType.Builder typeBuilder = new ExtendedType.Builder(qname, baseType, null, null, schemaPath);
typeBuilder.ranges(rangeStatements);
* parent builder
* @return TypeDefinition object based on parsed values.
*/
- public static TypeDefinition<?> parseTypeWithBody(final String typeName,
- final Type_body_stmtsContext typeBody, final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix, final Builder parent) {
+ public static TypeDefinition<?> parseTypeWithBody(final String typeName, final Type_body_stmtsContext typeBody,
+ final Stack<QName> actualPath, final URI namespace, final Date revision, final String prefix,
+ final Builder parent) {
+
final String moduleName = parent.getModuleName();
final int line = typeBody.getStart().getLine();
TypeDefinition<?> baseType = null;
constraints.addPatterns(patternStatements);
constraints.addRanges(rangeStatements);
- SchemaPath baseTypePathFinal = createTypeSchemaPath(actualPath, namespace, revision, prefix, typeName, true,
- true);
- SchemaPath baseTypePath = createTypeSchemaPath(actualPath, namespace, revision, prefix, typeName, true, false);
+ SchemaPath baseTypePath = createBaseTypePath(actualPath, typeName);
+ SchemaPath extBaseTypePath = createExtendedBaseTypePath(actualPath, namespace, revision, prefix, typeName);
+
+ if (parent instanceof TypeDefinitionBuilder && !(parent instanceof UnionTypeBuilder)) {
+ extBaseTypePath = baseTypePath;
+ }
if ("decimal64".equals(typeName)) {
if (rangeStatements.isEmpty()) {
- return new Decimal64(baseTypePathFinal, fractionDigits);
+ return new Decimal64(baseTypePath, fractionDigits);
}
- Decimal64 decimalType = new Decimal64(baseTypePath, fractionDigits);
+ Decimal64 decimalType = new Decimal64(extBaseTypePath, fractionDigits);
constraints.addRanges(decimalType.getRangeStatements());
baseType = decimalType;
} else if (typeName.startsWith("int")) {
IntegerTypeDefinition intType = null;
if ("int8".equals(typeName)) {
- intType = new Int8(baseTypePath);
+ intType = new Int8(extBaseTypePath);
} else if ("int16".equals(typeName)) {
- intType = new Int16(baseTypePath);
+ intType = new Int16(extBaseTypePath);
} else if ("int32".equals(typeName)) {
- intType = new Int32(baseTypePath);
+ intType = new Int32(extBaseTypePath);
} else if ("int64".equals(typeName)) {
- intType = new Int64(baseTypePath);
+ intType = new Int64(extBaseTypePath);
}
if (intType == null) {
throw new YangParseException(moduleName, line, "Unknown yang type " + typeName);
} else if (typeName.startsWith("uint")) {
UnsignedIntegerTypeDefinition uintType = null;
if ("uint8".equals(typeName)) {
- uintType = new Uint8(baseTypePath);
+ uintType = new Uint8(extBaseTypePath);
} else if ("uint16".equals(typeName)) {
- uintType = new Uint16(baseTypePath);
+ uintType = new Uint16(extBaseTypePath);
} else if ("uint32".equals(typeName)) {
- uintType = new Uint32(baseTypePath);
+ uintType = new Uint32(extBaseTypePath);
} else if ("uint64".equals(typeName)) {
- uintType = new Uint64(baseTypePath);
+ uintType = new Uint64(extBaseTypePath);
}
if (uintType == null) {
throw new YangParseException(moduleName, line, "Unknown yang type " + typeName);
constraints.addRanges(uintType.getRangeStatements());
baseType = uintType;
} else if ("enumeration".equals(typeName)) {
- List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, moduleName, namespace,
- revision, prefix);
- return new EnumerationType(baseTypePathFinal, enumConstants);
+ List<EnumTypeDefinition.EnumPair> enumConstants = getEnumConstants(typeBody, actualPath, moduleName);
+ return new EnumerationType(baseTypePath, enumConstants);
} else if ("string".equals(typeName)) {
- StringTypeDefinition stringType = new StringType(baseTypePath);
+ StringTypeDefinition stringType = new StringType(extBaseTypePath);
constraints.addLengths(stringType.getLengthStatements());
baseType = stringType;
} else if ("bits".equals(typeName)) {
- return new BitsType(baseTypePathFinal, getBits(typeBody, actualPath, moduleName, namespace, revision, prefix));
+ return new BitsType(baseTypePath, getBits(typeBody, actualPath, moduleName));
} else if ("leafref".equals(typeName)) {
final String path = parseLeafrefPath(typeBody);
final boolean absolute = path.startsWith("/");
RevisionAwareXPath xpath = new RevisionAwareXPathImpl(path, absolute);
- return new Leafref(baseTypePathFinal, xpath);
+ return new Leafref(baseTypePath, xpath);
} else if ("binary".equals(typeName)) {
- BinaryTypeDefinition binaryType = new BinaryType(baseTypePath);
+ BinaryTypeDefinition binaryType = new BinaryType(extBaseTypePath);
constraints.addLengths(binaryType.getLengthConstraints());
baseType = binaryType;
} else if ("instance-identifier".equals(typeName)) {
boolean requireInstance = isRequireInstance(typeBody);
- return new InstanceIdentifier(baseTypePath, null, requireInstance);
+ return new InstanceIdentifier(extBaseTypePath, null, requireInstance);
}
if (parent instanceof TypeDefinitionBuilder && !(parent instanceof UnionTypeBuilder)) {
}
TypeDefinition<?> result = null;
- QName qname = new QName(namespace, revision, prefix, typeName);
ExtendedType.Builder typeBuilder = null;
- SchemaPath schemaPath = createTypeSchemaPath(actualPath, namespace, revision, prefix, typeName, false, false);
+ List<QName> path = new ArrayList<QName>(actualPath);
+ path.add(new QName(namespace, revision, prefix, typeName));
+ SchemaPath schemaPath = new SchemaPath(path, true);
+
+ QName qname = schemaPath.getPath().get(schemaPath.getPath().size() - 1);
typeBuilder = new ExtendedType.Builder(qname, baseType, "", "", schemaPath);
typeBuilder.ranges(constraints.getRange());
return result;
}
- /**
- * Create SchemaPath object from given path list with namespace, revision
- * and prefix based on given values.
- *
- * @param actualPath
- * current position in model
- * @param namespace
- * @param revision
- * @param prefix
- * @param typeName
- * @param isBaseYangType
- * if this is base yang type
- * @param isBaseYangTypeFinal
- * if this is base yang type without restrictions
- * @return SchemaPath object.
- */
- private static SchemaPath createTypeSchemaPath(final List<String> actualPath, final URI namespace,
- final Date revision, final String prefix, final String typeName, final boolean isBaseYangType,
- final boolean isBaseYangTypeFinal) {
- List<String> typePath = new ArrayList<String>(actualPath);
- if (isBaseYangType && !isBaseYangTypeFinal) {
- typePath.add(typeName);
- }
-
- final List<QName> path = new ArrayList<QName>();
- QName qname;
- // start from index 1 -> module name omited
- for (int i = 1; i < typePath.size(); i++) {
- qname = new QName(namespace, revision, prefix, typePath.get(i));
- path.add(qname);
- }
- QName typeQName;
- if (isBaseYangType) {
- typeQName = new QName(BaseTypes.BaseTypesNamespace, typeName);
- } else {
- typeQName = new QName(namespace, revision, prefix, typeName);
- }
+ private static SchemaPath createTypePath(Stack<QName> actual, String typeName) {
+ QName last = actual.peek();
+ QName typeQName = new QName(last.getNamespace(), last.getRevision(), last.getPrefix(), typeName);
+ List<QName> path = new ArrayList<QName>(actual);
path.add(typeQName);
return new SchemaPath(path, true);
}
+ private static SchemaPath createBaseTypePath(Stack<QName> actual, String typeName) {
+ List<QName> path = new ArrayList<QName>(actual);
+ path.add(BaseTypes.constructQName(typeName));
+ return new SchemaPath(path, true);
+ }
+
+ private static SchemaPath createExtendedBaseTypePath(Stack<QName> actual, URI namespace, Date revision,
+ String prefix, String typeName) {
+ QName extTypeName = new QName(namespace, revision, prefix, typeName);
+ QName baseTypeName = BaseTypes.constructQName(typeName);
+ List<QName> path = new ArrayList<QName>(actual);
+ path.add(extTypeName);
+ path.add(baseTypeName);
+ return new SchemaPath(path, true);
+ }
+
/**
* Parse given context and find identityref base value.
*
*
* @param refineCtx
* refine statement
+ * @param moduleName name of current module
* @return RefineHolder object representing this refine statement
*/
public static RefineHolder parseRefine(Refine_stmtContext refineCtx, String moduleName) {
*/
package org.opendaylight.yangtools.yang.parser.util;
-import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.MustDefinition;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
-import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
import org.opendaylight.yangtools.yang.model.util.InstanceIdentifier;
import org.opendaylight.yangtools.yang.model.util.Leafref;
+import org.opendaylight.yangtools.yang.model.util.StringType;
import org.opendaylight.yangtools.yang.model.util.UnionType;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataNodeContainerBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.api.GroupingMember;
import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeAwareBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.AnyXmlBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceBuilder.ChoiceNodeImpl;
import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceCaseBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ChoiceCaseBuilder.ChoiceCaseNodeImpl;
-import org.opendaylight.yangtools.yang.parser.builder.impl.ConstraintsBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder.ContainerSchemaNodeImpl;
-import org.opendaylight.yangtools.yang.parser.builder.impl.GroupingBuilderImpl;
import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder;
-import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ListSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.ListSchemaNodeBuilder.ListSchemaNodeImpl;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.NotificationBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.NotificationBuilder.NotificationDefinitionImpl;
-import org.opendaylight.yangtools.yang.parser.builder.impl.TypeDefinitionBuilderImpl;
-import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.UnionTypeBuilder;
public final class ParserUtils {
correctNodePath(childCopy, target.getPath());
try {
target.addChildNode(childCopy);
- } catch(YangParseException e) {
+ } catch (YangParseException e) {
// more descriptive message
- throw new YangParseException(augment.getModuleName(), augment.getLine(), "Failed to perform augmentation: "+ e.getMessage());
+ throw new YangParseException(augment.getModuleName(), augment.getLine(),
+ "Failed to perform augmentation: " + e.getMessage());
}
}
for (UsesNodeBuilder usesNode : augment.getUsesNodes()) {
- target.addUsesNode(CopyUtils.copyUses(usesNode, target));
+ UsesNodeBuilder copy = CopyUtils.copyUses(usesNode, target);
+ target.addUsesNode(copy);
}
}
"Error in augment parsing: cannot augment uses to choice");
}
}
-
}
static void correctNodePath(final SchemaNodeBuilder node, final SchemaPath parentSchemaPath) {
// if node can contains type, correct path for this type too
if (node instanceof TypeAwareBuilder) {
TypeAwareBuilder nodeBuilder = (TypeAwareBuilder) node;
- correctTypeAwareNodePath(nodeBuilder, node.getPath());
+ correctTypeAwareNodePath(nodeBuilder);
}
}
* @param parentSchemaPath
* schema path of parent node
*/
- private static void correctTypeAwareNodePath(final TypeAwareBuilder node, final SchemaPath parentSchemaPath) {
- final QName nodeBuilderQName = node.getQName();
+ public static void correctTypeAwareNodePath(final TypeAwareBuilder node) {
+ final SchemaPath parentSchemaPath = node.getPath();
final TypeDefinition<?> nodeType = node.getType();
- Integer fd = null;
- List<LengthConstraint> lengths = null;
- List<PatternConstraint> patterns = null;
- List<RangeConstraint> ranges = null;
-
- if (nodeType != null) {
- if (nodeType instanceof ExtendedType) {
- ExtendedType et = (ExtendedType) nodeType;
- if (nodeType.getQName().getLocalName().equals(nodeType.getBaseType().getQName().getLocalName())) {
- fd = et.getFractionDigits();
- lengths = et.getLengths();
- patterns = et.getPatterns();
- ranges = et.getRanges();
- if (!hasConstraints(fd, lengths, patterns, ranges)) {
- return;
- }
- }
+ // handle union type
+ if (node instanceof UnionTypeBuilder) {
+ for (TypeDefinitionBuilder tdb : ((UnionTypeBuilder) node).getTypedefs()) {
+ SchemaPath newSchemaPath = createSchemaPath(node.getPath(), tdb.getQName());
+ tdb.setPath(newSchemaPath);
+ correctTypeAwareNodePath(tdb);
}
- TypeDefinition<?> newType = createCorrectTypeDefinition(parentSchemaPath, nodeBuilderQName, nodeType);
- node.setType(newType);
- } else {
- TypeDefinitionBuilder nodeBuilderTypedef = node.getTypedef();
-
- fd = nodeBuilderTypedef.getFractionDigits();
- lengths = nodeBuilderTypedef.getLengths();
- patterns = nodeBuilderTypedef.getPatterns();
- ranges = nodeBuilderTypedef.getRanges();
-
- String tdbTypeName = nodeBuilderTypedef.getQName().getLocalName();
- String baseTypeName = null;
- if (nodeBuilderTypedef.getType() == null) {
- baseTypeName = nodeBuilderTypedef.getTypedef().getQName().getLocalName();
- } else {
- baseTypeName = nodeBuilderTypedef.getType().getQName().getLocalName();
- }
- if (!(tdbTypeName.equals(baseTypeName))) {
- return;
- }
-
- if (!hasConstraints(fd, lengths, patterns, ranges)) {
- return;
+ List<TypeDefinition<?>> oldTypes = ((UnionTypeBuilder) node).getTypes();
+ List<TypeDefinition<?>> newTypes = new ArrayList<>();
+ for (TypeDefinition<?> td : oldTypes) {
+ TypeDefinition<?> newType = createCorrectTypeDefinition(node.getPath(), td);
+ newTypes.add(newType);
}
+ oldTypes.clear();
+ oldTypes.addAll(newTypes);
+ return;
+ }
- SchemaPath newSchemaPath = createSchemaPath(nodeBuilderTypedef.getPath(), nodeBuilderQName,
- nodeBuilderTypedef.getQName());
- nodeBuilderTypedef.setPath(newSchemaPath);
+ // handle identityref type
+ if (node instanceof IdentityrefTypeBuilder) {
+ return;
}
- }
- /**
- * Check if there are some constraints.
- *
- * @param fd
- * fraction digits
- * @param lengths
- * length constraints
- * @param patterns
- * pattern constraints
- * @param ranges
- * range constraints
- * @return true, if any of constraints are present, false otherwise
- */
- private static boolean hasConstraints(final Integer fd, final List<LengthConstraint> lengths,
- final List<PatternConstraint> patterns, final List<RangeConstraint> ranges) {
- if (fd == null && (lengths == null || lengths.isEmpty()) && (patterns == null || patterns.isEmpty())
- && (ranges == null || ranges.isEmpty())) {
- return false;
+ // default handling
+ if (nodeType == null) {
+ TypeDefinitionBuilder nodeTypedef = node.getTypedef();
+ SchemaPath newSchemaPath = createSchemaPath(parentSchemaPath, nodeTypedef.getQName());
+ nodeTypedef.setPath(newSchemaPath);
+ correctTypeAwareNodePath(nodeTypedef);
} else {
- return true;
+ TypeDefinition<?> newType = createCorrectTypeDefinition(parentSchemaPath, nodeType);
+ node.setType(newType);
}
+
}
- private static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, QName nodeQName,
- TypeDefinition<?> nodeType) {
+ public static TypeDefinition<?> createCorrectTypeDefinition(SchemaPath parentSchemaPath, TypeDefinition<?> nodeType) {
TypeDefinition<?> result = null;
if (nodeType != null) {
- QName nodeTypeQName = nodeType.getQName();
- SchemaPath newSchemaPath = createSchemaPath(parentSchemaPath, nodeQName, nodeTypeQName);
+ SchemaPath newSchemaPath = createSchemaPath(parentSchemaPath, nodeType.getQName());
if (nodeType instanceof BinaryTypeDefinition) {
BinaryTypeDefinition binType = (BinaryTypeDefinition) nodeType;
return new InstanceIdentifier(newSchemaPath, instIdType.getPathStatement(),
instIdType.requireInstance());
} else if (nodeType instanceof StringTypeDefinition) {
- result = TypeUtils.createNewStringType(parentSchemaPath, nodeQName, (StringTypeDefinition) nodeType);
+ result = new StringType(newSchemaPath);
} else if (nodeType instanceof IntegerTypeDefinition) {
- result = TypeUtils.createNewIntType(parentSchemaPath, nodeQName, (IntegerTypeDefinition) nodeType);
+ result = TypeUtils.createNewIntType(newSchemaPath, (IntegerTypeDefinition) nodeType);
} else if (nodeType instanceof UnsignedIntegerTypeDefinition) {
- result = TypeUtils.createNewUintType(parentSchemaPath, nodeQName,
- (UnsignedIntegerTypeDefinition) nodeType);
+ result = TypeUtils.createNewUintType(newSchemaPath, (UnsignedIntegerTypeDefinition) nodeType);
} else if (nodeType instanceof LeafrefTypeDefinition) {
result = new Leafref(newSchemaPath, ((LeafrefTypeDefinition) nodeType).getPathStatement());
} else if (nodeType instanceof UnionTypeDefinition) {
return result;
}
- /**
- * Create LeafSchemaNodeBuilder from given LeafSchemaNode.
- *
- * @param leaf
- * leaf from which to create builder
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * line in module
- * @return leaf builder based on given leaf node
- */
- public static LeafSchemaNodeBuilder createLeafBuilder(LeafSchemaNode leaf, QName qname, String moduleName, int line) {
- final LeafSchemaNodeBuilder builder = new LeafSchemaNodeBuilder(moduleName, line, qname, leaf.getPath());
- convertDataSchemaNode(leaf, builder);
- builder.setConfiguration(leaf.isConfiguration());
- final TypeDefinition<?> type = leaf.getType();
- builder.setType(type);
- builder.setPath(leaf.getPath());
- builder.setUnknownNodes(leaf.getUnknownSchemaNodes());
- builder.setDefaultStr(leaf.getDefault());
- builder.setUnits(leaf.getUnits());
- return builder;
- }
-
- /**
- * Create ContainerSchemaNodeBuilder from given ContainerSchemaNode.
- *
- * @param container
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return container builder based on given container node
- */
- public static ContainerSchemaNodeBuilder createContainer(ContainerSchemaNode container, QName qname,
- String moduleName, int line) {
- final ContainerSchemaNodeBuilder builder = new ContainerSchemaNodeBuilder(moduleName, line, qname,
- container.getPath());
- convertDataSchemaNode(container, builder);
- builder.setConfiguration(container.isConfiguration());
- builder.setUnknownNodes(container.getUnknownSchemaNodes());
- builder.setChildNodes(container.getChildNodes());
- builder.setGroupings(container.getGroupings());
- builder.setTypedefs(container.getTypeDefinitions());
- builder.setAugmentations(container.getAvailableAugmentations());
- builder.setUsesnodes(container.getUses());
- builder.setPresence(container.isPresenceContainer());
- return builder;
- }
-
- /**
- * Create ListSchemaNodeBuilder from given ListSchemaNode.
- *
- * @param list
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return list builder based on given list node
- */
- public static ListSchemaNodeBuilder createList(ListSchemaNode list, QName qname, String moduleName, int line) {
- ListSchemaNodeBuilder builder = new ListSchemaNodeBuilder(moduleName, line, qname, list.getPath());
- convertDataSchemaNode(list, builder);
- builder.setConfiguration(list.isConfiguration());
- builder.setUnknownNodes(list.getUnknownSchemaNodes());
- builder.setTypedefs(list.getTypeDefinitions());
- builder.setChildNodes(list.getChildNodes());
- builder.setGroupings(list.getGroupings());
- builder.setAugmentations(list.getAvailableAugmentations());
- builder.setUsesnodes(list.getUses());
- builder.setUserOrdered(builder.isUserOrdered());
- return builder;
- }
-
- /**
- * Create LeafListSchemaNodeBuilder from given LeafListSchemaNode.
- *
- * @param leafList
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return leaf-list builder based on given leaf-list node
- */
- public static LeafListSchemaNodeBuilder createLeafList(LeafListSchemaNode leafList, QName qname, String moduleName,
- int line) {
- final LeafListSchemaNodeBuilder builder = new LeafListSchemaNodeBuilder(moduleName, line, qname,
- leafList.getPath());
- convertDataSchemaNode(leafList, builder);
- builder.setConfiguration(leafList.isConfiguration());
- builder.setType(leafList.getType());
- builder.setUnknownNodes(leafList.getUnknownSchemaNodes());
- builder.setUserOrdered(leafList.isUserOrdered());
- return builder;
- }
-
- /**
- * Create ChoiceBuilder from given ChoiceNode.
- *
- * @param choice
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return choice builder based on given choice node
- */
- public static ChoiceBuilder createChoice(ChoiceNode choice, QName qname, String moduleName, int line) {
- final ChoiceBuilder builder = new ChoiceBuilder(moduleName, line, qname);
- convertDataSchemaNode(choice, builder);
- builder.setConfiguration(choice.isConfiguration());
- builder.setCases(choice.getCases());
- builder.setUnknownNodes(choice.getUnknownSchemaNodes());
- builder.setDefaultCase(choice.getDefaultCase());
- return builder;
- }
-
- /**
- * Create AnyXmlBuilder from given AnyXmlSchemaNode.
- *
- * @param anyxml
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return anyxml builder based on given anyxml node
- */
- public static AnyXmlBuilder createAnyXml(AnyXmlSchemaNode anyxml, QName qname, String moduleName, int line) {
- final AnyXmlBuilder builder = new AnyXmlBuilder(moduleName, line, qname, anyxml.getPath());
- convertDataSchemaNode(anyxml, builder);
- builder.setConfiguration(anyxml.isConfiguration());
- builder.setUnknownNodes(anyxml.getUnknownSchemaNodes());
- return builder;
- }
-
- /**
- * Create GroupingBuilder from given GroupingDefinition.
- *
- * @param grouping
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return grouping builder based on given grouping node
- */
- public static GroupingBuilder createGrouping(GroupingDefinition grouping, QName qname, String moduleName, int line) {
- final GroupingBuilderImpl builder = new GroupingBuilderImpl(moduleName, line, qname);
- builder.setPath(grouping.getPath());
- builder.setChildNodes(grouping.getChildNodes());
- builder.setGroupings(grouping.getGroupings());
- builder.setTypedefs(grouping.getTypeDefinitions());
- builder.setUsesnodes(grouping.getUses());
- builder.setUnknownNodes(grouping.getUnknownSchemaNodes());
- builder.setDescription(grouping.getDescription());
- builder.setReference(grouping.getReference());
- builder.setStatus(grouping.getStatus());
- return builder;
- }
-
- /**
- * Create TypeDefinitionBuilder from given ExtendedType.
- *
- * @param typedef
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return typedef builder based on given typedef node
- */
- public static TypeDefinitionBuilder createTypedef(ExtendedType typedef, QName qname, String moduleName, int line) {
- final TypeDefinitionBuilderImpl builder = new TypeDefinitionBuilderImpl(moduleName, line, qname);
- builder.setPath(typedef.getPath());
- builder.setDefaultValue(typedef.getDefaultValue());
- builder.setUnits(typedef.getUnits());
- builder.setDescription(typedef.getDescription());
- builder.setReference(typedef.getReference());
- builder.setStatus(typedef.getStatus());
- builder.setRanges(typedef.getRanges());
- builder.setLengths(typedef.getLengths());
- builder.setPatterns(typedef.getPatterns());
- builder.setFractionDigits(typedef.getFractionDigits());
- final TypeDefinition<?> type = typedef.getBaseType();
- builder.setType(type);
- builder.setUnits(typedef.getUnits());
- builder.setUnknownNodes(typedef.getUnknownSchemaNodes());
- return builder;
- }
-
- /**
- * Create UnknownSchemaNodeBuilder from given UnknownSchemaNode.
- *
- * @param unknownNode
- * @param qname
- * @param moduleName
- * current module name
- * @param line
- * current line in module
- * @return unknown node builder based on given unknown node
- */
- public static UnknownSchemaNodeBuilder createUnknownSchemaNode(UnknownSchemaNode unknownNode, QName qname,
- String moduleName, int line) {
- final UnknownSchemaNodeBuilder builder = new UnknownSchemaNodeBuilder(moduleName, line, qname);
- builder.setPath(unknownNode.getPath());
- builder.setUnknownNodes(unknownNode.getUnknownSchemaNodes());
- builder.setDescription(unknownNode.getDescription());
- builder.setReference(unknownNode.getReference());
- builder.setStatus(unknownNode.getStatus());
- builder.setAddedByUses(unknownNode.isAddedByUses());
- builder.setNodeType(unknownNode.getNodeType());
- builder.setNodeParameter(unknownNode.getNodeParameter());
- return builder;
- }
-
- /**
- * Set DataSchemaNode arguments to builder object
- *
- * @param node
- * node from which arguments should be read
- * @param builder
- * builder to which arguments should be set
- */
- private static void convertDataSchemaNode(DataSchemaNode node, DataSchemaNodeBuilder builder) {
- builder.setPath(node.getPath());
- builder.setDescription(node.getDescription());
- builder.setReference(node.getReference());
- builder.setStatus(node.getStatus());
- builder.setAugmenting(node.isAugmenting());
- copyConstraintsFromDefinition(node.getConstraints(), builder.getConstraints());
- }
-
- /**
- * Copy constraints from constraints definition to constraints builder.
- *
- * @param nodeConstraints
- * definition from which constraints will be copied
- * @param constraints
- * builder to which constraints will be added
- */
- private static void copyConstraintsFromDefinition(final ConstraintDefinition nodeConstraints,
- final ConstraintsBuilder constraints) {
- final RevisionAwareXPath when = nodeConstraints.getWhenCondition();
- final Set<MustDefinition> must = nodeConstraints.getMustConstraints();
-
- if (when != null) {
- constraints.addWhenCondition(when.toString());
- }
- if (must != null) {
- for (MustDefinition md : must) {
- constraints.addMustDefinition(md);
- }
- }
- constraints.setMandatory(nodeConstraints.isMandatory());
- constraints.setMinElements(nodeConstraints.getMinElements());
- constraints.setMaxElements(nodeConstraints.getMaxElements());
- }
-
/**
* Find augment target node and perform augmentation.
*
* parent of first node in path
* @param path
* path to augment target
- * @param isUsesAugment
- * if this augment is defined under uses node
* @return true if augment process succeed, false otherwise
*/
public static boolean processAugmentation(final AugmentationSchemaBuilder augment, final Builder firstNodeParent,
- final List<QName> path, boolean isUsesAugment) {
+ final List<QName> path) {
// traverse augment target path and try to reach target node
String currentName = null;
Builder currentParent = firstNodeParent;
}
private static DataSchemaNodeBuilder findNodeInUses(String localName, UsesNodeBuilder uses) {
- Set<DataSchemaNodeBuilder> usesTargetChildren = uses.getTargetChildren();
- if (usesTargetChildren != null) {
- for (DataSchemaNodeBuilder child : uses.getTargetChildren()) {
- if (child.getQName().getLocalName().equals(localName)) {
- return child;
- }
+ GroupingBuilder target = uses.getGroupingBuilder();
+ for (DataSchemaNodeBuilder child : target.getChildNodeBuilders()) {
+ if (child.getQName().getLocalName().equals(localName)) {
+ return child;
}
}
- for (UsesNodeBuilder usesNode : uses.getTargetGroupingUses()) {
+ for (UsesNodeBuilder usesNode : target.getUsesNodes()) {
DataSchemaNodeBuilder result = findNodeInUses(localName, usesNode);
if (result != null) {
return result;
return result;
}
- /**
- * Load uses target nodes and all uses target uses target nodes. Set this
- * collection as uses final children.
- *
- * @param module
- * current module
- * @param usesNode
- */
- public static void processUsesNode(final UsesNodeBuilder usesNode) {
- ModuleBuilder module = getParentModule(usesNode);
- DataNodeContainerBuilder parent = usesNode.getParent();
- URI namespace = null;
- Date revision = null;
- String prefix = null;
- if (parent instanceof ModuleBuilder || parent instanceof AugmentationSchemaBuilder) {
- namespace = module.getNamespace();
- revision = module.getRevision();
- prefix = module.getPrefix();
- } else {
- QName parentQName = parent.getQName();
- namespace = parentQName.getNamespace();
- revision = parentQName.getRevision();
- prefix = parentQName.getPrefix();
- }
- SchemaPath parentPath = parent.getPath();
-
- // child nodes
- Set<DataSchemaNodeBuilder> finalChildren = new HashSet<>();
- Set<DataSchemaNodeBuilder> newChildren = GroupingUtils.copyUsesTargetNodesWithNewPath(usesNode, parent);
- finalChildren.addAll(newChildren);
- usesNode.getFinalChildren().addAll(finalChildren);
-
- // groupings
- Set<GroupingBuilder> finalGroupings = new HashSet<>();
- Set<GroupingBuilder> newGroupings = GroupingUtils.copyUsesTargetGroupingsWithNewPath(usesNode, parentPath,
- namespace, revision, prefix);
- finalGroupings.addAll(newGroupings);
- usesNode.getFinalGroupings().addAll(finalGroupings);
-
- // typedefs
- Set<TypeDefinitionBuilder> finalTypedefs = new HashSet<>();
- Set<TypeDefinitionBuilder> newTypedefs = GroupingUtils.copyUsesTargetTypedefsWithNewPath(usesNode, parentPath,
- namespace, revision, prefix);
- finalTypedefs.addAll(newTypedefs);
- usesNode.getFinalTypedefs().addAll(finalTypedefs);
-
- // unknown nodes
- List<UnknownSchemaNodeBuilder> finalUnknownNodes = new ArrayList<>();
- List<UnknownSchemaNodeBuilder> newUnknownNodes = GroupingUtils.copyUsesTargetUnknownNodesWithNewPath(usesNode,
- parentPath, namespace, revision, prefix);
- finalUnknownNodes.addAll(newUnknownNodes);
- usesNode.getFinalUnknownNodes().addAll(finalUnknownNodes);
- }
-
- /**
- * Add nodes defined in uses target grouping to uses parent.
- *
- * @param usesNode
- */
- public static void updateUsesParent(UsesNodeBuilder usesNode, DataNodeContainerBuilder parent) {
- // child nodes
- for (DataSchemaNodeBuilder child : usesNode.getFinalChildren()) {
- child.setParent(parent);
- parent.addChildNode(child);
- }
- for (UsesNodeBuilder uses : usesNode.getTargetGroupingUses()) {
- updateUsesParent(uses, parent);
- }
-
- // groupings
- for (GroupingBuilder gb : usesNode.getFinalGroupings()) {
- parent.addGrouping(gb);
- }
- // typedefs
- for (TypeDefinitionBuilder tdb : usesNode.getFinalTypedefs()) {
- parent.addTypedef(tdb);
- }
- // unknown nodes
- for (UnknownSchemaNodeBuilder un : usesNode.getFinalUnknownNodes()) {
- parent.addUnknownNodeBuilder(un);
- }
- }
-
- public static void fixUsesNodesPath(UsesNodeBuilder usesNode) {
- DataNodeContainerBuilder parent = usesNode.getParent();
-
- // child nodes
- Set<DataSchemaNodeBuilder> currentChildNodes = parent.getChildNodeBuilders();
- Set<DataSchemaNodeBuilder> toRemove = new HashSet<>();
- Set<DataSchemaNodeBuilder> toAdd = new HashSet<>();
- for (DataSchemaNodeBuilder child : currentChildNodes) {
- if (child instanceof GroupingMember) {
- GroupingMember gm = (GroupingMember) child;
- if (gm.isAddedByUses()) {
- toRemove.add(child);
- DataSchemaNodeBuilder copy = CopyUtils.copy(child, parent, true);
- correctNodePath(copy, parent.getPath());
- toAdd.add(copy);
- }
- }
- }
- currentChildNodes.removeAll(toRemove);
- currentChildNodes.addAll(toAdd);
-
- // groupings
- Set<GroupingBuilder> currentGroupings = parent.getGroupingBuilders();
- Set<GroupingBuilder> toRemoveG = new HashSet<>();
- Set<GroupingBuilder> toAddG = new HashSet<>();
- for (GroupingBuilder child : currentGroupings) {
- if (child.isAddedByUses()) {
- toRemoveG.add(child);
- GroupingBuilder copy = CopyUtils.copy(child, parent, true);
- correctNodePath(copy, parent.getPath());
- toAddG.add(copy);
- }
-
- }
- currentGroupings.removeAll(toRemoveG);
- currentGroupings.addAll(toAddG);
-
- // typedefs
- Set<TypeDefinitionBuilder> currentTypedefs = parent.getTypeDefinitionBuilders();
- Set<TypeDefinitionBuilder> toRemoveTD = new HashSet<>();
- Set<TypeDefinitionBuilder> toAddTD = new HashSet<>();
- for (TypeDefinitionBuilder child : currentTypedefs) {
- if (child.isAddedByUses()) {
- toRemoveTD.add(child);
- TypeDefinitionBuilder copy = CopyUtils.copy(child, parent, true);
- correctNodePath(copy, parent.getPath());
- toAddTD.add(copy);
- }
-
- }
- currentTypedefs.removeAll(toRemoveTD);
- currentTypedefs.addAll(toAddTD);
-
- // unknown nodes
- List<UnknownSchemaNodeBuilder> currentUN = parent.getUnknownNodeBuilders();
- List<UnknownSchemaNodeBuilder> toRemoveUN = new ArrayList<>();
- List<UnknownSchemaNodeBuilder> toAddUN = new ArrayList<>();
- for (UnknownSchemaNodeBuilder un : currentUN) {
- if (un.isAddedByUses()) {
- toRemoveUN.add(un);
- UnknownSchemaNodeBuilder copy = CopyUtils.copy(un, parent, true);
- correctNodePath(copy, parent.getPath());
- toAddUN.add(copy);
- }
- }
- currentUN.removeAll(toRemoveUN);
- currentUN.addAll(toAddUN);
- }
-
- /**
- * Perform refine process on uses children. It is expected that uses has
- * already resolved all dependencies.
- *
- * @param usesNode
- */
- public static void performRefine(UsesNodeBuilder usesNode) {
- for (RefineHolder refine : usesNode.getRefines()) {
- DataSchemaNodeBuilder nodeToRefine = null;
- for (DataSchemaNodeBuilder dataNode : usesNode.getFinalChildren()) {
- if (refine.getName().equals(dataNode.getQName().getLocalName())) {
- nodeToRefine = dataNode;
- break;
- }
- }
- if (nodeToRefine == null) {
- throw new YangParseException(refine.getModuleName(), refine.getLine(), "Refine target node '"
- + refine.getName() + "' not found");
- }
- RefineUtils.performRefine(nodeToRefine, refine);
- usesNode.addRefineNode(nodeToRefine);
- }
- }
-
/**
* Get module in which this node is defined.
*
import org.opendaylight.yangtools.yang.model.util.Int32;
import org.opendaylight.yangtools.yang.model.util.Int64;
import org.opendaylight.yangtools.yang.model.util.Int8;
-import org.opendaylight.yangtools.yang.model.util.StringType;
import org.opendaylight.yangtools.yang.model.util.Uint16;
import org.opendaylight.yangtools.yang.model.util.Uint32;
import org.opendaylight.yangtools.yang.model.util.Uint64;
*/
static ExtendedType createNewExtendedType(final ExtendedType oldType, final SchemaPath newPath) {
QName qname = oldType.getQName();
- TypeDefinition<?> baseType = oldType.getBaseType();
+ TypeDefinition<?> newBaseType = ParserUtils.createCorrectTypeDefinition(newPath, oldType.getBaseType());
String desc = oldType.getDescription();
String ref = oldType.getReference();
- ExtendedType.Builder builder = new ExtendedType.Builder(qname, baseType, desc, ref, newPath);
+ ExtendedType.Builder builder = new ExtendedType.Builder(qname, newBaseType, desc, ref, newPath);
builder.status(oldType.getStatus());
builder.lengths(oldType.getLengths());
builder.patterns(oldType.getPatterns());
return builder.build();
}
- static StringTypeDefinition createNewStringType(final SchemaPath schemaPath, final QName nodeQName,
- final StringTypeDefinition nodeType) {
- final List<QName> path = schemaPath.getPath();
- final List<QName> newPath = new ArrayList<QName>(path);
- newPath.add(nodeQName);
- newPath.add(nodeType.getQName());
- final SchemaPath newSchemaPath = new SchemaPath(newPath, schemaPath.isAbsolute());
- return new StringType(newSchemaPath);
- }
-
- static IntegerTypeDefinition createNewIntType(final SchemaPath schemaPath, final QName nodeQName,
+ static IntegerTypeDefinition createNewIntType(final SchemaPath newSchemaPath,
final IntegerTypeDefinition type) {
- final QName typeQName = type.getQName();
- final SchemaPath newSchemaPath = createSchemaPath(schemaPath, nodeQName, typeQName);
- final String localName = typeQName.getLocalName();
-
+ final String localName = type.getQName().getLocalName();
if ("int8".equals(localName)) {
return new Int8(newSchemaPath);
} else if ("int16".equals(localName)) {
}
}
- static UnsignedIntegerTypeDefinition createNewUintType(final SchemaPath schemaPath, final QName nodeQName,
+ static UnsignedIntegerTypeDefinition createNewUintType(final SchemaPath newSchemaPath,
final UnsignedIntegerTypeDefinition type) {
- final QName typeQName = type.getQName();
- final SchemaPath newSchemaPath = createSchemaPath(schemaPath, nodeQName, typeQName);
- final String localName = typeQName.getLocalName();
-
+ final String localName = type.getQName().getLocalName();
if ("uint8".equals(localName)) {
return new Uint8(newSchemaPath);
} else if ("uint16".equals(localName)) {
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.Leafref;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
import com.google.common.collect.Lists;
qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
assertEquals(expectedPath, ds0ChannelNumber.getPath());
+ // type of leaf ds0ChannelNumber
+ QName typeQName = BaseTypes.constructQName("string");
+ List<QName> typePath = new ArrayList<>(Arrays.asList(qnames));
+ typePath.add(typeQName);
+ expectedPath = new SchemaPath(typePath, true);
+ assertEquals(expectedPath, ds0ChannelNumber.getType().getPath());
// leaf interface-id
qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
assertEquals(expectedPath, caseNode3Child.getPath());
}
- @Test
- public void testAugmentNodesTypeSchemaPath() throws Exception {
- Module testModule = TestUtils.findModule(modules, "nodes");
- Set<AugmentationSchema> augments = testModule.getAugmentations();
- assertEquals(1, augments.size());
- AugmentationSchema augment = augments.iterator().next();
-
- LeafSchemaNode ifcId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
- Leafref ifcIdType = (Leafref) ifcId.getType();
- SchemaPath ifcIdTypeSchemaPath = ifcIdType.getPath();
- List<QName> ifcIdTypePath = ifcIdTypeSchemaPath.getPath();
-
- Date expectedDate = simpleDateFormat.parse("2013-02-27");
-
- QName q3 = new QName(types1NS, expectedDate, "data", "interface-id");
- assertEquals(q0, ifcIdTypePath.get(0));
- assertEquals(q1, ifcIdTypePath.get(1));
- assertEquals(q2, ifcIdTypePath.get(2));
- assertEquals(q3, ifcIdTypePath.get(3));
-
- LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
- ExtendedType leafType = (ExtendedType) myType.getType();
-
- testModule = TestUtils.findModule(modules, "types");
- TypeDefinition<?> typedef = TestUtils.findTypedef(testModule.getTypeDefinitions(), "int32-ext2");
-
- assertEquals(typedef, leafType);
- }
-
}
+ "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?";
assertEquals(expectedPattern, ipv4.getPatterns().get(0).getRegularExpression());
- TypeDefinition<?> ipv4Address = TestUtils.findTypedef(typedefs, "ipv4-address");
- assertEquals(ipv4Address, ipv4);
-
ExtendedType ipv6 = (ExtendedType) unionTypes.get(1);
assertTrue(ipv6.getBaseType() instanceof StringTypeDefinition);
List<PatternConstraint> ipv6Patterns = ipv6.getPatterns();
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?";
assertEquals(expectedPattern, ipv6Patterns.get(0).getRegularExpression());
- TypeDefinition<?> ipv6Address = TestUtils.findTypedef(typedefs, "ipv6-address");
- assertEquals(ipv6Address, ipv6);
-
expectedPattern = "(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)"
+ "(%.+)?";
assertEquals(expectedPattern, ipv6Patterns.get(1).getRegularExpression());
LeafSchemaNode type = (LeafSchemaNode)tested.getDataChildByName("type");
assertNotNull(type);
- TypeDefinition<?> leafType = type.getType();
- assertEquals(testedType, leafType);
}
}
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.UnionType;
+
+import com.google.common.collect.Lists;
public class UsesAugmentTest {
private final URI ns = URI.create("urn:opendaylight:params:xml:ns:yang:uses-grouping");
rev = TestUtils.simpleDateFormat.parse("2013-07-30");
}
-
/**
* Structure of testing model:
*
* notification pcreq
* |-- leaf version (U)
+ * |-- leaf type (U)
* |-- list requests
* |-- |-- container rp
* |-- |-- |-- leaf priority (U)
* |-- |-- path-key-expansion
* |-- |-- |-- container path-key
* |-- |-- |-- |-- list path-keys (U)
- * |-- |-- |-- |-- |-- leaf version (U, A)
+ * |-- |-- |-- |-- |-- leaf version (U)
+ * |-- |-- |-- |-- |-- leaf type (U)
* |-- |-- |-- |-- |-- leaf processing-rule (U)
* |-- |-- |-- |-- |-- leaf ignore (U)
* |-- |-- container segment-computation
* |-- |-- leaf processing-rule (U)
* |-- |-- leaf ignore (U)
*
- * U = added by uses
- * A = added by augment
+ * U = added by uses A = added by augment
*/
@Test
public void testAugmentInUses() throws Exception {
assertNotNull(pcreq);
assertEquals(createPath("pcreq"), pcreq.getPath());
Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
- assertEquals(3, childNodes.size());
+ assertEquals(4, childNodes.size());
// * |-- leaf version (U)
- LeafSchemaNode version = (LeafSchemaNode)pcreq.getDataChildByName("version");
+ LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");
assertNotNull(version);
assertEquals(createPath("pcreq", "version"), version.getPath());
+ assertEquals(createPath("pcreq", "version", "protocol-version"), version.getType().getPath());
+ assertEquals(createPathForYangType("pcreq", "version", "protocol-version", "uint8"), version.getType()
+ .getBaseType().getPath());
assertTrue(version.isAddedByUses());
+ // * |-- leaf type (U)
+ LeafSchemaNode type = (LeafSchemaNode) pcreq.getDataChildByName("type");
+ assertNotNull(type);
+ assertTrue(type.isAddedByUses());
+ assertEquals(createPath("pcreq", "type"), type.getPath());
+ assertEquals(createPath("pcreq", "type", "int-ext"), type.getType().getPath());
+ UnionType union = (UnionType)type.getType().getBaseType();
+ assertEquals(createPathForYangType("pcreq", "type", "int-ext", "union"), union.getPath());
+ assertEquals(2, union.getTypes().size());
// * |-- list requests
- ListSchemaNode requests = (ListSchemaNode)pcreq.getDataChildByName("requests");
+ ListSchemaNode requests = (ListSchemaNode) pcreq.getDataChildByName("requests");
assertNotNull(requests);
assertEquals(createPath("pcreq", "requests"), requests.getPath());
assertFalse(requests.isAddedByUses());
childNodes = requests.getChildNodes();
assertEquals(3, childNodes.size());
// * |-- |-- container rp
- ContainerSchemaNode rp = (ContainerSchemaNode)requests.getDataChildByName("rp");
+ ContainerSchemaNode rp = (ContainerSchemaNode) requests.getDataChildByName("rp");
assertNotNull(rp);
assertEquals(createPath("pcreq", "requests", "rp"), rp.getPath());
assertFalse(rp.isAddedByUses());
childNodes = rp.getChildNodes();
assertEquals(4, childNodes.size());
// * |-- |-- |-- leaf priority (U)
- LeafSchemaNode priority = (LeafSchemaNode)rp.getDataChildByName("priority");
+ LeafSchemaNode priority = (LeafSchemaNode) rp.getDataChildByName("priority");
assertNotNull(priority);
assertEquals(createPath("pcreq", "requests", "rp", "priority"), priority.getPath());
+ assertEquals(createPath("pcreq", "requests", "rp", "priority", "uint8"), priority.getType().getPath());
+ assertEquals(createPathForYangType("pcreq", "requests", "rp", "priority", "uint8", "uint8"), priority.getType()
+ .getBaseType().getPath());
assertTrue(priority.isAddedByUses());
// * |-- |-- |-- container box (U)
- ContainerSchemaNode box = (ContainerSchemaNode)rp.getDataChildByName("box");
+ ContainerSchemaNode box = (ContainerSchemaNode) rp.getDataChildByName("box");
assertNotNull(box);
assertEquals(createPath("pcreq", "requests", "rp", "box"), box.getPath());
assertTrue(box.isAddedByUses());
// * |-- |-- |-- |-- container order (A)
- ContainerSchemaNode order = (ContainerSchemaNode)box.getDataChildByName("order");
+ ContainerSchemaNode order = (ContainerSchemaNode) box.getDataChildByName("order");
assertNotNull(order);
assertEquals(createPath("pcreq", "requests", "rp", "box", "order"), order.getPath());
assertFalse(order.isAddedByUses());
assertTrue(order.isAugmenting());
assertEquals(2, order.getChildNodes().size());
- // * |-- |-- |-- |-- |-- leaf processing-rule (U)
- LeafSchemaNode delete = (LeafSchemaNode)order.getDataChildByName("delete");
+ // * |-- |-- |-- |-- |-- leaf delete (U)
+ LeafSchemaNode delete = (LeafSchemaNode) order.getDataChildByName("delete");
assertNotNull(delete);
assertEquals(createPath("pcreq", "requests", "rp", "box", "order", "delete"), delete.getPath());
+ assertEquals(createPathForYangType("pcreq", "requests", "rp", "box", "order", "delete", "uint32"), delete
+ .getType().getPath());
assertTrue(delete.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf ignore (U)
- LeafSchemaNode setup = (LeafSchemaNode)order.getDataChildByName("setup");
+ LeafSchemaNode setup = (LeafSchemaNode) order.getDataChildByName("setup");
assertNotNull(setup);
assertEquals(createPath("pcreq", "requests", "rp", "box", "order", "setup"), setup.getPath());
+ assertEquals(createPathForYangType("pcreq", "requests", "rp", "box", "order", "setup", "uint32"), setup
+ .getType().getPath());
assertTrue(setup.isAddedByUses());
// * |-- |-- |-- leaf processing-rule (U)
- LeafSchemaNode processingRule = (LeafSchemaNode)rp.getDataChildByName("processing-rule");
+ LeafSchemaNode processingRule = (LeafSchemaNode) rp.getDataChildByName("processing-rule");
assertNotNull(processingRule);
assertEquals(createPath("pcreq", "requests", "rp", "processing-rule"), processingRule.getPath());
+ assertEquals(createPathForYangType("pcreq", "requests", "rp", "processing-rule", "boolean"), processingRule
+ .getType().getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- leaf ignore (U)
- LeafSchemaNode ignore = (LeafSchemaNode)rp.getDataChildByName("ignore");
+ LeafSchemaNode ignore = (LeafSchemaNode) rp.getDataChildByName("ignore");
assertNotNull(ignore);
assertEquals(createPath("pcreq", "requests", "rp", "ignore"), ignore.getPath());
+ assertEquals(createPathForYangType("pcreq", "requests", "rp", "ignore", "boolean"), ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
// * |-- |-- path-key-expansion
- ContainerSchemaNode pke = (ContainerSchemaNode)requests.getDataChildByName("path-key-expansion");
+ ContainerSchemaNode pke = (ContainerSchemaNode) requests.getDataChildByName("path-key-expansion");
assertNotNull(pke);
assertEquals(createPath("pcreq", "requests", "path-key-expansion"), pke.getPath());
assertFalse(pke.isAddedByUses());
// * |-- |-- |-- path-key
- ContainerSchemaNode pathKey = (ContainerSchemaNode)pke.getDataChildByName("path-key");
+ ContainerSchemaNode pathKey = (ContainerSchemaNode) pke.getDataChildByName("path-key");
assertNotNull(pathKey);
assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key"), pathKey.getPath());
assertFalse(pathKey.isAddedByUses());
assertEquals(3, pathKey.getChildNodes().size());
// * |-- |-- |-- |-- list path-keys (U)
- ListSchemaNode pathKeys = (ListSchemaNode)pathKey.getDataChildByName("path-keys");
+ ListSchemaNode pathKeys = (ListSchemaNode) pathKey.getDataChildByName("path-keys");
assertNotNull(pathKeys);
assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys"), pathKeys.getPath());
assertTrue(pathKeys.isAddedByUses());
childNodes = pathKeys.getChildNodes();
- assertEquals(1, childNodes.size());
+ assertEquals(2, childNodes.size());
// * |-- |-- |-- |-- |-- leaf version (U)
- version = (LeafSchemaNode)pathKeys.getDataChildByName("version");
+ version = (LeafSchemaNode) pathKeys.getDataChildByName("version");
assertNotNull(version);
- assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version"), version.getPath());
+ assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version"),
+ version.getPath());
+ assertEquals(
+ createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version",
+ "protocol-version"), version.getType().getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "version",
+ "protocol-version", "uint8"), version.getType().getBaseType().getPath());
assertTrue(version.isAddedByUses());
assertFalse(version.isAugmenting());
+ // * |-- |-- |-- |-- |-- leaf type (U)
+ type = (LeafSchemaNode) pathKeys.getDataChildByName("type");
+ assertNotNull(type);
+ assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "type"),
+ type.getPath());
+ assertEquals(
+ createPath("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "type",
+ "int-ext"), type.getType().getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "path-keys", "type",
+ "int-ext", "union"), type.getType().getBaseType().getPath());
+ assertTrue(type.isAddedByUses());
+ assertFalse(type.isAugmenting());
// * |-- |-- |-- |-- |-- leaf processing-rule (U)
- processingRule = (LeafSchemaNode)pathKey.getDataChildByName("processing-rule");
+ processingRule = (LeafSchemaNode) pathKey.getDataChildByName("processing-rule");
assertNotNull(processingRule);
- assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "processing-rule"), processingRule.getPath());
+ assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "processing-rule"),
+ processingRule.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "processing-rule",
+ "boolean"), processingRule.getType().getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf ignore (U)
- ignore = (LeafSchemaNode)pathKey.getDataChildByName("ignore");
+ ignore = (LeafSchemaNode) pathKey.getDataChildByName("ignore");
assertNotNull(ignore);
assertEquals(createPath("pcreq", "requests", "path-key-expansion", "path-key", "ignore"), ignore.getPath());
+ assertEquals(createPathForYangType("pcreq", "requests", "path-key-expansion", "path-key", "ignore", "boolean"),
+ ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
// * |-- |-- container segment-computation
- ContainerSchemaNode sc = (ContainerSchemaNode)requests.getDataChildByName("segment-computation");
+ ContainerSchemaNode sc = (ContainerSchemaNode) requests.getDataChildByName("segment-computation");
assertNotNull(sc);
assertEquals(createPath("pcreq", "requests", "segment-computation"), sc.getPath());
assertFalse(sc.isAddedByUses());
// * |-- |-- |-- container p2p
- ContainerSchemaNode p2p = (ContainerSchemaNode)sc.getDataChildByName("p2p");
+ ContainerSchemaNode p2p = (ContainerSchemaNode) sc.getDataChildByName("p2p");
assertNotNull(p2p);
assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p"), p2p.getPath());
assertFalse(p2p.isAddedByUses());
// * |-- |-- |-- |-- container endpoints
- ContainerSchemaNode endpoints = (ContainerSchemaNode)p2p.getDataChildByName("endpoints");
+ ContainerSchemaNode endpoints = (ContainerSchemaNode) p2p.getDataChildByName("endpoints");
assertNotNull(endpoints);
assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints"), endpoints.getPath());
assertFalse(endpoints.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf processing-rule (U)
- processingRule = (LeafSchemaNode)endpoints.getDataChildByName("processing-rule");
+ processingRule = (LeafSchemaNode) endpoints.getDataChildByName("processing-rule");
assertNotNull(processingRule);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "processing-rule"), processingRule.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "processing-rule"),
+ processingRule.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "endpoints",
+ "processing-rule", "boolean"), processingRule.getType().getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf ignore (U)
- ignore = (LeafSchemaNode)endpoints.getDataChildByName("ignore");
+ ignore = (LeafSchemaNode) endpoints.getDataChildByName("ignore");
assertNotNull(ignore);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "ignore"), ignore.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "ignore"),
+ ignore.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "endpoints", "ignore",
+ "boolean"), ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
// * |-- |-- |-- |-- |-- container box
- box = (ContainerSchemaNode)endpoints.getDataChildByName("box");
+ box = (ContainerSchemaNode) endpoints.getDataChildByName("box");
assertNotNull(box);
assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "box"), box.getPath());
assertTrue(box.isAddedByUses());
// * |-- |-- |-- |-- |-- choice address-family (U)
- ChoiceNode af = (ChoiceNode)endpoints.getDataChildByName("address-family");
+ ChoiceNode af = (ChoiceNode) endpoints.getDataChildByName("address-family");
assertNotNull(af);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "address-family"), af.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "endpoints", "address-family"),
+ af.getPath());
assertTrue(af.isAddedByUses());
// * |-- |-- |-- |-- container reported-route
- ContainerSchemaNode reportedRoute = (ContainerSchemaNode)p2p.getDataChildByName("reported-route");
+ ContainerSchemaNode reportedRoute = (ContainerSchemaNode) p2p.getDataChildByName("reported-route");
assertNotNull(reportedRoute);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route"), reportedRoute.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route"),
+ reportedRoute.getPath());
assertFalse(reportedRoute.isAddedByUses());
// * |-- |-- |-- |-- |-- container bandwidth
- ContainerSchemaNode bandwidth = (ContainerSchemaNode)reportedRoute.getDataChildByName("bandwidth");
+ ContainerSchemaNode bandwidth = (ContainerSchemaNode) reportedRoute.getDataChildByName("bandwidth");
assertNotNull(bandwidth);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "bandwidth"), bandwidth.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "bandwidth"),
+ bandwidth.getPath());
assertFalse(bandwidth.isAddedByUses());
// * |-- |-- |-- |-- |-- list subobjects
- ListSchemaNode subobjects = (ListSchemaNode)reportedRoute.getDataChildByName("subobjects");
+ ListSchemaNode subobjects = (ListSchemaNode) reportedRoute.getDataChildByName("subobjects");
assertNotNull(subobjects);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "subobjects"), subobjects.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "subobjects"),
+ subobjects.getPath());
assertTrue(subobjects.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf processing-rule (U)
- processingRule = (LeafSchemaNode)reportedRoute.getDataChildByName("processing-rule");
+ processingRule = (LeafSchemaNode) reportedRoute.getDataChildByName("processing-rule");
assertNotNull(processingRule);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "processing-rule"), processingRule.getPath());
+ assertEquals(
+ createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "processing-rule"),
+ processingRule.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "reported-route",
+ "processing-rule", "boolean"), processingRule.getType().getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf ignore (U)
- ignore = (LeafSchemaNode)reportedRoute.getDataChildByName("ignore");
+ ignore = (LeafSchemaNode) reportedRoute.getDataChildByName("ignore");
assertNotNull(ignore);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "ignore"), ignore.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "reported-route", "ignore"),
+ ignore.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "reported-route", "ignore",
+ "boolean"), ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
// * |-- |-- |-- |-- container bandwidth (U)
- bandwidth = (ContainerSchemaNode)p2p.getDataChildByName("bandwidth");
+ bandwidth = (ContainerSchemaNode) p2p.getDataChildByName("bandwidth");
assertNotNull(bandwidth);
assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth"), bandwidth.getPath());
assertTrue(bandwidth.isAddedByUses());
// * |-- |-- |-- |-- |-- container bandwidth (U)
- ContainerSchemaNode bandwidthInner = (ContainerSchemaNode)bandwidth.getDataChildByName("bandwidth");
+ ContainerSchemaNode bandwidthInner = (ContainerSchemaNode) bandwidth.getDataChildByName("bandwidth");
assertNotNull(bandwidthInner);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "bandwidth"), bandwidthInner.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "bandwidth"),
+ bandwidthInner.getPath());
assertTrue(bandwidthInner.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf processing-rule (U)
- processingRule = (LeafSchemaNode)bandwidth.getDataChildByName("processing-rule");
+ processingRule = (LeafSchemaNode) bandwidth.getDataChildByName("processing-rule");
assertNotNull(processingRule);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "processing-rule"), processingRule.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "processing-rule"),
+ processingRule.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "bandwidth",
+ "processing-rule", "boolean"), processingRule.getType().getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- |-- |-- leaf ignore (U)
- ignore = (LeafSchemaNode)bandwidth.getDataChildByName("ignore");
+ ignore = (LeafSchemaNode) bandwidth.getDataChildByName("ignore");
assertNotNull(ignore);
- assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "ignore"), ignore.getPath());
+ assertEquals(createPath("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "ignore"),
+ ignore.getPath());
+ assertEquals(
+ createPathForYangType("pcreq", "requests", "segment-computation", "p2p", "bandwidth", "ignore",
+ "boolean"), ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
// * |-- list svec
- ListSchemaNode svec = (ListSchemaNode)pcreq.getDataChildByName("svec");
+ ListSchemaNode svec = (ListSchemaNode) pcreq.getDataChildByName("svec");
assertNotNull(svec);
assertEquals(createPath("pcreq", "svec"), svec.getPath());
assertFalse(svec.isAddedByUses());
// * |-- |-- list metric
- ListSchemaNode metric = (ListSchemaNode)svec.getDataChildByName("metric");
+ ListSchemaNode metric = (ListSchemaNode) svec.getDataChildByName("metric");
assertNotNull(metric);
assertEquals(createPath("pcreq", "svec", "metric"), metric.getPath());
assertFalse(metric.isAddedByUses());
// * |-- |-- |-- leaf metric-type (U)
- LeafSchemaNode metricType = (LeafSchemaNode)metric.getDataChildByName("metric-type");
+ LeafSchemaNode metricType = (LeafSchemaNode) metric.getDataChildByName("metric-type");
assertNotNull(metricType);
assertEquals(createPath("pcreq", "svec", "metric", "metric-type"), metricType.getPath());
+ assertEquals(createPathForYangType("pcreq", "svec", "metric", "metric-type", "uint8"), metricType.getType()
+ .getPath());
assertTrue(metricType.isAddedByUses());
// * |-- |-- |-- box (U)
- box = (ContainerSchemaNode)metric.getDataChildByName("box");
+ box = (ContainerSchemaNode) metric.getDataChildByName("box");
assertNotNull(box);
assertEquals(createPath("pcreq", "svec", "metric", "box"), box.getPath());
assertTrue(box.isAddedByUses());
// * |-- |-- |-- leaf processing-rule (U)
- processingRule = (LeafSchemaNode)metric.getDataChildByName("processing-rule");
+ processingRule = (LeafSchemaNode) metric.getDataChildByName("processing-rule");
assertNotNull(processingRule);
assertEquals(createPath("pcreq", "svec", "metric", "processing-rule"), processingRule.getPath());
+ assertEquals(createPathForYangType("pcreq", "svec", "metric", "processing-rule", "boolean"), processingRule
+ .getType().getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- |-- leaf ignore (U)
- ignore = (LeafSchemaNode)metric.getDataChildByName("ignore");
+ ignore = (LeafSchemaNode) metric.getDataChildByName("ignore");
assertNotNull(ignore);
assertEquals(createPath("pcreq", "svec", "metric", "ignore"), ignore.getPath());
+ assertEquals(createPathForYangType("pcreq", "svec", "metric", "ignore", "boolean"), ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
// * |-- |-- leaf link-diverse (U)
- LeafSchemaNode linkDiverse = (LeafSchemaNode)svec.getDataChildByName("link-diverse");
+ LeafSchemaNode linkDiverse = (LeafSchemaNode) svec.getDataChildByName("link-diverse");
assertNotNull(linkDiverse);
assertEquals(createPath("pcreq", "svec", "link-diverse"), linkDiverse.getPath());
+ assertEquals(createPathForYangType("pcreq", "svec", "link-diverse", "boolean"), linkDiverse.getType().getPath());
assertTrue(linkDiverse.isAddedByUses());
// * |-- |-- leaf processing-rule (U)
- processingRule = (LeafSchemaNode)svec.getDataChildByName("processing-rule");
+ processingRule = (LeafSchemaNode) svec.getDataChildByName("processing-rule");
assertNotNull(processingRule);
assertEquals(createPath("pcreq", "svec", "processing-rule"), processingRule.getPath());
+ assertEquals(createPathForYangType("pcreq", "svec", "processing-rule", "boolean"), processingRule.getType()
+ .getPath());
assertTrue(processingRule.isAddedByUses());
// * |-- |-- leaf ignore (U)
- ignore = (LeafSchemaNode)svec.getDataChildByName("ignore");
+ ignore = (LeafSchemaNode) svec.getDataChildByName("ignore");
assertNotNull(ignore);
assertEquals(createPath("pcreq", "svec", "ignore"), ignore.getPath());
+ assertEquals(createPathForYangType("pcreq", "svec", "ignore", "boolean"), ignore.getType().getPath());
assertTrue(ignore.isAddedByUses());
}
private SchemaPath createPath(String... names) {
List<QName> path = new ArrayList<>();
- for(String name : names) {
+ for (String name : names) {
path.add(new QName(ns, rev, prefix, name));
}
return new SchemaPath(path, true);
}
+ private SchemaPath createPathForYangType(String... names) {
+ List<QName> path = new ArrayList<>();
+ for (int i = 0; i < names.length - 1; i++) {
+ path.add(new QName(ns, rev, prefix, names[i]));
+ }
+ path.add(new QName(URI.create("urn:ietf:params:xml:ns:yang:1"), names[names.length - 1]));
+ return new SchemaPath(path, true);
+ }
+
+ @Test
+ public void testTypedefs() throws FileNotFoundException {
+ modules = TestUtils.loadModules(getClass().getResource("/grouping-test").getPath());
+ Module testModule = TestUtils.findModule(modules, "uses-grouping");
+ Set<TypeDefinition<?>> types = testModule.getTypeDefinitions();
+
+ TypeDefinition<?> intExt = null;
+ for(TypeDefinition<?> td : types) {
+ if("int-ext".equals(td.getQName().getLocalName())) {
+ intExt = td;
+ }
+ }
+ assertNotNull(intExt);
+ assertEquals(createPath("int-ext"), intExt.getPath());
+
+ UnionType union = (UnionType)intExt.getBaseType();
+
+ TypeDefinition<?> uint8 = null;
+ TypeDefinition<?> pv = null;
+ for(TypeDefinition<?> td : union.getTypes()) {
+ if("uint8".equals(td.getQName().getLocalName())) {
+ uint8 = td;
+ } else if("protocol-version".equals(td.getQName().getLocalName())) {
+ pv = td;
+ }
+ }
+ assertNotNull(uint8);
+ assertNotNull(pv);
+
+ SchemaPath expectedPath = null;
+ QName q0 = new QName(ns, rev, prefix, "int-ext");
+ QName q1 = BaseTypes.constructQName("union");
+
+ expectedPath = new SchemaPath(Lists.newArrayList(q0, q1), true);
+ assertEquals(expectedPath, union.getPath());
+ }
+
}
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import java.util.Set;
import org.junit.Before;
assertNotNull(nodesId);
LeafListSchemaNode added = (LeafListSchemaNode)nodes.getDataChildByName("added");
assertNotNull(added);
+ assertEquals(createPath("nodes", "added"), added.getPath());
+ assertEquals(createPath("nodes", "added", "mytype"), added.getType().getPath());
+
ListSchemaNode links = (ListSchemaNode) nodes.getDataChildByName("links");
assertNotNull(links);
assertFalse(links.isUserOrdered());
assertEquals(nodeGroupPath, use.getGroupingPath());
}
+
+ private final URI ns = URI.create("urn:opendaylight:simple-nodes");
+ private Date rev;
+ private final String prefix = "sn";
+
+ private SchemaPath createPath(String... names) {
+ try {
+ rev = TestUtils.simpleDateFormat.parse("2013-07-30");
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+
+ List<QName> path = new ArrayList<>();
+ for (String name : names) {
+ path.add(new QName(ns, rev, prefix, name));
+ }
+ return new SchemaPath(path, true);
+ }
+
}
Module test = TestUtils.findModule(modules, "types");
Set<TypeDefinition<?>> types = test.getTypeDefinitions();
- // my-base-int32-type
+ // int32-ext1
ExtendedType int32Typedef = (ExtendedType) TestUtils.findTypedef(types, "int32-ext1");
QName int32TypedefQName = int32Typedef.getQName();
assertEquals(1, typePath.size());
assertEquals(int32TypedefQName, typePath.get(0));
- // my-base-int32-type/int32
+ // int32-ext1/int32
Int32 int32 = (Int32) int32Typedef.getBaseType();
QName int32QName = int32.getQName();
assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), int32QName.getNamespace());
SchemaPath int32SchemaPath = int32.getPath();
List<QName> int32Path = int32SchemaPath.getPath();
- assertEquals(3, int32Path.size());
+ assertEquals(2, int32Path.size());
assertEquals(int32TypedefQName, int32Path.get(0));
- assertEquals(int32QName, int32Path.get(2));
+ assertEquals(int32QName, int32Path.get(1));
}
@Test
Module test = TestUtils.findModule(modules, "types");
Set<TypeDefinition<?>> types = test.getTypeDefinitions();
- // my-base-int32-type
+ // my-decimal-type
ExtendedType myDecType = (ExtendedType) TestUtils.findTypedef(types, "my-decimal-type");
QName myDecTypeQName = myDecType.getQName();
revision "2013-07-30" {
}
+
+ typedef int-ext {
+ type union {
+ type uint8;
+ type protocol-version;
+ }
+ }
typedef protocol-version {
type uint8 {
type protocol-version;
default 1;
}
+ leaf type {
+ type int-ext;
+ }
}
grouping metric-object {
"Initial revision.";
reference "will be defined";
}
+
+ typedef mytype {
+ type string;
+ }
// NOTE: simple comment
type int32;
}
leaf-list added {
- type int64;
+ type mytype;
}
list links {
}