X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-codec%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fcodec%2Fimpl%2FValueTypeCodec.java;h=45343e560fe83e612603b8d895641a74502f53d6;hb=2d6a0b57921b934540c6c198d3351b58e354f98d;hp=42168b1b51de92ad7920a618aa3834aaa345ff21;hpb=afcffc25b637b243daa0e7aad6a80048cfdeb21d;p=mdsal.git diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueTypeCodec.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueTypeCodec.java index 42168b1b51..45343e560f 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueTypeCodec.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueTypeCodec.java @@ -7,116 +7,12 @@ */ package org.opendaylight.mdsal.binding.dom.codec.impl; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import org.opendaylight.yangtools.concepts.Codec; -import org.opendaylight.yangtools.yang.binding.util.BindingReflections; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; +import org.opendaylight.yangtools.concepts.IllegalArgumentCodec; /** * Value codec, which serializes / deserializes values from DOM simple values. */ -abstract class ValueTypeCodec implements Codec { - - private static final Cache, SchemaUnawareCodec> staticCodecs = CacheBuilder.newBuilder().weakKeys() - .build(); - - - /** - * Marker interface for codecs, which functionality will not be - * affected by schema change (introduction of new YANG modules) - * they may have one static instance generated when - * first time needed. - * - */ - interface SchemaUnawareCodec extends Codec { - - } - - - /** - * - * No-op Codec, Java YANG Binding uses same types as NormalizedNode model - * for base YANG types, representing numbers, binary and strings. - * - * - */ - public static final SchemaUnawareCodec NOOP_CODEC = new SchemaUnawareCodec() { - - @Override - public Object serialize(final Object input) { - return input; - } - - @Override - public Object deserialize(final Object input) { - return input; - } - }; - - public static final SchemaUnawareCodec EMPTY_CODEC = new SchemaUnawareCodec() { - - @Override - public Object serialize(final Object arg0) { - // Empty type has null value in NormalizedNode and Composite Node - // representation - return null; - } - - @Override - public Object deserialize(final Object arg0) { - /* Empty type has boolean.TRUE representation in Binding-aware world - * otherwise it is null / false. - * So when codec is triggered, empty leaf is present, that means we - * are safe to return true. - */ - return Boolean.TRUE; - } - }; - - private static final Callable EMPTY_LOADER = () -> EMPTY_CODEC; - - - public static SchemaUnawareCodec getCodecFor(final Class typeClz, final TypeDefinition def) { - if (BindingReflections.isBindingClass(typeClz)) { - return getCachedSchemaUnawareCodec(typeClz, getCodecLoader(typeClz, def)); - } - return def instanceof EmptyTypeDefinition ? EMPTY_CODEC : NOOP_CODEC; - } - - private static SchemaUnawareCodec getCachedSchemaUnawareCodec(final Class typeClz, final Callable loader) { - try { - return staticCodecs.get(typeClz, loader); - } catch (ExecutionException e) { - throw new IllegalStateException(e); - } - } - - private static Callable getCodecLoader(final Class typeClz, final TypeDefinition def) { - - TypeDefinition rootType = def; - while (rootType.getBaseType() != null) { - rootType = rootType.getBaseType(); - } - if (rootType instanceof EnumTypeDefinition) { - return EnumerationCodec.loader(typeClz, (EnumTypeDefinition) rootType); - } else if (rootType instanceof BitsTypeDefinition) { - return BitsCodec.loader(typeClz, (BitsTypeDefinition) rootType); - } else if (rootType instanceof EmptyTypeDefinition) { - return EMPTY_LOADER; - } - return EncapsulatedValueCodec.loader(typeClz); - } - - @SuppressWarnings("rawtypes") - static ValueTypeCodec encapsulatedValueCodecFor(final Class typeClz, final Codec delegate) { - SchemaUnawareCodec extractor = getCachedSchemaUnawareCodec(typeClz, EncapsulatedValueCodec.loader(typeClz)); - return new CompositeValueCodec(extractor, delegate); - } +// FIXME: IllegalArgumentCodec is perhaps not appropriate here due to null behavior +abstract class ValueTypeCodec implements IllegalArgumentCodec { }