YANG Tools:YANG to Java Mapping
1 YANG to JAVA mapping
The process for setter is:
Data Interface
Data Interface has a mapping similar to container, but contains only top level nodes defined in module.
Service Interface
Service Interface serves to describe RPC contract defined in the module. This RPC contract is defined by rpc statements.
Rpc's substatement are mapped as follows:
Example of notification mapping:
- 1.1 Package name
- 1.2 Class and interface name
- 1.3 Getters and setters name
- 1.4 Module
- 1.5 Typedef
- 1.6 Container
- 1.7 Leaf
- 1.8 Leaf-list
- 1.9 List
- 1.10 Choice and case
- 1.11 Grouping and uses
- 1.12 Rpc
- 1.13 Notification
- 1.14 Augment
- 1.15 Identity
Package name
The package name consists from following parts:
- opendaylight prefix - every package name starts with prefix
org.opendaylight.yang.gen.v1
which is hardcoded inBindingGeneratorUtil.moduleNamespaceToPackageName()
. - YANG version - is specified through module substatement yang-version
- namespace - equals to value of module subelement namespace argument value. The namespace characters : / : - @ $ # ' * + , ; = and character group:/) are replaced with periods (.).
- revision - concatenation of word
rev
and value of module subelement revision argument value without leading zeros before month and day (e.g. rev201379)
After the package name is generated then it is checked if it contains any JAVA key words or digits. If it is so then before this tokens is adden underscore (_). List of key words which are prefixed with underscore:
As an example suppose following yang model:
module module { namespace "urn:2:case#module" prefix "sbd"; organization "OPEN DAYLIGHT"; contact "http://www.whatever.com/"; revision <font color="violet">2013-07-09</font color> { } }
Package name will be org.opendaylight.yang.gen.v1.urn:2:case#module.rev201379
and after replacing digits and JAVA keywords
org.opendaylight.yang.gen.v1.urn._2._case.module.rev201379
and after replacing digits and JAVA keywords
org.opendaylight.yang.gen.v1.urn._2._case.module.rev201379
Getters and setters name
In some cases are YANG elements generated as getter or setter methods. This methods are created through class
The process for getter is:
MethodSignatureBuilder
The process for getter is:
- name of YANG element is converted to JAVA class name style
- the word
get
is added as preffix - return type of the getter method is set to element's
type
substatement value
The process for setter is:
- name of YANG element is converted to JAVA class name style
- word
set
is added as preffix - input parameter name is set to element's name converted to JAVA parameter style
- return parameter is set to void
Module
YANG module is converted to JAVA as two JAVA classes. Each of the class is in the separate JAVA file. The names of JAVA files are composed as follows:
<YANG_module_name><Sufix>.java where <sufix> can be Data or Service.
<YANG_module_name><Sufix>.java where <sufix> can be Data or Service.
YANG | JAVA |
module module { namespace "urn:module"; prefix "sbd"; organization "OPEN DAYLIGHT"; contact "http://www.whatever.com/"; revision 2013-07-09 { } } |
ModuleData.java
package org.opendaylight.yang.gen.v1.urn.module.rev201379; public interface ModuleData { } |
ModuleService.java
package org.opendaylight.yang.gen.v1.urn.module.rev201379; public interface ModuleService { } |
Data Interface
Data Interface has a mapping similar to container, but contains only top level nodes defined in module.
Service Interface
Service Interface serves to describe RPC contract defined in the module. This RPC contract is defined by rpc statements.
Typedef
YANG
typedef
statement is mapped to JAVA class. Typedef may contain following substatement:Substatement | How si argument mapped to JAVA |
---|---|
type | is mapped as class attribute |
descripton | isn't mapped |
units | isn't mapped |
default | isn't mapped |
Rpc
Rpc
is mapped to JAVA as method of class ModuleService.java
.Rpc's substatement are mapped as follows:
Rpc substatement | mapped to JAVA |
---|---|
input | interface |
output | interface |
YANG | JAVA |
---|---|
rpc rpc-test1 { output { leaf lf-output { type string; } } input { leaf lf-input { type string; } } } |
ModuleService.java
package org.opendaylight.yang.gen.v1.urn.module.rev201379; import java.util.concurrent.Future; import org.opendaylight.yangtools.yang.common.RpcResult; public interface ModuleService { Future<RpcResult<RpcTest1Output>> rpcTest1(RpcTest1Input input); }
RpcTest1Input.java
package org.opendaylight.yang.gen.v1.urn.module.rev201379; public interface RpcTest1Input { String getLfInput(); }
RpcTest1Output.java
package org.opendaylight.yang.gen.v1.urn.module.rev201379; public interface RpcTest1Output { String getLfOutput(); |
Notification
Notification
is mapped to the JAVA interface which extends Notification interface.Example of notification mapping:
YANG | JAVA |
---|---|
notification notif { } | package org.opendaylight.yang.gen.v1.urn.module.rev201379; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Augmentable; import org.opendaylight.yangtools.yang.binding.Notification; public interface Notif extends DataObject, Augmentable<Notif>, Notification {} |
https://wiki.opendaylight.org/view/YANG_Tools:YANG_to_Java_Mapping#Package_name
评论
发表评论