org.openprovenance.prov.xml.builder.JAXBToStringBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of prov-xml Show documentation
Show all versions of prov-xml Show documentation
Java Objects representing the PROV model and an XML serialiser/deserialiser for them. Classes were initially generated by JAXB, from the XML schema for PROV, and over time edited by hand.
package org.openprovenance.prov.xml.builder;
import javax.xml.bind.JAXBElement;
import org.openprovenance.apache.commons.lang.SystemUtils;
import org.openprovenance.apache.commons.lang.builder.ToStringBuilder;
import org.openprovenance.apache.commons.lang.builder.ToStringStyle;
public class JAXBToStringBuilder extends ToStringBuilder {
public static final ToStringStyle JAXB_STYLE = new JAXBToStringStyle();
private static ToStringStyle defaultStyle = JAXBToStringBuilder.JAXB_STYLE;
public static ToStringStyle getDefaultStyle() {
return defaultStyle;
}
public JAXBToStringBuilder(Object object, ToStringStyle style,
StringBuffer buffer) {
super(object, style, buffer);
}
public JAXBToStringBuilder(Object object, ToStringStyle style) {
super(object, style);
}
public JAXBToStringBuilder(Object object) {
this(object, getDefaultStyle(), null);
}
private static final class JAXBToStringStyle extends ToStringStyle {
private static final long serialVersionUID = 1L;
/**
*
* Constructor.
*
*
*
* Use the static constant rather than instantiating.
*
*/
private JAXBToStringStyle() {
super();
this.setContentStart("[");
this.setFieldSeparator(SystemUtils.LINE_SEPARATOR + " ");
this.setFieldSeparatorAtStart(true);
this.setContentEnd(SystemUtils.LINE_SEPARATOR + "]");
}
/**
*
* Ensure Singleton
after serialization.
*
*
* @return the singleton
*/
private Object readResolve() {
return ToStringStyle.MULTI_LINE_STYLE;
}
@Override
protected void appendSummary(StringBuffer buffer, String fieldName,
Object value) {
super.appendSummary(buffer, fieldName, value);
}
@Override
protected void appendDetail(StringBuffer buffer, String fieldName,
Object value) {
if (value instanceof JAXBElement>) {
appendDetail(buffer, fieldName, (JAXBElement>) value);
} else {
super.appendDetail(buffer, fieldName, value);
}
}
protected void appendDetail(StringBuffer buffer, String fieldName,
JAXBElement> element) {
buffer.append('<');
buffer.append(element.getName());
buffer.append('>');
buffer.append(element.getValue());
}
}
}