import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNodeForRelativeXPath;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
+import com.google.common.base.Optional;
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.opendaylight.mdsal.binding.javav2.generator.context.ModuleContext;
import org.opendaylight.mdsal.binding.javav2.generator.spi.TypeProvider;
import org.opendaylight.mdsal.binding.javav2.generator.util.BindingGeneratorUtil;
import org.opendaylight.mdsal.binding.javav2.generator.util.JavaIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort;
import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
+
@Beta
public final class TypeProviderImpl implements TypeProvider {
}
@Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode) {
- return javaTypeForSchemaDefinitionType(type, parentNode, null);
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
+ ModuleContext context) {
+ return javaTypeForSchemaDefinitionType(type, parentNode, null, context);
}
/**
* </ul>
*/
@Override
- public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode, final Restrictions restrictions) {
- return javaTypeForSchemaDefType(type, parentNode, restrictions, this.schemaContext, this.genTypeDefsContextMap);
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode, final
+ Restrictions restrictions, ModuleContext context) {
+ return javaTypeForSchemaDefType(type, parentNode, restrictions, this.schemaContext, this
+ .genTypeDefsContextMap, context);
}
@Override
*
*/
private void resolveTypeDefsFromContext(final SchemaContext schemaContext, final Map<String, Map<Date, Map<String,
- Type>>> genTypeDefsContextMap, final Map<Module, Set<Type>> additionalTypes) {
+ Type>>> genTypeDefsContextMap, final Map<Module, Set<Type>> additionalTypes) {
final Set<Module> modules = schemaContext.getModules();
Preconditions.checkArgument(modules != null, "Set of Modules cannot be NULL!");
- final Module[] modulesArray = new Module[modules.size()];
- int i = 0;
- for (final Module modul : modules) {
- modulesArray[i++] = modul;
- }
- final List<Module> modulesSortedByDependency = org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort
- .sort(modulesArray);
+ final List<Module> modulesSortedByDependency = ModuleDependencySort.sort(modules);
for (final Module module : modulesSortedByDependency) {
Map<Date, Map<String, Type>> dateTypeMap = genTypeDefsContextMap.get(module.getName());
}
modulesSortedByDependency.stream().filter(module -> module != null).forEach(module -> {
+ ModuleContext context = new ModuleContext();
final String basePackageName = packageNameWithNamespacePrefix(getRootPackageName(module),
BindingNamespaceType.Typedef);
final List<TypeDefinition<?>> typeDefinitions = getAllTypedefs(module);
if (listTypeDefinitions != null) {
for (final TypeDefinition<?> typedef : listTypeDefinitions) {
typedefToGeneratedType(basePackageName, module, typedef, genTypeDefsContextMap,
- additionalTypes, schemaContext);
+ additionalTypes, schemaContext, context);
}
}
});
* </ul>
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
- public GeneratedTOBuilder provideGeneratedTOBuilderForBitsTypeDefinition(final String basePackageName, final
- TypeDefinition<?> typeDef, final String typeDefName, final String moduleName) {
+ public GeneratedTOBuilder provideGeneratedTOBuilderForBitsTypeDefinition(final String basePackageName,
+ final TypeDefinition<?> typeDef, final String typeDefName, final String moduleName, ModuleContext context) {
Preconditions.checkArgument(typeDef != null, "typeDef cannot be NULL!");
Preconditions.checkArgument(basePackageName != null, "Base Package Name cannot be NULL!");
if (typeDef instanceof BitsTypeDefinition) {
final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) typeDef;
- final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName, true, false);
+ final GeneratedTOBuilderImpl genTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName,
+ true, false, context);
final String typedefDescription = encodeAngleBrackets(typeDef.getDescription());
genTOBuilder.setDescription(typedefDescription);
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<GeneratedTOBuilder> provideGeneratedTOBuildersForUnionTypeDef(final String basePackageName,
- final UnionTypeDefinition typedef, final String typeDefName, final SchemaNode parentNode, final SchemaContext
- schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final UnionTypeDefinition typedef, final String typeDefName, final SchemaNode parentNode,
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, ModuleContext context) {
Preconditions.checkNotNull(basePackageName, "Base Package Name cannot be NULL!");
Preconditions.checkNotNull(typedef, "Type Definition cannot be NULL!");
Preconditions.checkNotNull(typedef.getQName(), "Type definition QName cannot be NULL!");
final Module module = findParentModule(schemaContext, parentNode);
final GeneratedTOBuilderImpl unionGenTOBuilder;
- unionGenTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName, true, false);
+ unionGenTOBuilder = new GeneratedTOBuilderImpl(basePackageName, typeDefName, true, false,
+ context);
final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
unionGenTOBuilder.setDescription(typedefDescription);
unionGenTOBuilder.setReference(typedef.getReference());
parentNode, schemaContext, genTypeDefsContextMap);
} else if (unionType instanceof UnionTypeDefinition) {
generatedTOBuilders.add(resolveUnionSubtypeAsUnion(unionGenTOBuilder, (UnionTypeDefinition) unionType,
- unionGenTOBuilder.getFullyQualifiedName(), parentNode, schemaContext, genTypeDefsContextMap));
+ unionGenTOBuilder.getFullyQualifiedName(), parentNode, schemaContext, genTypeDefsContextMap,
+ context));
} else if (unionType instanceof EnumTypeDefinition) {
final Enumeration enumeration = addInnerEnumerationToTypeBuilder((EnumTypeDefinition) unionType,
- unionTypeName, unionGenTOBuilder);
+ unionTypeName, unionGenTOBuilder, context);
updateUnionTypeAsProperty(unionGenTOBuilder, enumeration, unionTypeName);
} else {
final Type javaType = javaTypeForSchemaDefType(unionType, parentNode, null, schemaContext,
- genTypeDefsContextMap);
+ genTypeDefsContextMap, context);
updateUnionTypeAsProperty(unionGenTOBuilder, javaType, unionTypeName);
}
}
}
}
- private Type javaTypeForSchemaDefType(final TypeDefinition<?> typeDefinition, final SchemaNode
- parentNode, final Restrictions r, final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ private Type javaTypeForSchemaDefType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
+ final Restrictions r, final SchemaContext schemaContext,
+ final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, ModuleContext context) {
Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
final String typedefName = typeDefinition.getQName().getLocalName();
Preconditions.checkArgument(typedefName != null, "Type Definitions Local Name cannot be NULL!");
// and generated an enclosing ExtendedType to hold any range constraints. The new parser instantiates
// a base type which holds these constraints.
if (typeDefinition instanceof DecimalTypeDefinition) {
- final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode, r);
+ final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType
+ (typeDefinition, parentNode, r, null);
if (ret != null) {
return ret;
}
}
// Deal with leafrefs/identityrefs
- Type ret = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode, schemaContext, genTypeDefsContextMap);
+ Type ret = javaTypeForLeafrefOrIdentityRef(typeDefinition, parentNode, schemaContext,
+ genTypeDefsContextMap, context);
if (ret != null) {
return ret;
}
- ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode);
+ ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode,
+ null);
if (ret == null) {
LOG.debug("Failed to resolve Java type for {}", typeDefinition);
}
return ret;
}
- Type returnType = javaTypeForExtendedType(typeDefinition, schemaContext, genTypeDefsContextMap);
+ Type returnType = javaTypeForExtendedType(typeDefinition, schemaContext, genTypeDefsContextMap, context);
if (r != null && !r.isEmpty() && returnType instanceof GeneratedTransferObject) {
final GeneratedTransferObject gto = (GeneratedTransferObject) returnType;
final Module module = findParentModule(schemaContext, parentNode);
+ final Module module1 = findParentModule(schemaContext, typeDefinition);
final String basePackageName = BindingMapping.getRootPackageName(module);
final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typeDefinition
.getPath(), BindingNamespaceType.Typedef);
final String genTOName =
JavaIdentifierNormalizer.normalizeSpecificIdentifier(typedefName, JavaIdentifier.CLASS);
final String name = packageName + "." + genTOName;
- if (!(returnType.getFullyQualifiedName().equals(name))) {
- returnType = shadedTOWithRestrictions(gto, r);
+ if (module.equals(module1) && !(returnType.getFullyQualifiedName().equals(name))) {
+ returnType = shadedTOWithRestrictions(gto, r, context);
}
}
return returnType;
* <code>modulName</code> or <code>typedef</code> or Q name of
* <code>typedef</code> equals <code>null</code>
*/
- private Type typedefToGeneratedType(final String basePackageName, final Module module, final
- TypeDefinition<?> typedef, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, final Map<Module,
- Set<Type>> additionalTypes, final SchemaContext schemaContext) {
+ private Type typedefToGeneratedType(final String basePackageName, final Module module,
+ final TypeDefinition<?> typedef, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap,
+ final Map<Module, Set<Type>> additionalTypes, final SchemaContext schemaContext, ModuleContext context) {
final String moduleName = module.getName();
final Date moduleRevision = module.getRevision();
if ((basePackageName != null) && (moduleName != null) && (typedef != null)) {
Type returnType;
if (innerTypeDefinition.getBaseType() != null) {
returnType = provideGeneratedTOFromExtendedType(typedef, innerTypeDefinition, basePackageName,
- module.getName(), schemaContext, genTypeDefsContextMap);
+ module.getName(), schemaContext, genTypeDefsContextMap, context);
} else if (innerTypeDefinition instanceof UnionTypeDefinition) {
final GeneratedTOBuilder genTOBuilder = provideGeneratedTOBuilderForUnionTypeDef(basePackageName,
- (UnionTypeDefinition) innerTypeDefinition, typedefName, typedef, schemaContext, genTypeDefsContextMap);
+ (UnionTypeDefinition) innerTypeDefinition, typedefName, typedef, schemaContext,
+ genTypeDefsContextMap, context);
genTOBuilder.setTypedef(true);
genTOBuilder.setIsUnion(true);
addUnitsToGenTO(genTOBuilder, typedef.getUnits());
// enums are automatically Serializable
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) innerTypeDefinition;
// TODO units for typedef enum
- returnType = provideTypeForEnum(enumTypeDef, typedefName, typedef, schemaContext);
+ returnType = provideTypeForEnum(enumTypeDef, typedefName, typedef, schemaContext, context);
} else if (innerTypeDefinition instanceof BitsTypeDefinition) {
final BitsTypeDefinition bitsTypeDefinition = (BitsTypeDefinition) innerTypeDefinition;
final GeneratedTOBuilder genTOBuilder =
provideGeneratedTOBuilderForBitsTypeDefinition(
- basePackageName, bitsTypeDefinition, typedefName, module.getName());
+ basePackageName, bitsTypeDefinition, typedefName, module.getName(), context);
genTOBuilder.setTypedef(true);
addUnitsToGenTO(genTOBuilder, typedef.getUnits());
makeSerializable((GeneratedTOBuilderImpl) genTOBuilder);
returnType = genTOBuilder.toInstance();
} else {
final Type javaType = javaTypeForSchemaDefType(innerTypeDefinition, typedef, null,
- schemaContext, genTypeDefsContextMap);
- returnType = wrapJavaTypeIntoTO(basePackageName, typedef, javaType, module.getName());
+ schemaContext, genTypeDefsContextMap, context);
+ returnType = wrapJavaTypeIntoTO(basePackageName, typedef, javaType, module.getName(), context);
}
if (returnType != null) {
final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(moduleName);
* type definition which is converted to JAVA <code>Type</code>
* @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
*/
- private Type javaTypeForExtendedType(final TypeDefinition<?> typeDefinition, final SchemaContext
- schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ private Type javaTypeForExtendedType(final TypeDefinition<?> typeDefinition, final SchemaContext schemaContext,
+ final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, ModuleContext context) {
final String typedefName = typeDefinition.getQName().getLocalName();
final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
- Type returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition, schemaContext, genTypeDefsContextMap);
+ Type returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition, schemaContext,
+ genTypeDefsContextMap, context);
if (returnType == null) {
- if (baseTypeDef instanceof EnumTypeDefinition) {
- final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
- returnType = provideTypeForEnum(enumTypeDef, typedefName, typeDefinition, schemaContext);
- } else {
- final Module module = findParentModule(schemaContext, typeDefinition);
- final Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
- if (module != null) {
- final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
- final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
- if (genTOs != null) {
- returnType = genTOs.get(typedefName);
- }
- if (returnType == null) {
- returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
- baseTypeDef, typeDefinition, r);
- }
+ final Module module = findParentModule(schemaContext, typeDefinition);
+ final Restrictions r = BindingGeneratorUtil.getRestrictions(typeDefinition);
+ if (module != null) {
+ final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
+ final Map<String, Type> genTOs = modulesByDate.get(module.getRevision());
+ if (genTOs != null) {
+ returnType = genTOs.get(typedefName);
+ }
+ if (returnType == null) {
+ returnType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(
+ baseTypeDef, typeDefinition, r, context);
}
}
}
* @return JAVA <code>Type</code> instance for <code>typeDefinition</code>
*/
private Type javaTypeForLeafrefOrIdentityRef(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
- final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap,
+ ModuleContext context) {
if (typeDefinition instanceof LeafrefTypeDefinition) {
final LeafrefTypeDefinition leafref = (LeafrefTypeDefinition) typeDefinition;
if (isLeafRefSelfReference(leafref, parentNode, schemaContext)) {
throw new YangValidationException("Leafref " + leafref.toString() + " is referencing itself, incoming" +
" StackOverFlowError detected.");
}
- return provideTypeForLeafref(leafref, parentNode, schemaContext, genTypeDefsContextMap);
+ return provideTypeForLeafref(leafref, parentNode, schemaContext, genTypeDefsContextMap, context);
} else if (typeDefinition instanceof IdentityrefTypeDefinition) {
final IdentityrefTypeDefinition idref = (IdentityrefTypeDefinition) typeDefinition;
return provideTypeForIdentityref(idref, schemaContext);
*
*/
public Type provideTypeForLeafref(final LeafrefTypeDefinition leafrefType, final SchemaNode parentNode,
- final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap,
+ ModuleContext context) {
Type returnType = null;
Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
final RevisionAwareXPath xpath = leafrefType.getPathStatement();
final String strXPath = xpath.toString();
-
if (strXPath != null) {
if (strXPath.indexOf('[') == -1) {
- final Module module = findParentModule(schemaContext, parentNode);
+ final Module module;
+ final SchemaNode actualParentSchemaNode;
+ if ((parentNode instanceof DerivableSchemaNode) && ((DerivableSchemaNode) parentNode).isAddedByUses()) {
+ final Optional<? extends SchemaNode> originalNode = ((DerivableSchemaNode) parentNode).getOriginal();
+ Preconditions.checkArgument(originalNode.isPresent(), "originalNode can not be null.");
+ actualParentSchemaNode = originalNode.get();
+ module = findParentModule(schemaContext, originalNode.get());
+ } else {
+ actualParentSchemaNode = parentNode;
+ module = findParentModule(schemaContext, parentNode);
+ }
Preconditions.checkArgument(module != null, "Failed to find module for parent %s", parentNode);
final SchemaNode dataNode;
if (xpath.isAbsolute()) {
dataNode = findDataSchemaNode(schemaContext, module, xpath);
} else {
- dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
+ dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, actualParentSchemaNode, xpath);
}
Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)",
strXPath, getParentModule(parentNode, schemaContext).getName(), parentNode.getQName().getModule());
} else if (leafListContainsEnumDefinition(dataNode)) {
returnType = Types.listTypeFor(this.referencedTypes.get(dataNode.getPath()));
} else {
- returnType = resolveTypeFromDataSchemaNode(dataNode, schemaContext, genTypeDefsContextMap);
+ returnType = resolveTypeFromDataSchemaNode(dataNode, schemaContext, genTypeDefsContextMap, context);
}
} else {
returnType = Types.typeForClass(Object.class);
* @return JAVA <code>Type</code> representation of <code>dataNode</code>
*/
private Type resolveTypeFromDataSchemaNode(final SchemaNode dataNode, final SchemaContext schemaContext,
- final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap, ModuleContext context) {
Type returnType = null;
if (dataNode != null) {
if (dataNode instanceof LeafSchemaNode) {
final LeafSchemaNode leaf = (LeafSchemaNode) dataNode;
//not using CompatUtils here anymore
final TypeDefinition<?> type = leaf.getType();
- returnType = javaTypeForSchemaDefType(type, leaf, null, schemaContext, genTypeDefsContextMap);
+ returnType = javaTypeForSchemaDefType(type, leaf, null, schemaContext, genTypeDefsContextMap, context);
} else if (dataNode instanceof LeafListSchemaNode) {
final LeafListSchemaNode leafList = (LeafListSchemaNode) dataNode;
- returnType = javaTypeForSchemaDefType(leafList.getType(), leafList, null, schemaContext, genTypeDefsContextMap);
+ returnType = javaTypeForSchemaDefType(leafList.getType(), leafList, null, schemaContext,
+ genTypeDefsContextMap, context);
}
}
return returnType;
JavaIdentifier.CLASS);
final Type baseType = Types.typeForClass(Class.class);
- final Type paramType = Types.wildcardTypeFor(packageName, genTypeName, true, true);
+ final Type paramType = Types.wildcardTypeFor(packageName, genTypeName, true, true, null);
return Types.parameterizedTypeFor(baseType, paramType);
}
- /**
- * Converts <code>typedef</code> to the generated TO builder.
- *
- * @param basePackageName
- * string with name of package to which the module belongs
- * @param typedef
- * type definition from which is the generated TO builder created
- * @return generated TO builder which contains data from
- * <code>typedef</code> and <code>basePackageName</code>
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private static GeneratedTOBuilderImpl typedefToTransferObject(final String basePackageName, final TypeDefinition<?> typedef, final String moduleName) {
-
- final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typedef.getPath
- (), BindingNamespaceType.Typedef);
- final String typeDefTOName = typedef.getQName().getLocalName();
-
- if ((packageName != null) && (typeDefTOName != null)) {
- final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, typeDefTOName);
- final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
-
- newType.setDescription(typedefDescription);
- newType.setReference(typedef.getReference());
- newType.setSchemaPath((List) typedef.getPath().getPathFromRoot());
- newType.setModuleName(moduleName);
-
- return newType;
- }
- return null;
- }
-
- private static GeneratedTransferObject shadedTOWithRestrictions(final GeneratedTransferObject gto, final Restrictions r) {
- final GeneratedTOBuilder gtob = new GeneratedTOBuilderImpl(gto.getPackageName(), gto.getName());
+ private static GeneratedTransferObject shadedTOWithRestrictions(final GeneratedTransferObject gto,
+ final Restrictions r, ModuleContext context) {
+ final GeneratedTOBuilder gtob = new GeneratedTOBuilderImpl(gto.getPackageName(), gto.getName(), context);
final GeneratedTransferObject parent = gto.getSuperType();
if (parent != null) {
gtob.setExtendsType(parent);
*
* In this case the new generated TO is created for union subtype (recursive
* call of method
- * {@link #provideGeneratedTOBuildersForUnionTypeDef(String, UnionTypeDefinition,
- * String, SchemaNode, SchemaContext, Map)}
+ * {@link #provideGeneratedTOBuilderForUnionTypeDef(String, UnionTypeDefinition, String, SchemaNode, SchemaContext, Map, ModuleContext)}
* provideGeneratedTOBuilderForUnionTypeDef} and in parent TO builder
* <code>parentUnionGenTOBuilder</code> is created property which type is
* equal to new generated TO.
* bigger one due to recursive call of
* <code>provideGeneratedTOBuildersForUnionTypeDef</code> method.
*/
- private GeneratedTOBuilder resolveUnionSubtypeAsUnion(final GeneratedTOBuilder
- parentUnionGenTOBuilder, final UnionTypeDefinition unionSubtype, final String basePackageName,
- final SchemaNode parentNode, final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ private GeneratedTOBuilder resolveUnionSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
+ final UnionTypeDefinition unionSubtype, final String basePackageName, final SchemaNode parentNode,
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap,
+ ModuleContext context) {
final String newTOBuilderName = provideAvailableNameForGenTOBuilder(parentUnionGenTOBuilder.getName());
final GeneratedTOBuilder subUnionGenTOBUilder = provideGeneratedTOBuilderForUnionTypeDef(
- basePackageName, unionSubtype, newTOBuilderName, parentNode, schemaContext, genTypeDefsContextMap);
+ basePackageName, unionSubtype, newTOBuilderName, parentNode, schemaContext, genTypeDefsContextMap,
+ context);
final GeneratedPropertyBuilder propertyBuilder;
propertyBuilder = parentUnionGenTOBuilder
* builders
*/
public GeneratedTOBuilder provideGeneratedTOBuilderForUnionTypeDef(final String basePackageName,
- final UnionTypeDefinition typedef, final String typeDefName, final SchemaNode parentNode, final SchemaContext
- schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final UnionTypeDefinition typedef, final String typeDefName, final SchemaNode parentNode,
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap,
+ ModuleContext context) {
final List<GeneratedTOBuilder> builders = provideGeneratedTOBuildersForUnionTypeDef(basePackageName,
- typedef, typeDefName, parentNode, schemaContext, genTypeDefsContextMap);
+ typedef, typeDefName, parentNode, schemaContext, genTypeDefsContextMap, context);
Preconditions.checkState(!builders.isEmpty(), "No GeneratedTOBuilder objects generated from union %s", typedef);
final GeneratedTOBuilder resultTOBuilder = builders.remove(0);
private GeneratedTOBuilder provideGeneratedTOBuilderForUnionBuilder(final Module parentModule,
- final GeneratedTOBuilder genTOBuilder) {
+ final GeneratedTOBuilder genTOBuilder) {
final String outerCls = Types.getOuterClassName(genTOBuilder);
final StringBuilder name;
if (outerCls != null) {
* parent Schema Node for Extended Subtype
*
*/
- private static void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder, final
- TypeDefinition<?> unionSubtype, final List<String> regularExpressions, final SchemaNode parentNode,
- final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ private static void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
+ final TypeDefinition<?> unionSubtype, final List<String> regularExpressions, final SchemaNode parentNode,
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
final String unionTypeName = unionSubtype.getQName().getLocalName();
final Type genTO = findGenTO(unionTypeName, unionSubtype, schemaContext, genTypeDefsContextMap);
if (genTO != null) {
- updateUnionTypeAsProperty(parentUnionGenTOBuilder, genTO, genTO.getName());
+ updateUnionTypeAsProperty(parentUnionGenTOBuilder, genTO, unionTypeName);
} else {
final TypeDefinition<?> baseType = baseTypeDefForExtendedType(unionSubtype);
if (unionTypeName.equals(baseType.getQName().getLocalName())) {
final Type javaType = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(baseType,
- parentNode);
+ parentNode, null);
if (javaType != null) {
updateUnionTypeAsProperty(parentUnionGenTOBuilder, javaType, unionTypeName);
}
* <code>null</code> it it doesn't exist
*/
private static Type findGenTO(final String searchedTypeName, final SchemaNode parentNode,
- final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
+ final SchemaContext schemaContext, final Map<String, Map<Date, Map<String, Type>>> genTypeDefsContextMap) {
final Module typeModule = findParentModule(schemaContext, parentNode);
if (typeModule != null && typeModule.getName() != null) {
* </ul>
*
*/
- private static Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef, final String enumName, final GeneratedTypeBuilderBase<?> typeBuilder) {
+ private static Enumeration addInnerEnumerationToTypeBuilder(final EnumTypeDefinition enumTypeDef,
+ final String enumName, final GeneratedTypeBuilderBase<?> typeBuilder, ModuleContext context) {
Preconditions.checkArgument(enumTypeDef != null, "EnumTypeDefinition reference cannot be NULL!");
Preconditions.checkArgument(enumTypeDef.getQName().getLocalName() != null,
"Local Name in EnumTypeDefinition QName cannot be NULL!");
Preconditions.checkArgument(typeBuilder != null, "Generated Type Builder reference cannot be NULL!");
- final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumName);
+ final EnumBuilder enumBuilder = typeBuilder.addEnumeration(enumName, context);
final String enumTypedefDescription = encodeAngleBrackets(enumTypeDef.getDescription());
enumBuilder.setDescription(enumTypedefDescription);
enumBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDef);
}
private static boolean isLeafRefSelfReference(final LeafrefTypeDefinition leafref, final SchemaNode parentNode,
- final SchemaContext schemaContext) {
+ final SchemaContext schemaContext) {
final SchemaNode leafRefValueNode;
final RevisionAwareXPath leafRefXPath = leafref.getPathStatement();
final RevisionAwareXPath leafRefStrippedXPath = new RevisionAwareXPathImpl(leafRefXPath.toString()