final TypeDefinition<?> type ;
if (node instanceof LeafSchemaNode) {
type = ((LeafSchemaNode) node).getType();
- } else if(node instanceof LeafListSchemaNode) {
+ } else if (node instanceof LeafListSchemaNode) {
type = ((LeafListSchemaNode) node).getType();
} else {
type = null;
}
- String prefix = "get";
- if(type != null) {
- TypeDefinition<?> rootType = type;
- while (rootType.getBaseType() != null) {
- rootType = rootType.getBaseType();
- }
- if(rootType instanceof BooleanTypeDefinition || rootType instanceof EmptyTypeDefinition) {
- prefix = "is";
- }
+ final String prefix;
+ if (type instanceof BooleanTypeDefinition || type instanceof EmptyTypeDefinition) {
+ prefix = "is";
+ } else {
+ prefix = "get";
}
return prefix + BindingMapping.getGetterSuffix(node.getQName());
}
return getLeafNodesUsingReflection(parentClass, getterToLeafSchema);
}
- private static String getGetterName(final QName qName, TypeDefinition<?> typeDef) {
+ private static String getGetterName(final QName qName, final TypeDefinition<?> typeDef) {
final String suffix = BindingMapping.getGetterSuffix(qName);
- while (typeDef.getBaseType() != null) {
- typeDef = typeDef.getBaseType();
- }
if (typeDef instanceof BooleanTypeDefinition || typeDef instanceof EmptyTypeDefinition) {
return "is" + suffix;
}
return ValueTypeCodec.NOOP_CODEC;
}
- private Codec<Object, Object> getCodecForBindingClass(final Class<?> valueType, final TypeDefinition<?> instantiatedType) {
- @SuppressWarnings("rawtypes")
- TypeDefinition rootType = instantiatedType;
- while (rootType.getBaseType() != null) {
- rootType = rootType.getBaseType();
- }
- if (rootType instanceof IdentityrefTypeDefinition) {
+ private Codec<Object, Object> getCodecForBindingClass(final Class<?> valueType, final TypeDefinition<?> typeDef) {
+ if (typeDef instanceof IdentityrefTypeDefinition) {
return ValueTypeCodec.encapsulatedValueCodecFor(valueType, identityCodec);
- } else if (rootType instanceof InstanceIdentifierTypeDefinition) {
+ } else if (typeDef instanceof InstanceIdentifierTypeDefinition) {
return ValueTypeCodec.encapsulatedValueCodecFor(valueType, instanceIdentifierCodec);
- } else if (rootType instanceof UnionTypeDefinition) {
- final Callable<UnionTypeCodec> loader = UnionTypeCodec.loader(valueType, (UnionTypeDefinition) rootType, this);
+ } else if (typeDef instanceof UnionTypeDefinition) {
+ final Callable<UnionTypeCodec> loader = UnionTypeCodec.loader(valueType, (UnionTypeDefinition) typeDef, this);
try {
return loader.call();
} catch (final Exception e) {
throw new IllegalStateException("Unable to load codec for " + valueType, e);
}
- } else if (rootType instanceof LeafrefTypeDefinition) {
+ } else if (typeDef instanceof LeafrefTypeDefinition) {
final Entry<GeneratedType, Object> typeWithSchema = context.getTypeWithSchema(valueType);
final Object schema = typeWithSchema.getValue();
Preconditions.checkState(schema instanceof TypeDefinition<?>);
return getCodec(valueType, (TypeDefinition<?>) schema);
}
- return ValueTypeCodec.getCodecFor(valueType, instantiatedType);
+ return ValueTypeCodec.getCodecFor(valueType, typeDef);
}
@Override
if (BindingReflections.isBindingClass(typeClz)) {
return getCachedSchemaUnawareCodec(typeClz, getCodecLoader(typeClz, def));
}
- TypeDefinition<?> rootType = def;
- while (rootType.getBaseType() != null) {
- rootType = rootType.getBaseType();
- }
- if (rootType instanceof EmptyTypeDefinition) {
- return EMPTY_CODEC;
- }
- return NOOP_CODEC;
+ return def instanceof EmptyTypeDefinition ? EMPTY_CODEC : NOOP_CODEC;
}
private static SchemaUnawareCodec getCachedSchemaUnawareCodec(final Class<?> typeClz, final Callable<? extends SchemaUnawareCodec> loader) {