CacheBuilder.newBuilder().build(new CacheLoader<>() {
@Override
public DataContainerCodecContext<?, ?> load(final Class<? extends DataObject> key) {
- if (Notification.class.isAssignableFrom(key)) {
- checkArgument(key.isInterface(), "Supplied class must be interface.");
- final QName qname = BindingReflections.findQName(key);
- final NotificationDefinition schema = getSchema().findNotification(qname).orElseThrow(
- () -> new IllegalArgumentException("Supplied " + key + " is not valid notification"));
- return new NotificationCodecContext<>(key, schema, factory());
- }
return createDataTreeChildContext(key);
}
});
}
});
+ private final LoadingCache<Class<?>, NotificationCodecContext<?>> notificationsByClass = CacheBuilder.newBuilder()
+ .build(new CacheLoader<Class<?>, NotificationCodecContext<?>>() {
+ @Override
+ public NotificationCodecContext<?> load(final Class<?> key) {
+ checkArgument(key.isInterface(), "Supplied class must be interface.");
+ final QName qname = BindingReflections.findQName(key);
+ final NotificationDefinition schema = getSchema().findNotification(qname).orElseThrow(
+ () -> new IllegalArgumentException("Supplied " + key + " is not valid notification"));
+ return new NotificationCodecContext<>(key, schema, factory());
+ }
+ });
+
private final LoadingCache<Class<?>, ContainerNodeCodecContext<?>> rpcDataByClass = CacheBuilder.newBuilder()
.build(new CacheLoader<Class<?>, ContainerNodeCodecContext<?>>() {
@Override
}
NotificationCodecContext<?> getNotification(final Class<? extends Notification<?>> notification) {
- return (NotificationCodecContext<?>) streamChild((Class<? extends DataObject>)notification);
+ return getOrRethrow(notificationsByClass, notification);
}
NotificationCodecContext<?> getNotification(final Absolute notification) {
*/
package org.opendaylight.mdsal.binding.dom.codec.impl;
+import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import org.junit.Test;
import org.opendaylight.mdsal.binding.dom.codec.api.IncorrectNestingException;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OutOfPixieDustNotification;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.md.sal.knock.knock.rev180723.KnockKnockInput;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
public class Mdsal724Test extends AbstractBindingCodecTest {
+ @Test
+ public void testNotificationInstanceIdentifier() {
+ // An InstanceIdentifier pointing at a notification, unsafe to create
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ final var iid = InstanceIdentifier.create((Class) OutOfPixieDustNotification.class);
+
+ final var ex = assertThrows(IllegalArgumentException.class, () -> codecContext.toYangInstanceIdentifier(iid));
+ assertThat(ex.getMessage(), startsWith("Supplied class must not be a notification ("));
+ }
+
@Test
public void testRpcInputInstanceIdentifier() {
// An InstanceIdentifier pointing at a notification, unsafe to create
import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.yangtools.yang.binding.Action;
import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
checkArgument(!Augmentation.class.isAssignableFrom(cls), "Supplied class must not be an augmentation (%s is)",
cls);
checkArgument(!Action.class.isAssignableFrom(cls), "Supplied class must not be an action (%s is)", cls);
+ checkArgument(!Notification.class.isAssignableFrom(cls), "Supplied class must not be a notification (%s is)",
+ cls);
return (DataSchemaNode) getTypes().findSchema(Type.of(cls)).orElse(null);
}