Merge "ArpHandler to ignore ip packet sent to default GW"
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / sal / binding / dom / serializer / impl / LazyGeneratedCodecRegistry.java
index 39bd0816f50fb63e68bbbdb85ca7cbdce74812b6..89d9b49081bc5dbe032fa47572062a5570d3279f 100644 (file)
@@ -44,6 +44,7 @@ import org.opendaylight.yangtools.yang.binding.BindingCodec;
 import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.Node;
@@ -153,6 +154,12 @@ public class LazyGeneratedCodecRegistry implements //
         }
         return codec;
     }
+    
+    @Override
+    public QName getQNameForAugmentation(Class<?> cls) {
+        checkArgument(Augmentation.class.isAssignableFrom(cls));
+        return getCodecForAugmentation((Class<? extends Augmentation>)cls).getAugmentationQName();
+    }
 
     private static Class<? extends Augmentable<?>> getAugmentableArgumentFrom(
             final Class<? extends Augmentation<?>> augmentation) {
@@ -175,7 +182,7 @@ public class LazyGeneratedCodecRegistry implements //
                     });
             return ret;
         } catch (Exception e) {
-            LOG.error("Could not find augmentable for {}", augmentation, e);
+            LOG.debug("Could not find augmentable for {} using {}", augmentation, augmentation.getClassLoader(), e);
             return null;
         }
     }
@@ -233,7 +240,7 @@ public class LazyGeneratedCodecRegistry implements //
         if (typeToClass.containsKey(typeRef)) {
             return;
         }
-        LOG.info("Binding Class {} encountered.", cls);
+        LOG.trace("Binding Class {} encountered.", cls);
         WeakReference<Class> weakRef = new WeakReference<>(cls);
         typeToClass.put(typeRef, weakRef);
         if (Augmentation.class.isAssignableFrom(cls)) {
@@ -250,7 +257,7 @@ public class LazyGeneratedCodecRegistry implements //
         if (typeToClass.containsKey(typeRef)) {
             return;
         }
-        LOG.info("Binding Class {} encountered.", cls);
+        LOG.trace("Binding Class {} encountered.", cls);
         WeakReference<Class> weakRef = new WeakReference<>((Class) cls);
         typeToClass.put(typeRef, weakRef);
     }
@@ -389,8 +396,10 @@ public class LazyGeneratedCodecRegistry implements //
     public void onModuleContextAdded(SchemaContext schemaContext, Module module, ModuleContext context) {
         pathToType.putAll(context.getChildNodes());
         qnamesToIdentityMap.putAll(context.getIdentities());
-        for(Entry<QName, GeneratedTOBuilder> identity : context.getIdentities().entrySet()) {
-            typeToQname.put(new ReferencedTypeImpl(identity.getValue().getPackageName(), identity.getValue().getName()),identity.getKey());
+        for (Entry<QName, GeneratedTOBuilder> identity : context.getIdentities().entrySet()) {
+            typeToQname.put(
+                    new ReferencedTypeImpl(identity.getValue().getPackageName(), identity.getValue().getName()),
+                    identity.getKey());
         }
         captureCases(context.getCases(), schemaContext);
     }
@@ -907,9 +916,11 @@ public class LazyGeneratedCodecRegistry implements //
             Delegator<BindingCodec> {
 
         private BindingCodec delegate;
+        private QName augmentationQName;
 
         public AugmentationCodecWrapper(BindingCodec<Map<QName, Object>, Object> rawCodec) {
             this.delegate = rawCodec;
+            this.augmentationQName = BindingReflections.findQName(rawCodec.getClass());
         }
 
         @Override
@@ -934,6 +945,11 @@ public class LazyGeneratedCodecRegistry implements //
             Object rawCodecValue = getDelegate().deserialize((Map<QName, Object>) input);
             return new ValueWithQName<T>(input.getNodeType(), (T) rawCodecValue);
         }
+        
+        @Override
+        public QName getAugmentationQName() {
+            return augmentationQName;
+        }
     }
 
     private class IdentityCompositeCodec implements IdentitityCodec {
@@ -947,12 +963,12 @@ public class LazyGeneratedCodecRegistry implements //
         @Override
         public Class<?> deserialize(QName input) {
             Type type = qnamesToIdentityMap.get(input);
-            if(type == null) {
+            if (type == null) {
                 return null;
             }
             ReferencedTypeImpl typeref = new ReferencedTypeImpl(type.getPackageName(), type.getName());
             WeakReference<Class> softref = typeToClass.get(typeref);
-            if(softref == null) {
+            if (softref == null) {
                 return null;
             }
             return softref.get();
@@ -963,12 +979,12 @@ public class LazyGeneratedCodecRegistry implements //
             checkArgument(BaseIdentity.class.isAssignableFrom(input));
             bindingClassEncountered(input);
             QName qname = identityQNames.get(input);
-            if(qname != null) {
+            if (qname != null) {
                 return qname;
             }
             ConcreteType typeref = Types.typeForClass(input);
             qname = typeToQname.get(typeref);
-            if(qname != null) {
+            if (qname != null) {
                 identityQNames.put(input, qname);
             }
             return qname;
@@ -980,4 +996,26 @@ public class LazyGeneratedCodecRegistry implements //
             return serialize((Class) input);
         }
     }
+
+    public boolean isCodecAvailable(Class<? extends DataContainer> cls) {
+        if (containerCodecs.containsKey(cls)) {
+            return true;
+        }
+        if (identifierCodecs.containsKey(cls)) {
+            return true;
+        }
+        if (choiceCodecs.containsKey(cls)) {
+            return true;
+        }
+        if (caseCodecs.containsKey(cls)) {
+            return true;
+        }
+        if (augmentableCodecs.containsKey(cls)) {
+            return true;
+        }
+        if (augmentationCodecs.containsKey(cls)) {
+            return true;
+        }
+        return false;
+    }
 }
\ No newline at end of file