X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Freactor%2Floader%2FChainWatcher.java;h=a6a5004be6440b6b9dc0d9183c8bfb7c4a4278d0;hb=d959856be39657398f81519240b4e3baa497efa0;hp=c373b88f7457ca54b6df809f765cb712e9c463fa;hpb=a1d9ae96de02dc129dbcbd7023cdba323e37ab50;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/reactor/loader/ChainWatcher.java b/src/main/java/net/pterodactylus/reactor/loader/ChainWatcher.java index c373b88..a6a5004 100644 --- a/src/main/java/net/pterodactylus/reactor/loader/ChainWatcher.java +++ b/src/main/java/net/pterodactylus/reactor/loader/ChainWatcher.java @@ -24,14 +24,16 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + import net.pterodactylus.reactor.Reaction; import net.pterodactylus.reactor.engine.Engine; import net.pterodactylus.reactor.loader.Chain.Parameter; import net.pterodactylus.reactor.loader.Chain.Part; import org.apache.log4j.Logger; -import org.simpleframework.xml.Serializer; -import org.simpleframework.xml.core.Persister; import com.google.common.base.Predicate; import com.google.common.collect.Maps; @@ -107,9 +109,9 @@ public class ChainWatcher extends AbstractExecutionThreadService { /* now parse all XML files. */ Map chains = new HashMap(); for (File xmlFile : xmlFiles) { - Serializer serializer = new Persister(); - logger.debug(String.format("Reading %s...", xmlFile.getPath())); - Chain chain = serializer.read(Chain.class, xmlFile); + + /* parse XML file. */ + Chain chain = parseXmlFile(xmlFile); /* dump chain */ logger.debug(String.format(" Enabled: %s", chain.enabled())); @@ -179,4 +181,27 @@ public class ChainWatcher extends AbstractExecutionThreadService { } } + // + // STATIC METHODS + // + + /** + * Parses the given XML file into a {@link Chain}. + * + * @param xmlFile + * The XML file to parse + * @return The parsed chain + */ + private static Chain parseXmlFile(File xmlFile) { + try { + JAXBContext context = JAXBContext.newInstance(Chain.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + logger.debug(String.format("Reading %s...", xmlFile.getPath())); + return (Chain) unmarshaller.unmarshal(xmlFile); + } catch (JAXBException e) { + e.printStackTrace(); + return null; + } + } + }