1 17 package org.apache.ws.jaxme.generator.types; 18 19 import java.util.Calendar ; 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 ; 31 32 35 public class TimeSG extends DateTimeSG { 36 37 39 public TimeSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException { 40 super(pFactory, pSchema, pType); 41 } 42 43 protected String getDatatypeName() { return "Time"; } 44 protected Class getFormatClass() { return XsTimeFormat.class; } 45 46 public TypedValue getCastFromString(SimpleTypeSG pController, String pValue) 47 throws SAXException { 48 try { 49 Calendar calendar = new DatatypeConverterImpl().parseTime(pValue); 50 return new TypedValueImpl( 51 new Object [] { "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 e) { 60 try { 61 throw new LocSAXException("Failed to convert string value to " 62 + getDatatypeName() + " instance: " + pValue, getLocator()); 63 } catch (Exception e1) { 64 throw new SAXException("Failed to convert string value to " 65 + getDatatypeName() + " instance: " + pValue); 66 } 67 } 68 } 69 } 70 | Popular Tags |