Fix license header violations in binding-data-codec
[yangtools.git] / code-generator / binding-data-codec / src / main / java / org / opendaylight / yangtools / binding / data / codec / gen / impl / DataNodeContainerSerializerSource.java
index 4d52dab58deefab413fd78cd50a82ff7f8c2cc53..d9094acc31cbab5624f5332e937f63570d67f546 100644 (file)
@@ -1,10 +1,12 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
- */package org.opendaylight.yangtools.binding.data.codec.gen.impl;
+ */
+
+package org.opendaylight.yangtools.binding.data.codec.gen.impl;
 
 import com.google.common.base.Preconditions;
 import java.util.HashMap;
@@ -31,9 +33,13 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSource {
 
+    private static final Logger LOG = LoggerFactory.getLogger(DataNodeContainerSerializerSource.class);
+
     protected static final String INPUT = "_input";
     private static final String CHOICE_PREFIX = "CHOICE_";
 
@@ -99,7 +105,7 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
         return hashMap;
     }
 
-    private static final String getGetterName(final DataSchemaNode node) {
+    private static String getGetterName(final DataSchemaNode node) {
         final TypeDefinition<?> type ;
         if (node instanceof LeafSchemaNode) {
             type = ((LeafSchemaNode) node).getType();
@@ -128,6 +134,19 @@ abstract class DataNodeContainerSerializerSource extends DataObjectSerializerSou
             if (!schemaChild.isAugmenting()) {
                 final String getter = getGetterName(schemaChild);
                 final Type childType = getterToType.get(getter);
+                if (childType == null) {
+                    // FIXME AnyXml nodes are ignored, since their type cannot be found in generated bindnig
+                    // Bug-706 https://bugs.opendaylight.org/show_bug.cgi?id=706
+                    if (schemaChild instanceof AnyXmlSchemaNode) {
+                        LOG.warn("Node {} will be ignored. AnyXml is not yet supported from binding aware code." +
+                                "Binding Independent code can be used to serialize anyXml nodes.", schemaChild.getPath());
+                        continue;
+                    } else {
+                        throw new IllegalStateException(
+                                String.format("Unable to find type for child node %s. Expected child nodes: %s",
+                                        schemaChild.getPath(), getterToType));
+                    }
+                }
                 emitChild(b, getter, childType, schemaChild);
             }
         }