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="PdbxStructAssemblyGenXMLContainer")
034public class PdbxStructAssemblyGenXMLContainer {
035
036        private List<PdbxStructAssemblyGen> data ;
037
038        static JAXBContext jaxbContext;
039        static {
040                try {
041                        jaxbContext= JAXBContext.newInstance(PdbxStructAssemblyGenXMLContainer.class);
042                } catch (Exception e){
043                        e.printStackTrace();
044                }
045        }
046
047        @XmlElementWrapper
048        public List<PdbxStructAssemblyGen> getPdbxStructAssemblyGens(){
049                return data;
050
051        }
052
053        public void setPdbxStructAssemblies(List<PdbxStructAssemblyGen> d){
054                data = d;
055        }
056
057        public  String toXML(){
058
059                System.out.println("converting to XML: " + data);
060
061                ByteArrayOutputStream baos = new ByteArrayOutputStream();
062
063                PrintStream ps = new PrintStream(baos);
064
065                try {
066
067                        Marshaller m = jaxbContext.createMarshaller();
068
069                        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
070
071                        m.marshal( this, ps);
072
073
074                } catch (Exception e){
075                        e.printStackTrace();
076                }
077
078                return baos.toString();
079
080        }
081
082        public static PdbxStructAssemblyGenXMLContainer fromXML(String xml){
083
084                PdbxStructAssemblyGenXMLContainer job = null;
085
086                try {
087
088                        Unmarshaller un = jaxbContext.createUnmarshaller();
089
090                        ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
091
092                        job = (PdbxStructAssemblyGenXMLContainer) un.unmarshal(bais);
093
094                } catch (Exception e){
095                        e.printStackTrace();
096                }
097
098                return job;
099        }
100
101}