From d454c211f8ab58c22d7f421360004c8532a3be4b Mon Sep 17 00:00:00 2001 From: Josef Rokos Date: Fri, 5 Sep 2014 09:40:51 +0200 Subject: [PATCH] =?UTF-8?q?Opravena=20serializace=20nastaven=C3=AD=20do=20?= =?UTF-8?q?XML.=20refs=20#132?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bukova/isspst/services/StringXmlMarshaller.java | 11 +++++------ .../services/settings/GlobalSettingServiceImpl.java | 2 +- .../bukova/isspst/services/users/UserServiceImpl.java | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/info/bukova/isspst/services/StringXmlMarshaller.java b/src/main/java/info/bukova/isspst/services/StringXmlMarshaller.java index 38480d3c..fc447195 100644 --- a/src/main/java/info/bukova/isspst/services/StringXmlMarshaller.java +++ b/src/main/java/info/bukova/isspst/services/StringXmlMarshaller.java @@ -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 { - 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 dataClass; - public StringXmlMarshaller(Marshaller marshaller, Unmarshaller unmarshaller) { + public StringXmlMarshaller(Marshaller marshaller, Unmarshaller unmarshaller, Class dataClass) { this.marshaller = marshaller; this.unmarshaller = unmarshaller; + this.dataClass = dataClass; } public String marshalData(T data) { @@ -57,7 +56,7 @@ public class StringXmlMarshaller { 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()); diff --git a/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java b/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java index 6827ccbe..70fea14f 100644 --- a/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/settings/GlobalSettingServiceImpl.java @@ -19,7 +19,7 @@ public class GlobalSettingServiceImpl extends AbstractOwnedService(marshaller, unmarshaller); + this.marshaller = new StringXmlMarshaller(marshaller, unmarshaller, SettingsData.class); } @Override diff --git a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java index 9dc2c205..e35dc814 100644 --- a/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/users/UserServiceImpl.java @@ -35,7 +35,7 @@ public class UserServiceImpl extends AbstractService implements UserServic private StringXmlMarshaller marshaller; public UserServiceImpl(Marshaller marshaller, Unmarshaller unmarshaller) { - this.marshaller = new StringXmlMarshaller(marshaller, unmarshaller); + this.marshaller = new StringXmlMarshaller(marshaller, unmarshaller, UserSettingsData.class); } public void setEncoder(PasswordEncoder encoder) {