KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.axis.encoding.ser;
17
18 import java.io.IOException JavaDoc;
19 import java.text.SimpleDateFormat JavaDoc;
20 import java.util.Calendar JavaDoc;
21 import java.util.TimeZone JavaDoc;
22
23 import javax.xml.namespace.QName JavaDoc;
24
25 import org.w3c.dom.Element JavaDoc;
26 import org.xml.sax.Attributes JavaDoc;
27
28 import org.apache.axis.Constants;
29 import org.apache.axis.encoding.SerializationContext;
30 import org.apache.axis.encoding.SimpleValueSerializer;
31 import org.apache.axis.wsdl.fromJava.Types;
32
33 /**
34  * Serializer for Time.
35  * @author Florent Benoit
36 */

37 public class TimeSerializer implements SimpleValueSerializer {
38
39     /**
40      * Parser
41      */

42     private static SimpleDateFormat JavaDoc zulu = new SimpleDateFormat JavaDoc("HH:mm:ss.SSS'Z'");
43
44     // We should always format dates in the GMT timezone
45
static {
46         zulu.setTimeZone(TimeZone.getTimeZone("GMT"));
47     }
48
49     
50     /**
51      * Serialize a Time.
52      */

53     public void serialize(QName JavaDoc name, Attributes JavaDoc attributes,
54                           Object JavaDoc value, SerializationContext context)
55         throws IOException JavaDoc
56     {
57         context.startElement(name, attributes);
58         context.writeString(getValueAsString(value, context));
59         context.endElement();
60     }
61
62     public String JavaDoc getValueAsString(Object JavaDoc value, SerializationContext context) {
63         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
64         // Reset year, month, day
65
((Calendar JavaDoc) value).set(0,0,0);
66         buf.append(zulu.format(((Calendar JavaDoc)value).getTime()));
67         return buf.toString();
68     }
69
70     public String JavaDoc getMechanismType() { return Constants.AXIS_SAX; }
71
72     /**
73      * Return XML schema for the specified type, suitable for insertion into
74      * the <types> element of a WSDL document, or underneath an
75      * <element> or <attribute> declaration.
76      *
77      * @param javaType the Java Class we're writing out schema for
78      * @param types the Java2WSDL Types object which holds the context
79      * for the WSDL being generated.
80      * @return a type element containing a schema simpleType/complexType
81      * @see org.apache.axis.wsdl.fromJava.Types
82      */

83     public Element JavaDoc writeSchema(Class JavaDoc javaType, Types types) throws Exception JavaDoc {
84         return null;
85     }
86 }
87
Popular Tags