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="PdbxStructOperListXMLContainer")
034public class PdbxStructOperListXMLContainer {
035
036
037
038                private List<PdbxStructOperList> data ;
039
040                static JAXBContext jaxbContext;
041                static {
042                        try {
043                                jaxbContext= JAXBContext.newInstance(PdbxStructOperList.class);
044                        } catch (Exception e){
045                                e.printStackTrace();
046                        }
047                }
048
049                @XmlElementWrapper
050                public List<PdbxStructOperList> getPdbxStructOperLists(){
051                        return data;
052
053                }
054
055                public void setPdbxStructOperLists(List<PdbxStructOperList> d){
056                        data = d;
057                }
058
059                public  String toXML(){
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 PdbxStructOperListXMLContainer fromXML(String xml){
083
084                        PdbxStructOperListXMLContainer job = null;
085
086                        try {
087
088                                Unmarshaller un = jaxbContext.createUnmarshaller();
089
090                                ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
091
092                                job = (PdbxStructOperListXMLContainer) un.unmarshal(bais);
093
094                        } catch (Exception e){
095                                e.printStackTrace();
096                        }
097
098                        return job;
099                }
100
101}