Fixed resolving of leafref types with relative xpath. 79/979/1
authorMartin Vitez <mvitez@cisco.com>
Fri, 23 Aug 2013 12:43:47 +0000 (14:43 +0200)
committerMartin Vitez <mvitez@cisco.com>
Fri, 23 Aug 2013 12:43:47 +0000 (14:43 +0200)
Signed-off-by: Martin Vitez <mvitez@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java [moved from code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRleativeXPathTest.java with 97% similarity]
code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java

index e4660f583c9ff50356781be263bb2c26d1116612..452811eb5e5fbf5a07b813a575b2487acf870064 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.yangtools.sal.binding.generator.impl;\r
 \r
 import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*;\r
+import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*;\r
+import static org.opendaylight.yangtools.binding.generator.util.Types.BOOLEAN;\r
 import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*;\r
 \r
 import java.util.ArrayList;\r
@@ -36,7 +38,6 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTy
 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;\r
 import org.opendaylight.yangtools.sal.binding.yang.types.GroupingDefinitionDependencySort;\r
 import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl;\r
-import org.opendaylight.yangtools.yang.binding.Augmentable;\r
 import org.opendaylight.yangtools.yang.binding.DataRoot;\r
 import org.opendaylight.yangtools.yang.binding.Identifiable;\r
 import org.opendaylight.yangtools.yang.binding.Identifier;\r
@@ -65,18 +66,13 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.UsesNode;\r
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;\r
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;\r
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;\r
 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;\r
 import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;\r
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;\r
 import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;\r
 import org.opendaylight.yangtools.yang.model.util.UnionType;\r
-import static org.opendaylight.yangtools.binding.generator.util.Types.*;\r
-import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*;\r
-\r
 \r
 import com.google.common.base.Preconditions;\r
-import com.google.common.base.Predicates;\r
 \r
 public final class BindingGeneratorImpl implements BindingGenerator {\r
 \r
@@ -260,7 +256,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
         final List<Type> generatedTypes = new ArrayList<>();\r
         for (final TypeDefinition<?> typedef : typeDefinitions) {\r
             if (typedef != null) {\r
-                final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef);\r
+                final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef, typedef);\r
                 if ((type != null) && !generatedTypes.contains(type)) {\r
                     generatedTypes.add(type);\r
                 }\r
@@ -555,7 +551,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
                     addImplementedInterfaceFromUses(output, outType);\r
                     outType.addImplementsType(DATA_OBJECT);\r
                     outType.addImplementsType(augmentable(outType));\r
-                    \r
+\r
                     resolveDataSchemaNodes(basePackageName, outType, output.getChildNodes());\r
                     outTypeInstance = outType.toInstance();\r
                     genRPCTypes.add(outTypeInstance);\r
@@ -961,7 +957,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
     }\r
 \r
     /**\r
-     * \r
+     *\r
      * @param unknownSchemaNodes\r
      * @return\r
      */\r
@@ -1389,7 +1385,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
 \r
                 Type returnType = null;\r
                 if (typeDef instanceof EnumTypeDefinition) {\r
-                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);\r
+                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);\r
                     final EnumTypeDefinition enumTypeDef = enumTypeDefFromExtendedType(typeDef);\r
                     final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName,\r
                             typeBuilder);\r
@@ -1399,17 +1395,17 @@ public final class BindingGeneratorImpl implements BindingGenerator {
                     }\r
                     ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);\r
                 } else if (typeDef instanceof UnionType) {\r
-                    GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, parentModule);\r
+                    GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule);\r
                     if (genTOBuilder != null) {\r
                         returnType = new ReferencedTypeImpl(genTOBuilder.getPackageName(), genTOBuilder.getName());\r
                     }\r
                 } else if (typeDef instanceof BitsTypeDefinition) {\r
-                    GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, parentModule);\r
+                    GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule);\r
                     if (genTOBuilder != null) {\r
                         returnType = new ReferencedTypeImpl(genTOBuilder.getPackageName(), genTOBuilder.getName());\r
                     }\r
                 } else {\r
-                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);\r
+                    returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);\r
                 }\r
                 if (returnType != null) {\r
                     constructGetter(typeBuilder, leafName, leafDesc, returnType);\r
@@ -1452,7 +1448,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
                 final TypeDefinition<?> typeDef = leaf.getType();\r
 \r
                 // TODO: properly resolve enum types\r
-                final Type returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef);\r
+                final Type returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);\r
 \r
                 if (returnType != null) {\r
                     final GeneratedPropertyBuilder propBuilder = toBuilder.addProperty(parseToClassName(leafName));\r
@@ -1499,7 +1495,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
 \r
             if (nodeName != null && !node.isAddedByUses()) {\r
                 final TypeDefinition<?> type = node.getType();\r
-                final Type listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type));\r
+                final Type listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type, node));\r
 \r
                 constructGetter(typeBuilder, nodeName, nodeDesc, listType);\r
                 return true;\r
@@ -1749,7 +1745,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      */\r
     private MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder,\r
             final String schemaNodeName, final String comment, final Type returnType) {\r
-        \r
+\r
         final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName,returnType));\r
 \r
         getMethod.setComment(comment);\r
@@ -1904,7 +1900,7 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      * If more then one generated TO builder is created for enclosing then all\r
      * of the generated TO builders are added to <code>typeBuilder</code> as\r
      * enclosing transfer objects.\r
-     * \r
+     *\r
      * @param typeDef\r
      *            type definition which can be of type <code>UnionType</code> or\r
      *            <code>BitsTypeDefinition</code>\r
@@ -1916,13 +1912,13 @@ public final class BindingGeneratorImpl implements BindingGenerator {
      * @return generated TO builder for <code>typeDef</code>\r
      */\r
     private GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition<?> typeDef, GeneratedTypeBuilder typeBuilder,\r
-            String leafName, Module parentModule) {\r
+            String leafName, LeafSchemaNode leaf, Module parentModule) {\r
         final String classNameFromLeaf = parseToClassName(leafName);\r
         List<GeneratedTOBuilder> genTOBuilders = new ArrayList<>();\r
         final String packageName = typeBuilder.getFullyQualifiedName();\r
         if (typeDef instanceof UnionTypeDefinition) {\r
             genTOBuilders.addAll(((TypeProviderImpl) typeProvider).provideGeneratedTOBuildersForUnionTypeDef(\r
-                    packageName, typeDef, classNameFromLeaf));\r
+                    packageName, typeDef, classNameFromLeaf, leaf));\r
         } else if (typeDef instanceof BitsTypeDefinition) {\r
             genTOBuilders.add(((TypeProviderImpl) typeProvider).provideGeneratedTOBuilderForBitsTypeDefinition(\r
                     packageName, typeDef, classNameFromLeaf));\r
index 8c72960c091fff35bf8d2695533455b27b16d165..f6391d8c9f8cf41964a74568c761ead2e6cdf2f0 100644 (file)
@@ -9,14 +9,13 @@ package org.opendaylight.yangtools.sal.binding.yang.types;
 \r
 import java.math.BigDecimal;\r
 import java.math.BigInteger;\r
-import java.math.BigDecimal;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
 \r
 import org.opendaylight.yangtools.binding.generator.util.Types;\r
 import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;\r
 import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
-\r
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
 \r
 public final class BaseYangTypes {\r
@@ -112,7 +111,7 @@ public final class BaseYangTypes {
         /**\r
          * Searches <code>Type</code> value to which is YANG <code>type</code>\r
          * mapped.\r
-         * \r
+         *\r
          * @param type\r
          *            string with YANG type name\r
          * @return java <code>Type</code> representation of <code>type</code>\r
@@ -125,7 +124,7 @@ public final class BaseYangTypes {
         /**\r
          * Searches <code>Type</code> value to which is YANG <code>type</code>\r
          * mapped.\r
-         * \r
+         *\r
          * @param type\r
          *            type definition representation of YANG type\r
          * @return java <code>Type</code> representation of <code>type</code>.\r
@@ -133,7 +132,7 @@ public final class BaseYangTypes {
          *          returned.\r
          */\r
         @Override\r
-        public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type) {\r
+        public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode) {\r
             if (type != null) {\r
                 return typeMap.get(type.getQName().getLocalName());\r
             }\r
index e7f81b2af55d0b8ae33befc21104564d8495e93f..1b9abbc6520ac0341831258151f2a7007ab42627 100644 (file)
@@ -41,12 +41,12 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 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.type.BitsTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
@@ -78,7 +78,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Creates new instance of class <code>TypeProviderImpl</code>.
-     * 
+     *
      * @param schemaContext
      *            contains the schema data red from YANG files
      * @throws IllegalArgumentException
@@ -95,7 +95,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Puts <code>refType</code> to map with key <code>refTypePath</code>
-     * 
+     *
      * @param refTypePath
      *            schema path used as the map key
      * @param refType
@@ -105,7 +105,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if <code>refTypePath</code> equal null</li>
      *             <li>if <code>refType</code> equal null</li>
      *             </ul>
-     * 
+     *
      */
     public void putReferencedType(final SchemaPath refTypePath, final Type refType) {
         Preconditions.checkArgument(refTypePath != null,
@@ -116,9 +116,9 @@ public final class TypeProviderImpl implements TypeProvider {
     }
 
     /**
-     * 
+     *
      * Converts basic YANG type <code>type</code> to JAVA <code>Type</code>.
-     * 
+     *
      * @param type
      *            string with YANG name of type
      * @returns JAVA <code>Type</code> for YANG type <code>type</code>
@@ -133,7 +133,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts schema definition type <code>typeDefinition</code> to JAVA
      * <code>Type</code>
-     * 
+     *
      * @param typeDefinition
      *            type definition which is converted to JAVA type
      * @throws IllegalArgumentException
@@ -144,7 +144,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             </ul>
      */
     @Override
-    public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition) {
+    public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
         Type returnType = null;
         Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
         if (typeDefinition.getQName() == null) {
@@ -157,9 +157,9 @@ public final class TypeProviderImpl implements TypeProvider {
         if (typeDefinition instanceof ExtendedType) {
             returnType = javaTypeForExtendedType(typeDefinition);
         } else {
-            returnType = javaTypeForLeafrefOrIdentityRef(typeDefinition);
+            returnType = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode);
             if (returnType == null) {
-                returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition);
+                returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode);
             }
         }
         // TODO: add throw exception when we will be able to resolve ALL yang
@@ -175,15 +175,15 @@ public final class TypeProviderImpl implements TypeProvider {
      * Returns JAVA <code>Type</code> for instances of the type
      * <code>LeafrefTypeDefinition</code> or
      * <code>IdentityrefTypeDefinition</code>.
-     * 
+     *
      * @param typeDefinition
      *            type definition which is converted to JAVA <code>Type</code>
      * @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
      */
-    private Type javaTypeForLeafrefOrIdentityRef(TypeDefinition<?> typeDefinition) {
+    private Type javaTypeForLeafrefOrIdentityRef(TypeDefinition<?> typeDefinition, SchemaNode parentNode) {
         if (typeDefinition instanceof LeafrefTypeDefinition) {
             final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
-            return provideTypeForLeafref(leafref);
+            return provideTypeForLeafref(leafref, parentNode);
         } else if (typeDefinition instanceof IdentityrefTypeDefinition) {
             final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;
             return provideTypeForIdentityref(idref);
@@ -195,7 +195,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Returns JAVA <code>Type</code> for instances of the type
      * <code>ExtendedType</code>.
-     * 
+     *
      * @param typeDefinition
      *            type definition which is converted to JAVA <code>Type</code>
      * @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
@@ -204,13 +204,13 @@ public final class TypeProviderImpl implements TypeProvider {
         final String typedefName = typeDefinition.getQName().getLocalName();
         final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
         Type returnType = null;
-        returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef);
+        returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition);
         if (returnType == null) {
             if (baseTypeDef instanceof EnumTypeDefinition) {
                 final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
-                returnType = provideTypeForEnum(enumTypeDef, typedefName);
+                returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition);
             } else {
-                final Module module = findParentModuleForTypeDefinition(schemaContext, typeDefinition);
+                final Module module = findParentModule(schemaContext, typeDefinition);
                 if (module != null) {
                     final Map<String, Type> genTOs = genTypeDefsContextMap.get(module.getName());
                     if (genTOs != null) {
@@ -218,7 +218,7 @@ public final class TypeProviderImpl implements TypeProvider {
                     }
                     if (returnType == null) {
                         returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
-                                .javaTypeForSchemaDefinitionType(baseTypeDef);
+                                .javaTypeForSchemaDefinitionType(baseTypeDef, typeDefinition);
                     }
                 }
             }
@@ -236,11 +236,11 @@ public final class TypeProviderImpl implements TypeProvider {
      * Seeks for identity reference <code>idref</code> the JAVA
      * <code>type</code>.<br />
      * <br />
-     * 
+     *
      * <i>Example:<br />
      * If identy which is referenced via <code>idref</code> has name <b>Idn</b>
      * then returning type is <b>{@code Class<? extends Idn>}</b></i>
-     * 
+     *
      * @param idref
      *            identityref type definition for which JAVA <code>Type</code>
      *            is sought
@@ -269,7 +269,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>typeDefinition</code> to concrete JAVA <code>Type</code>.
-     * 
+     *
      * @param typeDefinition
      *            type definition which should be converted to JAVA
      *            <code>Type</code>
@@ -282,7 +282,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if name of <code>typeDefinition</code></li>
      *             </ul>
      */
-    public Type generatedTypeForExtendedDefinitionType(final TypeDefinition<?> typeDefinition) {
+    public Type generatedTypeForExtendedDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode) {
         Type returnType = null;
         Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
         if (typeDefinition.getQName() == null) {
@@ -297,7 +297,7 @@ public final class TypeProviderImpl implements TypeProvider {
             final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
 
             if (!(baseTypeDef instanceof LeafrefTypeDefinition) && !(baseTypeDef instanceof IdentityrefTypeDefinition)) {
-                final Module module = findParentModuleForTypeDefinition(schemaContext, typeDefinition);
+                final Module module = findParentModule(schemaContext, parentNode);
 
                 if (module != null) {
                     final Map<String, Type> genTOs = genTypeDefsContextMap.get(module.getName());
@@ -313,7 +313,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Gets base type definition for <code>extendTypeDef</code>. The method is
      * recursivelly called until non <code>ExtendedType</code> type is found.
-     * 
+     *
      * @param extendTypeDef
      *            type definition for which is the base type definition sought
      * @return type definition which is base type for <code>extendTypeDef</code>
@@ -333,10 +333,10 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>leafrefType</code> to JAVA <code>Type</code>.
-     * 
+     *
      * The path of <code>leafrefType</code> is followed to find referenced node
      * and its <code>Type</code> is returned.
-     * 
+     *
      * @param leafrefType
      *            leafref type definition for which is the type sought
      * @return JAVA <code>Type</code> of data schema node which is referenced in
@@ -346,9 +346,9 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if <code>leafrefType</code> equal null</li>
      *             <li>if path statement of <code>leafrefType</code> equal null</li>
      *             </ul>
-     * 
+     *
      */
-    public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType) {
+    public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode) {
         Type returnType = null;
         Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
 
@@ -362,13 +362,13 @@ public final class TypeProviderImpl implements TypeProvider {
             if (strXPath.contains("[")) {
                 returnType = Types.typeForClass(Object.class);
             } else {
-                final Module module = findParentModuleForTypeDefinition(schemaContext, leafrefType);
+                final Module module = findParentModule(schemaContext, parentNode);
                 if (module != null) {
                     final DataSchemaNode dataNode;
                     if (xpath.isAbsolute()) {
                         dataNode = findDataSchemaNode(schemaContext, module, xpath);
                     } else {
-                        dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, leafrefType, xpath);
+                        dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
                     }
 
                     if (leafContainsEnumDefinition(dataNode)) {
@@ -387,7 +387,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Checks if <code>dataNode</code> is <code>LeafSchemaNode</code> and if it
      * so then checks if it is of type <code>EnumTypeDefinition</code>.
-     * 
+     *
      * @param dataNode
      *            data schema node for which is checked if it is leaf and if it
      *            is of enum type
@@ -410,7 +410,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Checks if <code>dataNode</code> is <code>LeafListSchemaNode</code> and if
      * it so then checks if it is of type <code>EnumTypeDefinition</code>.
-     * 
+     *
      * @param dataNode
      *            data schema node for which is checked if it is leaflist and if
      *            it is of enum type
@@ -435,7 +435,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Converts <code>enumTypeDef</code> to
      * {@link org.opendaylight.yangtools.sal.binding.model.api.Enumeration
      * enumeration}.
-     * 
+     *
      * @param enumTypeDef
      *            enumeration type definition which is converted to enumeration
      * @param enumName
@@ -450,7 +450,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if name of <code>enumTypeDef</code> equal null</li>
      *             </ul>
      */
-    private Enumeration provideTypeForEnum(final EnumTypeDefinition enumTypeDef, final String enumName) {
+    private Enumeration provideTypeForEnum(final EnumTypeDefinition enumTypeDef, final String enumName, final SchemaNode parentNode) {
         Preconditions.checkArgument(enumTypeDef != null, "EnumTypeDefinition reference cannot be NULL!");
         Preconditions.checkArgument(enumTypeDef.getValues() != null,
                 "EnumTypeDefinition MUST contain at least ONE value definition!");
@@ -460,7 +460,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
         final String enumerationName = parseToClassName(enumName);
 
-        Module module = findParentModuleForTypeDefinition(schemaContext, enumTypeDef);
+        Module module = findParentModule(schemaContext, parentNode);
         final String basePackageName = moduleNamespaceToPackageName(module);
 
         final EnumBuilder enumBuilder = new EnumerationBuilderImpl(basePackageName, enumerationName);
@@ -471,7 +471,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Adds enumeration to <code>typeBuilder</code>. The enumeration data are
      * taken from <code>enumTypeDef</code>.
-     * 
+     *
      * @param enumTypeDef
      *            enumeration type definition is source of enumeration data for
      *            <code>typeBuilder</code>
@@ -489,7 +489,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             <li>if name of <code>enumTypeDef</code> equal null</li>
      *             <li>if name of <code>typeBuilder</code> equal null</li>
      *             </ul>
-     * 
+     *
      */
     private Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName,
             final GeneratedTypeBuilder typeBuilder) {
@@ -510,7 +510,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>dataNode</code> to JAVA <code>Type</code>.
-     * 
+     *
      * @param dataNode
      *            contains information about YANG type
      * @return JAVA <code>Type</code> representation of <code>dataNode</code>
@@ -520,10 +520,10 @@ public final class TypeProviderImpl implements TypeProvider {
         if (dataNode != null) {
             if (dataNode instanceof LeafSchemaNode) {
                 final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
-                returnType = javaTypeForSchemaDefinitionType(leaf.getType());
+                returnType = javaTypeForSchemaDefinitionType(leaf.getType(), leaf);
             } else if (dataNode instanceof LeafListSchemaNode) {
                 final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
-                returnType = javaTypeForSchemaDefinitionType(leafList.getType());
+                returnType = javaTypeForSchemaDefinitionType(leafList.getType(), leafList);
             }
         }
         return returnType;
@@ -532,7 +532,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Passes through all modules and through all its type definitions and
      * convert it to generated types.
-     * 
+     *
      * The modules are firstly sorted by mutual dependencies. The modules are
      * sequentially passed. All type definitions of a module are at the
      * beginning sorted so that type definition with less amount of references
@@ -541,7 +541,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap}
      * which map current module name to the map which maps type names to
      * returned types (generated types).
-     * 
+     *
      */
     private void resolveTypeDefsFromContext() {
         final Set<Module> modules = schemaContext.getModules();
@@ -575,7 +575,7 @@ public final class TypeProviderImpl implements TypeProvider {
     }
 
     /**
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param moduleName
@@ -603,11 +603,11 @@ public final class TypeProviderImpl implements TypeProvider {
                     returnType = provideGeneratedTOFromExtendedType(innerExtendedType, basePackageName, typedefName);
                 } else if (innerTypeDefinition instanceof UnionTypeDefinition) {
                     final GeneratedTOBuilder genTOBuilder = provideGeneratedTOBuilderForUnionTypeDef(basePackageName,
-                            typedef, typedefName);
+                            typedef, typedefName, typedef);
                     returnType = genTOBuilder.toInstance();
                 } else if (innerTypeDefinition instanceof EnumTypeDefinition) {
                     final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) innerTypeDefinition;
-                    returnType = provideTypeForEnum(enumTypeDef, typedefName);
+                    returnType = provideTypeForEnum(enumTypeDef, typedefName, typedef);
 
                 } else if (innerTypeDefinition instanceof BitsTypeDefinition) {
                     final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) innerTypeDefinition;
@@ -617,7 +617,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
                 } else {
                     final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
-                            .javaTypeForSchemaDefinitionType(innerTypeDefinition);
+                            .javaTypeForSchemaDefinitionType(innerTypeDefinition, typedef);
 
                     returnType = wrapJavaTypeIntoTO(basePackageName, typedef, javaType);
                 }
@@ -635,7 +635,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Wraps base YANG type to generated TO.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -670,7 +670,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts output list of generated TO builders to one TO builder (first
      * from list) which contains the remaining builders as its enclosing TO.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -682,9 +682,9 @@ public final class TypeProviderImpl implements TypeProvider {
      *         builders
      */
     public GeneratedTOBuilder provideGeneratedTOBuilderForUnionTypeDef(final String basePackageName,
-            final TypeDefinition<?> typedef, String typeDefName) {
+            final TypeDefinition<?> typedef, String typeDefName, SchemaNode parentNode) {
         final List<GeneratedTOBuilder> genTOBuilders = provideGeneratedTOBuildersForUnionTypeDef(basePackageName,
-                typedef, typeDefName);
+                typedef, typeDefName, parentNode);
         GeneratedTOBuilder resultTOBuilder = null;
         if (!genTOBuilders.isEmpty()) {
             resultTOBuilder = genTOBuilders.get(0);
@@ -700,7 +700,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Converts <code>typedef</code> to generated TO with
      * <code>typeDefName</code>. Every union type from <code>typedef</code> is
      * added to generated TO builder as property.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -717,7 +717,7 @@ public final class TypeProviderImpl implements TypeProvider {
      *             </ul>
      */
     public List<GeneratedTOBuilder> provideGeneratedTOBuildersForUnionTypeDef(final String basePackageName,
-            final TypeDefinition<?> typedef, final String typeDefName) {
+            final TypeDefinition<?> typedef, final String typeDefName, final SchemaNode parentNode) {
         Preconditions.checkArgument(basePackageName != null, "Base Package Name cannot be NULL!");
         Preconditions.checkArgument(typedef != null, "Type Definition cannot be NULL!");
         if (typedef.getQName() == null) {
@@ -747,17 +747,17 @@ public final class TypeProviderImpl implements TypeProvider {
                 final String unionTypeName = unionType.getQName().getLocalName();
                 if (unionType instanceof UnionType) {
                     generatedTOBuilders
-                            .addAll(resolveUnionSubtypeAsUnion(unionGenTOBuilder, unionType, basePackageName));
+                            .addAll(resolveUnionSubtypeAsUnion(unionGenTOBuilder, unionType, basePackageName, parentNode));
                 } else if (unionType instanceof ExtendedType) {
                     resolveExtendedSubtypeAsUnion(unionGenTOBuilder, (ExtendedType) unionType, unionTypeName,
-                            regularExpressions);
+                            regularExpressions, parentNode);
                 } else if (unionType instanceof EnumTypeDefinition) {
                     final Enumeration enumeration = addInnerEnumerationToTypeBuilder((EnumTypeDefinition) unionType,
                             unionTypeName, unionGenTOBuilder);
                     updateUnionTypeAsProperty(unionGenTOBuilder, enumeration, unionTypeName);
                 } else {
                     final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER
-                            .javaTypeForSchemaDefinitionType(unionType);
+                            .javaTypeForSchemaDefinitionType(unionType, parentNode);
                     if (javaType != null) {
                         updateUnionTypeAsProperty(unionGenTOBuilder, javaType, unionTypeName);
                     }
@@ -767,7 +767,7 @@ public final class TypeProviderImpl implements TypeProvider {
                 addStringRegExAsConstant(unionGenTOBuilder, regularExpressions);
             }
 
-            storeGenTO(typedef, unionGenTOBuilder);
+            storeGenTO(typedef, unionGenTOBuilder, parentNode);
         }
         return generatedTOBuilders;
     }
@@ -775,14 +775,14 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Wraps code which handle case when union subtype is also of the type
      * <code>UnionType</code>.
-     * 
+     *
      * In this case the new generated TO is created for union subtype (recursive
      * call of method
      * {@link #provideGeneratedTOBuilderForUnionTypeDef(String, TypeDefinition, String)
      * provideGeneratedTOBuilderForUnionTypeDef} and in parent TO builder
      * <code>parentUnionGenTOBuilder</code> is created property which type is
      * equal to new generated TO.
-     * 
+     *
      * @param parentUnionGenTOBuilder
      *            generated TO builder to which is the property with the child
      *            union subtype added
@@ -795,10 +795,10 @@ public final class TypeProviderImpl implements TypeProvider {
      *         <code>provideGeneratedTOBuildersForUnionTypeDef</code> method.
      */
     private List<GeneratedTOBuilder> resolveUnionSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
-            final TypeDefinition<?> unionSubtype, final String basePackageName) {
+            final TypeDefinition<?> unionSubtype, final String basePackageName, final SchemaNode parentNode) {
         final String newTOBuilderName = provideAvailableNameForGenTOBuilder(parentUnionGenTOBuilder.getName());
         final List<GeneratedTOBuilder> subUnionGenTOBUilders = provideGeneratedTOBuildersForUnionTypeDef(
-                basePackageName, unionSubtype, newTOBuilderName);
+                basePackageName, unionSubtype, newTOBuilderName, parentNode);
 
         final GeneratedPropertyBuilder propertyBuilder;
         propertyBuilder = parentUnionGenTOBuilder.addProperty(BindingGeneratorUtil
@@ -813,11 +813,11 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Wraps code which handle case when union subtype is of the type
      * <code>ExtendedType</code>.
-     * 
+     *
      * If TO for this type already exists it is used for the creation of the
      * property in <code>parentUnionGenTOBuilder</code>. In other case the base
      * type is used for the property creation.
-     * 
+     *
      * @param parentUnionGenTOBuilder
      *            generated TO builder in which new property is created
      * @param unionSubtype
@@ -829,14 +829,14 @@ public final class TypeProviderImpl implements TypeProvider {
      *            list of strings with the regular expressions
      */
     private void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
-            final ExtendedType unionSubtype, final String unionTypeName, final List<String> regularExpressions) {
-        final Type genTO = findGenTO(unionSubtype, unionTypeName);
+            final ExtendedType unionSubtype, final String unionTypeName, final List<String> regularExpressions, final SchemaNode parentNode) {
+        final Type genTO = findGenTO(unionSubtype, unionTypeName, parentNode);
         if (genTO != null) {
             updateUnionTypeAsProperty(parentUnionGenTOBuilder, genTO, genTO.getName());
         } else {
             final TypeDefinition<?> baseType = baseTypeDefForExtendedType(unionSubtype);
             if (unionTypeName.equals(baseType.getQName().getLocalName())) {
-                final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(baseType);
+                final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(baseType, parentNode);
                 if (javaType != null) {
                     updateUnionTypeAsProperty(parentUnionGenTOBuilder, javaType, unionTypeName);
                 }
@@ -850,7 +850,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Searches for generated TO for <code>searchedTypeDef</code> type
      * definition in {@link #genTypeDefsContextMap genTypeDefsContextMap}
-     * 
+     *
      * @param searchedTypeDef
      *            type definition for which is generatet TO sought
      * @param searchedTypeName
@@ -858,8 +858,8 @@ public final class TypeProviderImpl implements TypeProvider {
      * @return generated TO for <code>searchedTypeDef</code> or
      *         <code>null</code> it it doesn't exist
      */
-    private Type findGenTO(final TypeDefinition<?> searchedTypeDef, final String searchedTypeName) {
-        final Module typeModule = findParentModuleForTypeDefinition(schemaContext, searchedTypeDef);
+    private Type findGenTO(final TypeDefinition<?> searchedTypeDef, final String searchedTypeName, final SchemaNode parentNode) {
+        final Module typeModule = findParentModule(schemaContext, parentNode);
         if (typeModule != null && typeModule.getName() != null) {
             final Map<String, Type> genTOs = genTypeDefsContextMap.get(typeModule.getName());
             if (genTOs != null) {
@@ -873,17 +873,17 @@ public final class TypeProviderImpl implements TypeProvider {
      * Stores generated TO created from <code>genTOBuilder</code> for
      * <code>newTypeDef</code> to {@link #genTypeDefsContextMap
      * genTypeDefsContextMap} if the module for <code>newTypeDef</code> exists
-     * 
+     *
      * @param newTypeDef
      *            type definition for which is <code>genTOBuilder</code> created
      * @param genTOBuilder
      *            generated TO builder which is converted to generated TO and
      *            stored
      */
-    private void storeGenTO(TypeDefinition<?> newTypeDef, GeneratedTOBuilder genTOBuilder) {
+    private void storeGenTO(TypeDefinition<?> newTypeDef, GeneratedTOBuilder genTOBuilder, SchemaNode parentNode) {
         if (!(newTypeDef instanceof UnionType)) {
             Map<String, Type> genTOsMap = null;
-            final Module parentModule = findParentModuleForTypeDefinition(schemaContext, newTypeDef);
+            final Module parentModule = findParentModule(schemaContext, parentNode);
             if (parentModule != null && parentModule.getName() != null) {
                 genTOsMap = genTypeDefsContextMap.get(parentModule.getName());
                 genTOsMap.put(newTypeDef.getQName().getLocalName(), genTOBuilder.toInstance());
@@ -894,7 +894,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Adds a new property with the name <code>propertyName</code> and with type
      * <code>type</code> to <code>unonGenTransObject</code>.
-     * 
+     *
      * @param unionGenTransObject
      *            generated TO to which should be property added
      * @param type
@@ -921,7 +921,7 @@ public final class TypeProviderImpl implements TypeProvider {
 
     /**
      * Converts <code>typedef</code> to the generated TO builder.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typedef
@@ -946,10 +946,10 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts <code>typeDef</code> which should be of the type
      * <code>BitsTypeDefinition</code> to <code>GeneratedTOBuilder</code>.
-     * 
+     *
      * All the bits of the typeDef are added to returning generated TO as
      * properties.
-     * 
+     *
      * @param basePackageName
      *            string with name of package to which the module belongs
      * @param typeDef
@@ -996,13 +996,13 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Converts the pattern constraints from <code>typedef</code> to the list of
      * the strings which represents these constraints.
-     * 
+     *
      * @param typedef
      *            extended type in which are the pattern constraints sought
      * @return list of strings which represents the constraint patterns
      * @throws IllegalArgumentException
      *             if <code>typedef</code> equals null
-     * 
+     *
      */
     private List<String> resolveRegExpressionsFromTypedef(ExtendedType typedef) {
         final List<String> regExps = new ArrayList<String>();
@@ -1024,10 +1024,10 @@ public final class TypeProviderImpl implements TypeProvider {
     }
 
     /**
-     * 
+     *
      * Adds to the <code>genTOBuilder</code> the constant which contains regular
      * expressions from the <code>regularExpressions</code>
-     * 
+     *
      * @param genTOBuilder
      *            generated TO builder to which are
      *            <code>regular expressions</code> added
@@ -1056,11 +1056,11 @@ public final class TypeProviderImpl implements TypeProvider {
      * <code>innerExtendedType</code>, about the package name
      * <code>typedefName</code> and about the generated TO name
      * <code>typedefName</code>.
-     * 
+     *
      * It is supposed that <code>innerExtendedType</code> is already present in
      * {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap} to
      * be possible set it as extended type for the returning generated TO.
-     * 
+     *
      * @param innerExtendedType
      *            extended type which is part of some other extended type
      * @param basePackageName
@@ -1088,7 +1088,7 @@ public final class TypeProviderImpl implements TypeProvider {
         final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, classTypedefName);
 
         Map<String, Type> typeMap = null;
-        final Module parentModule = findParentModuleForTypeDefinition(schemaContext, innerExtendedType);
+        final Module parentModule = findParentModule(schemaContext, innerExtendedType);
         if (parentModule != null) {
             typeMap = genTypeDefsContextMap.get(parentModule.getName());
         }
@@ -1110,7 +1110,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * equal depth. In next step are lists from this map concatenated to one
      * list in ascending order according to their depth. All type definitions
      * are in the list behind all type definitions on which depends.
-     * 
+     *
      * @param unsortedTypeDefinitions
      *            list of type definitions which should be sorted by depth
      * @return list of type definitions sorted according their each other
@@ -1144,7 +1144,7 @@ public final class TypeProviderImpl implements TypeProvider {
     /**
      * Returns how many immersion is necessary to get from the type definition
      * to the base type.
-     * 
+     *
      * @param typeDefinition
      *            type definition for which is depth sought.
      * @return number of immersions which are necessary to get from the type
@@ -1176,7 +1176,7 @@ public final class TypeProviderImpl implements TypeProvider {
      * Returns string which contains the same value as <code>name</code> but
      * integer suffix is incremented by one. If <code>name</code> contains no
      * number suffix then number 1 is added.
-     * 
+     *
      * @param name
      *            string with name of augmented node
      * @return string with the number suffix incremented by one (or 1 is added)
@@ -15,7 +15,6 @@ import java.util.List;
 import java.util.Set;
 
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
@@ -28,7 +27,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-public class AugmentRleativeXPathTest {
+public class AugmentRelativeXPathTest {
 
     private final static List<File> augmentModels = new ArrayList<>();
     private final static String augmentFolderPath = AugmentedTypeTest.class
@@ -45,7 +44,6 @@ public class AugmentRleativeXPathTest {
         }
     }
 
-    @Ignore
     @Test
     public void AugmentationWithRelativeXPathTest() {
         final YangModelParser parser = new YangParserImpl();
@@ -82,7 +80,7 @@ public class AugmentRleativeXPathTest {
         assertNotNull("gtInterfaceMethods is null", gtInterfaceMethods);
         MethodSignature getIfcKeyMethod = null;
         for (final MethodSignature method : gtInterfaceMethods) {
-            if (method.getName().equals("getInterfaceKey")) {
+            if (method.getName().equals("getKey")) {
                 getIfcKeyMethod = method;
                 break;
             }
@@ -118,7 +116,7 @@ public class AugmentRleativeXPathTest {
         assertNotNull("tunnelMethods is null", tunnelMethods);
         MethodSignature getTunnelKeyMethod = null;
         for (MethodSignature method : tunnelMethods) {
-            if (method.getName().equals("getTunnelKey")) {
+            if (method.getName().equals("getKey")) {
                 getTunnelKeyMethod = method;
                 break;
             }
index e22d32f2ca8346089ed02001338694b67c14998a..b0722b4164c6d39c2d49241a5ce2f3a67b483b2b 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.sal.binding.generator.spi;\r
 \r
 import org.opendaylight.yangtools.sal.binding.model.api.Type;\r
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;\r
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;\r
 \r
 public interface TypeProvider {\r
@@ -31,5 +32,5 @@ public interface TypeProvider {
      * @param type Type Definition to resolve from\r
      * @return Resolved Type\r
      */\r
-    Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type);\r
+    Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode);\r
 }\r
index 2a52b0f453adb70e6a852a63f4b3ca8155619bbf..f5a9bbf5595d1b2cffc2e83167aae4c3fdaaf57b 100644 (file)
@@ -24,124 +24,62 @@ import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
  * @see LeafrefTypeDefinition
  */
 public final class Leafref implements LeafrefTypeDefinition {
-    private static final QName name = BaseTypes.constructQName("leafref");
-    private static final String description = "The leafref type is used to reference a "
-            + "particular leaf instance in the data tree.";
-    private static final String reference = "https://tools.ietf.org/html/rfc6020#section-9.9";
-    private final SchemaPath path;
+    private static final QName NAME = BaseTypes.constructQName("leafref");
+    private static final SchemaPath PATH = BaseTypes.schemaPath(NAME);
+    private static final String DESCRIPTION = "The leafref type is used to reference a particular leaf instance in the data tree.";
+    private static final String REF = "https://tools.ietf.org/html/rfc6020#section-9.9";
+
     private final RevisionAwareXPath xpath;
-    private final String units = "";
-    private final LeafrefTypeDefinition baseType;
 
-    public Leafref(final SchemaPath path, final RevisionAwareXPath xpath) {
-        this.path = path;
+    public Leafref(final RevisionAwareXPath xpath) {
         this.xpath = xpath;
-        baseType = this;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getBaseType()
-     */
     @Override
     public LeafrefTypeDefinition getBaseType() {
-        return baseType;
+        return this;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.TypeDefinition#getUnits()
-     */
     @Override
     public String getUnits() {
-        return units;
+        return "";
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.TypeDefinition#getDefaultValue
-     * ()
-     */
     @Override
     public Object getDefaultValue() {
         return this;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getQName()
-     */
     @Override
     public QName getQName() {
-        return name;
+        return NAME;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getPath()
-     */
     @Override
     public SchemaPath getPath() {
-        return path;
+        return PATH;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.SchemaNode#getDescription()
-     */
     @Override
     public String getDescription() {
-        return description;
+        return DESCRIPTION;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getReference()
-     */
     @Override
     public String getReference() {
-        return reference;
+        return REF;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.opendaylight.yangtools.yang.model.api.SchemaNode#getStatus()
-     */
     @Override
     public Status getStatus() {
         return Status.CURRENT;
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.SchemaNode#getExtensionSchemaNodes
-     * ()
-     */
     @Override
     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
         return Collections.emptyList();
     }
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see
-     * org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition
-     * #getPathStatement()
-     */
     @Override
     public RevisionAwareXPath getPathStatement() {
         return xpath;
@@ -151,8 +89,6 @@ public final class Leafref implements LeafrefTypeDefinition {
     public int hashCode() {
         final int prime = 31;
         int result = 1;
-        result = prime * result + ((path == null) ? 0 : path.hashCode());
-        result = prime * result + ((units == null) ? 0 : units.hashCode());
         result = prime * result + ((xpath == null) ? 0 : xpath.hashCode());
         return result;
     }
@@ -169,20 +105,6 @@ public final class Leafref implements LeafrefTypeDefinition {
             return false;
         }
         Leafref other = (Leafref) obj;
-        if (path == null) {
-            if (other.path != null) {
-                return false;
-            }
-        } else if (!path.equals(other.path)) {
-            return false;
-        }
-        if (units == null) {
-            if (other.units != null) {
-                return false;
-            }
-        } else if (!units.equals(other.units)) {
-            return false;
-        }
         if (xpath == null) {
             if (other.xpath != null) {
                 return false;
@@ -196,12 +118,10 @@ public final class Leafref implements LeafrefTypeDefinition {
     @Override
     public String toString() {
         StringBuilder builder = new StringBuilder();
-        builder.append("Leafref [path=");
-        builder.append(path);
-        builder.append("xpath=");
+        builder.append("type ");
+        builder.append(NAME);
+        builder.append(" [xpath=");
         builder.append(xpath);
-        builder.append(", units=");
-        builder.append(units);
         builder.append("]");
         return builder.toString();
     }
index ed8fbd15e1f9d7b23f91454458663b5029415554..91ba9364d114667d46c05c8c0a9bff0fa18c8da9 100644 (file)
@@ -25,7 +25,6 @@ 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;
 
 /**
  * The Schema Context Util contains support methods for searching through Schema Context modules for specified schema
@@ -179,7 +178,7 @@ public final class SchemaContextUtil {
 
         final SchemaPath actualNodePath = actualSchemaNode.getPath();
         if (actualNodePath != null) {
-            final Queue<QName> qnamePath = resolveRelativeXPath(context, module, relativeXPath, actualNodePath);
+            final Queue<QName> qnamePath = resolveRelativeXPath(context, module, relativeXPath, actualSchemaNode);
 
             if (qnamePath != null) {
                 final DataSchemaNode dataNode = findSchemaNodeForGivenPath(context, module, qnamePath);
@@ -224,44 +223,6 @@ public final class SchemaContextUtil {
         return null;
     }
 
-    /**
-     * Returns the Yang Module from specified Schema Context in which the TypeDefinition is declared. If the
-     * TypeDefinition si not present in Schema Context then the method will return <code>null</code>
-     *
-     * If Schema Context or TypeDefinition contains <code>null</code> references the method will throw IllegalArgumentException
-     *
-     * @throws IllegalArgumentException
-     *
-     * @param context Schema Context
-     * @param type Type Definition
-     * @return Yang Module in which the TypeDefinition is declared, if is not present, returns <code>null</code>.
-     */
-    public static Module findParentModuleForTypeDefinition(final SchemaContext context, final TypeDefinition<?> type) {
-        final SchemaPath schemaPath = type.getPath();
-        if (schemaPath == null) {
-            throw new IllegalArgumentException("Schema Path reference cannot be NULL");
-        }
-        final List<QName> qnamedPath = schemaPath.getPath();
-        if (qnamedPath == null || qnamedPath.isEmpty()) {
-            throw new IllegalStateException("Schema Path contains invalid state of path parts."
-                    + "The Schema Path MUST contain at least ONE QName which defines namespace and Local name"
-                    + "of path.");
-        }
-
-        if (type instanceof ExtendedType) {
-            final QName qname = qnamedPath.get(qnamedPath.size() - 1);
-            if ((qname != null) && (qname.getNamespace() != null)) {
-                return context.findModuleByNamespace(qname.getNamespace());
-            }
-        } else {
-            final QName qname = qnamedPath.get(qnamedPath.size() - 2);
-            if ((qname != null) && (qname.getNamespace() != null)) {
-                return context.findModuleByNamespace(qname.getNamespace());
-            }
-        }
-        return null;
-    }
-
     /**
      * Returns parent Yang Module for specified Schema Context in which Schema Node is declared. If the Schema Node
      * is not present in Schema Context the operation will return <code>null</code>.
@@ -342,7 +303,7 @@ public final class SchemaContextUtil {
             if (childNodeQName != null) {
                 final URI childNodeNamespace = childNodeQName.getNamespace();
 
-                schemaNode = nextNode.getDataChildByName(childNodeQName);
+                schemaNode = nextNode.getDataChildByName(childNodeQName.getLocalName());
                 if (schemaNode != null) {
                     if (schemaNode instanceof ContainerSchemaNode) {
                         nextNode = (ContainerSchemaNode) schemaNode;
@@ -503,7 +464,7 @@ public final class SchemaContextUtil {
      * @return
      */
     private static Queue<QName> resolveRelativeXPath(final SchemaContext context, final Module module,
-            final RevisionAwareXPath relativeXPath, final SchemaPath leafrefSchemaPath) {
+            final RevisionAwareXPath relativeXPath, final SchemaNode leafrefParentNode) {
         final Queue<QName> absolutePath = new LinkedList<>();
         if (context == null) {
             throw new IllegalArgumentException("Schema Context reference cannot be NULL!");
@@ -518,7 +479,7 @@ public final class SchemaContextUtil {
             throw new IllegalArgumentException("Revision Aware XPath MUST be relative i.e. MUST contains ../, "
                     + "for non relative Revision Aware XPath use findDataSchemaNode method!");
         }
-        if (leafrefSchemaPath == null) {
+        if (leafrefParentNode.getPath() == null) {
             throw new IllegalArgumentException("Schema Path reference for Leafref cannot be NULL!");
         }
 
@@ -530,9 +491,9 @@ public final class SchemaContextUtil {
                 while (xpaths[colCount].contains("..")) {
                     ++colCount;
                 }
-                final List<QName> path = leafrefSchemaPath.getPath();
+                final List<QName> path = leafrefParentNode.getPath().getPath();
                 if (path != null) {
-                    int lenght = path.size() - colCount - 1;
+                    int lenght = path.size() - colCount;
                     for (int i = 0; i < lenght; ++i) {
                         absolutePath.add(path.get(i));
                     }
index 9a71a24269080767d7a404c93da648b5f9c4f800..de8cf8567713a2ba2b32a2b0c293913aa0bba096 100644 (file)
@@ -1128,7 +1128,7 @@ public final class ParserListenerUtils {
             final String path = parseLeafrefPath(typeBody);
             final boolean absolute = path.startsWith("/");
             RevisionAwareXPath xpath = new RevisionAwareXPathImpl(path, absolute);
-            return new Leafref(baseTypePath, xpath);
+            return new Leafref(xpath);
         } else if ("binary".equals(typeName)) {
             BinaryTypeDefinition binaryType = BinaryType.getInstance();
             constraints.addLengths(binaryType.getLengthConstraints());