Binding2 runtime - Codecs impl - context - part2
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / java / org / opendaylight / mdsal / binding / javav2 / dom / codec / impl / context / NotificationCodecContext.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies 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.mdsal.binding.javav2.dom.codec.impl.context;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.base.DataContainerCodecPrototype;
14 import org.opendaylight.mdsal.binding.javav2.dom.codec.impl.context.base.TreeNodeCodecContext;
15 import org.opendaylight.mdsal.binding.javav2.spec.base.Notification;
16 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
20 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
21
22 /**
23  * Context for prototype of notification.
24  *
25  * @param <D>
26  *            - type of tree node
27  */
28 @SuppressWarnings("rawtypes")
29 @Beta
30 public final class NotificationCodecContext<D extends TreeNode & Notification>
31         extends TreeNodeCodecContext<D, NotificationDefinition> {
32
33     /**
34      * Prepare context for notification from prototype.
35      *
36      * @param key
37      *            - binding class
38      * @param schema
39      *            - schema of notification
40      * @param factory
41      *            - codec context factory
42      */
43     public NotificationCodecContext(final Class<?> key, final NotificationDefinition schema,
44             final CodecContextFactory factory) {
45         super(DataContainerCodecPrototype.from(key, schema, factory));
46     }
47
48     @Nonnull
49     @Override
50     public D deserialize(@Nonnull final NormalizedNode<?, ?> data) {
51         Preconditions.checkState(data instanceof ContainerNode);
52         return createBindingProxy((NormalizedNodeContainer<?, ?, ?>) data);
53     }
54
55     @Override
56     protected Object deserializeObject(final NormalizedNode<?, ?> normalizedNode) {
57         return deserialize(normalizedNode);
58     }
59 }