1 17 package org.apache.ws.jaxme.generator.types; 18 19 import org.apache.ws.jaxme.generator.sg.AtomicTypeSG; 20 import org.apache.ws.jaxme.generator.sg.Facet; 21 import org.apache.ws.jaxme.generator.sg.ListTypeSG; 22 import org.apache.ws.jaxme.generator.sg.SGFactory; 23 import org.apache.ws.jaxme.generator.sg.SchemaSG; 24 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG; 25 import org.apache.ws.jaxme.generator.sg.SimpleTypeSGChain; 26 import org.apache.ws.jaxme.generator.sg.UnionTypeSG; 27 import org.apache.ws.jaxme.generator.sg.impl.JAXBSGItem; 28 import org.apache.ws.jaxme.js.DirectAccessible; 29 import org.apache.ws.jaxme.js.JavaMethod; 30 import org.apache.ws.jaxme.js.JavaQNameImpl; 31 import org.apache.ws.jaxme.js.JavaSource; 32 import org.apache.ws.jaxme.xs.XSType; 33 import org.xml.sax.Locator ; 34 import org.xml.sax.SAXException ; 35 36 37 40 public abstract class SimpleTypeSGImpl extends JAXBSGItem implements SimpleTypeSGChain { 41 private boolean isNullable; 42 43 45 protected SimpleTypeSGImpl(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException { 46 super(pFactory, pSchema, pType); 47 if (!pType.isSimple()) { 48 throw new IllegalStateException ("The given type is complex."); 49 } 50 } 51 52 protected XSType getXSType() { return (XSType) super.getXSObject(); } 53 public SGFactory getFactory(SimpleTypeSG pController) { return getFactory(); } 54 public SchemaSG getSchema(SimpleTypeSG pController) { return getSchema(); } 55 public Locator getLocator(SimpleTypeSG pController) { return getLocator(); } 56 public boolean isAtomic(SimpleTypeSG pController) { return false; } 57 public boolean isList(SimpleTypeSG pController) { return false; } 58 public boolean isUnion(SimpleTypeSG pController) { return false; } 59 public boolean hasSetMethod(SimpleTypeSG pController) { return true; } 60 public void setNullable(SimpleTypeSG pController, boolean pNullable) { 61 setNullable(pNullable); 62 } 63 65 public void setNullable(boolean pNullable) { isNullable = pNullable; } 66 public boolean isNullable(SimpleTypeSG pController) { return isNullable; } 67 68 public void init(SimpleTypeSG pController) throws SAXException { 69 } 70 71 public String getCollectionType(SimpleTypeSG pController) { 72 return getSchema().getCollectionType(); 73 } 74 75 public UnionTypeSG getUnionType(SimpleTypeSG pController) { 76 throw new IllegalStateException ("This type is no union."); 77 } 78 79 public ListTypeSG getListType(SimpleTypeSG pController) { 80 throw new IllegalStateException ("This type is no list."); 81 } 82 83 public AtomicTypeSG getAtomicType(SimpleTypeSG pController) { 84 throw new IllegalStateException ("This type is not atomic."); 85 } 86 87 public Facet[] getFacets(SimpleTypeSG pController) { 88 return new Facet[0]; 89 } 90 91 public Facet getFacet(SimpleTypeSG pController, Facet.Type pType) { 92 Facet[] facets = pController.getFacets(); 93 for (int i = 0; i < facets.length; i++) { 94 Facet f = facets[i]; 95 if (f.getType().equals(pType)) { 96 return f; 97 } 98 } 99 return null; 100 } 101 102 public void generate(SimpleTypeSG pController) { 103 } 104 105 public void generate(SimpleTypeSG pController, JavaSource pSource) { 106 } 107 108 public Object getInitialValue(SimpleTypeSG pController, JavaSource pSource) throws SAXException { 109 return null; 110 } 111 112 public JavaMethod getXMLSetMethod(SimpleTypeSG pController, JavaSource pSource, 113 String pFieldName, String pParamName, String pMethodName) throws SAXException { 114 if (pController.hasSetMethod()) { 115 JavaMethod jm = pSource.newJavaMethod(pMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC); 116 DirectAccessible param = jm.addParam(pController.getRuntimeType(), pParamName); 117 if (!pSource.isInterface()) { 118 pController.addValidation(jm, param); 119 jm.addLine(pFieldName, " = ", param, ";"); 120 } 121 return jm; 122 } else { 123 return null; 124 } 125 } 126 127 public void addValidation(SimpleTypeSG pController, JavaMethod pMethod, DirectAccessible pValue) throws SAXException { 128 } 129 } 130 | Popular Tags |