From: Martin Vitez Date: Fri, 23 Aug 2013 12:43:47 +0000 (+0200) Subject: Fixed resolving of leafref types with relative xpath. X-Git-Tag: yangtools-0.1.0~51 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8457cb6ef2f2eeb59836cbfd561c8d0d7399229a;p=yangtools.git Fixed resolving of leafref types with relative xpath. Signed-off-by: Martin Vitez --- diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java index e4660f583c..452811eb5e 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -8,6 +8,8 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil.*; +import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*; +import static org.opendaylight.yangtools.binding.generator.util.Types.BOOLEAN; import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.*; import java.util.ArrayList; @@ -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; import org.opendaylight.yangtools.sal.binding.yang.types.GroupingDefinitionDependencySort; import org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl; -import org.opendaylight.yangtools.yang.binding.Augmentable; import org.opendaylight.yangtools.yang.binding.DataRoot; import org.opendaylight.yangtools.yang.binding.Identifiable; import org.opendaylight.yangtools.yang.binding.Identifier; @@ -65,18 +66,13 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; 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.UnionTypeDefinition; import org.opendaylight.yangtools.yang.model.util.DataNodeIterator; import org.opendaylight.yangtools.yang.model.util.ExtendedType; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; import org.opendaylight.yangtools.yang.model.util.UnionType; -import static org.opendaylight.yangtools.binding.generator.util.Types.*; -import static org.opendaylight.yangtools.binding.generator.util.BindingTypes.*; - import com.google.common.base.Preconditions; -import com.google.common.base.Predicates; public final class BindingGeneratorImpl implements BindingGenerator { @@ -260,7 +256,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { final List generatedTypes = new ArrayList<>(); for (final TypeDefinition typedef : typeDefinitions) { if (typedef != null) { - final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef); + final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef, typedef); if ((type != null) && !generatedTypes.contains(type)) { generatedTypes.add(type); } @@ -555,7 +551,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { addImplementedInterfaceFromUses(output, outType); outType.addImplementsType(DATA_OBJECT); outType.addImplementsType(augmentable(outType)); - + resolveDataSchemaNodes(basePackageName, outType, output.getChildNodes()); outTypeInstance = outType.toInstance(); genRPCTypes.add(outTypeInstance); @@ -961,7 +957,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { } /** - * + * * @param unknownSchemaNodes * @return */ @@ -1389,7 +1385,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { Type returnType = null; if (typeDef instanceof EnumTypeDefinition) { - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef); + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); final EnumTypeDefinition enumTypeDef = enumTypeDefFromExtendedType(typeDef); final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leafName, typeBuilder); @@ -1399,17 +1395,17 @@ public final class BindingGeneratorImpl implements BindingGenerator { } ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType); } else if (typeDef instanceof UnionType) { - GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, parentModule); + GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule); if (genTOBuilder != null) { returnType = new ReferencedTypeImpl(genTOBuilder.getPackageName(), genTOBuilder.getName()); } } else if (typeDef instanceof BitsTypeDefinition) { - GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, parentModule); + GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leafName, leaf, parentModule); if (genTOBuilder != null) { returnType = new ReferencedTypeImpl(genTOBuilder.getPackageName(), genTOBuilder.getName()); } } else { - returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef); + returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); } if (returnType != null) { constructGetter(typeBuilder, leafName, leafDesc, returnType); @@ -1452,7 +1448,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { final TypeDefinition typeDef = leaf.getType(); // TODO: properly resolve enum types - final Type returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef); + final Type returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf); if (returnType != null) { final GeneratedPropertyBuilder propBuilder = toBuilder.addProperty(parseToClassName(leafName)); @@ -1499,7 +1495,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { if (nodeName != null && !node.isAddedByUses()) { final TypeDefinition type = node.getType(); - final Type listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type)); + final Type listType = Types.listTypeFor(typeProvider.javaTypeForSchemaDefinitionType(type, node)); constructGetter(typeBuilder, nodeName, nodeDesc, listType); return true; @@ -1749,7 +1745,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { */ private MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder, final String schemaNodeName, final String comment, final Type returnType) { - + final MethodSignatureBuilder getMethod = interfaceBuilder.addMethod(getterMethodName(schemaNodeName,returnType)); getMethod.setComment(comment); @@ -1904,7 +1900,7 @@ public final class BindingGeneratorImpl implements BindingGenerator { * If more then one generated TO builder is created for enclosing then all * of the generated TO builders are added to typeBuilder as * enclosing transfer objects. - * + * * @param typeDef * type definition which can be of type UnionType or * BitsTypeDefinition @@ -1916,13 +1912,13 @@ public final class BindingGeneratorImpl implements BindingGenerator { * @return generated TO builder for typeDef */ private GeneratedTOBuilder addTOToTypeBuilder(TypeDefinition typeDef, GeneratedTypeBuilder typeBuilder, - String leafName, Module parentModule) { + String leafName, LeafSchemaNode leaf, Module parentModule) { final String classNameFromLeaf = parseToClassName(leafName); List genTOBuilders = new ArrayList<>(); final String packageName = typeBuilder.getFullyQualifiedName(); if (typeDef instanceof UnionTypeDefinition) { genTOBuilders.addAll(((TypeProviderImpl) typeProvider).provideGeneratedTOBuildersForUnionTypeDef( - packageName, typeDef, classNameFromLeaf)); + packageName, typeDef, classNameFromLeaf, leaf)); } else if (typeDef instanceof BitsTypeDefinition) { genTOBuilders.add(((TypeProviderImpl) typeProvider).provideGeneratedTOBuilderForBitsTypeDefinition( packageName, typeDef, classNameFromLeaf)); diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java index 8c72960c09..f6391d8c9f 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/BaseYangTypes.java @@ -9,14 +9,13 @@ package org.opendaylight.yangtools.sal.binding.yang.types; import java.math.BigDecimal; import java.math.BigInteger; -import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; import org.opendaylight.yangtools.binding.generator.util.Types; import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider; import org.opendaylight.yangtools.sal.binding.model.api.Type; - +import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; public final class BaseYangTypes { @@ -112,7 +111,7 @@ public final class BaseYangTypes { /** * Searches Type value to which is YANG type * mapped. - * + * * @param type * string with YANG type name * @return java Type representation of type @@ -125,7 +124,7 @@ public final class BaseYangTypes { /** * Searches Type value to which is YANG type * mapped. - * + * * @param type * type definition representation of YANG type * @return java Type representation of type. @@ -133,7 +132,7 @@ public final class BaseYangTypes { * returned. */ @Override - public Type javaTypeForSchemaDefinitionType(TypeDefinition type) { + public Type javaTypeForSchemaDefinitionType(TypeDefinition type, SchemaNode parentNode) { if (type != null) { return typeMap.get(type.getQName().getLocalName()); } diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index e7f81b2af5..1b9abbc652 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -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 TypeProviderImpl. - * + * * @param schemaContext * contains the schema data red from YANG files * @throws IllegalArgumentException @@ -95,7 +95,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Puts refType to map with key refTypePath - * + * * @param refTypePath * schema path used as the map key * @param refType @@ -105,7 +105,7 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if refTypePath equal null
  • *
  • if refType equal null
  • * - * + * */ 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 type to JAVA Type. - * + * * @param type * string with YANG name of type * @returns JAVA Type for YANG type type @@ -133,7 +133,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts schema definition type typeDefinition to JAVA * Type - * + * * @param typeDefinition * type definition which is converted to JAVA type * @throws IllegalArgumentException @@ -144,7 +144,7 @@ public final class TypeProviderImpl implements TypeProvider { * */ @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 Type for instances of the type * LeafrefTypeDefinition or * IdentityrefTypeDefinition. - * + * * @param typeDefinition * type definition which is converted to JAVA Type * @return JAVA Type instance for typeDefinition */ - 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 Type for instances of the type * ExtendedType. - * + * * @param typeDefinition * type definition which is converted to JAVA Type * @return JAVA Type instance for typeDefinition @@ -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 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 idref the JAVA * type.
    *
    - * + * * Example:
    * If identy which is referenced via idref has name Idn * then returning type is {@code Class}
    - * + * * @param idref * identityref type definition for which JAVA Type * is sought @@ -269,7 +269,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts typeDefinition to concrete JAVA Type. - * + * * @param typeDefinition * type definition which should be converted to JAVA * Type @@ -282,7 +282,7 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if name of typeDefinition
  • * */ - 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 genTOs = genTypeDefsContextMap.get(module.getName()); @@ -313,7 +313,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Gets base type definition for extendTypeDef. The method is * recursivelly called until non ExtendedType type is found. - * + * * @param extendTypeDef * type definition for which is the base type definition sought * @return type definition which is base type for extendTypeDef @@ -333,10 +333,10 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts leafrefType to JAVA Type. - * + * * The path of leafrefType is followed to find referenced node * and its Type is returned. - * + * * @param leafrefType * leafref type definition for which is the type sought * @return JAVA Type of data schema node which is referenced in @@ -346,9 +346,9 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if leafrefType equal null
  • *
  • if path statement of leafrefType equal null
  • * - * + * */ - 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 dataNode is LeafSchemaNode and if it * so then checks if it is of type EnumTypeDefinition. - * + * * @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 dataNode is LeafListSchemaNode and if * it so then checks if it is of type EnumTypeDefinition. - * + * * @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 enumTypeDef 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 { *
  • if name of enumTypeDef equal null
  • * */ - 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 typeBuilder. The enumeration data are * taken from enumTypeDef. - * + * * @param enumTypeDef * enumeration type definition is source of enumeration data for * typeBuilder @@ -489,7 +489,7 @@ public final class TypeProviderImpl implements TypeProvider { *
  • if name of enumTypeDef equal null
  • *
  • if name of typeBuilder equal null
  • * - * + * */ private Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName, final GeneratedTypeBuilder typeBuilder) { @@ -510,7 +510,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts dataNode to JAVA Type. - * + * * @param dataNode * contains information about YANG type * @return JAVA Type representation of dataNode @@ -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 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 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 typedef to generated TO with * typeDefName. Every union type from typedef 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 { * */ public List 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 * UnionType. - * + * * 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 * parentUnionGenTOBuilder 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 { * provideGeneratedTOBuildersForUnionTypeDef method. */ private List 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 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 * ExtendedType. - * + * * If TO for this type already exists it is used for the creation of the * property in parentUnionGenTOBuilder. 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 regularExpressions) { - final Type genTO = findGenTO(unionSubtype, unionTypeName); + final ExtendedType unionSubtype, final String unionTypeName, final List 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 searchedTypeDef 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 searchedTypeDef or * null 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 genTOs = genTypeDefsContextMap.get(typeModule.getName()); if (genTOs != null) { @@ -873,17 +873,17 @@ public final class TypeProviderImpl implements TypeProvider { * Stores generated TO created from genTOBuilder for * newTypeDef to {@link #genTypeDefsContextMap * genTypeDefsContextMap} if the module for newTypeDef exists - * + * * @param newTypeDef * type definition for which is genTOBuilder 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 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 propertyName and with type * type to unonGenTransObject. - * + * * @param unionGenTransObject * generated TO to which should be property added * @param type @@ -921,7 +921,7 @@ public final class TypeProviderImpl implements TypeProvider { /** * Converts typedef 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 typeDef which should be of the type * BitsTypeDefinition to GeneratedTOBuilder. - * + * * 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 typedef 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 typedef equals null - * + * */ private List resolveRegExpressionsFromTypedef(ExtendedType typedef) { final List regExps = new ArrayList(); @@ -1024,10 +1024,10 @@ public final class TypeProviderImpl implements TypeProvider { } /** - * + * * Adds to the genTOBuilder the constant which contains regular * expressions from the regularExpressions - * + * * @param genTOBuilder * generated TO builder to which are * regular expressions added @@ -1056,11 +1056,11 @@ public final class TypeProviderImpl implements TypeProvider { * innerExtendedType, about the package name * typedefName and about the generated TO name * typedefName. - * + * * It is supposed that innerExtendedType 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 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 name but * integer suffix is incremented by one. If name 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) diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRleativeXPathTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java similarity index 97% rename from code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRleativeXPathTest.java rename to code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java index 7a4b93df4d..b1638414e7 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRleativeXPathTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/AugmentRelativeXPathTest.java @@ -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 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; } diff --git a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java index e22d32f2ca..b0722b4164 100644 --- a/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java +++ b/code-generator/binding-generator-spi/src/main/java/org/opendaylight/yangtools/sal/binding/generator/spi/TypeProvider.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.sal.binding.generator.spi; import org.opendaylight.yangtools.sal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; public interface TypeProvider { @@ -31,5 +32,5 @@ public interface TypeProvider { * @param type Type Definition to resolve from * @return Resolved Type */ - Type javaTypeForSchemaDefinitionType(final TypeDefinition type); + Type javaTypeForSchemaDefinitionType(final TypeDefinition type, final SchemaNode parentNode); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java index 2a52b0f453..f5a9bbf559 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/Leafref.java @@ -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 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(); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java index ed8fbd15e1..91ba9364d1 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java @@ -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 qnamePath = resolveRelativeXPath(context, module, relativeXPath, actualNodePath); + final Queue 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 null - * - * If Schema Context or TypeDefinition contains null 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 null. - */ - 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 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 null. @@ -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 resolveRelativeXPath(final SchemaContext context, final Module module, - final RevisionAwareXPath relativeXPath, final SchemaPath leafrefSchemaPath) { + final RevisionAwareXPath relativeXPath, final SchemaNode leafrefParentNode) { final Queue 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 path = leafrefSchemaPath.getPath(); + final List 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)); } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java index 9a71a24269..de8cf85677 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ParserListenerUtils.java @@ -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());