2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
10 import static java.util.Objects.requireNonNull;
12 import org.opendaylight.yangtools.concepts.AbstractIllegalArgumentCodec;
13 import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
15 final class CompositeValueCodec extends AbstractIllegalArgumentCodec<Object, Object> {
16 private final EncapsulatedValueCodec typeObjectCodec;
17 @SuppressWarnings("rawtypes")
18 // FIXME: specialize for the two possibilities
19 private final IllegalArgumentCodec valueCodec;
21 CompositeValueCodec(final Class<?> valueType, final IdentityCodec codec) {
22 typeObjectCodec = EncapsulatedValueCodec.ofUnchecked(valueType);
23 valueCodec = requireNonNull(codec);
26 CompositeValueCodec(final Class<?> valueType, final InstanceIdentifierCodec codec) {
27 typeObjectCodec = EncapsulatedValueCodec.ofUnchecked(valueType);
28 valueCodec = requireNonNull(codec);
31 @SuppressWarnings("unchecked")
33 protected Object deserializeImpl(final Object input) {
34 // FIXME: throws NPE on unrepresentable InstanceIdentifierCodec
35 return typeObjectCodec.deserialize(valueCodec.deserialize(input));
38 @SuppressWarnings("unchecked")
40 protected Object serializeImpl(final Object input) {
41 return valueCodec.serialize(typeObjectCodec.serialize(input));