import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
+import org.opendaylight.yangtools.yang.data.util.AbstractStringInstanceIdentifierCodec;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
-abstract sealed class JSONInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec
+abstract sealed class JSONInstanceIdentifierCodec extends AbstractStringInstanceIdentifierCodec
implements JSONCodec<YangInstanceIdentifier> {
static final class Lhotka02 extends JSONInstanceIdentifierCodec {
Lhotka02(final EffectiveModelContext context, final JSONCodecFactory jsonCodecFactory) {
import static java.util.Objects.requireNonNull;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
+import org.opendaylight.yangtools.yang.data.util.AbstractStringInstanceIdentifierCodec;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
-abstract sealed class AbstractInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec
+abstract sealed class AbstractInstanceIdentifierCodec extends AbstractStringInstanceIdentifierCodec
permits InstanceIdentifierDeserializer, InstanceIdentifierSerializer {
private final @NonNull DataSchemaContextTree dataContextTree;
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. 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.yangtools.yang.data.util;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import com.google.common.annotations.Beta;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
-
-/**
- * Extension of {@link AbstractStringInstanceIdentifierCodec}, which instantiates
- * QNames by first resolving the namespace and then looking the target namespace
- * in the list of currently-subscribed modules.
- */
-@Beta
-public abstract class AbstractModuleStringInstanceIdentifierCodec extends AbstractStringInstanceIdentifierCodec {
- /**
- * Resolve a string prefix into the corresponding module.
- *
- * @param prefix Prefix
- * @return module mapped to prefix, or null if the module cannot be resolved
- */
- protected abstract @Nullable ModuleEffectiveStatement moduleForPrefix(@NonNull String prefix);
-
- @Override
- protected final QName createQName(final String prefix, final String localName) {
- final var module = moduleForPrefix(prefix);
- checkArgument(module != null, "Failed to lookup prefix %s", prefix);
- return QName.create(module.localQNameModule(), localName);
- }
-}
import static java.util.Objects.requireNonNull;
-import com.google.common.annotations.Beta;
import com.google.common.escape.Escaper;
import com.google.common.escape.Escapers;
import java.util.Set;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.Composite;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContext.PathMixin;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement;
import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
/**
* Abstract utility class for representations which encode {@link YangInstanceIdentifier} as a
* prefix:name tuple. Typical uses are RESTCONF/JSON (module:name) and XML (prefix:name).
*/
-@Beta
public abstract class AbstractStringInstanceIdentifierCodec extends AbstractNamespaceCodec<YangInstanceIdentifier>
implements InstanceIdentifierCodec<String> {
// Escaper as per https://www.rfc-editor.org/rfc/rfc7950#section-6.1.3
return createQName(XMLConstants.DEFAULT_NS_PREFIX, localName);
}
+ @Override
+ protected final QName createQName(final String prefix, final String localName) {
+ final var module = moduleForPrefix(prefix);
+ if (module != null) {
+ return QName.create(module.localQNameModule(), localName);
+ }
+ throw new IllegalArgumentException("Failed to lookup prefix " + prefix);
+ }
+
+ /**
+ * Resolve a string prefix into the corresponding module.
+ *
+ * @param prefix Prefix
+ * @return module mapped to prefix, or null if the module cannot be resolved
+ */
+ protected abstract @Nullable ModuleEffectiveStatement moduleForPrefix(@NonNull String prefix);
+
// FIXME: YANGTOOLS-1426: this will not be necessary when we have dedicated bits type
private static @NonNull String checkBitsItem(final Object obj) {
if (obj instanceof String str) {