KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > bind > annotation > adapters > HexBinaryAdapter


1 /*
2  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
3  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
4  */

5
6 package javax.xml.bind.annotation.adapters;
7
8 import javax.xml.bind.DatatypeConverter;
9
10 /**
11  * {@link XmlAdapter} for <tt>xs:hexBinary</tt>.
12  *
13  * <p>
14  * This {@link XmlAdapter} binds <tt>byte[]</tt> to the hexBinary representation in XML.
15  *
16  * @author Kohsuke Kawaguchi
17  * @since JAXB 2.0
18  */

19 public final class HexBinaryAdapter extends XmlAdapter<String JavaDoc,byte[]> {
20     public byte[] unmarshal(String JavaDoc s) {
21         if(s==null) return null;
22         return DatatypeConverter.parseHexBinary(s);
23     }
24
25     public String JavaDoc marshal(byte[] bytes) {
26         if(bytes==null) return null;
27         return DatatypeConverter.printHexBinary(bytes);
28     }
29 }
30
Popular Tags