import java.util.Map.Entry;
import java.util.Optional;
import java.util.ServiceLoader;
-import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.binding.Action;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.BaseNotification;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Identifiable;
// FIXME: this is probably not right w.r.t. nulls
IllegalArgumentCodec<Object, Object> getCodec(final Class<?> valueType, final TypeDefinition<?> instantiatedType) {
- if (Class.class.equals(valueType)) {
+ if (BaseIdentity.class.isAssignableFrom(valueType)) {
@SuppressWarnings({ "unchecked", "rawtypes" })
final IllegalArgumentCodec<Object, Object> casted = (IllegalArgumentCodec) identityCodec;
return casted;
}
// FIXME: MDSAL-670: this is right for most situations, but we must never return NOOP_CODEC for
// valueType=Object.class
- return ValueTypeCodec.NOOP_CODEC;
+ return SchemaUnawareCodec.NOOP_CODEC;
}
@SuppressWarnings("checkstyle:illegalCatch")
private IllegalArgumentCodec<Object, Object> getCodecForBindingClass(final Class<?> valueType,
final TypeDefinition<?> typeDef) {
if (typeDef instanceof IdentityrefTypeDefinition) {
- return ValueTypeCodec.encapsulatedValueCodecFor(valueType, typeDef, identityCodec);
+ return new CompositeValueCodec.OfIdentity(valueType, identityCodec);
} else if (typeDef instanceof InstanceIdentifierTypeDefinition) {
- return ValueTypeCodec.encapsulatedValueCodecFor(valueType, typeDef, instanceIdentifierCodec);
+ return new CompositeValueCodec.OfInstanceIdentifier(valueType, instanceIdentifierCodec);
} else if (typeDef instanceof UnionTypeDefinition) {
- final Callable<UnionTypeCodec> unionLoader = UnionTypeCodec.loader(valueType, (UnionTypeDefinition) typeDef,
- this);
try {
- return unionLoader.call();
- } catch (final Exception e) {
+ return UnionTypeCodec.of(valueType, (UnionTypeDefinition) typeDef, this);
+ } catch (Exception e) {
throw new IllegalStateException("Unable to load codec for " + valueType, e);
}
} else if (typeDef instanceof LeafrefTypeDefinition) {
}
return getCodec(valueType, def);
}
- return ValueTypeCodec.getCodecFor(valueType, typeDef);
+ return SchemaUnawareCodec.of(valueType, typeDef);
}
@Override
return IdentifiableItemCodec.of(type.statement(), identifier, listClz, valueCtx);
}
- @SuppressWarnings("unchecked")
@Override
+ public <E extends DataObject> BindingDataObjectCodecTreeNode<E> streamChild(final Class<E> childClass) {
+ return root.streamChild(childClass);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
public <T extends DataObject> BindingDataObjectCodecTreeNode<T> getSubtreeCodec(final InstanceIdentifier<T> path) {
// TODO Do we need defensive check here?
return (BindingDataObjectCodecTreeNode<T>) getCodecContextNode(path, null);
}
final DataObject lazyObj = codec.deserialize(data);
- final InstanceIdentifier<?> bindingPath = InstanceIdentifier.create(builder);
+ final InstanceIdentifier<?> bindingPath = InstanceIdentifier.unsafeOf(builder);
return Map.entry(bindingPath, lazyObj);
}
@Override
- public Notification<?> fromNormalizedNodeNotification(final Absolute path, final ContainerNode data) {
+ public BaseNotification fromNormalizedNodeNotification(final Absolute path, final ContainerNode data) {
return getNotificationContext(path).deserialize(data);
}
@Override
- public Notification<?> fromNormalizedNodeNotification(final Absolute path, final ContainerNode data,
+ public BaseNotification fromNormalizedNodeNotification(final Absolute path, final ContainerNode data,
final Instant eventInstant) {
return eventInstant == null ? fromNormalizedNodeNotification(path, data)
: getNotificationContext(path).deserialize(data, eventInstant);
-
}
@Override
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
- public ContainerNode toNormalizedNodeNotification(@NonNull final Notification<?> data) {
+ public ContainerNode toNormalizedNodeNotification(final Notification<?> data) {
// FIXME: Should the cast to DataObject be necessary?
return serializeDataObject((DataObject) data,
(ctx, iface, domWriter) -> ctx.newNotificationWriter(
(Class<? extends Notification<?>>) iface.asSubclass(Notification.class), domWriter));
}
+ @Override
+ public ContainerNode toNormalizedNodeNotification(final Absolute path, final BaseNotification data) {
+ checkArgument(data instanceof DataObject, "Unexpected data %s", data);
+ @SuppressWarnings("rawtypes")
+ final NotificationCodecContext notifContext = getNotificationContext(path);
+ @SuppressWarnings("unchecked")
+ final var result = notifContext.serialize((DataObject) data);
+ verify(result instanceof ContainerNode, "Unexpected result %s from %s", result, data);
+ return (ContainerNode) result;
+ }
+
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST")
public ContainerNode toNormalizedNodeRpcData(final DataContainer data) {