1 17 package org.apache.ws.jaxme.generator.sg.impl; 18 19 import org.apache.ws.jaxme.generator.sg.AttributeSG; 20 import org.apache.ws.jaxme.generator.sg.AttributeSGChain; 21 import org.apache.ws.jaxme.generator.sg.Context; 22 import org.apache.ws.jaxme.generator.sg.PropertySG; 23 import org.apache.ws.jaxme.generator.sg.PropertySGChain; 24 import org.apache.ws.jaxme.generator.sg.SGFactory; 25 import org.apache.ws.jaxme.generator.sg.SGlet; 26 import org.apache.ws.jaxme.generator.sg.SchemaSG; 27 import org.apache.ws.jaxme.generator.sg.TypeSG; 28 import org.apache.ws.jaxme.js.DirectAccessible; 29 import org.apache.ws.jaxme.js.JavaMethod; 30 import org.apache.ws.jaxme.xs.XSAttribute; 31 import org.apache.ws.jaxme.xs.XSType; 32 import org.apache.ws.jaxme.xs.XSWildcard; 33 import org.apache.ws.jaxme.xs.xml.XsNamespaceList; 34 import org.apache.ws.jaxme.xs.xml.XsQName; 35 import org.apache.ws.jaxme.xs.xml.XsTWildcard; 36 import org.apache.ws.jaxme.xs.xml.XsTWildcard.ProcessContents; 37 import org.xml.sax.Locator ; 38 import org.xml.sax.SAXException ; 39 40 41 44 class JAXBAttributeSG extends JAXBSGItem implements AttributeSGChain { 45 private final boolean isRequired, isWildcard; 46 private final XsQName name; 47 private final XsNamespaceList namespaceList; 48 private final XsTWildcard.ProcessContents processContents; 49 private XSAttribute xsAttribute; 50 private XSWildcard xsWildcard; 51 private final TypeSG typeSG; 52 private PropertySG propertySG; 53 54 55 protected JAXBAttributeSG(SchemaSG pSchema, XSAttribute pAttribute, Context pClassContext) throws SAXException { 56 super(pSchema.getFactory(), pSchema, pAttribute); 57 xsAttribute = pAttribute; 58 xsWildcard = null; 59 isRequired = !pAttribute.isOptional(); 60 name = pAttribute.getName(); 61 XSType type = pAttribute.getType(); 62 if (type == null) { 63 throw new IllegalStateException ("The attribute type must not be null."); 64 } 65 if (type.isGlobal()) { 66 typeSG = getFactory().getTypeSG(type); 67 if (typeSG == null) { 68 throw new IllegalStateException ("Unknown global type: " + type.getName()); 69 } 70 } else { 71 typeSG = getFactory().getTypeSG(pAttribute.getType(), pClassContext, name); 72 } 73 isWildcard = false; 74 namespaceList = null; 75 processContents = null; 76 } 77 78 protected JAXBAttributeSG(SchemaSG pSchema, XSWildcard pWildcard, Context pClassContext) throws SAXException { 79 super(pSchema.getFactory(), pSchema, pWildcard); 80 xsWildcard = pWildcard; 81 xsAttribute = null; 82 isRequired = false; 83 name = null; 84 typeSG = null; 85 isWildcard = true; 86 namespaceList = pWildcard.getNamespaceList(); 87 processContents = pWildcard.getProcessContents(); 88 } 89 90 public Object newPropertySGChain(AttributeSG pController) { 91 PropertySGChain result; 92 if (xsWildcard != null) { 93 result = new AnyAttributePropertySG(pController, xsWildcard); 94 xsWildcard = null; 95 } else if (xsAttribute != null) { 96 result = new JAXBPropertySG(pController, xsAttribute); 97 xsAttribute = null; } else { 99 throw new IllegalStateException ("PropertySG is already created."); 100 } 101 return result; 102 } 103 104 public void init(AttributeSG pController) throws SAXException { 105 PropertySGChain chain = (PropertySGChain) pController.newPropertySGChain(); 106 propertySG = new PropertySGImpl(chain); 107 propertySG.init(); 108 } 109 110 public PropertySG getPropertySG(AttributeSG pController) { return propertySG; } 111 public TypeSG getTypeSG(AttributeSG pController) { return typeSG; } 112 public SGFactory getFactory(AttributeSG pController) { return getFactory(); } 113 public SchemaSG getSchema(AttributeSG pController) { return getSchema(); } 114 public Locator getLocator(AttributeSG pController) { return getLocator(); } 115 public XsQName getName(AttributeSG pController) { return name; } 116 117 public boolean isRequired(AttributeSG pAttrController) { return isRequired; } 118 119 public void forAllValues(AttributeSG pController, JavaMethod pMethod, 120 DirectAccessible pElement, SGlet pSGlet) throws SAXException { 121 pController.getPropertySG().forAllValues(pMethod, pElement, pSGlet); 122 } 123 124 public void forAllNonNullValues(AttributeSG pController, JavaMethod pMethod, 125 DirectAccessible pElement, SGlet pSGlet) throws SAXException { 126 pController.getPropertySG().forAllNonNullValues(pMethod, pElement, pSGlet); 127 } 128 129 public boolean isWildcard(AttributeSG pController) { 130 return isWildcard; 131 } 132 133 public XsNamespaceList getNamespaceList(AttributeSG pController) { 134 return namespaceList; 135 } 136 137 public ProcessContents getProcessContents(AttributeSG pController) { 138 return processContents; 139 } 140 } 141 | Popular Tags |