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 */ 021package org.biojava.nbio.structure.io.mmcif.model; 022 023import javax.xml.bind.JAXBContext; 024import javax.xml.bind.Marshaller; 025import javax.xml.bind.Unmarshaller; 026import javax.xml.bind.annotation.XmlElementWrapper; 027import javax.xml.bind.annotation.XmlRootElement; 028import java.io.ByteArrayInputStream; 029import java.io.ByteArrayOutputStream; 030import java.io.PrintStream; 031import java.util.List; 032 033@XmlRootElement(name="PdbxStructAssemblyXMLContainer") 034public class PdbxStructAssemblyXMLContainer { 035 036 private List<PdbxStructAssembly> data ; 037 038 static JAXBContext jaxbContext; 039 static { 040 try { 041 jaxbContext= JAXBContext.newInstance(PdbxStructAssemblyXMLContainer.class); 042 } catch (Exception e){ 043 e.printStackTrace(); 044 } 045 } 046 047 @XmlElementWrapper 048 public List<PdbxStructAssembly> getPdbxStructAssemblies(){ 049 return data; 050 051 } 052 053 public void setPdbxStructAssemblies(List<PdbxStructAssembly> d){ 054 data = d; 055 } 056 057 public String toXML(){ 058 059 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 060 061 PrintStream ps = new PrintStream(baos); 062 063 try { 064 065 Marshaller m = jaxbContext.createMarshaller(); 066 067 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 068 069 m.marshal( this, ps); 070 071 072 } catch (Exception e){ 073 e.printStackTrace(); 074 } 075 076 return baos.toString(); 077 078 } 079 080 public static PdbxStructAssemblyXMLContainer fromXML(String xml){ 081 082 PdbxStructAssemblyXMLContainer job = null; 083 084 try { 085 086 Unmarshaller un = jaxbContext.createUnmarshaller(); 087 088 ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); 089 090 job = (PdbxStructAssemblyXMLContainer) un.unmarshal(bais); 091 092 } catch (Exception e){ 093 e.printStackTrace(); 094 } 095 096 return job; 097 } 098 099}