Skip to content
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

few lints (logger-guards, assign to method param, etc.) resolved #129

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public class Client {

private Device dev;
private DeviceUser duser;

public Client() {
this.init();
Expand All @@ -24,7 +23,7 @@ public Client() {
private void init() {
String emsUserName = "bobby";
String ip = "localhost";
duser = new DeviceUser(emsUserName, "admin", "admin");
DeviceUser duser = new DeviceUser(emsUserName, "admin", "admin");
dev = new Device("mydev", duser, ip, 2022);

try {
Expand Down Expand Up @@ -52,8 +51,7 @@ private NodeSet editConfig(Device d, Element config) throws IOException,

private NodeSet getConfig(Device d) throws IOException, JNCException {
NetconfSession session = d.getSession("cfg");
NodeSet reply = session.getConfig(NetconfSession.RUNNING);
return reply;
return session.getConfig(NetconfSession.RUNNING);
}

public NodeSet getConfig() throws IOException, JNCException {
Expand Down
45 changes: 21 additions & 24 deletions src/main/java/com/tailf/jnc/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ protected Element cloneShallow() {
*
*/
public Element merge(Element root, int op) throws JNCException {
Element rootElem = root;

// make list of nodes down to this node from root
final NodeSet list = new NodeSet();
Expand All @@ -1173,9 +1174,9 @@ public Element merge(Element root, int op) throws JNCException {
Element x = list.getElement(0);
list.remove(0);

if (root == null) {
if (rootElem == null) {
if (list.size() >= 1) {
root = x.cloneShallow();
rootElem = x.cloneShallow();
} else {
// special case. only one path in root. Differ already
if (op == OP_CREATE) {
Expand All @@ -1198,16 +1199,16 @@ public Element merge(Element root, int op) throws JNCException {
}
}

if (x.compare(root) == -1) {
if (x.compare(rootElem) == -1) {
System.err.println(" x= " + x);
System.err.println(" root= " + root);
System.err.println(" compare: " + x.compare(root));
System.err.println(" root= " + rootElem);
System.err.println(" compare: " + x.compare(rootElem));

throw new JNCException(JNCException.ELEMENT_MISSING,
x.getElementPath() + ", " + (root != null ? root.getElementPath() : null));
x.getElementPath() + ", " + (rootElem != null ? rootElem.getElementPath() : null));
}
// same now, go down
Element parent = root;
Element parent = rootElem;
while (list.size() > 1) {
// pop first element from list
x = list.getElement(0);
Expand Down Expand Up @@ -1249,7 +1250,7 @@ public Element merge(Element root, int op) throws JNCException {
}
}
// done
return root;
return rootElem;
}

/**
Expand Down Expand Up @@ -1679,9 +1680,10 @@ public String toXMLString() {
}

private void toXMLString(int indent, StringBuffer s) {
int currentIndent = indent;
final boolean flag = hasChildren();
final String qName = qualifiedName();
String whitespacePrefix = new String(new char[indent * 2]).replace('\0', ' ');
String whitespacePrefix = new String(new char[currentIndent * 2]).replace('\0', ' ');
s.append(whitespacePrefix).append('<').append(qName);
// add xmlns attributes (prefixes)
if (prefixes != null) {
Expand All @@ -1695,28 +1697,28 @@ private void toXMLString(int indent, StringBuffer s) {
s.append(' ').append(attr.toXMLString(this));
}
}
indent++;
currentIndent++;
// add children elements if any
if (flag) {
s.append(">\n");
for (final Element child : children) {
child.toXMLString(indent, s);
child.toXMLString(currentIndent, s);
}
} else { // add value if any
if (value != null) {
s.append('>');
final String stringValue = value.toString().replaceAll("&",
"&amp;");
s.append(getIndentationSpacing(false, indent));
s.append(getIndentationSpacing(false, currentIndent));
s.append(stringValue);
} else {
// self-closing tag
s.append("/>");
return;
}
}
indent--;
s.append(getIndentationSpacing(flag, indent)).append("</").append(qName).append(">\n");
currentIndent--;
s.append(getIndentationSpacing(flag, currentIndent)).append("</").append(qName).append(">\n");
}

public String encodedXMLString(boolean newlineAtEnd) {
Expand Down Expand Up @@ -1922,16 +1924,11 @@ public ElementChildrenIterator iterator(String name) {
* @see #readFile(String)
*/
public void writeFile(String filename) throws IOException {
final OutputStream fos = Files.newOutputStream(Paths.get(filename));
try {
final DataOutputStream dos = new DataOutputStream(fos);
try {
dos.writeBytes(toXMLString());
} finally {
dos.close();
}
} finally {
fos.close();
try (
OutputStream fos = Files.newOutputStream(Paths.get(filename));
DataOutputStream dos = new DataOutputStream(fos);
) {
dos.writeBytes(toXMLString());
}
}

Expand Down
Loading