import java.net.URI;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.opendaylight.restconf.utils.patch.Draft16StringModuleInstanceIdentifierCodec;
import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
+/**
+ * @deprecated This class will be replaced by
+ * {@link Draft16StringModuleInstanceIdentifierCodec}
+ */
+@Deprecated
+public final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
private final DataSchemaContextTree dataContextTree;
private final SchemaContext context;
+ private final String defaultPrefix;
+
+ public StringModuleInstanceIdentifierCodec(final SchemaContext context) {
+ this.context = Preconditions.checkNotNull(context);
+ this.dataContextTree = DataSchemaContextTree.from(context);
+ this.defaultPrefix = "";
+ }
- StringModuleInstanceIdentifierCodec(SchemaContext context) {
+ StringModuleInstanceIdentifierCodec(final SchemaContext context, @Nonnull final String defaultPrefix) {
this.context = Preconditions.checkNotNull(context);
this.dataContextTree = DataSchemaContextTree.from(context);
+ this.defaultPrefix = defaultPrefix;
}
@Override
- protected Module moduleForPrefix(@Nonnull String prefix) {
- return context.findModuleByName(prefix, null);
+ protected Module moduleForPrefix(@Nonnull final String prefix) {
+ if (prefix.isEmpty() && !this.defaultPrefix.isEmpty()) {
+ return this.context.findModuleByName(this.defaultPrefix, null);
+ } else {
+ return this.context.findModuleByName(prefix, null);
+ }
}
@Nonnull
@Override
protected DataSchemaContextTree getDataContextTree() {
- return dataContextTree;
+ return this.dataContextTree;
}
@Nullable
@Override
- protected String prefixForNamespace(@Nonnull URI namespace) {
- final Module module = context.findModuleByNamespaceAndRevision(namespace, null);
+ protected String prefixForNamespace(@Nonnull final URI namespace) {
+ final Module module = this.context.findModuleByNamespaceAndRevision(namespace, null);
return module == null ? null : module.getName();
}
}
\ No newline at end of file