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 31, 2011 021 * Created by Andreas Prlic 022 * 023 * @since 3.0.2 024 */ 025package org.biojava.nbio.structure.xtal.io; 026 027import org.biojava.nbio.structure.xtal.SpaceGroup; 028 029import javax.xml.bind.JAXBContext; 030import javax.xml.bind.JAXBException; 031import javax.xml.bind.Marshaller; 032import javax.xml.bind.Unmarshaller; 033import javax.xml.bind.annotation.XmlAccessType; 034import javax.xml.bind.annotation.XmlAccessorType; 035import javax.xml.bind.annotation.XmlRootElement; 036import java.io.ByteArrayInputStream; 037import java.io.ByteArrayOutputStream; 038import java.io.PrintStream; 039import java.io.Serializable; 040import java.util.TreeMap; 041 042 043 044@XmlRootElement(name = "TreeSetSpaceGroupWrapper", namespace ="http://www.biojava.org") 045@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER) 046public class TreeMapSpaceGroupWrapper implements Serializable{ 047 048 049 private static final long serialVersionUID = 4193799052494327416L; 050 051 private TreeMap<Integer,SpaceGroup> data; 052 053 054 public TreeMapSpaceGroupWrapper(){ 055 data = new TreeMap<Integer,SpaceGroup>(); 056 } 057 058 public TreeMap<Integer,SpaceGroup> getData() { 059 return data; 060 } 061 062 public void setData(TreeMap<Integer,SpaceGroup> data) { 063 this.data = data; 064 } 065 066 public String toXML() throws JAXBException{ 067 068 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 069 070 PrintStream ps = new PrintStream(baos); 071 072 JAXBContext jaxbContext = JAXBContext.newInstance(TreeMapSpaceGroupWrapper.class); 073 074 Marshaller m = jaxbContext.createMarshaller(); 075 076 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); 077 078 m.marshal( this, ps); 079 080 JAXBContext.newInstance(TreeMapSpaceGroupWrapper.class); 081 082 return baos.toString(); 083 084 } 085 086 public static TreeMapSpaceGroupWrapper fromXML(String xml) throws JAXBException{ 087 088 TreeMapSpaceGroupWrapper job = null; 089 090 JAXBContext jaxbContext = JAXBContext.newInstance(TreeMapSpaceGroupWrapper.class); 091 092 Unmarshaller un = jaxbContext.createUnmarshaller(); 093 094 ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); 095 096 job = (TreeMapSpaceGroupWrapper) un.unmarshal(bais); 097 098 return job; 099 } 100 101 102}