From 92974183ece842f4d41481ab9be84b505f9a8137 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 8 Nov 2018 13:27:49 +0000 Subject: [PATCH] JAL-3116 better unmarshalling of EMBL/Uniprot XML --- src/jalview/ws/dbsources/EmblXmlSource.java | 7 +++++-- src/jalview/ws/dbsources/Uniprot.java | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/jalview/ws/dbsources/EmblXmlSource.java b/src/jalview/ws/dbsources/EmblXmlSource.java index e114ea9..668aab5 100644 --- a/src/jalview/ws/dbsources/EmblXmlSource.java +++ b/src/jalview/ws/dbsources/EmblXmlSource.java @@ -40,6 +40,8 @@ import jalview.ws.ebi.EBIFetchClient; import jalview.xml.binding.embl.EntryType; import jalview.xml.binding.embl.EntryType.Feature; import jalview.xml.binding.embl.EntryType.Feature.Qualifier; +import jalview.xml.binding.jalview.JalviewModel; +import jalview.xml.binding.embl.ROOT; import jalview.xml.binding.embl.XrefType; import java.io.File; @@ -55,6 +57,7 @@ import java.util.Map.Entry; import java.util.regex.Pattern; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLInputFactory; @@ -183,8 +186,8 @@ public abstract class EmblXmlSource extends EbiFileRetrievedProxy XMLStreamReader streamReader = XMLInputFactory.newInstance() .createXMLStreamReader(is); javax.xml.bind.Unmarshaller um = jc.createUnmarshaller(); - jalview.xml.binding.embl.ROOT root = (jalview.xml.binding.embl.ROOT) um - .unmarshal(streamReader); + JAXBElement rootElement = um.unmarshal(streamReader, ROOT.class); + ROOT root = rootElement.getValue(); /* * document root contains either "entry" or "entrySet" diff --git a/src/jalview/ws/dbsources/Uniprot.java b/src/jalview/ws/dbsources/Uniprot.java index 86282c7..d1da9de 100644 --- a/src/jalview/ws/dbsources/Uniprot.java +++ b/src/jalview/ws/dbsources/Uniprot.java @@ -32,6 +32,7 @@ import jalview.datamodel.SequenceI; import jalview.schemes.ResidueProperties; import jalview.util.StringUtils; import jalview.ws.seqfetcher.DbSourceProxyImpl; +import jalview.xml.binding.embl.ROOT; import jalview.xml.binding.uniprot.DbReferenceType; import jalview.xml.binding.uniprot.Entry; import jalview.xml.binding.uniprot.FeatureType; @@ -47,6 +48,7 @@ import java.util.List; import java.util.Vector; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.stream.FactoryConfigurationError; import javax.xml.stream.XMLInputFactory; @@ -505,7 +507,10 @@ public class Uniprot extends DbSourceProxyImpl XMLStreamReader streamReader = XMLInputFactory.newInstance() .createXMLStreamReader(is); javax.xml.bind.Unmarshaller um = jc.createUnmarshaller(); - jalview.xml.binding.uniprot.Uniprot uniprot = (jalview.xml.binding.uniprot.Uniprot) um.unmarshal(streamReader); + JAXBElement uniprotElement = + um.unmarshal(streamReader, jalview.xml.binding.uniprot.Uniprot.class); + jalview.xml.binding.uniprot.Uniprot uniprot = uniprotElement.getValue(); + if (uniprot != null && !uniprot.getEntry().isEmpty()) { entries = uniprot.getEntry(); -- 1.7.10.2