/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.das2.qstream; import java.beans.XMLDecoder; import java.io.ByteArrayInputStream; import java.net.URLDecoder; import java.net.URLEncoder; import java.text.ParseException; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; import org.das2.datum.Units; import org.das2.util.Base64; import org.das2.qds.DataSetUtil; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * Store map property to QStream. * @author jbf */ public class MapSerializeDelegate implements SerializeDelegate, XMLSerializeDelegate { private static final Logger logger= Logger.getLogger("qstream"); @Override public Element xmlFormat( Document doc, Object o ) { Map m= (Map)o; Element result= doc.createElement( typeId( o.getClass() ) ); for ( Object o2: m.entrySet() ) { Entry e= (Entry)o2; Object oval= e.getValue(); SerializeDelegate sd= SerializeRegistry.getDelegate(oval.getClass()); if ( sd==null ) { logger.log(Level.FINE, "sorry, can''t serialize {0}", e); continue; } Element child= doc.createElement("entry"); child.setAttribute( "key", String.valueOf(e.getKey()) ); if ( sd instanceof XMLSerializeDelegate ) { child.appendChild( ((XMLSerializeDelegate)sd).xmlFormat(doc,oval) ); } else { String sval= sd.format(oval); child.setAttribute( "type", sd.typeId(oval.getClass()) ); child.setAttribute( "value", sval ); } result.appendChild(child); } return result; } @Override public Object xmlParse( Element e ) throws ParseException { LinkedHashMap result= new LinkedHashMap(); NodeList nl= e.getChildNodes(); for ( int i=0; i