KickJava   Java API By Example, From Geeks To Geeks.

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


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.XsDateFormat;
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
34  */

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

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