KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > encoding > ser > HexSerializer


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.encoding.ser;
18
19 import org.apache.axis.Constants;
20 import org.apache.axis.encoding.SerializationContext;
21 import org.apache.axis.encoding.SimpleValueSerializer;
22 import org.apache.axis.types.HexBinary;
23 import org.apache.axis.utils.JavaUtils;
24 import org.apache.axis.wsdl.fromJava.Types;
25 import org.w3c.dom.Element JavaDoc;
26 import org.xml.sax.Attributes JavaDoc;
27
28 import javax.xml.namespace.QName JavaDoc;
29 import java.io.IOException JavaDoc;
30 /**
31  * Serializer for hexBinary.
32  *
33  * @author Davanum Srinivas <dims@yahoo.com>
34  * Modified by @author Rich scheuerle <scheu@us.ibm.com>
35  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#hexBinary">XML Schema 3.2.16</a>
36  */

37 public class HexSerializer implements SimpleValueSerializer {
38
39     public QName JavaDoc xmlType;
40     public Class JavaDoc javaType;
41     public HexSerializer(Class JavaDoc javaType, QName JavaDoc xmlType) {
42         this.xmlType = xmlType;
43         this.javaType = javaType;
44     }
45
46     /**
47      * Serialize a HexBinary quantity.
48      */

49     public void serialize(QName JavaDoc name, Attributes JavaDoc attributes,
50                           Object JavaDoc value, SerializationContext context)
51         throws IOException JavaDoc
52     {
53         context.startElement(name, attributes);
54         context.writeString(getValueAsString(value, context));
55         context.endElement();
56     }
57
58     public String JavaDoc getValueAsString(Object JavaDoc value, SerializationContext context) {
59         value = JavaUtils.convert(value, javaType);
60         if (javaType == HexBinary.class) {
61             return value.toString();
62         } else {
63             return HexBinary.encode((byte[]) value);
64         }
65     }
66
67     public String JavaDoc getMechanismType() { return Constants.AXIS_SAX; }
68
69     /**
70      * Return XML schema for the specified type, suitable for insertion into
71      * the &lt;types&gt; element of a WSDL document, or underneath an
72      * &lt;element&gt; or &lt;attribute&gt; declaration.
73      *
74      * @param javaType the Java Class we're writing out schema for
75      * @param types the Java2WSDL Types object which holds the context
76      * for the WSDL being generated.
77      * @return a type element containing a schema simpleType/complexType
78      * @see org.apache.axis.wsdl.fromJava.Types
79      */

80     public Element JavaDoc writeSchema(Class JavaDoc javaType, Types types) throws Exception JavaDoc {
81         return null;
82     }
83 }
84
Popular Tags