Limit the references IdentityCodec retains 97/13797/2
authorRobert Varga <rovarga@cisco.com>
Sat, 20 Dec 2014 23:33:31 +0000 (00:33 +0100)
committerRobert Varga <rovarga@cisco.com>
Sun, 21 Dec 2014 10:33:46 +0000 (11:33 +0100)
IdentityCodec does not really need the codec context -- the runtime
context is enough.

Change-Id: I9dcef7e64f326491030b969b53d7b3c61d0bcd04
Signed-off-by: Robert Varga <rovarga@cisco.com>
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java

index 11f8d3f5bae2c0e9ead199655c2ee052bd0e5ee8..0ecb622367bd7e29ddee09742725e279d673a76a 100644 (file)
@@ -59,19 +59,20 @@ import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-class BindingCodecContext implements CodecContextFactory, Immutable {
+final class BindingCodecContext implements CodecContextFactory, Immutable {
     private static final Logger LOG = LoggerFactory.getLogger(BindingCodecContext.class);
     private static final String GETTER_PREFIX = "get";
 
-    private final SchemaRootCodecContext root;
-    private final BindingRuntimeContext context;
     private final Codec<YangInstanceIdentifier, InstanceIdentifier<?>> instanceIdentifierCodec =
             new InstanceIdentifierCodec();
-    private final Codec<QName, Class<?>> identityCodec = new IdentityCodec();
+    private final Codec<QName, Class<?>> identityCodec;
+    private final BindingRuntimeContext context;
+    private final SchemaRootCodecContext root;
 
     public BindingCodecContext(final BindingRuntimeContext context) {
         this.context = Preconditions.checkNotNull(context, "Binding Runtime Context is required.");
         this.root = SchemaRootCodecContext.create(this);
+        this.identityCodec = new IdentityCodec(context);
     }
 
     @Override
@@ -315,7 +316,12 @@ class BindingCodecContext implements CodecContextFactory, Immutable {
         }
     }
 
-    private class IdentityCodec implements Codec<QName, Class<?>> {
+    private static class IdentityCodec implements Codec<QName, Class<?>> {
+        private final BindingRuntimeContext context;
+
+        IdentityCodec(final BindingRuntimeContext context) {
+            this.context = Preconditions.checkNotNull(context);
+        }
 
         @Override
         public Class<?> deserialize(final QName input) {