Tolerate unresolvable leafrefs in groupings
[mdsal.git] / binding / mdsal-binding-generator-api / src / main / java / org / opendaylight / mdsal / binding / generator / spi / TypeProvider.java
index daa5e6fb15965f8bff2058877983963efe87b2f4..2f0cc09d5caa086722bc03750431ef2aa094913e 100644 (file)
@@ -19,24 +19,39 @@ public interface TypeProvider {
     Type javaTypeForYangType(String type);
 
     /**
-     * Resolve of yang Type Definition to it's java counter part.
-     * If the Type Definition contains one of yang primitive types the method
-     * will return java.lang. counterpart. (For example if yang type is int32
-     * the java counterpart is java.lang.Integer). In case that Type
-     * Definition contains extended type defined via yang typedef statement
-     * the method SHOULD return Generated Type or Generated Transfer Object
-     * if that Type is correctly referenced to resolved imported yang module.
-     * The method will return <code>null</code> value in situations that
-     * TypeDefinition can't be resolved (either due missing yang import or
-     * incorrectly specified type).
+     * Resolve of YANG Type Definition to it's java counter part. If the Type Definition contains one of YANG primitive
+     * types the method will return {@code java.lang.} counterpart. (For example if YANG type is int32 the Java
+     * counterpart is {@link Integer}). In case that Type Definition contains extended type defined via YANG typedef
+     * statement the method SHOULD return Generated Type or Generated Transfer Object if that Type is correctly
+     * referenced to resolved imported YANG module.
      *
+     * <p>
+     * The method will return <code>null</code> value in situations that TypeDefinition can't be resolved (either due
+     * to missing YANG import or incorrectly specified type).
+     *
+     * <p>
+     * {@code leafref} resolution for relative paths has two models of operation: lenient and strict. This is needed to
+     * handle the case where a grouping leaf's path points outside of the grouping tree. In such a case we cannot
+     * completely determine the correct type and need to fallback to {@link Object}.
      *
      * @param type Type Definition to resolve from
+     * @param lenientRelativeLeafrefs treat relative leafrefs leniently
      * @return Resolved Type
      */
-    Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode);
+    Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode,
+            boolean lenientRelativeLeafrefs);
+
+    default Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode) {
+        return javaTypeForSchemaDefinitionType(type, parentNode, false);
+    }
+
+    Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode, Restrictions restrictions,
+            boolean lenient);
 
-    Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode, Restrictions restrictions);
+    default Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
+            final Restrictions restrictions) {
+        return javaTypeForSchemaDefinitionType(type, parentNode, restrictions, false);
+    }
 
     /**
      * Returns string containing code for creation of new type instance.