Reimplement SchemaContextUtil.getBaseTypeForLeafRef()
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / JSONInstanceIdentifierCodec.java
index 4d54a8f55bf0e3ac78a9cc3f614f8d0fc6194a4b..cf7388f7e4cd66c26265a69796e1d52026c0a694 100644 (file)
@@ -12,23 +12,24 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
-import java.net.URI;
 import java.util.Iterator;
+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.DataSchemaContextTree;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.util.LeafrefResolver;
 
 abstract class JSONInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec
         implements JSONCodec<YangInstanceIdentifier> {
     private final DataSchemaContextTree dataContextTree;
     private final JSONCodecFactory codecFactory;
-    private final SchemaContext context;
+    private final EffectiveModelContext context;
 
-    JSONInstanceIdentifierCodec(final SchemaContext context, final JSONCodecFactory jsonCodecFactory) {
+    JSONInstanceIdentifierCodec(final EffectiveModelContext context, final JSONCodecFactory jsonCodecFactory) {
         this.context = requireNonNull(context);
         this.dataContextTree = DataSchemaContextTree.from(context);
         this.codecFactory = requireNonNull(jsonCodecFactory);
@@ -36,13 +37,13 @@ abstract class JSONInstanceIdentifierCodec extends AbstractModuleStringInstanceI
 
     @Override
     protected final Module moduleForPrefix(final String prefix) {
-        final Iterator<Module> modules = context.findModules(prefix).iterator();
+        final Iterator<? extends Module> modules = context.findModules(prefix).iterator();
         return modules.hasNext() ? modules.next() : null;
     }
 
     @Override
-    protected final String prefixForNamespace(final URI namespace) {
-        final Iterator<Module> modules = context.findModules(namespace).iterator();
+    protected final String prefixForNamespace(final XMLNamespace namespace) {
+        final Iterator<? extends Module> modules = context.findModules(namespace).iterator();
         return modules.hasNext() ? modules.next().getName() : null;
     }
 
@@ -52,10 +53,11 @@ abstract class JSONInstanceIdentifierCodec extends AbstractModuleStringInstanceI
     }
 
     @Override
-    protected final Object deserializeKeyValue(final DataSchemaNode schemaNode, final String value) {
+    protected final Object deserializeKeyValue(final DataSchemaNode schemaNode, final LeafrefResolver resolver,
+            final String value) {
         requireNonNull(schemaNode, "schemaNode cannot be null");
         checkArgument(schemaNode instanceof LeafSchemaNode, "schemaNode must be of type LeafSchemaNode");
-        final JSONCodec<?> objectJSONCodec = codecFactory.codecFor((LeafSchemaNode) schemaNode);
+        final JSONCodec<?> objectJSONCodec = codecFactory.codecFor((LeafSchemaNode) schemaNode, resolver);
         return objectJSONCodec.parseValue(null, value);
     }