- // FIXME: cascade assumes that ExtendedType does not resolve into any of the TypeDefinitions and
- // will pass on to the default case. That default case will be also taken for base types.
- // There is another twist here, which is the fact that the new parser will wrap the type
- // if we have redefined the default value -- which is not something that was done before.
-
- final TypeDefinition<?> typeDef = leaf.getType();
- if (typeDef instanceof EnumTypeDefinition) {
- returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
- final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
- final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(),
- typeBuilder, module);
-
- if (enumBuilder != null) {
- returnType = enumBuilder.toInstance(typeBuilder);
- }
- ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
- } else if (typeDef instanceof UnionTypeDefinition) {
- GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
- if (genTOBuilder != null) {
- returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule);
- }
- } else if (typeDef instanceof BitsTypeDefinition) {
- GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
- if (genTOBuilder != null) {
- returnType = genTOBuilder.toInstance();
+ final TypeDefinition<?> typeDef = CompatUtils.compatLeafType(leaf);
+ if (isInnerType(leaf, typeDef)) {
+ if (typeDef instanceof EnumTypeDefinition) {
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(typeDef, leaf);
+ final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) typeDef;
+ final EnumBuilder enumBuilder = resolveInnerEnumFromTypeDefinition(enumTypeDef, leaf.getQName(),
+ typeBuilder, module);
+ if (enumBuilder != null) {
+ returnType = enumBuilder.toInstance(typeBuilder);
+ }
+ ((TypeProviderImpl) typeProvider).putReferencedType(leaf.getPath(), returnType);
+ } else if (typeDef instanceof UnionTypeDefinition) {
+ GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
+ if (genTOBuilder != null) {
+ returnType = createReturnTypeForUnion(genTOBuilder, typeDef, typeBuilder, parentModule);
+ }
+ } else if (typeDef instanceof BitsTypeDefinition) {
+ GeneratedTOBuilder genTOBuilder = addTOToTypeBuilder(typeDef, typeBuilder, leaf, parentModule);
+ if (genTOBuilder != null) {
+ returnType = genTOBuilder.toInstance();
+ }
+ } else {
+ // It is constrained version of already declared type (inner declared type exists,
+ // onlyfor special cases (Enum, Union, Bits), which were already checked.
+ // In order to get proper class we need to look up closest derived type
+ // and apply restrictions from leaf type
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(typeDef);
+ returnType = typeProvider.javaTypeForSchemaDefinitionType(getBaseOrDeclaredType(typeDef), leaf,
+ restrictions);