import org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilder;
-public class GroupingUtils {
+public final class GroupingUtils {
private GroupingUtils() {
}
/**
* Search given modules for grouping by name defined in uses node.
- *
+ *
* @param usesBuilder
* builder of uses statement
* @param modules
/**
* Search context for grouping by name defined in uses node.
- *
+ *
* @param usesBuilder
* builder of uses statement
* @param module
/**
* Find grouping by name.
- *
+ *
* @param groupings
* collection of grouping builders to search
* @param name
/**
* Find grouping by name.
- *
+ *
* @param groupings
* collection of grouping definitions to search
* @param name
/**
* Add nodes defined in uses target grouping to uses parent.
- *
+ *
* @param usesNode
*/
public static void updateUsesParent(UsesNodeBuilder usesNode) {
/**
* Read data defined in target grouping builder, make a copy and add them to
* uses node builder.
- *
+ *
* @param usesNode
* uses node builder
*/
/**
* Read child nodes defined in target grouping and make a copy of them.
- *
+ *
* @param usesNode
* @return copy of child nodes defined in uses target grouping
*/
/**
* Read typedefs defined in target grouping and make a copy of them.
- *
+ *
* @param usesNode
* @return copy of typedefs defined in uses target grouping
*/
/**
* Read groupings defined in target grouping and make a copy of them.
- *
+ *
* @param usesNode
* @return copy of groupings defined in uses target grouping
*/
/**
* Read unknown nodes defined in target grouping and make a copy of them.
- *
+ *
* @param usesNode
* @return copy of unknown nodes defined in uses target grouping
*/
/**
* Read data defined in target grouping definition, make a copy and add them
* to uses node builder.
- *
+ *
* @param usesNode
* uses node builder
*/
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);
- }
-
- newChildren.add(newChild);
- }
- }
- usesNode.setTargetChildren(newChildren);
+ copyGroupingNodesToUsesNode(usesNode, namespace, revision, prefix, moduleName, line);
// groupings
final Set<GroupingBuilder> newGroupings = new HashSet<>();
usesNode.setDataCollected(true);
}
+ /**
+ * Read data defined in target grouping definition, make a copy and add them
+ * to uses node builder.
+ *
+ * @param usesNode
+ * used node builder to which are copied nodes from its
+ * <code>GroupingDefinition</code>
+ * @param namespace
+ * URI with parent namespace
+ * @param revision
+ * date with parent revision date
+ * @param prefix
+ * string with parent prefix
+ * @param moduleName
+ * string with parent module name
+ * @param lineNumber
+ * number with YANG file row where is the parent defined
+ */
+ private static void copyGroupingNodesToUsesNode(final UsesNodeBuilder usesNode, final URI namespace,
+ final Date revision, final String prefix, final String moduleName, final int lineNumber) {
+ 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, lineNumber);
+ } else if (child instanceof ChoiceNode) {
+ newChild = CopyUtils.createChoice((ChoiceNode) child, newQName, moduleName, lineNumber);
+ } else if (child instanceof ContainerSchemaNode) {
+ newChild = CopyUtils.createContainer((ContainerSchemaNode) child, newQName, moduleName, lineNumber);
+ } else if (child instanceof LeafListSchemaNode) {
+ newChild = CopyUtils.createLeafList((LeafListSchemaNode) child, newQName, moduleName, lineNumber);
+ } else if (child instanceof LeafSchemaNode) {
+ newChild = CopyUtils.createLeafBuilder((LeafSchemaNode) child, newQName, moduleName, lineNumber);
+ } else if (child instanceof ListSchemaNode) {
+ newChild = CopyUtils.createList((ListSchemaNode) child, newQName, moduleName, lineNumber);
+ }
+
+ if (newChild == null) {
+ throw new YangParseException(moduleName, lineNumber,
+ "Unknown member of target grouping while resolving uses node.");
+ }
+ if (newChild instanceof GroupingMember) {
+ ((GroupingMember) newChild).setAddedByUses(true);
+ }
+
+ newChildren.add(newChild);
+ }
+ }
+ usesNode.setTargetChildren(newChildren);
+
+ }
+
/**
* Fix schema path of all nodes which were defined by this usesNode.
- *
+ *
* @param usesNode
*/
public static void fixUsesNodesPath(UsesNodeBuilder usesNode) {
/**
* Perform refinement of uses target grouping nodes. Uses process has to be
* already performed.
- *
+ *
* @param usesNode
*/
public static void performRefine(UsesNodeBuilder usesNode) {