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.IllegalArgumentCodec;
14 final class CompositeValueCodec extends ValueTypeCodec {
15 private final EncapsulatedValueCodec typeObjectCodec;
16 @SuppressWarnings("rawtypes")
17 // FIXME: specialize for the two possibilities
18 private final IllegalArgumentCodec valueCodec;
20 CompositeValueCodec(final Class<?> valueType, final IdentityCodec codec) {
21 typeObjectCodec = EncapsulatedValueCodec.ofUnchecked(valueType);
22 valueCodec = requireNonNull(codec);
25 CompositeValueCodec(final Class<?> valueType, final InstanceIdentifierCodec codec) {
26 typeObjectCodec = EncapsulatedValueCodec.ofUnchecked(valueType);
27 valueCodec = requireNonNull(codec);
30 @SuppressWarnings("unchecked")
32 public Object deserialize(final Object input) {
33 return typeObjectCodec.deserialize(valueCodec.deserialize(input));
36 @SuppressWarnings("unchecked")
38 public Object serialize(final Object input) {
39 return valueCodec.serialize(typeObjectCodec.serialize(input));