...
Container is a holder that can hold many nodes within it. It is used for logically grouping certain set of nodes.
Java mapping
In java, container acts as a class which can hold information contained within. A class of the container is formed only when container has nodes in it. In addition to that, container's parent holder will have container class’s information.
...
- Interface
It includes:
a) The interface file has two interfaces defined. One interface which is for the impl class and one for the builder class.
b) The interface for builder class contains method for getter and setters of the attributes without get and set prefix respectively. And a method to create object of impl class. The interface for impl class contains only a getter of the attribute without get prefix - Builder Class
It includes:
a) Builder class implements the builder interface.
b) It has impl class inside which also implements impl interface. This also has hashCode(), equals(), toString() methods overridden in it. Further augmentation also is implemented here(refer augmentation for more details).
...
Example
| Code Block | ||
|---|---|---|
| ||
File : acme-system.yang
module acme-system {
namespace "http://acme.example.com/system";
prefix "acme";
organization "ACME Inc.";
contact "joe@acme.example.com";
description
"The module for entities implementing the ACME system.";
revision 2007-06-09 {
description "Initial revision.";
}
container system {
container login {
leaf message {
type string;
description
"Message given at start of login session";
}
}
}
.
.
.
} |
...
List is also like container that can hold many nodes by logically grouping. The only difference is, list can have multiple instances whereas container has only one instance.
Java mapping
In java, list acts as a class which can hold information contained within. A class of the list is formed only when list has nodes in it. In addition to that, list's parent holder will have list information by creating the list information in java List so that many instances of the class can be stored in it.
The list statement mapping in java is as same as container for the generation of java (refer container to know what files are generated).
In the below example the list holder is also a list with the same name. In such cases the complete path is defined for attribute in parent, in order to make sure that they are not referring to themselves. This case is same for any class generating YANG constructs.
Example
| Code Block | ||
|---|---|---|
| ||
File : acme-system.yang module acme-system { namespace "http://acme.example.com/system"; prefix "acme"; organization "ACME Inc."; contact "joe@acme.example.com"; description "The module for entities implementing the ACME system."; revision 2007-06-09 { description "Initial revision."; .} list userlogin { key "name"; list userlogin { key "name"; leaf name { type string; } leaf full-name { type string; } leaf class { type string; } } leaf name { type string; } }} . }. . } |
| Code Block | ||
|---|---|---|
| ||
File : UserLogin.java public interface UserLogin extends AugmentationHolder { String name(); String fullName(); String yangAutoPrefixClassaddThisBeforeClass(); interface UserBuilderLoginBuilder { String name(); String fullName(); String yangAutoPrefixClassaddThisBeforeClass(); UserBuilderLoginBuilder name(String name); UserBuilderLoginBuilder fullName(String fullName); UserBuilderLoginBuilder yangAutoPrefixClassaddThisBeforeClass(String yangAutoPrefixClassaddThisBeforeClass); UserLogin build(); } } File : UserBuilder.java public class UserBuilderLoginBuilder implements UserLogin.UserBuilderLoginBuilder { private String name; private String fullName; private String yangAutoPrefixClassaddThisBeforeClass; @Override public String name() { return name; } @Override public String fullName() { return fullName; } @Override public String yangAutoPrefixClassaddThisBeforeClass() { return yangAutoPrefixClassaddThisBeforeClass; } @Override public UserBuilderLoginBuilder name(String name) { this.name = name; return this; } @Override public UserBuilderLoginBuilder fullName(String fullName) { this.fullName = fullName; return this; } @Override public UserBuilderLoginBuilder yangAutoPrefixClassaddThisBeforeClass(String yangAutoPrefixClassaddThisBeforeClass) { this.yangAutoPrefixClassaddThisBeforeClass = yangAutoPrefixClassaddThisBeforeClass; return this; } .@Override public . Login build() { . public finalreturn class UserImpl implements User { . . .new LoginImpl(this); } public LoginBuilder() { } public final class LoginImpl implements Login { private List<AugmentedInfo> augmentedInfoList = new ArrayList<>(); private String name; private String fullName; private String addThisBeforeClass; @Override public String name() { return name; } @Override public String fullName() { return fullName; } @Override public String addThisBeforeClass() { return addThisBeforeClass; } @Override public int hashCode() { return Objects.hash(name, fullName, addThisBeforeClass); } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof LoginImpl) { LoginImpl other = (LoginImpl) obj; return Objects.equals(name, other.name) && Objects.equals(fullName, other.fullName) && Objects.equals(addThisBeforeClass, other.addThisBeforeClass); } return false; } @Override public String toString() { return MoreObjects.toStringHelper(getClass()) .add("name", name) .add("fullName", fullName) .add("addThisBeforeClass", addThisBeforeClass) .toString(); } public LoginImpl(LoginBuilder builderObject) { this.name = builderObject.name(); this.fullName = builderObject.fullName(); this.addThisBeforeClass = builderObject.addThisBeforeClass(); } @Override public void addAugmentation(AugmentedInfo value) { getAugmentedInfoList().add(value); } @Override public List<AugmentedInfo> getAugmentedInfoList() { return augmentedInfoList; } @Override public void removeAugmentation() { getAugmentedInfoList().clear(); } } } File : User.java public interface UserLogin extends AugmentationHolder { String name(); List<orgList<org.onosproject.yang.gen.v1.urnhttp.ietfacme.paramsexample.xmlcom.nssystem.yang.ietf.network.rev20160520.rev20070609.acmesystem.userlogin.User>Login> userlogin(); interface UserBuilderLoginBuilder { String name(); List<org.onosproject.yang.gen.v1.urnhttp.ietfacme.paramsexample.xmlcom.nssystem.yang.ietf.network.rev20160520.rev20070609.acmesystem.userlogin.User>Login> userlogin(); UserBuilderLoginBuilder name(String name); UserBuilderLoginBuilder userlogin(List<org.onosproject.yang.gen.v1.urnhttp.ietfacme.paramsexample.xmlcom.ns.yang.ietf.network.rev20160520.acmesystem.user.User> usersystem.rev20070609.acmesystem .login .Login> login); UserLogin build(); } } File : UserBuilder.java public class UserBuilderLoginBuilder implements UserLogin.UserBuilderLoginBuilder { private String name; private List<org.onosproject.yang.gen.v1.urnhttp.ietfacme.paramsexample.xmlcom.nssystem.yang.ietf.network.rev20160520.rev20070609.acmesystem.userlogin.User>Login> userlogin; @Override public String name() { return name; } @Override public List<org.onosproject.yang.gen.v1.urnhttp.ietfacme.paramsexample.xmlcom.ns.yang.ietf.network.rev20160520.acmesystem.user.User> usersystem.rev20070609.acmesystem.login .Login> login() { return userlogin; } @Override public UserBuilderLoginBuilder name(String name) { this.name = name; return this; } @Override public UserBuilderLoginBuilder userlogin(List<org.onosproject.yang.gen.v1.urnhttp.ietfacme.paramsexample.xmlcom.ns.yang.ietf.network.rev20160520.acmesystem.user.User> usersystem.rev20070609 .acmesystem .login.Login> login) { this.userlogin = userlogin; return this; } . . . public final class UserImplLoginImpl implements UserLogin { . . . } } |
Grouping and uses
Overview
...