001    /*
002     @license.text@
003      */
004    package biz.hammurapi.xml.dom;
005    
006    import java.util.Collection;
007    import java.util.Iterator;
008    
009    import org.w3c.dom.Element;
010    
011    import biz.hammurapi.convert.Converter;
012    
013    /**
014     * @author Pavel Vlasov
015     *
016     * @version $Revision: 1.3 $
017     */
018    public class CollectionDomSerializer {
019    
020            public DomSerializable convert(final Collection col, final Converter master) {
021                    return new DomSerializable() {
022    
023                            public void toDom(Element holder) {
024                                holder.setAttribute("type", col.getClass().getName());
025                                Iterator it=col.iterator();
026                                while (it.hasNext()) {
027                                    DomSerializable ds=(DomSerializable) master.convert(it.next(), DomSerializable.class, null);
028                                    if (ds!=null) {
029                                            Element el=holder.getOwnerDocument().createElement("element");
030                                            holder.appendChild(el);
031                                            ds.toDom(el);
032                                    }
033                                }
034                            }
035                            
036                    };
037            }
038    }