001    /*
002     @license.text@
003      */
004    package biz.hammurapi.xml.dom;
005    
006    import org.w3c.dom.Element;
007    
008    /**
009     * @author Pavel Vlasov
010     *
011     * @version $Revision: 1.2 $
012     */
013    public class ByteArrayDomSerializer {
014    
015            public DomSerializable toDomSerializable(final byte[] oa) {
016                    return new DomSerializable() {
017    
018                            public void toDom(Element holder) {
019                                    holder.setAttribute("type", "byte[]");
020                                    StringBuffer sb=new StringBuffer();
021                                for (int i=0; i<oa.length; i++) {
022                                    String str=Integer.toHexString(oa[i] & 0xFF);
023                                    if (str.length()==1) {
024                                            sb.append("0");
025                                    }
026                                    sb.append(str);
027                                }                   
028                                holder.appendChild(holder.getOwnerDocument().createTextNode(sb.toString()));
029                            }
030                            
031                    };
032            }
033    }