...
| 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
leaf host-name {
"The module for entities implementing the typeACME stringsystem.";
}
} |
| Code Block | ||
|---|---|---|
| ||
File : AcmeSystemService.java public interface AcmeSystemService revision 2007-06-09 { String getHostName(); void setHostName(String hostName); } File: AcmeSystemManager.java @Component (immediate = true) @Service public class AcmeSystemManager implements AcmeSystemService { description "Initial revision."; } container system { private final Logger log = getLogger(getClass()); leaf @Activate host-name { public void activate() { type string; //TODO: YANG utils generated code description "Hostname for log.info("Started")this system"; } @Deactivate } public void deactivate() {} . . //TODO: YANG. } |
| Code Block | ||
|---|---|---|
| ||
File: System.java public interface System extends AugmentationHolder { utils generated code String log.info("Stopped"hostName(); interface SystemBuilder }{ @Override public String getHostNamehostName() {; SystemBuilder //TODO: YANG utils generated codehostName(String hostName); return nullSystem build(); } } File @Override public void setHostName(String hostName) {: SystemBuilder.java public class SystemBuilder implements System.SystemBuilder { private String hostName; @Override public String hostName() { //TODO: YANG utils generatedreturn codehostName; } } |
Leaf-list
Overview
A leaf-list is also used for defining scalar variable, like leaf, but in an array of a particular type. The type of the variable can be either built-in type or a derived type.
Java mapping
In java leaf-list is stored in List, with respect to, java built-in type or derived type.
Example
| Code Block | ||
|---|---|---|
| ||
File : AcmeSystemService.java public interface AcmeSystemService@Override { public List<Short>SystemBuilder getDomainSearchhostName(String hostName); { void setDomainSearch(List<Short> domainSearch); } |
| Code Block | ||
|---|---|---|
| ||
File : AcmeSystemManager.java @Component (immediate = true) @Service public class AcmeSystemManager implements AcmeSystemService { this.hostName = hostName; privatereturn finalthis; Logger log = getLogger(getClass()); } @Activate. . public void activate() {. public final class SystemImpl //TODO: YANG utils generated code implements System { private log.info("Started"); String hostName; }@Override @Deactivate public voidString deactivatehostName() { //TODO: YANG utils generatedreturn codehostName; log.info("Stopped");} }. @Override. public List<Short> getDomainSearch() {. //TODO: YANG utils generated code } } |
Leaf-list
Overview
A leaf-list is also used for defining scalar variable, like leaf, but in an array of a particular type. The type of the variable can be either built-in type or a derived type.
Java mapping
In java leaf-list is stored in List, with respect to, java built-in type or derived type.
Example
| Code Block | ||
|---|---|---|
| ||
File : acme-system.yang module acme-system { return null; namespace "http://acme.example.com/system"; prefix } "acme"; @Override organization "ACME Inc."; public void setDomainSearch(List<Short> domainSearch) {contact "joe@acme.example.com"; description "The module for entities implementing the ACME system."; revision 2007-06-09 { description "Initial revision."; } container system { leaf-list domain-search { type string; description "List of domain names to search"; } } . . . } |
| Code Block | ||
|---|---|---|
| ||
File : System.java public interface System extends AugmentationHolder { String hostName(); interface SystemBuilder { String hostName(); SystemBuilder hostName(String hostName); System build(); } } File : SystemBuilder.java public class SystemBuilder implements System.SystemBuilder { private List<String> domainSearch; @Override public List<String> domainSearch() { return domainSearch; } @Override public SystemBuilder domainSearch(List<String> domainSearch) { this.domainSearch = domainSearch; return this; } . . . public final class SystemImpl implements System { private List<String> domainSearch; @Override public List<String> domainSearch() { return domainSearch; } . . . //TODO: YANG utils generated code } } |
Container
Overview
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. It is used for logically grouping certain set of nodes.
Java mapping
. In addition to that, container's parent holder will have container class’s information.
Container statement is mapped to java as
- 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).
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.
Example
| Code Block | ||
|---|---|---|
| ||
File : acme-system.yang
module acme-system {
.
.
.
container holder {
container system {
leaf host-name {
type string;
}
leaf-list domain-search {
type string;
}
}
}
} |
...