1 17 package org.apache.ws.jaxme.xs.jaxb.impl; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.StringTokenizer ; 22 23 import javax.xml.XMLConstants ; 24 25 import org.apache.ws.jaxme.xs.XSParser; 26 import org.apache.ws.jaxme.xs.impl.XSLogicalParser; 27 import org.apache.ws.jaxme.xs.jaxb.JAXBGlobalBindings; 28 import org.apache.ws.jaxme.xs.jaxb.JAXBJavaType; 29 import org.apache.ws.jaxme.xs.jaxb.JAXBXsObjectFactory; 30 import org.apache.ws.jaxme.xs.jaxb.JAXBXsSchema; 31 import org.apache.ws.jaxme.xs.parser.XsObjectCreator; 32 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 33 import org.apache.ws.jaxme.xs.types.XSBase64Binary; 34 import org.apache.ws.jaxme.xs.types.XSDate; 35 import org.apache.ws.jaxme.xs.types.XSDateTime; 36 import org.apache.ws.jaxme.xs.types.XSDuration; 37 import org.apache.ws.jaxme.xs.types.XSGDay; 38 import org.apache.ws.jaxme.xs.types.XSGMonth; 39 import org.apache.ws.jaxme.xs.types.XSGMonthDay; 40 import org.apache.ws.jaxme.xs.types.XSGYear; 41 import org.apache.ws.jaxme.xs.types.XSGYearMonth; 42 import org.apache.ws.jaxme.xs.types.XSHexBinary; 43 import org.apache.ws.jaxme.xs.types.XSNCName; 44 import org.apache.ws.jaxme.xs.types.XSQName; 45 import org.apache.ws.jaxme.xs.types.XSTime; 46 import org.apache.ws.jaxme.xs.xml.XsObject; 47 import org.apache.ws.jaxme.xs.xml.XsQName; 48 import org.apache.ws.jaxme.xs.xml.impl.XsObjectImpl; 49 import org.xml.sax.ContentHandler ; 50 import org.xml.sax.Locator ; 51 import org.xml.sax.SAXException ; 52 import org.xml.sax.helpers.DefaultHandler ; 53 54 55 58 public class JAXBGlobalBindingsImpl extends XsObjectImpl implements JAXBGlobalBindings { 59 private static final XsQName[] forbiddenEnumQNames = 60 new XsQName[]{ 61 XSQName.getInstance().getName(), 62 XSBase64Binary.getInstance().getName(), 63 XSHexBinary.getInstance().getName(), 64 XSDate.getInstance().getName(), 65 XSDateTime.getInstance().getName(), 66 XSTime.getInstance().getName(), 67 XSDuration.getInstance().getName(), 68 XSGDay.getInstance().getName(), 69 XSGMonth.getInstance().getName(), 70 XSGYear.getInstance().getName(), 71 XSGMonthDay.getInstance().getName(), 72 XSGYearMonth.getInstance().getName() 73 }; 74 75 private String collectionType; 76 private boolean fixedAttributeAsConstantProperty, generateIsSetMethod, 77 enableFailFastCheck, choiceContentProperty, 78 javaNamingConventionsDisabled, typesafeEnumMemberNameGeneratesName, 79 isBindingStyleModelGroup; 80 private List javaTypes; 81 private JAXBGlobalBindings.UnderscoreBinding underscoreBinding = 82 JAXBGlobalBindings.UnderscoreBinding.AS_WORD_SEPARATOR; 83 private XsQName[] typesafeEnumBase = new XsQName[]{XSNCName.getInstance().getName()}; 84 85 87 protected JAXBGlobalBindingsImpl(XsObject pParent) { 88 super(pParent); 89 } 90 91 public void setCollectionType(String pType) { 92 collectionType = pType; 93 } 94 95 public String getCollectionType() { 96 return collectionType; 97 } 98 99 public void setFixedAttributeAsConstantProperty(boolean pFixedAttributeAsConstantProperty) { 100 fixedAttributeAsConstantProperty = pFixedAttributeAsConstantProperty; 101 } 102 103 public boolean isFixedAttributeAsConstantProperty() { 104 return fixedAttributeAsConstantProperty; 105 } 106 107 public void setGenerateIsSetMethod(boolean pGenerateIsSetMethod) { 108 generateIsSetMethod = pGenerateIsSetMethod; 109 } 110 111 public boolean isGenerateIsSetMethod() { 112 return generateIsSetMethod; 113 } 114 115 public void setEnableFailFastCheck(boolean pEnableFailFastCheck) { 116 enableFailFastCheck = pEnableFailFastCheck; 117 } 118 119 public boolean isEnableFailFastCheck() { 120 return enableFailFastCheck; 121 } 122 123 public void setChoiceContentProperty(boolean pChoiceContentProperty) { 124 choiceContentProperty = pChoiceContentProperty; 125 } 126 127 public boolean isChoiceContentProperty() { 128 return choiceContentProperty; 129 } 130 131 public void setUnderscoreBinding(JAXBGlobalBindings.UnderscoreBinding pUnderscoreBinding) { 132 underscoreBinding = pUnderscoreBinding; 133 } 134 135 public JAXBGlobalBindings.UnderscoreBinding getUnderscoreBinding() { 136 return underscoreBinding; 137 } 138 139 public void setEnableJavaNamingConventions(boolean pEnableJavaNamingConventions) { 140 javaNamingConventionsDisabled = !pEnableJavaNamingConventions; 141 } 142 143 public boolean isEnableJavaNamingConventions() { 144 return !javaNamingConventionsDisabled; 145 } 146 147 public void setTypesafeEnumBase(XsQName[] pTypes) { 148 typesafeEnumBase = pTypes; 149 } 150 151 public void setTypesafeEnumBase(String pTypesafeEnumBase) throws SAXException { 152 List list = new ArrayList (); 153 String [] parts = new String [3]; 154 for (StringTokenizer st = new StringTokenizer (pTypesafeEnumBase, " ,"); 155 st.hasMoreTokens(); ) { 156 String token = st.nextToken(); 157 getNamespaceSupport().processName(token, parts, false); 158 XsQName qName = new XsQName(parts[0], parts[1], XsQName.prefixOf(token)); 159 for (int i = 0; i < forbiddenEnumQNames.length; i++) { 160 if (forbiddenEnumQNames[i].equals(qName)) { 161 throw new LocSAXException("The type " + qName + 162 " must not be specified in the typesafeEnumBase (JAXB 6.5.1)", 163 getLocator()); 164 } 165 } 166 list.add(qName); 167 } 168 setTypesafeEnumBase((XsQName[]) list.toArray(new XsQName[list.size()])); 169 } 170 171 public XsQName[] getTypesafeEnumBase() { 172 return typesafeEnumBase; 173 } 174 175 public void setTypesafeEnumMemberName(boolean pTypesafeEnumMemberName) { 176 typesafeEnumMemberNameGeneratesName = pTypesafeEnumMemberName; 177 } 178 179 public boolean isTypesafeEnumMemberName() { 180 return typesafeEnumMemberNameGeneratesName; 181 } 182 183 public void setBindingStyle(String pBindingStyle) throws SAXException { 184 if ("elementBinding".equals(pBindingStyle)) { 185 isBindingStyleModelGroup = false; 186 } else if ("modelGroupBinding".equals(pBindingStyle)) { 187 isBindingStyleModelGroup = true; 188 } else { 189 throw new LocSAXException("Illegal value for 'bindingStyle': " + pBindingStyle + ", expected either of 'elementBinding' or 'modelGroupBinding'.", 190 getLocator()); 191 } 192 } 193 194 public boolean isBindingStyleModelGroup() { 195 return isBindingStyleModelGroup; 196 } 197 198 public JAXBJavaType createJavaType() { 199 JAXBJavaType.JAXBGlobalJavaType javaTypeImpl = ((JAXBXsObjectFactory) getObjectFactory()).newJAXBGlobalJavaType(this); 200 if (javaTypes == null) { 201 javaTypes = new ArrayList (); 202 } 203 javaTypes.add(javaTypeImpl); 204 return javaTypeImpl; 205 } 206 207 private static final JAXBJavaType.JAXBGlobalJavaType[] DEFAULT_JAXB_JAVA_TYPES = 208 new JAXBJavaType.JAXBGlobalJavaType[0]; 209 public JAXBJavaType.JAXBGlobalJavaType[] getJavaType() { 210 if (javaTypes == null) { 211 return DEFAULT_JAXB_JAVA_TYPES; 212 } else { 213 return (JAXBJavaType.JAXBGlobalJavaType[]) javaTypes.toArray(new JAXBJavaType.JAXBGlobalJavaType[javaTypes.size()]); 214 } 215 } 216 217 protected XsObjectCreator[] getXsObjectCreators() { 218 return null; 219 } 220 221 protected boolean isPrefixEnabled(String pPrefix) { 222 String [] prefixes; 224 XSLogicalParser xsParser = getContext().getXSLogicalParser(); 225 if (xsParser == null) { 226 JAXBXsSchema jaxbXsSchema = (JAXBXsSchema) getXsESchema(); 228 prefixes = jaxbXsSchema.getJaxbExtensionBindingPrefixes(); 229 } else { 230 prefixes = ((JAXBXsSchema) xsParser.getSyntaxSchemas()[0]).getJaxbExtensionBindingPrefixes(); 231 } 232 233 for (int i = 0; i < prefixes.length; i++) { 234 if (prefixes[i].equals(pPrefix)) { 235 return true; 236 } 237 } 238 return false; 239 } 240 241 protected XsObject getBeanByParent(XsObject pParent, Locator pLocator, XsQName pQName) throws SAXException { 242 XsObjectCreator[] creators = getXsObjectCreators(); 243 if (creators != null) { 244 for (int i = 0; i < creators.length; i++) { 245 XsObject result = creators[i].newBean(pParent, pLocator, pQName); 246 if (result != null) { 247 return result; 248 } 249 } 250 } 251 return null; 252 } 253 254 public ContentHandler getChildHandler(String pQName, String pNamespaceURI, 255 String pLocalName) throws SAXException { 256 if (JAXBParser.JAXB_SCHEMA_URI.equals(pNamespaceURI) || 257 XSParser.XML_SCHEMA_URI.equals(pNamespaceURI) || 258 XMLConstants.XML_NS_URI.equals(pNamespaceURI)) { 259 return null; 260 } 261 262 int offset = pQName.indexOf(':'); 263 if (offset > 0) { 264 String prefix = pQName.substring(0, offset); 265 if (isPrefixEnabled(prefix)) { 266 XsQName qName = new XsQName(pNamespaceURI, pLocalName, XsQName.prefixOf(pQName)); 267 XsObject result = getBeanByParent(this, getObjectFactory().getLocator(), qName); 268 if (result != null) { 269 return getObjectFactory().newXsSAXParser(result); 270 } else { 271 return new DefaultHandler (); 272 } 273 } 274 } 275 throw new LocSAXException("Unknown child element " + pQName + ", use the schemas jaxb:extensionBindingPrefixes attribute to ignore it.", 276 getLocator()); 277 } 278 } 279 | Popular Tags |