1 22 package org.jboss.xb.binding.sunday.unmarshalling; 23 24 import java.util.Map ; 25 import java.util.HashMap ; 26 import java.util.Collections ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 30 import javax.xml.namespace.QName ; 31 32 import org.jboss.xb.binding.Constants; 33 import org.jboss.xb.binding.JBossXBRuntimeException; 34 import org.jboss.xb.binding.sunday.xop.XOPUnmarshaller; 35 import org.jboss.xb.binding.sunday.xop.XOPMarshaller; 36 import org.jboss.xb.binding.metadata.PackageMetaData; 37 38 45 public class SchemaBinding 46 { 47 private static final ValueAdapter DATE_ADAPTER = new ValueAdapter() 48 { 49 public Object cast(Object o, Class c) 50 { 51 if (o != null && java.util.Date .class.isAssignableFrom(c)) 52 { 53 o = ((java.util.Calendar ) o).getTime(); 54 } 55 return o; 56 } 57 }; 58 59 60 private Set namespaces = Collections.EMPTY_SET; 61 62 private Map types = new HashMap (); 63 64 private Map elements = new HashMap (); 65 66 private PackageMetaData packageMetaData; 67 68 private SchemaBindingResolver schemaResolver; 69 70 private boolean strictSchema = true; 71 72 private boolean ignoreUnresolvedFieldOrClass = true; 73 74 private boolean ignoreLowLine = true; 75 76 private boolean replacePropertyRefs = true; 77 78 private boolean unmarshalListsToArrays; 79 80 private boolean useNoArgCtorIfFound; 81 82 private String simpleContentProperty = "value"; 83 84 85 private XOPUnmarshaller xopUnmarshaller; 86 87 private XOPMarshaller xopMarshaller; 88 89 public SchemaBinding() 90 { 91 addType(new SimpleTypeBinding(Constants.QNAME_ANYSIMPLETYPE)); 92 addType(new SimpleTypeBinding(Constants.QNAME_STRING)); 93 addType(new SimpleTypeBinding(Constants.QNAME_BOOLEAN)); 94 addType(new SimpleTypeBinding(Constants.QNAME_DECIMAL)); 95 addType(new SimpleTypeBinding(Constants.QNAME_FLOAT)); 96 addType(new SimpleTypeBinding(Constants.QNAME_DOUBLE)); 97 addType(new SimpleTypeBinding(Constants.QNAME_DURATION)); 98 addType(new SimpleTypeBinding(Constants.QNAME_DATETIME, DATE_ADAPTER)); 99 addType(new SimpleTypeBinding(Constants.QNAME_TIME, DATE_ADAPTER)); 100 addType(new SimpleTypeBinding(Constants.QNAME_DATE, DATE_ADAPTER)); 101 addType(new SimpleTypeBinding(Constants.QNAME_GYEARMONTH)); 102 addType(new SimpleTypeBinding(Constants.QNAME_GYEAR)); 103 addType(new SimpleTypeBinding(Constants.QNAME_GMONTHDAY)); 104 addType(new SimpleTypeBinding(Constants.QNAME_GDAY)); 105 addType(new SimpleTypeBinding(Constants.QNAME_GMONTH)); 106 addType(new SimpleTypeBinding(Constants.QNAME_HEXBINARY)); 107 addType(new SimpleTypeBinding(Constants.QNAME_BASE64BINARY)); 108 addType(new SimpleTypeBinding(Constants.QNAME_ANYURI)); 109 addType(new SimpleTypeBinding(Constants.QNAME_QNAME)); 110 addType(new SimpleTypeBinding(Constants.QNAME_NOTATION)); 111 addType(new SimpleTypeBinding(Constants.QNAME_NORMALIZEDSTRING)); 112 addType(new SimpleTypeBinding(Constants.QNAME_TOKEN)); 113 addType(new SimpleTypeBinding(Constants.QNAME_LANGUAGE)); 114 addType(new SimpleTypeBinding(Constants.QNAME_NMTOKEN)); 115 addType(new SimpleTypeBinding(Constants.QNAME_NMTOKENS)); 116 addType(new SimpleTypeBinding(Constants.QNAME_NAME)); 117 addType(new SimpleTypeBinding(Constants.QNAME_NCNAME)); 118 addType(new SimpleTypeBinding(Constants.QNAME_ID)); 119 addType(new SimpleTypeBinding(Constants.QNAME_IDREF)); 120 addType(new SimpleTypeBinding(Constants.QNAME_IDREFS)); 121 addType(new SimpleTypeBinding(Constants.QNAME_ENTITY)); 122 addType(new SimpleTypeBinding(Constants.QNAME_ENTITIES)); 123 addType(new SimpleTypeBinding(Constants.QNAME_INTEGER)); 124 addType(new SimpleTypeBinding(Constants.QNAME_NONPOSITIVEINTEGER)); 125 addType(new SimpleTypeBinding(Constants.QNAME_NEGATIVEINTEGER)); 126 addType(new SimpleTypeBinding(Constants.QNAME_LONG)); 127 addType(new SimpleTypeBinding(Constants.QNAME_INT)); 128 addType(new SimpleTypeBinding(Constants.QNAME_SHORT)); 129 addType(new SimpleTypeBinding(Constants.QNAME_BYTE)); 130 addType(new SimpleTypeBinding(Constants.QNAME_NONNEGATIVEINTEGER)); 131 addType(new SimpleTypeBinding(Constants.QNAME_UNSIGNEDLONG)); 132 addType(new SimpleTypeBinding(Constants.QNAME_UNSIGNEDINT)); 133 addType(new SimpleTypeBinding(Constants.QNAME_UNSIGNEDSHORT)); 134 addType(new SimpleTypeBinding(Constants.QNAME_UNSIGNEDBYTE)); 135 addType(new SimpleTypeBinding(Constants.QNAME_POSITIVEINTEGER)); 136 } 137 138 143 public Set getNamespaces() 144 { 145 return namespaces; 146 } 147 148 154 public void setNamespaces(Set namespaces) 155 { 156 if (namespaces == null) 157 throw new IllegalArgumentException ("Null namespaces"); 158 this.namespaces = namespaces; 159 } 160 161 public TypeBinding getType(QName qName) 162 { 163 return (TypeBinding)types.get(qName); 164 } 165 166 public void addType(TypeBinding type) 167 { 168 QName qName = type.getQName(); 169 if(qName == null) 170 { 171 throw new JBossXBRuntimeException("Global type must have a name."); 172 } 173 types.put(qName, type); 174 } 175 176 public ElementBinding getElement(QName name) 177 { 178 ParticleBinding particle = (ParticleBinding)elements.get(name); 179 ElementBinding element = (ElementBinding)(particle == null ? null : particle.getTerm()); 180 return element; 181 } 182 183 public ParticleBinding getElementParticle(QName name) 184 { 185 return (ParticleBinding)elements.get(name); 186 } 187 188 public void addElement(ElementBinding element) 189 { 190 ParticleBinding particle = new ParticleBinding(element); 191 elements.put(element.getQName(), particle); 192 } 193 194 public ElementBinding addElement(QName name, TypeBinding type) 195 { 196 ElementBinding element = new ElementBinding(this, name, type); 197 addElement(element); 198 return element; 199 } 200 201 public Iterator getElements() 202 { 203 return new Iterator () 204 { 205 private Iterator particleIterator = elements.values().iterator(); 206 207 public boolean hasNext() 208 { 209 return particleIterator.hasNext(); 210 } 211 212 public Object next() 213 { 214 ParticleBinding particle = (ParticleBinding)particleIterator.next(); 215 return particle.getTerm(); 216 } 217 218 public void remove() 219 { 220 throw new UnsupportedOperationException ("remove is not implemented."); 221 } 222 }; 223 } 224 225 public Iterator getElementParticles() 226 { 227 return elements.values().iterator(); 228 } 229 230 public Iterator getTypes() 231 { 232 return Collections.unmodifiableCollection(types.values()).iterator(); 233 } 234 235 public PackageMetaData getPackageMetaData() 236 { 237 return packageMetaData; 238 } 239 240 public void setPackageMetaData(PackageMetaData packageMetaData) 241 { 242 this.packageMetaData = packageMetaData; 243 } 244 245 public SchemaBindingResolver getSchemaResolver() 246 { 247 return schemaResolver; 248 } 249 250 public void setSchemaResolver(SchemaBindingResolver schemaResolver) 251 { 252 this.schemaResolver = schemaResolver; 253 } 254 255 public boolean isStrictSchema() 256 { 257 return strictSchema; 258 } 259 260 265 public void setStrictSchema(boolean strictSchema) 266 { 267 this.strictSchema = strictSchema; 268 } 269 270 public boolean isIgnoreUnresolvedFieldOrClass() 271 { 272 return ignoreUnresolvedFieldOrClass; 273 } 274 275 281 public void setIgnoreUnresolvedFieldOrClass(boolean ignoreUnresolvedFieldOrClass) 282 { 283 this.ignoreUnresolvedFieldOrClass = ignoreUnresolvedFieldOrClass; 284 } 285 286 public boolean isReplacePropertyRefs() 287 { 288 return replacePropertyRefs; 289 } 290 294 public void setReplacePropertyRefs(boolean flag) 295 { 296 this.replacePropertyRefs = flag; 297 } 298 299 public boolean isIgnoreLowLine() 300 { 301 return ignoreLowLine; 302 } 303 304 308 public void setIgnoreLowLine(boolean ignoreLowLine) 309 { 310 this.ignoreLowLine = ignoreLowLine; 311 } 312 313 public boolean isUnmarshalListsToArrays() 314 { 315 return unmarshalListsToArrays; 316 } 317 318 322 public void setUnmarshalListsToArrays(boolean unmarshalListsToArrays) 323 { 324 this.unmarshalListsToArrays = unmarshalListsToArrays; 325 } 326 327 public boolean isUseNoArgCtorIfFound() 328 { 329 return useNoArgCtorIfFound; 330 } 331 332 336 public void setUseNoArgCtorIfFound(boolean useNoArgCtorIfFound) 337 { 338 this.useNoArgCtorIfFound = useNoArgCtorIfFound; 339 } 340 341 public String getSimpleContentProperty() 342 { 343 return simpleContentProperty; 344 } 345 346 350 public void setSimpleContentProperty(String simpleContentProperty) 351 { 352 this.simpleContentProperty = simpleContentProperty; 353 } 354 355 358 public XOPUnmarshaller getXopUnmarshaller() 359 { 360 return xopUnmarshaller; 361 } 362 363 366 public void setXopUnmarshaller(XOPUnmarshaller xopUnmarshaller) 367 { 368 this.xopUnmarshaller = xopUnmarshaller; 369 } 370 371 374 public XOPMarshaller getXopMarshaller() 375 { 376 return xopMarshaller; 377 } 378 379 382 public void setXopMarshaller(XOPMarshaller xopMarshaller) 383 { 384 this.xopMarshaller = xopMarshaller; 385 } 386 387 void addElementParticle(ParticleBinding particle) 388 { 389 ElementBinding element = (ElementBinding)particle.getTerm(); 390 elements.put(element.getQName(), particle); 391 } 392 } 393 | Popular Tags |