9ba6885c758c9c9559c8b5b8c0f323fb7004de7d
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / LazySerializedDOMNotification.java
1 /*
2  * Copyright (c) 2015 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.controller.md.sal.binding.impl;
9
10 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
11 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
12 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
13 import org.opendaylight.yangtools.yang.binding.Notification;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
15 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
16
17 /**
18  * Lazy serialized implementation of DOM Notification.
19  *
20  * <p>
21  * This implementation performs serialization of data, only if receiver
22  * of notification actually accessed data from notification.
23  *
24  */
25 @Deprecated
26 public final class LazySerializedDOMNotification implements DOMNotification {
27
28     private final BindingNormalizedNodeSerializer codec;
29     private final Notification data;
30     private final SchemaPath type;
31
32     private ContainerNode domBody;
33
34     private LazySerializedDOMNotification(final BindingNormalizedNodeSerializer codec, final Notification data,
35             final SchemaPath type) {
36         this.codec = codec;
37         this.data = data;
38         this.type = type;
39     }
40
41     static DOMNotification create(final BindingNormalizedNodeSerializer codec, final Notification data) {
42         final SchemaPath type = SchemaPath.create(true, BindingReflections.findQName(data.implementedInterface()));
43         return new LazySerializedDOMNotification(codec, data, type);
44     }
45
46     @Override
47     public SchemaPath getType() {
48         return type;
49     }
50
51     @Override
52     public ContainerNode getBody() {
53         if (domBody == null) {
54             domBody = codec.toNormalizedNodeNotification(data);
55         }
56         return domBody;
57     }
58
59     public Notification getBindingData() {
60         return data;
61     }
62 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.