Mass-migrate to use EffectiveModelContext
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / Lhotka02JSONCodecFactory.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.yangtools.yang.data.codec.gson;
9
10 import org.opendaylight.yangtools.yang.data.impl.codec.AbstractIntegerStringCodec;
11 import org.opendaylight.yangtools.yang.data.impl.codec.DecimalStringCodec;
12 import org.opendaylight.yangtools.yang.data.util.codec.CodecCache;
13 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
14 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
15
16 final class Lhotka02JSONCodecFactory extends JSONCodecFactory {
17     private final JSONInstanceIdentifierCodec iidCodec;
18
19     Lhotka02JSONCodecFactory(final EffectiveModelContext context, final CodecCache<JSONCodec<?>> cache) {
20         super(context, cache);
21         iidCodec = new Lhotka02JSONInstanceIdentifierCodec(context, this);
22     }
23
24     @Override
25     protected JSONCodec<?> instanceIdentifierCodec(final InstanceIdentifierTypeDefinition type) {
26         return iidCodec;
27     }
28
29     @Override
30     Lhotka02JSONCodecFactory rebaseTo(final EffectiveModelContext newSchemaContext,
31             final CodecCache<JSONCodec<?>> newCache) {
32         return new Lhotka02JSONCodecFactory(newSchemaContext, newCache);
33     }
34
35     @Override
36     JSONCodec<?> wrapDecimalCodec(final DecimalStringCodec decimalCodec) {
37         return new NumberJSONCodec<>(decimalCodec);
38     }
39
40     @Override
41     JSONCodec<?> wrapIntegerCodec(final AbstractIntegerStringCodec<?, ?> integerCodec) {
42         return new NumberJSONCodec<>(integerCodec);
43     }
44 }