KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > generator > types > TimeSG


1 /*
2  * Copyright 2003, 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.ws.jaxme.generator.types;
18
19 import java.util.Calendar JavaDoc;
20
21 import org.apache.ws.jaxme.generator.sg.SGFactory;
22 import org.apache.ws.jaxme.generator.sg.SchemaSG;
23 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG;
24 import org.apache.ws.jaxme.impl.DatatypeConverterImpl;
25 import org.apache.ws.jaxme.js.TypedValue;
26 import org.apache.ws.jaxme.js.impl.TypedValueImpl;
27 import org.apache.ws.jaxme.xs.XSType;
28 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
29 import org.apache.ws.jaxme.xs.util.XsTimeFormat;
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
34  */

35 public class TimeSG extends DateTimeSG {
36
37   /** <p>Creates a new instance of TimeSG.</p>
38    */

39   public TimeSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException {
40     super(pFactory, pSchema, pType);
41   }
42
43   protected String JavaDoc getDatatypeName() { return "Time"; }
44   protected Class JavaDoc getFormatClass() { return XsTimeFormat.class; }
45   
46     public TypedValue getCastFromString(SimpleTypeSG pController, String JavaDoc pValue)
47             throws SAXException {
48         try {
49             Calendar JavaDoc calendar = new DatatypeConverterImpl().parseTime(pValue);
50             return new TypedValueImpl(
51                     new Object JavaDoc[] { "new java.util.GregorianCalendar("
52                             + calendar.get(Calendar.YEAR) + ","
53                             + calendar.get(Calendar.MONTH) + ","
54                             + calendar.get(Calendar.DAY_OF_MONTH) + ","
55                             + calendar.get(Calendar.HOUR_OF_DAY) + ","
56                             + calendar.get(Calendar.MINUTE) + ","
57                             + calendar.get(Calendar.SECOND) + ")" },
58                     getDatatypeType());
59         } catch (RuntimeException JavaDoc e) {
60             try {
61                 throw new LocSAXException("Failed to convert string value to "
62                         + getDatatypeName() + " instance: " + pValue, getLocator());
63             } catch (Exception JavaDoc e1) {
64                 throw new SAXException("Failed to convert string value to "
65                         + getDatatypeName() + " instance: " + pValue);
66             }
67         }
68     }
69 }
70
Popular Tags