Tolerate unresolvable leafrefs in groupings
[mdsal.git] / binding / mdsal-binding-generator-api / src / main / java / org / opendaylight / mdsal / binding / generator / spi / TypeProvider.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.mdsal.binding.generator.spi;
9
10 import org.opendaylight.mdsal.binding.model.api.Restrictions;
11 import org.opendaylight.mdsal.binding.model.api.Type;
12 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
13 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
15
16 public interface TypeProvider {
17     /**
18      * Resolve of YANG Type Definition to it's java counter part. If the Type Definition contains one of YANG primitive
19      * types the method will return {@code java.lang.} counterpart. (For example if YANG type is int32 the Java
20      * counterpart is {@link Integer}). In case that Type Definition contains extended type defined via YANG typedef
21      * statement the method SHOULD return Generated Type or Generated Transfer Object if that Type is correctly
22      * referenced to resolved imported YANG module.
23      *
24      * <p>
25      * The method will return <code>null</code> value in situations that TypeDefinition can't be resolved (either due
26      * to missing YANG import or incorrectly specified type).
27      *
28      * <p>
29      * {@code leafref} resolution for relative paths has two models of operation: lenient and strict. This is needed to
30      * handle the case where a grouping leaf's path points outside of the grouping tree. In such a case we cannot
31      * completely determine the correct type and need to fallback to {@link Object}.
32      *
33      * @param type Type Definition to resolve from
34      * @param lenientRelativeLeafrefs treat relative leafrefs leniently
35      * @return Resolved Type
36      */
37     Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode,
38             boolean lenientRelativeLeafrefs);
39
40     default Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode) {
41         return javaTypeForSchemaDefinitionType(type, parentNode, false);
42     }
43
44     Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode, Restrictions restrictions,
45             boolean lenient);
46
47     default Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
48             final Restrictions restrictions) {
49         return javaTypeForSchemaDefinitionType(type, parentNode, restrictions, false);
50     }
51
52     /**
53      * Returns string containing code for creation of new type instance.
54      */
55     String getTypeDefaultConstruction(LeafSchemaNode node);
56
57     String getConstructorPropertyName(SchemaNode node);
58
59     String getParamNameFromType(TypeDefinition<?> type);
60 }