Map identities to proper objects
[mdsal.git] / binding / mdsal-binding-generator / src / main / java / org / opendaylight / mdsal / binding / generator / impl / reactor / IdentityGenerator.java
index e5fc913e726ecafd17000914ead935643879a740..efffb79ecc0b9e4e018eaee8cda25994fd8e76e4 100644 (file)
@@ -7,15 +7,19 @@
  */
 package org.opendaylight.mdsal.binding.generator.impl.reactor;
 
+import static com.google.common.base.Verify.verify;
 import static org.opendaylight.mdsal.binding.model.ri.BindingTypes.BASE_IDENTITY;
 
 import java.util.List;
 import java.util.stream.Collectors;
 import org.opendaylight.mdsal.binding.generator.impl.rt.DefaultIdentityRuntimeType;
 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.Type;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
 import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
 import org.opendaylight.mdsal.binding.runtime.api.IdentityRuntimeType;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
 import org.opendaylight.yangtools.yang.model.api.stmt.BaseEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.IdentityEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
@@ -60,9 +64,14 @@ public final class IdentityGenerator
             builder.addImplementsType(BASE_IDENTITY);
         }
 
+        narrowImplementedInterface(builder);
+
         final ModuleGenerator module = currentModule();
         module.addQNameConstant(builder, localName());
 
+        // Constant implementation
+        builder.addConstant(Type.of(builder), BindingMapping.VALUE_STATIC_FIELD_NAME, BaseIdentity.class);
+
         builderFactory.addCodegenInformation(module, statement(), builder);
         builder.setModuleName(module.statement().argument().getLocalName());
 //        builder.setSchemaPath(identity.getPath());
@@ -71,13 +80,21 @@ public final class IdentityGenerator
     }
 
     @Override
-    IdentityRuntimeType createRuntimeType() {
-        return generatedType().map(type -> new DefaultIdentityRuntimeType(type, statement())).orElse(null);
+    GeneratedType runtimeJavaType() {
+        return generatedType().orElse(null);
+    }
+
+    @Override
+    IdentityRuntimeType createExternalRuntimeType(final Type type) {
+        verify(type instanceof GeneratedType, "Unexpected type %s", type);
+        return new DefaultIdentityRuntimeType((GeneratedType) type, statement());
     }
 
     @Override
-    IdentityRuntimeType rebaseRuntimeType(final IdentityRuntimeType type, final IdentityEffectiveStatement statement) {
-        return new DefaultIdentityRuntimeType(type.javaType(), statement);
+    IdentityRuntimeType createInternalRuntimeType(final AugmentResolver resolver,
+            final IdentityEffectiveStatement statement, final Type type) {
+        // 'identity' statements are not part of schema tree and hence should never an internal reference
+        throw new UnsupportedOperationException("Should never be called");
     }
 
     @Override