Refactored parsing of YANG uses statement. 85/685/1
authorMartin Vitez <mvitez@cisco.com>
Thu, 27 Jun 2013 14:26:12 +0000 (16:26 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 24 Jul 2013 11:44:53 +0000 (13:44 +0200)
Uses statement now add nodes from referenced grouping to context where uses is defined. Added GroupingMember interface as marker interface for nodes defined in grouping.
Fixed parsing of config statement: when config is not specified, the default is same as parent schema node. If top node does not specify config, default is true.
Added ConfigNode as marker interface for nodes which can contains 'config' statement.
Added AbstractSchemaNodeBuilder as base class for builders of SchemaNode nodes.
Updated tests.

Change-Id: Ibabcf590608bdf482258826fa250692507a71c01
Signed-off-by: Martin Vitez <mvitez@cisco.com>
yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/DataSchemaNode.java
yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/GroupingDefinition.java
yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UnknownSchemaNode.java
yang-model-api/src/main/java/org/opendaylight/controller/yang/model/api/UsesNode.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java
yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/InstanceIdentifier.java

index 25208aaab68b2af31cb325b34ab6d53121229405..87cdbfd0a6ae6b47c28f502e66d26669e475b693 100644 (file)
@@ -12,16 +12,25 @@ public interface DataSchemaNode extends SchemaNode {
     /**\r
      * Returns <code>true</code> if the data node was added by augmentation,\r
      * otherwise returns <code>false</code>\r
-     * \r
+     *\r
      * @return <code>true</code> if the data node was added by augmentation,\r
      *         otherwise returns <code>false</code>\r
      */\r
     boolean isAugmenting();\r
 \r
+    /**\r
+     * Returns <code>true</code> if the data node was added by uses statement,\r
+     * otherwise returns <code>false</code>\r
+     *\r
+     * @return <code>true</code> if the data node was added by uses statement,\r
+     *         otherwise returns <code>false</code>\r
+     */\r
+    boolean isAddedByUses();\r
+\r
     /**\r
      * Returns <code>true</code> if the data represents configuration data,\r
      * otherwise returns <code>false</code>\r
-     * \r
+     *\r
      * @return <code>true</code> if the data represents configuration data,\r
      *         otherwise returns <code>false</code>\r
      */\r
@@ -29,7 +38,7 @@ public interface DataSchemaNode extends SchemaNode {
 \r
     /**\r
      * Returns the constraints associated with Data Schema Node\r
-     * \r
+     *\r
      * @return the constraints associated with Data Schema Node\r
      */\r
     ConstraintDefinition getConstraints();\r
index 1c8398b86c23bd86f46e4446157f1fff89660f67..a04119b038901f98c7fb871992e5b55f3b8c8c4d 100644 (file)
@@ -17,4 +17,6 @@ package org.opendaylight.controller.yang.model.api;
  */\r
 public interface GroupingDefinition extends DataNodeContainer, SchemaNode {\r
 \r
+    boolean isAddedByUses();\r
+\r
 }\r
index 0430b7ab453e58ebe842632957d5b61f72ed30c9..8e03113a599389f1f329f3a6e5488a851a34505f 100644 (file)
@@ -12,6 +12,9 @@ import org.opendaylight.controller.yang.common.QName;
 public interface UnknownSchemaNode extends SchemaNode {
 
     QName getNodeType();
+
     String getNodeParameter();
 
+    boolean isAddedByUses();
+
 }
index e76f5e81318120f0af134446b1982ef3e1eef226..0fc8a0e49d2fb02d3438d0824dcd6c012a8b72e5 100644 (file)
@@ -31,6 +31,8 @@ public interface UsesNode {
      */\r
     boolean isAugmenting();\r
 \r
+    boolean isAddedByUses();\r
+\r
     /**\r
      * Some of the properties of each node in the grouping can be refined with\r
      * the "refine" statement.\r
index e5ef2026f17e9bb200dec87cecad2d70baeed396..b9729102c90b3b8d05a15f1380e5567d6663d802 100644 (file)
@@ -38,6 +38,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
     private Status status;
     private String units;
     private Object defaultValue;
+    private boolean addedByUses;
 
     public static class Builder {
         private final QName typeName;
@@ -52,6 +53,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private Status status = Status.CURRENT;
         private String units = "";
         private Object defaultValue = null;
+        private boolean addedByUses;
 
         private List<RangeConstraint> ranges = Collections.emptyList();
         private List<LengthConstraint> lengths = Collections.emptyList();
@@ -94,6 +96,11 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
             return this;
         }
 
+        public Builder addedByUses(final boolean addedByUses) {
+            this.addedByUses = addedByUses;
+            return this;
+        }
+
         public Builder unknownSchemaNodes(
                 final List<UnknownSchemaNode> unknownSchemaNodes) {
             this.unknownSchemaNodes = unknownSchemaNodes;
@@ -141,6 +148,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         this.status = builder.status;
         this.units = builder.units;
         this.defaultValue = builder.defaultValue;
+        this.addedByUses = builder.addedByUses;
 
         this.ranges = builder.ranges;
         this.lengths = builder.lengths;
@@ -163,6 +171,10 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         return defaultValue;
     }
 
+    public boolean isAddedByUses() {
+        return addedByUses;
+    }
+
     @Override
     public QName getQName() {
         return typeName;
index 8139d5b50b50bb302d1e5802b5a01ac74c8545b8..05dffc62d132c6c987d8b2d7fab2c65f68477f63 100644 (file)
@@ -1,10 +1,10 @@
 /*
 * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.yang.model.util;
 
 import java.util.Collections;
@@ -18,24 +18,31 @@ import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition;
 
 /**
- * The <code>default</code> implementation of Instance Identifier Type Definition interface.
+ * The <code>default</code> implementation of Instance Identifier Type
+ * Definition interface.
  *
  * @see InstanceIdentifierTypeDefinition
  */
 public final class InstanceIdentifier implements InstanceIdentifierTypeDefinition {
-    private static final QName name = BaseTypes
-            .constructQName("instance-identifier");
-    private static final String description = "The instance-identifier built-in type is used to " +
-               "uniquely identify a particular instance node in the data tree.";
+    private static final QName name = BaseTypes.constructQName("instance-identifier");
+    private static final String description = "The instance-identifier built-in type is used to "
+            + "uniquely identify a particular instance node in the data tree.";
     private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.13";
 
     private final transient SchemaPath path;
     private final RevisionAwareXPath xpath;
     private final String units = "";
     private final InstanceIdentifierTypeDefinition baseType;
-    private final boolean requireInstance;
+    private boolean requireInstance = true;
+
+    public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath) {
+        super();
+        this.path = path;
+        this.xpath = xpath;
+        this.baseType = this;
+    }
 
-    public InstanceIdentifier(final SchemaPath path, RevisionAwareXPath xpath, boolean requireInstance) {
+    public InstanceIdentifier(final SchemaPath path, final RevisionAwareXPath xpath, final boolean requireInstance) {
         super();
         this.path = path;
         this.xpath = xpath;
@@ -46,7 +53,8 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getBaseType()
      */
     @Override
     public InstanceIdentifierTypeDefinition getBaseType() {
@@ -66,7 +74,9 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue()
+     * @see
+     * org.opendaylight.controller.yang.model.api.TypeDefinition#getDefaultValue
+     * ()
      */
     @Override
     public Object getDefaultValue() {
@@ -96,7 +106,8 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
+     * @see
+     * org.opendaylight.controller.yang.model.api.SchemaNode#getDescription()
      */
     @Override
     public String getDescription() {
@@ -126,7 +137,9 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes()
+     * @see
+     * org.opendaylight.controller.yang.model.api.SchemaNode#getExtensionSchemaNodes
+     * ()
      */
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
@@ -136,8 +149,8 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
-     * getPathStatement()
+     * @see org.opendaylight.controller.yang.model.api.type.
+     * InstanceIdentifierTypeDefinition# getPathStatement()
      */
     @Override
     public RevisionAwareXPath getPathStatement() {
@@ -147,8 +160,8 @@ public final class InstanceIdentifier implements InstanceIdentifierTypeDefinitio
     /*
      * (non-Javadoc)
      *
-     * @see org.opendaylight.controller.yang.model.api.type.InstanceIdentifierTypeDefinition#
-     * requireInstance()
+     * @see org.opendaylight.controller.yang.model.api.type.
+     * InstanceIdentifierTypeDefinition# requireInstance()
      */
     @Override
     public boolean requireInstance() {