Add InstanceNotification(Publish)ServiceAdapter
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / LazySerializedNotification.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.mdsal.binding.dom.adapter;
9
10 import com.google.common.cache.CacheBuilder;
11 import com.google.common.cache.CacheLoader;
12 import com.google.common.cache.LoadingCache;
13 import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
14 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
15 import org.opendaylight.yangtools.yang.binding.Notification;
16 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
18
19 /**
20  * {@link AbstractLazySerializedEvent} specialized to RFC6020 global notifications.
21  */
22 final class LazySerializedNotification extends AbstractLazySerializedEvent<Notification<?>> {
23     private static final LoadingCache<Class<?>, Absolute> PATHS = CacheBuilder.newBuilder().weakKeys()
24         .build(new CacheLoader<>() {
25             @Override
26             public Absolute load(final Class<?> key) {
27                 // FIXME: do not use reflection here, look the QName up from BindingRuntimeType
28                 return Absolute.of(BindingReflections.findQName(key)).intern();
29             }
30         });
31
32     LazySerializedNotification(final BindingNormalizedNodeSerializer codec, final Notification<?> data) {
33         super(codec, data, PATHS.getUnchecked(data.implementedInterface()));
34     }
35
36     @Override
37     ContainerNode loadBody(final BindingNormalizedNodeSerializer codec) {
38         return codec.toNormalizedNodeNotification(getBindingData());
39     }
40 }