Bug 1743: Fixed resolving of Identityrefs in xml. 02/10902/1
authorLukas Sedlak <lsedlak@cisco.com>
Mon, 8 Sep 2014 12:46:42 +0000 (14:46 +0200)
committerLukas Sedlak <lsedlak@cisco.com>
Mon, 8 Sep 2014 12:46:42 +0000 (14:46 +0200)
Fixed resolving of Identityrefs when DataSchemaNode is defined as LeafListSchemaNode.
This is bugfix for: https://bugs.opendaylight.org/show_bug.cgi?id=1743

The overloaded methods toSimpleNodeWithType were refactored with resolveValueFromSchemaType method.
No code duplicity anymore which should prevent similiar bugs in future.

Change-Id: I6d974059369b46470ea81bdfc7694157d09bd2ed
Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java

index d944842bf983ca534804929c2cd3b28143b2f577..d49d7e599d65f4f162360e37f647d4204d7a6717 100644 (file)
@@ -228,38 +228,30 @@ public class XmlDocumentUtils {
 
     protected static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafSchemaNode schema,
             final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
-        final TypeDefinition<?> baseType = XmlUtils.resolveBaseTypeFrom(schema.getType());
-        final String text = xmlElement.getTextContent();
-        final Object value;
-
-        if (baseType instanceof InstanceIdentifierType) {
-            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
-        } else if (baseType instanceof IdentityrefTypeDefinition) {
-            value = InstanceIdentifierForXmlCodec.toIdentity(text, xmlElement, schemaCtx);
-        } else {
-            final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(schema.getType());
-            if (codec == null) {
-                LOG.info("No codec for schema {}, falling back to text", schema);
-                value = text;
-            } else {
-                value = codec.deserialize(text);
-            }
-        }
-
+        final Object value = resolveValueFromSchemaType(xmlElement, schema, schema.getType(), codecProvider, schemaCtx);
         Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
         return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
     }
 
     private static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafListSchemaNode schema,
             final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
+        final Object value = resolveValueFromSchemaType(xmlElement, schema, schema.getType(), codecProvider, schemaCtx);
+        Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
+        return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
+    }
+
+    private static Object resolveValueFromSchemaType(final Element xmlElement, final DataSchemaNode schema, final TypeDefinition<?> type,
+        final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
+        final TypeDefinition<?> baseType = XmlUtils.resolveBaseTypeFrom(type);
+        final String text = xmlElement.getTextContent();
         final Object value;
 
-        if (schema.getType() instanceof InstanceIdentifierType) {
+        if (baseType instanceof InstanceIdentifierType) {
             value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
+        } else if (baseType instanceof IdentityrefTypeDefinition) {
+            value = InstanceIdentifierForXmlCodec.toIdentity(text, xmlElement, schemaCtx);
         } else {
-            final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(schema.getType());
-            final String text = xmlElement.getTextContent();
-
+            final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(type);
             if (codec == null) {
                 LOG.info("No codec for schema {}, falling back to text", schema);
                 value = text;
@@ -267,9 +259,7 @@ public class XmlDocumentUtils {
                 value = codec.deserialize(text);
             }
         }
-
-        Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
-        return new SimpleNodeTOImpl<>(schema.getQName(), null, value, modifyAction.orNull());
+        return value;
     }
 
     private static Node<?> toCompositeNodeWithSchema(final Element xmlElement, final QName qName, final DataNodeContainer schema,