|
|
|
@ -1,7 +1,5 @@
|
|
|
|
|
package info.bukova.isspst.services;
|
|
|
|
|
|
|
|
|
|
import info.bukova.isspst.services.settings.GlobalSettingsService;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.StringReader;
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
@ -12,20 +10,21 @@ import org.exolab.castor.xml.Unmarshaller;
|
|
|
|
|
import org.exolab.castor.xml.ValidationException;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.core.GenericTypeResolver;
|
|
|
|
|
|
|
|
|
|
public class StringXmlMarshaller<T> {
|
|
|
|
|
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(GlobalSettingsService.class);
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(StringXmlMarshaller.class);
|
|
|
|
|
private final static String MARSHAL_ERROR = "Cannot marshal settings data: ";
|
|
|
|
|
private final static String UNMARSHAL_ERROR = "Cannot unmarshal settings data: ";
|
|
|
|
|
|
|
|
|
|
private Marshaller marshaller;
|
|
|
|
|
private Unmarshaller unmarshaller;
|
|
|
|
|
private Class<T> dataClass;
|
|
|
|
|
|
|
|
|
|
public StringXmlMarshaller(Marshaller marshaller, Unmarshaller unmarshaller) {
|
|
|
|
|
public StringXmlMarshaller(Marshaller marshaller, Unmarshaller unmarshaller, Class<T> dataClass) {
|
|
|
|
|
this.marshaller = marshaller;
|
|
|
|
|
this.unmarshaller = unmarshaller;
|
|
|
|
|
this.dataClass = dataClass;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String marshalData(T data) {
|
|
|
|
@ -57,7 +56,7 @@ public class StringXmlMarshaller<T> {
|
|
|
|
|
|
|
|
|
|
StringReader sr = new StringReader(data);
|
|
|
|
|
try {
|
|
|
|
|
unmarshaller.setClass(GenericTypeResolver.resolveTypeArgument(getClass(), StringXmlMarshaller.class));
|
|
|
|
|
unmarshaller.setClass(dataClass);
|
|
|
|
|
return (T) unmarshaller.unmarshal(sr);
|
|
|
|
|
} catch (MarshalException e) {
|
|
|
|
|
log.error(UNMARSHAL_ERROR + e.getMessage());
|
|
|
|
|