2 * Copyright (c) 2015 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 com.google.common.collect.ImmutableSet;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeCachingCodec;
15 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeCodec;
16 import org.opendaylight.yangtools.binding.lib.DataObject;
17 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 class CachingNormalizedNodeCodec<D extends DataObject,
20 C extends DataContainerCodecContext<D, ?, ?> & BindingNormalizedNodeCodec<D>>
21 extends AbstractBindingNormalizedNodeCacheHolder implements BindingNormalizedNodeCachingCodec<D> {
22 private final @NonNull C context;
24 CachingNormalizedNodeCodec(final C context, final ImmutableSet<Class<?>> cacheSpec) {
26 this.context = requireNonNull(context);
30 public D deserialize(final NormalizedNode data) {
31 return context.deserialize(data);
35 public NormalizedNode serialize(final D data) {
36 // Serialize data using stream writer with child cache enable or using the cache if it is available
37 final var cache = getCachingSerializer(context);
38 return cache == null ? CachingNormalizedNodeSerializer.serializeUsingStreamWriter(this, context, data)