Mercurial > hg > thermostat-tools-eclipse
changeset 105:28252d3475bd
Don't generate empty `commands` and `extensions` elements
author | Omair Majid <omajid@redhat.com> |
---|---|
date | Wed, 19 Feb 2014 16:39:36 -0500 |
parents | 5877be030593 |
children | 4356c844cff9 |
files | com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/Plugin.java |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/Plugin.java Fri Feb 07 16:11:46 2014 -0500 +++ b/com.redhat.thermostat.tools.eclipse.plugin/src/com/redhat/thermostat/tools/eclipse/plugin/model/Plugin.java Wed Feb 19 16:39:36 2014 -0500 @@ -3,6 +3,8 @@ import java.util.ArrayList; import java.util.List; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -100,4 +102,26 @@ } } + // JAXB-specific hooks + // try and pretty up the resulting xml file to create no empty lists + + /** Turn empty list into no-element when marshalling to xml */ + void beforeMarshal(Marshaller marshaller) { + if (this.commands == null || this.commands.isEmpty()) { + this.commands = null; + } + if (this.extensions == null || this.extensions.isEmpty()) { + this.extensions = null; + } + } + + /** If null elements were read, re-initialize to empty list */ + void afterUnmarshal(Unmarshaller unmarshaller, Object parent) { + if (this.commands == null) { + this.commands = new ArrayList<>(); + } + if (this.extensions == null) { + this.extensions = new ArrayList<>(); + } + } }