-
Notifications
You must be signed in to change notification settings - Fork 2
Added YangInstanceIdentifier and Made Java code generation return typed iterator. #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
krishnact
wants to merge
2
commits into
Celeral:master
Choose a base branch
from
krishnact:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| How to use this code to create Java class for Juniper? | ||
|
|
||
| Assuming | ||
| pyang is installed in ~/projects/pyang-pyang-2.1 folder. | ||
| Netconf-Async is in ~/projects/Netconf-Async | ||
|
|
||
| a) Go to pyang install root ~/projects/pyang-pyang-2.1 | ||
| b) Source env | ||
|
|
||
| ``` | ||
| source ./env.sh | ||
| ``` | ||
| c) Now you can run pyang to make sure its function. If not then fix that. | ||
|
|
||
| ``` | ||
| pyang -h | ||
| ``` | ||
|
|
||
| d) | ||
| get Juniper yang files: | ||
|
|
||
| ``` | ||
| mkdir ~/projects/juniper | ||
| cd ~/projects/juniper | ||
| git clone https://github.com/Juniper/yang.git | ||
| ``` | ||
|
|
||
| e) Now go to Netconf-Async folder | ||
|
|
||
| ``` | ||
| cd ~/projects/Netconf-Async | ||
| ``` | ||
|
|
||
| f) Execute java code genaration using a command similar to shown below: | ||
|
|
||
| ``` | ||
| developer@rapti:~/projects/Netconf-Async$ pyang --jnc-no-pkginfo --lax-quote-checks --plugindir jnc -f jnc --jnc-output src/org/himalay/juniper -p /home/developer/projects/juniper/yang/17.3/17.3R1/common --dsdl-no-documentation /home/developer/projects/juniper/yang/17.3/17.3R1/junos-es/configuration.yang | ||
| ``` | ||
|
|
||
| if you need to generate package info then remove --jnc-no-pkginfo. Generated package info and schema has one character per line which is not good. This can be fixed using following command: | ||
|
|
||
| ``` | ||
| find src/org/himalay/juniper -name package-info.java -exec sed -z -r -i 's/([^\n])\n/\1/g' {} \; | ||
| find src/org/himalay/juniper -name *.schema -exec sed -z -r -i 's/([^\n])\n/\1/g' {} \; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
jnc/jnc/src/main/java/com/tailf/jnc/TypedElementChildrenIterator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.tailf.jnc; | ||
|
|
||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| public class TypedElementChildrenIterator<T extends Element> implements Iterator<Element> { | ||
|
|
||
| private Iterator<Element> childrenIterator; | ||
| private Element nextChild; | ||
| private boolean hasNextChild = false; | ||
| private final String name; | ||
|
|
||
| /** | ||
| * Constructor to create new children iterator for all children. | ||
| */ | ||
| public TypedElementChildrenIterator(NodeSet children) { | ||
| if (children != null) { | ||
| childrenIterator = children.iterator(); | ||
| } else { | ||
| childrenIterator = null; | ||
| } | ||
| name = null; | ||
| } | ||
|
|
||
| /** | ||
| * Constructor to create a new children iterator for children of a specific | ||
| * name. | ||
| */ | ||
| public TypedElementChildrenIterator(NodeSet children, String name) { | ||
| if (children != null) { | ||
| childrenIterator = children.iterator(); | ||
| } else { | ||
| childrenIterator = null; | ||
| } | ||
| this.name = name; | ||
| } | ||
|
|
||
| /** | ||
| * @return <code>true</code> if there are more children; | ||
| * <code>false</code> otherwise. | ||
| */ | ||
| @Override | ||
| public boolean hasNext() { | ||
| if (hasNextChild) { | ||
| return true; | ||
| } | ||
| if (childrenIterator == null) { | ||
| return false; | ||
| } | ||
| while (childrenIterator.hasNext()) { | ||
| if (name == null) { | ||
| return true; | ||
| } | ||
| final Element child = childrenIterator.next(); | ||
| if (child.name.equals(name)) { | ||
| hasNextChild = true; | ||
| nextChild = child; | ||
| return true; | ||
| } | ||
| } | ||
| hasNextChild = false; | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Iterates the Node set. | ||
| * | ||
| * @return next element with this.name in set or null if none. | ||
| */ | ||
| public T nextElement() { | ||
| if (hasNextChild) { | ||
| hasNextChild = false; | ||
| return (T) nextChild; | ||
| } | ||
| while (childrenIterator.hasNext()) { | ||
| final T child = (T)childrenIterator.next(); | ||
| if (name == null) { | ||
| return child; | ||
| } else if (child.name.equals(name)) { | ||
| return child; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Iterates the Node set. | ||
| * | ||
| * @return next element with this.name in set or null if none. | ||
| */ | ||
| @Override | ||
| public T next() { | ||
| return nextElement(); | ||
| } | ||
|
|
||
| /** | ||
| * Remove is not supported. | ||
| */ | ||
| @Override | ||
| public void remove() { | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
jnc/jnc/src/main/java/com/tailf/jnc/YangInstanceIdentifier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.tailf.jnc; | ||
|
|
||
| public class YangInstanceIdentifier extends YangBaseString{ | ||
| /** | ||
| * | ||
| */ | ||
| private static final long serialVersionUID = 4335565686368455056L; | ||
| String value; | ||
|
|
||
| public YangInstanceIdentifier(String value) throws YangException { | ||
| super(value); | ||
|
|
||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasNextChild = true;missing here.