import org.opendaylight.mdsal.binding.dom.codec.api.CommonDataObjectCodecTreeNode.ChildAddressabilitySummary;
import org.opendaylight.mdsal.binding.dom.codec.impl.NodeCodecContext.CodecContextFactory;
import org.opendaylight.mdsal.binding.runtime.api.CompositeRuntimeType;
-import org.opendaylight.mdsal.binding.runtime.api.NotificationRuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.RuntimeType;
import org.opendaylight.mdsal.binding.runtime.api.RuntimeTypeContainer;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.Item;
return new DataObjectCodecPrototype<>(bindingArg, createIdentifier(type), type, factory);
}
- static DataContainerCodecPrototype<NotificationRuntimeType> from(final Class<?> augClass,
- final NotificationRuntimeType schema, final CodecContextFactory factory) {
- return new DataObjectCodecPrototype<>(augClass, NodeIdentifier.create(schema.statement().argument()), schema,
- factory);
- }
-
private static @NonNull NodeIdentifier createIdentifier(final CompositeRuntimeType type) {
final Object arg = type.statement().argument();
verify(arg instanceof QName, "Unexpected type %s argument %s", type, arg);
import org.opendaylight.yangtools.yang.binding.BaseNotification;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.EventInstantAware;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
private final MethodHandle eventProxy;
- NotificationCodecContext(final Class<?> key, final NotificationRuntimeType schema,
+ NotificationCodecContext(final Class<?> notificationClass, final NotificationRuntimeType type,
final CodecContextFactory factory) {
- super(DataContainerCodecPrototype.from(key, schema, factory));
+ super(new Prototype<>(notificationClass, type, factory));
final Class<D> bindingClass = getBindingClass();
final Class<?> awareClass = CodecPackage.EVENT_AWARE.generateClass(factory().getLoader(), bindingClass,
return deserialize(normalizedNode);
}
+ /**
+ * Prototype for a {@code notiofication}. This class only exists because DataContainerCodecContext requires a
+ * prototype.
+ */
+ private static final class Prototype<D extends DataObject & BaseNotification>
+ extends DataObjectCodecPrototype<NotificationRuntimeType> {
+ Prototype(final Class<?> cls, final NotificationRuntimeType type, final CodecContextFactory factory) {
+ super(cls, NodeIdentifier.create(type.statement().argument()), type, factory);
+ }
+
+ @Override
+ DataContainerCodecContext<?, NotificationRuntimeType> createInstance() {
+ throw new UnsupportedOperationException("Should never be invoked");
+ }
+ }
+
private enum ConstructorImplementation implements Implementation {
INSTANCE;
.build(new CacheLoader<Class<?>, NotificationCodecContext<?>>() {
@Override
public NotificationCodecContext<?> load(final Class<?> key) {
+ // FIXME: sharpen check to an Notification.class
checkArgument(key.isInterface(), "Supplied class must be interface.");
// TODO: we should be able to work with bindingChild() instead of schemaTreeChild() here
- final QName qname = BindingReflections.findQName(key);
- final RuntimeType child = getType().schemaTreeChild(qname);
- checkArgument(child instanceof NotificationRuntimeType, "Supplied %s is not valid notification",
- key);
- return new NotificationCodecContext<>(key, (NotificationRuntimeType) child, factory());
+ final var qname = BindingReflections.findQName(key);
+ if (getType().schemaTreeChild(qname) instanceof NotificationRuntimeType type) {
+ return new NotificationCodecContext<>(key, type, factory());
+ }
+ throw new IllegalArgumentException("Supplied " + key + " is not valid notification");
}
});
CacheBuilder.newBuilder().build(new CacheLoader<>() {
@Override
public NotificationCodecContext<?> load(final Absolute key) {
- final Class<?> cls = factory().getRuntimeContext().getClassForSchema(key);
- checkArgument(Notification.class.isAssignableFrom(cls), "Path %s does not represent a notification",
- key);
- return getNotificationImpl(cls);
+ final var cls = factory().getRuntimeContext().getClassForSchema(key);
+ try {
+ return getNotificationImpl(cls.asSubclass(Notification.class));
+ } catch (ClassCastException e) {
+ throw new IllegalArgumentException("Path " + key + " does not represent a notification", e);
+ }
}
});