Opravena serializace nastavení do XML.

refs #132
multitenant
Josef Rokos 10 years ago
parent 372814e4b3
commit d454c211f8

@ -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());

@ -19,7 +19,7 @@ public class GlobalSettingServiceImpl extends AbstractOwnedService<GlobalSetting
private SettingsData settings;
public GlobalSettingServiceImpl(Marshaller marshaller, Unmarshaller unmarshaller) {
this.marshaller = new StringXmlMarshaller<SettingsData>(marshaller, unmarshaller);
this.marshaller = new StringXmlMarshaller<SettingsData>(marshaller, unmarshaller, SettingsData.class);
}
@Override

@ -35,7 +35,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
private StringXmlMarshaller<UserSettingsData> marshaller;
public UserServiceImpl(Marshaller marshaller, Unmarshaller unmarshaller) {
this.marshaller = new StringXmlMarshaller<UserSettingsData>(marshaller, unmarshaller);
this.marshaller = new StringXmlMarshaller<UserSettingsData>(marshaller, unmarshaller, UserSettingsData.class);
}
public void setEncoder(PasswordEncoder encoder) {

Loading…
Cancel
Save