X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Fcodecs%2FObjectCodec.java;fp=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Fcodecs%2FObjectCodec.java;h=0000000000000000000000000000000000000000;hb=4390392e41489434f554766916cd1c1870ffbe2e;hp=97fadfad579663971bc31d19225c16460d7535ec;hpb=9163c563d8e9fa949d72a7293db97e10eedbfb1c;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/ObjectCodec.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/ObjectCodec.java deleted file mode 100644 index 97fadfad57..0000000000 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/codecs/ObjectCodec.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2014 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.restconf.nb.rfc8040.codecs; - -import static java.util.Objects.requireNonNull; - -import org.opendaylight.restconf.common.util.RestUtil; -import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec; -import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class ObjectCodec { - private static final Logger LOG = LoggerFactory.getLogger(ObjectCodec.class); - - private final EffectiveModelContext schemaContext; - private final TypeDefinition type; - - private ObjectCodec(final EffectiveModelContext schemaContext, final TypeDefinition typeDefinition) { - this.schemaContext = requireNonNull(schemaContext); - type = RestUtil.resolveBaseTypeFrom(typeDefinition); - } - - public static ObjectCodec of(final EffectiveModelContext schemaContext, final TypeDefinition typeDefinition) { - return new ObjectCodec(schemaContext, typeDefinition); - } - - public Object deserialize(final String input) { - try { - if (type instanceof IdentityrefTypeDefinition) { - if (LOG.isDebugEnabled()) { - LOG.debug( - "Value is not instance of IdentityrefTypeDefinition but is {}. " - + "Therefore NULL is used as translation of - {}", - input == null ? "null" : input.getClass(), String.valueOf(input)); - } - // FIXME: this should be a hard error - return null; - } else if (type instanceof InstanceIdentifierTypeDefinition) { - // FIXME: what is it that we are trying to decode here and why? - return new StringModuleInstanceIdentifierCodec(schemaContext).deserialize(input); - } else { - final TypeDefinitionAwareCodec> typeAwarecodec = - TypeDefinitionAwareCodec.from(type); - if (typeAwarecodec != null) { - return typeAwarecodec.deserialize(String.valueOf(input)); - } else { - // FIXME: this should be a hard error - LOG.debug("Codec for type \"{}\" is not implemented yet.", type.getQName().getLocalName()); - return null; - } - } - } catch (final ClassCastException e) { - // FIXME: remove this catch when everyone use codecs - // FIXME: this should be a hard error - LOG.error("ClassCastException was thrown when codec is invoked with parameter {}", input, e); - return null; - } - } -} \ No newline at end of file