@Nullable BindingCodecTreeNode getSubtreeCodec(SchemaPath path);
/**
- * Get the BindingIdentityCodec associated with this tree.
+ * Get the {@link BindingIdentityCodec} associated with this tree.
*
* @return A BindingIdentityCodec instance.
*/
@Beta
@NonNull BindingIdentityCodec getIdentityCodec();
+
+ /**
+ * Get the {@link BindingInstanceIdentifierCodec} associated with this tree.
+ *
+ * @return A BindingInstanceIdentifierCodec instance.
+ */
+ @Beta
+ @NonNull BindingInstanceIdentifierCodec getInstanceIdentifierCodec();
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.dom.codec.api;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+
+@Beta
+public interface BindingInstanceIdentifierCodec extends Immutable {
+ /**
+ * Translates supplied {@link YangInstanceIdentifier} into an {@link InstanceIdentifier}, if possible.
+ *
+ * @param domPath YANG Instance Identifier
+ * @return Binding Instance Identifier, or null if the instance identifier is not representable.
+ * @throws NullPointerException if domPath is null
+ */
+ <T extends DataObject> @Nullable InstanceIdentifier<T> toBinding(@NonNull YangInstanceIdentifier domPath);
+
+ /**
+ * Translates supplied {@link InstanceIdentifier} into {@link YangInstanceIdentifier}.
+ *
+ * @param bindingPath Binding Instance Identifier
+ * @return DOM Instance Identifier
+ * @throws NullPointerException if bindingPath is null
+ * @throws IllegalArgumentException if bindingPath is not valid.
+ */
+ @NonNull YangInstanceIdentifier fromBinding(@NonNull InstanceIdentifier<?> bindingPath);
+}
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingInstanceIdentifierCodec;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingStreamEventWriter;
import org.opendaylight.mdsal.binding.dom.codec.impl.NodeCodecContext.CodecContextFactory;
import org.opendaylight.mdsal.binding.dom.codec.loader.CodecClassLoader;
});
private final @NonNull CodecClassLoader loader = CodecClassLoader.create();
- private final InstanceIdentifierCodec instanceIdentifierCodec;
+ private final @NonNull InstanceIdentifierCodec instanceIdentifierCodec;
private final @NonNull IdentityCodec identityCodec;
private final BindingNormalizedNodeCodecRegistry registry;
private final BindingRuntimeContext context;
return loader;
}
- InstanceIdentifierCodec getInstanceIdentifierCodec() {
- return instanceIdentifierCodec;
- }
-
@Override
public IdentityCodec getIdentityCodec() {
return identityCodec;
}
@SuppressWarnings({"rawtypes", "unchecked"})
+ @Override
+ public BindingInstanceIdentifierCodec getInstanceIdentifierCodec() {
+ return instanceIdentifierCodec;
+ }
+
@Override
public DataObjectSerializer getEventStreamSerializer(final Class<?> type) {
return registry.getSerializer((Class) type);
@Override
public YangInstanceIdentifier toYangInstanceIdentifier(final InstanceIdentifier<?> binding) {
- return codecContext.getInstanceIdentifierCodec().serialize(binding);
+ return codecContext.getInstanceIdentifierCodec().fromBinding(binding);
}
@Override
- public InstanceIdentifier<?> fromYangInstanceIdentifier(final YangInstanceIdentifier dom) {
- return codecContext.getInstanceIdentifierCodec().deserialize(dom);
+ public <T extends DataObject> InstanceIdentifier<T> fromYangInstanceIdentifier(final YangInstanceIdentifier dom) {
+ return codecContext.getInstanceIdentifierCodec().toBinding(dom);
}
@Override
import com.google.common.collect.Iterables;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingDataObjectCodecTreeNode;
+import org.opendaylight.mdsal.binding.dom.codec.api.BindingInstanceIdentifierCodec;
import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
+import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-// FIXME: this is not really an IllegalArgumentCodec, as it can legally return null from deserialize()
-final class InstanceIdentifierCodec implements IllegalArgumentCodec<YangInstanceIdentifier, InstanceIdentifier<?>> {
+final class InstanceIdentifierCodec implements BindingInstanceIdentifierCodec,
+ //FIXME: this is not really an IllegalArgumentCodec, as it can legally return null from deserialize()
+ IllegalArgumentCodec<YangInstanceIdentifier, InstanceIdentifier<?>> {
private final BindingCodecContext context;
InstanceIdentifierCodec(final BindingCodecContext context) {
}
@Override
- public YangInstanceIdentifier serialize(final InstanceIdentifier<?> input) {
- final List<PathArgument> domArgs = new ArrayList<>();
- context.getCodecContextNode(input, domArgs);
- return YangInstanceIdentifier.create(domArgs);
- }
-
- @Override
- public InstanceIdentifier<?> deserialize(final YangInstanceIdentifier input) {
+ public <T extends DataObject> InstanceIdentifier<T> toBinding(final YangInstanceIdentifier domPath) {
final List<InstanceIdentifier.PathArgument> builder = new ArrayList<>();
- final BindingDataObjectCodecTreeNode<?> codec = context.getCodecContextNode(input, builder);
+ final BindingDataObjectCodecTreeNode<?> codec = context.getCodecContextNode(domPath, builder);
if (codec == null) {
return null;
}
// which is not binding representable.
return null;
}
- return InstanceIdentifier.create(builder);
+ @SuppressWarnings("unchecked")
+ final InstanceIdentifier<T> ret = (InstanceIdentifier<T>) InstanceIdentifier.create(builder);
+ return ret;
+ }
+
+ @Override
+ public @NonNull YangInstanceIdentifier fromBinding(@NonNull final InstanceIdentifier<?> bindingPath) {
+ final List<PathArgument> domArgs = new ArrayList<>();
+ context.getCodecContextNode(bindingPath, domArgs);
+ return YangInstanceIdentifier.create(domArgs);
+ }
+
+ @Override
+ @Deprecated
+ public YangInstanceIdentifier serialize(final InstanceIdentifier<?> input) {
+ return fromBinding(input);
+ }
+
+ @Override
+ @Deprecated
+ public InstanceIdentifier<?> deserialize(final YangInstanceIdentifier input) {
+ return toBinding(input);
}
-}
\ No newline at end of file
+}
binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsaltrace.rev160908.Config">
</odl:clustered-app-config>
+ <!-- FIXME: MDSAL-522: this should be BindingCodecTree, from which we need BindingInstanceIdentifierCodec -->
<reference id="codec"
interface="org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer"
odl:type="default" />