001/** 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on Aug 30, 2011 021 * Created by Andreas Prlic 022 * 023 * @since 3.0.2 024 */ 025package org.biojava.nbio.structure.scop.server; 026 027import org.biojava.nbio.structure.scop.ScopDescription; 028 029import javax.xml.bind.JAXBContext; 030import javax.xml.bind.Marshaller; 031import javax.xml.bind.Unmarshaller; 032import javax.xml.bind.annotation.XmlAccessType; 033import javax.xml.bind.annotation.XmlAccessorType; 034import javax.xml.bind.annotation.XmlRootElement; 035import java.io.ByteArrayInputStream; 036import java.io.ByteArrayOutputStream; 037import java.io.PrintStream; 038import java.io.Serializable; 039import java.util.List; 040 041 042 043@XmlRootElement(name = "ScopDescriptions", namespace ="http://source.rcsb.org") 044@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) 045public class ScopDescriptions implements Serializable{ 046 047 048 private static final long serialVersionUID = 4924350548761431852L; 049 050 static JAXBContext jaxbContext; 051 static { 052 try { 053 jaxbContext= JAXBContext.newInstance(ScopDescriptions.class); 054 } catch (Exception e){ 055 throw new RuntimeException("Could not initialize JAXB context for " + ScopDescriptions.class, e); 056 } 057 } 058 059 060 List<ScopDescription> scopDescriptions; 061 062 public List<ScopDescription> getScopDescription() { 063 return scopDescriptions; 064 } 065 066 public void setScopDescription(List<ScopDescription> descriptions) { 067 this.scopDescriptions = descriptions; 068 } 069 070 public String toXML(){ 071 072 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 073 074 PrintStream ps = new PrintStream(baos); 075 076 try { 077 078 Marshaller m = jaxbContext.createMarshaller(); 079 080 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 081 082 m.marshal( this, ps); 083 084 085 } catch (Exception e){ 086 throw new RuntimeException("Could not convert " + getClass() + " to XML", e); 087 } 088 089 return baos.toString(); 090 091 } 092 093 public static ScopDescriptions fromXML(String xml){ 094 095 ScopDescriptions job = null; 096 097 try { 098 099 Unmarshaller un = jaxbContext.createUnmarshaller(); 100 101 ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); 102 103 job = (ScopDescriptions) un.unmarshal(bais); 104 105 } catch (Exception e){ 106 throw new RuntimeException("Could not parse " + ScopDescriptions.class + " from XML", e); 107 } 108 109 return job; 110 } 111 112 113}