1 17 package org.apache.ws.jaxme.generator.types; 18 19 import org.apache.ws.jaxme.generator.sg.SGFactory; 20 import org.apache.ws.jaxme.generator.sg.SGlet; 21 import org.apache.ws.jaxme.generator.sg.SchemaSG; 22 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG; 23 import org.apache.ws.jaxme.impl.DatatypeConverterImpl; 24 import org.apache.ws.jaxme.js.DirectAccessible; 25 import org.apache.ws.jaxme.js.JavaMethod; 26 import org.apache.ws.jaxme.js.JavaQName; 27 import org.apache.ws.jaxme.js.JavaQNameImpl; 28 import org.apache.ws.jaxme.js.LocalJavaField; 29 import org.apache.ws.jaxme.js.TypedValue; 30 import org.apache.ws.jaxme.js.impl.TypedValueImpl; 31 import org.apache.ws.jaxme.util.Duration; 32 import org.apache.ws.jaxme.xs.XSType; 33 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 34 import org.xml.sax.SAXException ; 35 36 39 public class DurationSG extends AtomicTypeSGImpl { 40 public static final JavaQName DURATION_TYPE = JavaQNameImpl.getInstance(Duration.class); 41 42 44 public DurationSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException { 45 super(pFactory, pSchema, pType); 46 } 47 48 public JavaQName getRuntimeType(SimpleTypeSG pController) { return DURATION_TYPE; } 49 50 public TypedValue getCastFromString(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, Object pData) { 51 return new TypedValueImpl(new Object []{DURATION_TYPE, ".valueOf(", pValue, ")"}, DURATION_TYPE); 52 } 53 54 public TypedValue getCastFromString(SimpleTypeSG pController, String pValue) throws SAXException { 55 try { 56 return new TypedValueImpl("org.apache.ws.jaxme.util.Duration.valueOf(\"" + pValue + "\")", DURATION_TYPE); 57 } catch (RuntimeException e) { 58 try { 59 throw new LocSAXException("Failed to convert string value to " 60 + getDatatypeName() + " instance: " + pValue, getLocator()); 61 } catch (Exception e1) { 62 throw new SAXException("Failed to convert string value to " 63 + getDatatypeName() + " instance: " + pValue); 64 } 65 } 66 } 67 68 public TypedValue getCastToString(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, DirectAccessible pData) { 69 return new TypedValueImpl(new Object []{pValue, ".toString()"}, String .class); 70 } 71 72 public void forAllNonNullValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException { 73 LocalJavaField f = pMethod.newJavaField(DURATION_TYPE); 74 f.addLine(pValue); 75 pMethod.addIf(f, " != null"); 76 pSGlet.generate(pMethod, pValue); 77 pMethod.addEndIf(); 78 } 79 80 public void forAllValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException { 81 pSGlet.generate(pMethod, pValue); 82 } 83 84 protected String getDatatypeName() { return "Duration"; } 85 protected JavaQName getDatatypeType() { return DURATION_TYPE; } 86 } 87 | Popular Tags |