Use TypedSchemaNode 64/42664/5
authorRobert Varga <rovarga@cisco.com>
Wed, 27 Jul 2016 22:26:10 +0000 (00:26 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Thu, 28 Jul 2016 20:20:56 +0000 (20:20 +0000)
Now that the getType() method is available through a unified
interface use it to simplify type checks.

Change-Id: I9538c3677daf4ac4e3eac080220403bf2f75adb8
Signed-off-by: Robert Varga <rovarga@cisco.com>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/gen/impl/DataNodeContainerSerializerSource.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java

index bc220ff445da95ac93be6eecc2af77ec9166801a..791fe7e54175a31190c603dd6f1633fa7a63625b 100644 (file)
@@ -31,6 +31,7 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypedSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 import org.slf4j.Logger;
@@ -106,14 +107,13 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
     }
 
     private static String getGetterName(final DataSchemaNode node) {
-        final TypeDefinition<?> type ;
-        if (node instanceof LeafSchemaNode) {
-            type = ((LeafSchemaNode) node).getType();
-        } else if (node instanceof LeafListSchemaNode) {
-            type = ((LeafListSchemaNode) node).getType();
+        final TypeDefinition<?> type;
+        if (node instanceof TypedSchemaNode) {
+            type = ((TypedSchemaNode) node).getType();
         } else {
             type = null;
         }
+
         final String prefix;
         if (type instanceof BooleanTypeDefinition || type instanceof EmptyTypeDefinition) {
             prefix = "is";
index dbf066d44d9dee539658aec91901d03ae452b14e..31d3375336aaa3b2080ed959d121c1310c29589e 100644 (file)
@@ -52,6 +52,7 @@ import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.TypedSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
@@ -221,17 +222,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
             final DataNodeContainer childSchema) {
         final Map<String, DataSchemaNode> getterToLeafSchema = new HashMap<>();
         for (final DataSchemaNode leaf : childSchema.getChildNodes()) {
-            final TypeDefinition<?> typeDef;
-            if (leaf instanceof LeafSchemaNode) {
-                typeDef = ((LeafSchemaNode) leaf).getType();
-            } else if (leaf instanceof LeafListSchemaNode) {
-                typeDef = ((LeafListSchemaNode) leaf).getType();
-            } else {
-                continue;
+            if (leaf instanceof TypedSchemaNode) {
+                getterToLeafSchema.put(getGetterName(leaf.getQName(), ((TypedSchemaNode) leaf).getType()), leaf);
             }
-
-            final String getterName = getGetterName(leaf.getQName(), typeDef);
-            getterToLeafSchema.put(getterName, leaf);
         }
         return getLeafNodesUsingReflection(parentClass, getterToLeafSchema);
     }
@@ -276,15 +269,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
     }
 
     private Codec<Object, Object> getCodec(final Class<?> valueType, final DataSchemaNode schema) {
-        final TypeDefinition<?> instantiatedType;
-        if (schema instanceof LeafSchemaNode) {
-            instantiatedType = ((LeafSchemaNode) schema).getType();
-        } else if (schema instanceof LeafListSchemaNode) {
-            instantiatedType = ((LeafListSchemaNode) schema).getType();
-        } else {
-            throw new IllegalArgumentException("Unsupported leaf node type " + schema.getClass());
-        }
-        return getCodec(valueType, instantiatedType);
+        Preconditions.checkArgument(schema instanceof TypedSchemaNode, "Unsupported leaf node type %s", schema);
+
+        return getCodec(valueType, ((TypedSchemaNode)schema).getType());
     }
 
     Codec<Object, Object> getCodec(final Class<?> valueType, final TypeDefinition<?> instantiatedType) {