Remove ValueTypeCodec
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / CompositeValueCodec.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.yangtools.concepts.AbstractIllegalArgumentCodec;
13 import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
14
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;
20
21     CompositeValueCodec(final Class<?> valueType, final IdentityCodec codec) {
22         typeObjectCodec = EncapsulatedValueCodec.ofUnchecked(valueType);
23         valueCodec = requireNonNull(codec);
24     }
25
26     CompositeValueCodec(final Class<?> valueType, final InstanceIdentifierCodec codec) {
27         typeObjectCodec = EncapsulatedValueCodec.ofUnchecked(valueType);
28         valueCodec = requireNonNull(codec);
29     }
30
31     @SuppressWarnings("unchecked")
32     @Override
33     protected Object deserializeImpl(final Object input) {
34         // FIXME: throws NPE on unrepresentable InstanceIdentifierCodec
35         return typeObjectCodec.deserialize(valueCodec.deserialize(input));
36     }
37
38     @SuppressWarnings("unchecked")
39     @Override
40     protected Object serializeImpl(final Object input) {
41         return valueCodec.serialize(typeObjectCodec.serialize(input));
42     }
43 }