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.js.DirectAccessible; 24 import org.apache.ws.jaxme.js.JavaMethod; 25 import org.apache.ws.jaxme.js.JavaQName; 26 import org.apache.ws.jaxme.js.LocalJavaField; 27 import org.apache.ws.jaxme.js.TypedValue; 28 import org.apache.ws.jaxme.js.impl.TypedValueImpl; 29 import org.apache.ws.jaxme.xs.XSType; 30 import org.xml.sax.SAXException ; 31 32 33 36 public abstract class PrimitiveTypeSG extends AtomicTypeSGImpl { 37 39 protected PrimitiveTypeSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException { 40 super(pFactory, pSchema, pType); 41 } 42 43 protected boolean isUnsigned() { return false; } 44 protected abstract JavaQName getObjectRuntimeType(SimpleTypeSG pController); 45 protected abstract JavaQName getPrimitiveRuntimeType(SimpleTypeSG pController); 46 public JavaQName getRuntimeType(SimpleTypeSG pController) { 47 return pController.isNullable() ? getObjectRuntimeType(pController) : getPrimitiveRuntimeType(pController); 48 } 49 50 public TypedValue getCastFromString(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, Object pData) throws SAXException { 51 TypedValue v = super.getCastFromString(pController, pMethod, pValue, pData); 52 if (pController.isNullable()) { 53 JavaQName objectType = getObjectRuntimeType(pController); 54 v = new TypedValueImpl(new Object []{"new ", objectType, "(", v, ")"}, 55 objectType); 56 } 57 return v; 58 } 59 60 public TypedValue getCastToString(SimpleTypeSG pController, Object pValue, DirectAccessible pData) { 61 if (pController.isNullable()) { 62 pValue = new Object []{pValue, "." + getPrimitiveRuntimeType(pController).getClassName() +"Value()"}; 63 } 64 return super.getCastToString(pController, pValue, pData); 65 } 66 67 public void forAllValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException { 68 pSGlet.generate(pMethod, pValue); 69 } 70 71 public void forAllNonNullValues(SimpleTypeSG pController, JavaMethod pMethod, Object pValue, SGlet pSGlet) throws SAXException { 72 if (pController.isNullable()) { 73 LocalJavaField f = pMethod.newJavaField(getObjectRuntimeType(pController)); 74 f.addLine(pValue); 75 pMethod.addIf(f, " != null"); 76 pSGlet.generate(pMethod, pValue); 77 pMethod.addEndIf(); 78 } else { 79 pSGlet.generate(pMethod, pValue); 80 } 81 } 82 83 public Object getEqualsCheck(SimpleTypeSG pController, JavaMethod pMethod, Object pValue1, Object pValue2) throws SAXException { 84 if (pController.isNullable()) { 85 return super.getEqualsCheck(pController, pMethod, pValue1, pValue2); 86 } else { 87 return new Object []{pValue1, " == ", pValue2}; 88 } 89 } 90 } 91 | Popular Tags |