In application-level adapter, which are bound to particular models,
the nullable annotation gets in the way, as it flags a potential
error, which needs to be expensively masked.
Introduce a coerceFromYangInstanceIdentifier() method, which includes
the masking, leaving application code unburdened with this detail.
Change-Id: I0b6e052b6b9be7c42538ab25924fd47b0421b274
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
*/
package org.opendaylight.mdsal.binding.dom.codec.api;
*/
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.annotations.Beta;
+import com.google.common.base.VerifyException;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
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.
*
* @param dom YANG Instance Identifier
* @return Binding Instance Identifier, or null if the instance identifier is not representable.
<T extends DataObject> @Nullable 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.
*
/**
* Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
*
* @return NormalizedNode representation of action input
* @throws NullPointerException if any of the arguments is null
*/
* @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 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
*/
* @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();
return toLazyNormalizedNodeActionInput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input)
.getDelegate();
* @param output Binding action output
* @return NormalizedNode representation of action output
*/
* @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);
}
return toLazyNormalizedNodeActionOutput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output);
}
* @param output Binding action output
* @return NormalizedNode representation of 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();
return toLazyNormalizedNodeActionOutput(action,
new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output)
.getDelegate();
*/
package org.opendaylight.mdsal.eos.binding.dom.adapter;
*/
package org.opendaylight.mdsal.eos.binding.dom.adapter;
-import static com.google.common.base.Verify.verifyNotNull;
import static java.util.Objects.requireNonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import static java.util.Objects.requireNonNull;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
final YangInstanceIdentifier domId = domEntity.getIdentifier();
final InstanceIdentifier<?> bindingId;
try {
final YangInstanceIdentifier domId = domEntity.getIdentifier();
final InstanceIdentifier<?> bindingId;
try {
- bindingId = verifyNotNull(conversionCodec.fromYangInstanceIdentifier(domId));
+ bindingId = conversionCodec.coerceFromYangInstanceIdentifier(domId);
} catch (RuntimeException e) {
LOG.error("Error converting DOM entity ID {} to binding InstanceIdentifier", domId, e);
return;
} catch (RuntimeException e) {
LOG.error("Error converting DOM entity ID {} to binding InstanceIdentifier", domId, e);
return;