[Simple-support] Check for empty element
Brought to you by:
niallg
|
From: Joël C. <jo...@cr...> - 2013-05-17 19:40:16
|
Hello,
I'm trying to deserialize an IPTables XML configuration file. In the file there is a part like this:
<rule >
<actions>
<DROP />
</actions>
</rule>
The empty element inside the actions element can be one of these four: <DROP /> or <ACCEPT /> or <RETURN /> or <QUEUE />
When reading in the XML file, I have a Java class Rule.java like this:
package model;
import java.io.Serializable;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
@Root(name = "rule")
public class Rule implements Serializable {
private static final long serialVersionUID = 1L;
@Element(name = "actions", required = true)
private Actions action;
}
The actions class looks like this:
package model;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.convert.Convert;
@Root(name = "actions", strict = false)
public class Actions {
@Element(name = "DROP", required = false)
private String aDrop;
@Element(name = "ACCEPT", required = false)
private String aAccept;
@Element(name = "QUEUE", required = false)
private String aQueue;
@Element(name = "RETURN", required = false)
private String aReturn;
public String toString() {
if (aDrop != null) {
return "DROP";
} else if (aAccept != null) {
return "ACCEPT";
} else if (aQueue != null) {
return "QUEUE";
} else if (aReturn != null) {
return "RETURN";
} else {
return "NOTHING";
}
}
}
I want to check which element was present inside the actions element.
However all the attributes of the Actions class stay NULL.
What am I doing wrong?
Thanks in advance.
Joël Craenhals
|