*/
package org.opendaylight.mdsal.binding.dom.codec.api;
+import static com.google.common.base.Verify.verifyNotNull;
+
import com.google.common.annotations.Beta;
+import com.google.common.base.VerifyException;
import java.util.Map.Entry;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.yangtools.yang.binding.Action;
import org.opendaylight.yangtools.yang.binding.DataContainer;
import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.Notification;
import org.opendaylight.yangtools.yang.binding.RpcInput;
import org.opendaylight.yangtools.yang.binding.RpcOutput;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
* @return DOM Instance Identifier
* @throws IllegalArgumentException If supplied Instance Identifier is not valid.
*/
- YangInstanceIdentifier toYangInstanceIdentifier(@Nonnull InstanceIdentifier<?> binding);
+ YangInstanceIdentifier toYangInstanceIdentifier(@NonNull InstanceIdentifier<?> binding);
/**
- * Translates supplied YANG Instance Identifier into Binding instance identifier.
+ * Translates supplied YANG Instance Identifier into Binding instance identifier. This method can return null
+ * if the instance identifier is not representable in Binding. If it is statically known this is not the case,
+ * use {@link #coerceFromYangInstanceIdentifier(YangInstanceIdentifier)}.
*
* @param dom YANG Instance Identifier
* @return Binding Instance Identifier, or null if the instance identifier is not representable.
*/
- @Nullable
- <T extends DataObject> InstanceIdentifier<T> fromYangInstanceIdentifier(@Nonnull YangInstanceIdentifier dom);
+ <T extends DataObject> @Nullable InstanceIdentifier<T> fromYangInstanceIdentifier(
+ @NonNull YangInstanceIdentifier dom);
+
+ /**
+ * Translates supplied YANG Instance Identifier into Binding instance identifier.
+ *
+ * @param dom YANG Instance Identifier
+ * @return Binding Instance Identifier
+ * @throws VerifyException if the instance identifier is not representable.
+ */
+ @Beta
+ default <T extends DataObject> @NonNull InstanceIdentifier<T> coerceFromYangInstanceIdentifier(
+ final @NonNull YangInstanceIdentifier dom) {
+ return verifyNotNull(fromYangInstanceIdentifier(dom), "%s is not representable", dom);
+ }
/**
* Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
* @param data NormalizedNode representing data
* @return DOM Instance Identifier
*/
- @Nullable
- Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(@Nonnull YangInstanceIdentifier path,
+ @Nullable Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(@NonNull YangInstanceIdentifier path,
NormalizedNode<?, ?> data);
/**
* @param data NormalizedNode representing data
* @return Binding representation of Notification
*/
- @Nullable Notification fromNormalizedNodeNotification(@Nonnull SchemaPath path,@Nonnull ContainerNode data);
+ @Nullable Notification fromNormalizedNodeNotification(@NonNull SchemaPath path, @NonNull ContainerNode data);
/**
* Translates supplied NormalizedNode RPC input or output into Binding data.
* @param data NormalizedNode representing data
* @return Binding representation of RPC data
*/
- @Nullable DataObject fromNormalizedNodeRpcData(@Nonnull SchemaPath path,@Nonnull ContainerNode data);
+ @Nullable DataObject fromNormalizedNodeRpcData(@NonNull SchemaPath path, @NonNull ContainerNode data);
/**
* Translates supplied ContainerNode action input.
* @param data NormalizedNode representing notification data
* @return NormalizedNode representation of notification
*/
- @Nonnull ContainerNode toNormalizedNodeNotification(@Nonnull Notification data);
+ @NonNull ContainerNode toNormalizedNodeNotification(@NonNull Notification data);
/**
* Translates supplied Binding RPC input or output into NormalizedNode data.
* @param data NormalizedNode representing rpc data
* @return NormalizedNode representation of rpc data
*/
- @Nonnull ContainerNode toNormalizedNodeRpcData(@Nonnull DataContainer data);
+ @NonNull ContainerNode toNormalizedNodeRpcData(@NonNull DataContainer data);
/**
* Lazily translates supplied Binding action input into NormalizedNode data.
* @return NormalizedNode representation of action input
* @throws NullPointerException if any of the arguments is null
*/
- @Beta default @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
- @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcInput input) {
+ @Beta
+ default @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
+ final @NonNull Class<? extends Action<?, ?, ?>> action, final @NonNull RpcInput input) {
return toLazyNormalizedNodeActionInput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input);
}
* @return NormalizedNode representation of action input
* @throws NullPointerException if any of the arguments is null
*/
- @Beta default @NonNull ContainerNode toNormalizedNodeActionInput(
- @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcInput input) {
+ @Beta
+ default @NonNull ContainerNode toNormalizedNodeActionInput(final @NonNull Class<? extends Action<?, ?, ?>> action,
+ @NonNull final RpcInput input) {
return toLazyNormalizedNodeActionInput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input)
.getDelegate();
* @param output Binding action output
* @return NormalizedNode representation of action output
*/
- @Beta default @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
- @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcOutput output) {
+ @Beta
+ default @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
+ final @NonNull Class<? extends Action<?, ?, ?>> action, final @NonNull RpcOutput output) {
return toLazyNormalizedNodeActionOutput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output);
}
* @param output Binding action output
* @return NormalizedNode representation of action output
*/
- @Beta default @NonNull ContainerNode toNormalizedNodeActionOutput(
- @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcOutput output) {
+ @Beta
+ default @NonNull ContainerNode toNormalizedNodeActionOutput(final @NonNull Class<? extends Action<?, ?, ?>> action,
+ final @NonNull RpcOutput output) {
return toLazyNormalizedNodeActionOutput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output)
.getDelegate();