1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,1128 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.bind.v2.runtime; 1.30 + 1.31 +import java.io.IOException; 1.32 +import java.lang.ref.WeakReference; 1.33 +import java.lang.reflect.Field; 1.34 +import java.lang.reflect.Method; 1.35 +import java.lang.reflect.Type; 1.36 +import java.util.Arrays; 1.37 +import java.util.Collection; 1.38 +import java.util.Collections; 1.39 +import java.util.Comparator; 1.40 +import java.util.HashMap; 1.41 +import java.util.HashSet; 1.42 +import java.util.LinkedHashMap; 1.43 +import java.util.List; 1.44 +import java.util.Map; 1.45 +import java.util.Map.Entry; 1.46 +import java.util.Set; 1.47 +import java.util.TreeSet; 1.48 +import javax.xml.bind.Binder; 1.49 +import javax.xml.bind.JAXBContext; 1.50 +import javax.xml.bind.JAXBElement; 1.51 +import javax.xml.bind.JAXBException; 1.52 +import javax.xml.bind.JAXBIntrospector; 1.53 +import javax.xml.bind.Marshaller; 1.54 +import javax.xml.bind.SchemaOutputResolver; 1.55 +import javax.xml.bind.Unmarshaller; 1.56 +import javax.xml.bind.Validator; 1.57 +import javax.xml.bind.annotation.XmlAttachmentRef; 1.58 +import javax.xml.bind.annotation.XmlList; 1.59 +import javax.xml.bind.annotation.XmlNs; 1.60 +import javax.xml.bind.annotation.XmlSchema; 1.61 +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 1.62 +import javax.xml.namespace.QName; 1.63 +import javax.xml.parsers.DocumentBuilder; 1.64 +import javax.xml.parsers.DocumentBuilderFactory; 1.65 +import javax.xml.parsers.FactoryConfigurationError; 1.66 +import javax.xml.parsers.ParserConfigurationException; 1.67 +import javax.xml.transform.Result; 1.68 +import javax.xml.transform.Transformer; 1.69 +import javax.xml.transform.TransformerConfigurationException; 1.70 +import javax.xml.transform.TransformerFactory; 1.71 +import javax.xml.transform.sax.SAXTransformerFactory; 1.72 +import javax.xml.transform.sax.TransformerHandler; 1.73 + 1.74 +import com.sun.istack.internal.NotNull; 1.75 +import com.sun.istack.internal.Pool; 1.76 +import com.sun.xml.internal.bind.v2.WellKnownNamespace; 1.77 +import com.sun.xml.internal.bind.api.AccessorException; 1.78 +import com.sun.xml.internal.bind.api.Bridge; 1.79 +import com.sun.xml.internal.bind.api.BridgeContext; 1.80 +import com.sun.xml.internal.bind.api.CompositeStructure; 1.81 +import com.sun.xml.internal.bind.api.ErrorListener; 1.82 +import com.sun.xml.internal.bind.api.JAXBRIContext; 1.83 +import com.sun.xml.internal.bind.api.RawAccessor; 1.84 +import com.sun.xml.internal.bind.api.TypeReference; 1.85 +import com.sun.xml.internal.bind.unmarshaller.DOMScanner; 1.86 +import com.sun.xml.internal.bind.util.Which; 1.87 +import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader; 1.88 +import com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader; 1.89 +import com.sun.xml.internal.bind.v2.model.core.Adapter; 1.90 +import com.sun.xml.internal.bind.v2.model.core.NonElement; 1.91 +import com.sun.xml.internal.bind.v2.model.core.Ref; 1.92 +import com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl; 1.93 +import com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder; 1.94 +import com.sun.xml.internal.bind.v2.model.nav.Navigator; 1.95 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeArrayInfo; 1.96 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeBuiltinLeafInfo; 1.97 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeClassInfo; 1.98 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementInfo; 1.99 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeEnumLeafInfo; 1.100 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeLeafInfo; 1.101 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfo; 1.102 +import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet; 1.103 +import com.sun.xml.internal.bind.v2.runtime.output.Encoded; 1.104 +import com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty; 1.105 +import com.sun.xml.internal.bind.v2.runtime.property.Property; 1.106 +import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor; 1.107 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader; 1.108 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName; 1.109 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl; 1.110 +import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext; 1.111 +import com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator; 1.112 +import com.sun.xml.internal.bind.v2.util.EditDistance; 1.113 +import com.sun.xml.internal.bind.v2.util.QNameMap; 1.114 +import com.sun.xml.internal.bind.v2.util.XmlFactory; 1.115 +import com.sun.xml.internal.txw2.output.ResultFactory; 1.116 + 1.117 +import org.w3c.dom.Document; 1.118 +import org.w3c.dom.Element; 1.119 +import org.w3c.dom.Node; 1.120 +import org.xml.sax.SAXException; 1.121 +import org.xml.sax.SAXParseException; 1.122 + 1.123 +/** 1.124 + * This class provides the implementation of JAXBContext. 1.125 + * 1.126 + */ 1.127 +public final class JAXBContextImpl extends JAXBRIContext { 1.128 + 1.129 + /** 1.130 + * All the bridge classes. 1.131 + */ 1.132 + private final Map<TypeReference,Bridge> bridges = new LinkedHashMap<TypeReference,Bridge>(); 1.133 + 1.134 + /** 1.135 + * Shared instance of {@link DocumentBuilder}. 1.136 + * Lock before use. Lazily created. 1.137 + */ 1.138 + private static DocumentBuilder db; 1.139 + 1.140 + private final QNameMap<JaxBeanInfo> rootMap = new QNameMap<JaxBeanInfo>(); 1.141 + private final HashMap<QName,JaxBeanInfo> typeMap = new HashMap<QName,JaxBeanInfo>(); 1.142 + 1.143 + /** 1.144 + * Map from JAXB-bound {@link Class} to its {@link JaxBeanInfo}. 1.145 + */ 1.146 + private final Map<Class,JaxBeanInfo> beanInfoMap = new LinkedHashMap<Class,JaxBeanInfo>(); 1.147 + 1.148 + /** 1.149 + * All created {@link JaxBeanInfo}s. 1.150 + * Updated from each {@link JaxBeanInfo}s constructors to avoid infinite recursion 1.151 + * for a cyclic reference. 1.152 + * 1.153 + * <p> 1.154 + * This map is only used while the {@link JAXBContextImpl} is built and set to null 1.155 + * to avoid keeping references too long. 1.156 + */ 1.157 + protected Map<RuntimeTypeInfo,JaxBeanInfo> beanInfos = new LinkedHashMap<RuntimeTypeInfo, JaxBeanInfo>(); 1.158 + 1.159 + private final Map<Class/*scope*/,Map<QName,ElementBeanInfoImpl>> elements = new LinkedHashMap<Class, Map<QName, ElementBeanInfoImpl>>(); 1.160 + 1.161 + /** 1.162 + * Pool of {@link Marshaller}s. 1.163 + */ 1.164 + public final Pool<Marshaller> marshallerPool = new Pool.Impl<Marshaller>() { 1.165 + protected @NotNull Marshaller create() { 1.166 + return createMarshaller(); 1.167 + } 1.168 + }; 1.169 + 1.170 + public final Pool<Unmarshaller> unmarshallerPool = new Pool.Impl<Unmarshaller>() { 1.171 + protected @NotNull Unmarshaller create() { 1.172 + return createUnmarshaller(); 1.173 + } 1.174 + }; 1.175 + 1.176 + /** 1.177 + * Used to assign indices to known names in this grammar. 1.178 + * Reset to null once the build phase is completed. 1.179 + */ 1.180 + public NameBuilder nameBuilder = new NameBuilder(); 1.181 + 1.182 + /** 1.183 + * Keeps the list of known names. 1.184 + * This field is set once the build pahse is completed. 1.185 + */ 1.186 + public final NameList nameList; 1.187 + 1.188 + /** 1.189 + * Input to the JAXBContext.newInstance, so that we can recreate 1.190 + * {@link RuntimeTypeInfoSet} whenever we need. 1.191 + */ 1.192 + private final String defaultNsUri; 1.193 + private final Class[] classes; 1.194 + 1.195 + /** 1.196 + * true to reorder attributes lexicographically in preparation of the c14n support. 1.197 + */ 1.198 + protected final boolean c14nSupport; 1.199 + 1.200 + /** 1.201 + * Flag that user has provided a custom AccessorFactory for JAXB to use 1.202 + */ 1.203 + public final boolean xmlAccessorFactorySupport; 1.204 + 1.205 + /** 1.206 + * @see JAXBRIContext#TREAT_EVERYTHING_NILLABLE 1.207 + */ 1.208 + public final boolean allNillable; 1.209 + 1.210 + /** 1.211 + * Store properties, so that they can be recovered in the run (is here because of JSON encoding of Jersey). 1.212 + */ 1.213 + public final boolean retainPropertyInfo; 1.214 + 1.215 + /** 1.216 + * Suppress reflection accessor warnings. 1.217 + */ 1.218 + public final boolean supressAccessorWarnings; 1.219 + 1.220 + /** 1.221 + * Improved xsi type handling. 1.222 + */ 1.223 + public final boolean improvedXsiTypeHandling; 1.224 + 1.225 + /** 1.226 + * Disable security processing. 1.227 + */ 1.228 + public final boolean disableSecurityProcessing; 1.229 + 1.230 + private WeakReference<RuntimeTypeInfoSet> typeInfoSetCache; 1.231 + 1.232 + private @NotNull RuntimeAnnotationReader annotationReader; 1.233 + 1.234 + private /*almost final*/ boolean hasSwaRef; 1.235 + private final @NotNull Map<Class,Class> subclassReplacements; 1.236 + 1.237 + /** 1.238 + * If true, we aim for faster {@link JAXBContext} instantiation performance, 1.239 + * instead of going after efficient sustained unmarshalling/marshalling performance. 1.240 + * 1.241 + * @since 2.0.4 1.242 + */ 1.243 + public final boolean fastBoot; 1.244 + 1.245 + private Set<XmlNs> xmlNsSet = null; 1.246 + 1.247 + /** 1.248 + * Returns declared XmlNs annotations (from package-level annotation XmlSchema 1.249 + * 1.250 + * @return set of all present XmlNs annotations 1.251 + */ 1.252 + public Set<XmlNs> getXmlNsSet() { 1.253 + return xmlNsSet; 1.254 + } 1.255 + 1.256 + private JAXBContextImpl(JAXBContextBuilder builder) throws JAXBException { 1.257 + 1.258 + this.defaultNsUri = builder.defaultNsUri; 1.259 + this.retainPropertyInfo = builder.retainPropertyInfo; 1.260 + this.annotationReader = builder.annotationReader; 1.261 + this.subclassReplacements = builder.subclassReplacements; 1.262 + this.c14nSupport = builder.c14nSupport; 1.263 + this.classes = builder.classes; 1.264 + this.xmlAccessorFactorySupport = builder.xmlAccessorFactorySupport; 1.265 + this.allNillable = builder.allNillable; 1.266 + this.supressAccessorWarnings = builder.supressAccessorWarnings; 1.267 + this.improvedXsiTypeHandling = builder.improvedXsiTypeHandling; 1.268 + this.disableSecurityProcessing = builder.disableSecurityProcessing; 1.269 + 1.270 + Collection<TypeReference> typeRefs = builder.typeRefs; 1.271 + 1.272 + boolean fastB; 1.273 + try { 1.274 + fastB = Boolean.getBoolean(JAXBContextImpl.class.getName()+".fastBoot"); 1.275 + } catch (SecurityException e) { 1.276 + fastB = false; 1.277 + } 1.278 + this.fastBoot = fastB; 1.279 + 1.280 + RuntimeTypeInfoSet typeSet = getTypeInfoSet(); 1.281 + 1.282 + // at least prepare the empty table so that we don't have to check for null later 1.283 + elements.put(null,new LinkedHashMap<QName, ElementBeanInfoImpl>()); 1.284 + 1.285 + // recognize leaf bean infos 1.286 + for( RuntimeBuiltinLeafInfo leaf : RuntimeBuiltinLeafInfoImpl.builtinBeanInfos ) { 1.287 + LeafBeanInfoImpl<?> bi = new LeafBeanInfoImpl(this,leaf); 1.288 + beanInfoMap.put(leaf.getClazz(),bi); 1.289 + for( QName t : bi.getTypeNames() ) 1.290 + typeMap.put(t,bi); 1.291 + } 1.292 + 1.293 + for (RuntimeEnumLeafInfo e : typeSet.enums().values()) { 1.294 + JaxBeanInfo<?> bi = getOrCreate(e); 1.295 + for (QName qn : bi.getTypeNames()) 1.296 + typeMap.put( qn, bi ); 1.297 + if(e.isElement()) 1.298 + rootMap.put( e.getElementName(), bi ); 1.299 + } 1.300 + 1.301 + for (RuntimeArrayInfo a : typeSet.arrays().values()) { 1.302 + JaxBeanInfo<?> ai = getOrCreate(a); 1.303 + for (QName qn : ai.getTypeNames()) 1.304 + typeMap.put( qn, ai ); 1.305 + } 1.306 + 1.307 + for( Entry<Class, ? extends RuntimeClassInfo> e : typeSet.beans().entrySet() ) { 1.308 + ClassBeanInfoImpl<?> bi = getOrCreate(e.getValue()); 1.309 + 1.310 + XmlSchema xs = this.annotationReader.getPackageAnnotation(XmlSchema.class, e.getKey(), null); 1.311 + if(xs != null) { 1.312 + if(xs.xmlns() != null && xs.xmlns().length > 0) { 1.313 + if(xmlNsSet == null) 1.314 + xmlNsSet = new HashSet<XmlNs>(); 1.315 + xmlNsSet.addAll(Arrays.asList(xs.xmlns())); 1.316 + } 1.317 + } 1.318 + 1.319 + if(bi.isElement()) 1.320 + rootMap.put( e.getValue().getElementName(), bi ); 1.321 + 1.322 + for (QName qn : bi.getTypeNames()) 1.323 + typeMap.put( qn, bi ); 1.324 + } 1.325 + 1.326 + // fill in element mappings 1.327 + for( RuntimeElementInfo n : typeSet.getAllElements() ) { 1.328 + ElementBeanInfoImpl bi = getOrCreate(n); 1.329 + if(n.getScope()==null) 1.330 + rootMap.put(n.getElementName(),bi); 1.331 + 1.332 + RuntimeClassInfo scope = n.getScope(); 1.333 + Class scopeClazz = scope==null?null:scope.getClazz(); 1.334 + Map<QName,ElementBeanInfoImpl> m = elements.get(scopeClazz); 1.335 + if(m==null) { 1.336 + m = new LinkedHashMap<QName, ElementBeanInfoImpl>(); 1.337 + elements.put(scopeClazz,m); 1.338 + } 1.339 + m.put(n.getElementName(),bi); 1.340 + } 1.341 + 1.342 + // this one is so that we can handle plain JAXBElements. 1.343 + beanInfoMap.put(JAXBElement.class,new ElementBeanInfoImpl(this)); 1.344 + // another special BeanInfoImpl just for marshalling 1.345 + beanInfoMap.put(CompositeStructure.class,new CompositeStructureBeanInfo(this)); 1.346 + 1.347 + getOrCreate(typeSet.getAnyTypeInfo()); 1.348 + 1.349 + // then link them all! 1.350 + for (JaxBeanInfo bi : beanInfos.values()) 1.351 + bi.link(this); 1.352 + 1.353 + // register primitives for boxed types just to make GrammarInfo fool-proof 1.354 + for( Map.Entry<Class,Class> e : RuntimeUtil.primitiveToBox.entrySet() ) 1.355 + beanInfoMap.put( e.getKey(), beanInfoMap.get(e.getValue()) ); 1.356 + 1.357 + // build bridges 1.358 + Navigator<Type, Class, Field, Method> nav = typeSet.getNavigator(); 1.359 + 1.360 + for (TypeReference tr : typeRefs) { 1.361 + XmlJavaTypeAdapter xjta = tr.get(XmlJavaTypeAdapter.class); 1.362 + Adapter<Type,Class> a=null; 1.363 + XmlList xl = tr.get(XmlList.class); 1.364 + 1.365 + // eventually compute the in-memory type 1.366 + Class erasedType = (Class) nav.erasure(tr.type); 1.367 + 1.368 + if(xjta!=null) { 1.369 + a = new Adapter<Type,Class>(xjta.value(),nav); 1.370 + } 1.371 + if(tr.get(XmlAttachmentRef.class)!=null) { 1.372 + a = new Adapter<Type,Class>(SwaRefAdapter.class,nav); 1.373 + hasSwaRef = true; 1.374 + } 1.375 + 1.376 + if(a!=null) { 1.377 + erasedType = (Class) nav.erasure(a.defaultType); 1.378 + } 1.379 + 1.380 + Name name = nameBuilder.createElementName(tr.tagName); 1.381 + 1.382 + InternalBridge bridge; 1.383 + if(xl==null) 1.384 + bridge = new BridgeImpl(this, name,getBeanInfo(erasedType,true),tr); 1.385 + else 1.386 + bridge = new BridgeImpl(this, name,new ValueListBeanInfoImpl(this,erasedType),tr); 1.387 + 1.388 + if(a!=null) 1.389 + bridge = new BridgeAdapter(bridge,a.adapterType); 1.390 + 1.391 + bridges.put(tr,bridge); 1.392 + } 1.393 + 1.394 + this.nameList = nameBuilder.conclude(); 1.395 + 1.396 + for (JaxBeanInfo bi : beanInfos.values()) 1.397 + bi.wrapUp(); 1.398 + 1.399 + // no use for them now 1.400 + nameBuilder = null; 1.401 + beanInfos = null; 1.402 + } 1.403 + 1.404 + /** 1.405 + * True if this JAXBContext has {@link XmlAttachmentRef}. 1.406 + */ 1.407 + public boolean hasSwaRef() { 1.408 + return hasSwaRef; 1.409 + } 1.410 + 1.411 + public RuntimeTypeInfoSet getRuntimeTypeInfoSet() { 1.412 + try { 1.413 + return getTypeInfoSet(); 1.414 + } catch (IllegalAnnotationsException e) { 1.415 + // impossible, once the model is constructred 1.416 + throw new AssertionError(e); 1.417 + } 1.418 + } 1.419 + 1.420 + /** 1.421 + * Creates a {@link RuntimeTypeInfoSet}. 1.422 + */ 1.423 + public RuntimeTypeInfoSet getTypeInfoSet() throws IllegalAnnotationsException { 1.424 + 1.425 + // check cache 1.426 + if(typeInfoSetCache!=null) { 1.427 + RuntimeTypeInfoSet r = typeInfoSetCache.get(); 1.428 + if(r!=null) 1.429 + return r; 1.430 + } 1.431 + 1.432 + final RuntimeModelBuilder builder = new RuntimeModelBuilder(this,annotationReader,subclassReplacements,defaultNsUri); 1.433 + 1.434 + IllegalAnnotationsException.Builder errorHandler = new IllegalAnnotationsException.Builder(); 1.435 + builder.setErrorHandler(errorHandler); 1.436 + 1.437 + for( Class c : classes ) { 1.438 + if(c==CompositeStructure.class) 1.439 + // CompositeStructure doesn't have TypeInfo, so skip it. 1.440 + // We'll add JaxBeanInfo for this later automatically 1.441 + continue; 1.442 + builder.getTypeInfo(new Ref<Type,Class>(c)); 1.443 + } 1.444 + 1.445 + this.hasSwaRef |= builder.hasSwaRef; 1.446 + RuntimeTypeInfoSet r = builder.link(); 1.447 + 1.448 + errorHandler.check(); 1.449 + assert r!=null : "if no error was reported, the link must be a success"; 1.450 + 1.451 + typeInfoSetCache = new WeakReference<RuntimeTypeInfoSet>(r); 1.452 + 1.453 + return r; 1.454 + } 1.455 + 1.456 + 1.457 + public ElementBeanInfoImpl getElement(Class scope, QName name) { 1.458 + Map<QName,ElementBeanInfoImpl> m = elements.get(scope); 1.459 + if(m!=null) { 1.460 + ElementBeanInfoImpl bi = m.get(name); 1.461 + if(bi!=null) 1.462 + return bi; 1.463 + } 1.464 + m = elements.get(null); 1.465 + return m.get(name); 1.466 + } 1.467 + 1.468 + 1.469 + 1.470 + 1.471 + 1.472 + private ElementBeanInfoImpl getOrCreate( RuntimeElementInfo rei ) { 1.473 + JaxBeanInfo bi = beanInfos.get(rei); 1.474 + if(bi!=null) return (ElementBeanInfoImpl)bi; 1.475 + 1.476 + // all elements share the same type, so we can't register them to beanInfoMap 1.477 + return new ElementBeanInfoImpl(this, rei); 1.478 + } 1.479 + 1.480 + protected JaxBeanInfo getOrCreate( RuntimeEnumLeafInfo eli ) { 1.481 + JaxBeanInfo bi = beanInfos.get(eli); 1.482 + if(bi!=null) return bi; 1.483 + bi = new LeafBeanInfoImpl(this,eli); 1.484 + beanInfoMap.put(bi.jaxbType,bi); 1.485 + return bi; 1.486 + } 1.487 + 1.488 + protected ClassBeanInfoImpl getOrCreate( RuntimeClassInfo ci ) { 1.489 + ClassBeanInfoImpl bi = (ClassBeanInfoImpl)beanInfos.get(ci); 1.490 + if(bi!=null) return bi; 1.491 + bi = new ClassBeanInfoImpl(this,ci); 1.492 + beanInfoMap.put(bi.jaxbType,bi); 1.493 + return bi; 1.494 + } 1.495 + 1.496 + protected JaxBeanInfo getOrCreate( RuntimeArrayInfo ai ) { 1.497 + JaxBeanInfo abi = beanInfos.get(ai); 1.498 + if(abi!=null) return abi; 1.499 + 1.500 + abi = new ArrayBeanInfoImpl(this,ai); 1.501 + 1.502 + beanInfoMap.put(ai.getType(),abi); 1.503 + return abi; 1.504 + } 1.505 + 1.506 + public JaxBeanInfo getOrCreate(RuntimeTypeInfo e) { 1.507 + if(e instanceof RuntimeElementInfo) 1.508 + return getOrCreate((RuntimeElementInfo)e); 1.509 + if(e instanceof RuntimeClassInfo) 1.510 + return getOrCreate((RuntimeClassInfo)e); 1.511 + if(e instanceof RuntimeLeafInfo) { 1.512 + JaxBeanInfo bi = beanInfos.get(e); // must have been created 1.513 + assert bi!=null; 1.514 + return bi; 1.515 + } 1.516 + if(e instanceof RuntimeArrayInfo) 1.517 + return getOrCreate((RuntimeArrayInfo)e); 1.518 + if(e.getType()==Object.class) { 1.519 + // anyType 1.520 + JaxBeanInfo bi = beanInfoMap.get(Object.class); 1.521 + if(bi==null) { 1.522 + bi = new AnyTypeBeanInfo(this,e); 1.523 + beanInfoMap.put(Object.class,bi); 1.524 + } 1.525 + return bi; 1.526 + } 1.527 + 1.528 + throw new IllegalArgumentException(); 1.529 + } 1.530 + 1.531 + /** 1.532 + * Gets the {@link JaxBeanInfo} object that can handle 1.533 + * the given JAXB-bound object. 1.534 + * 1.535 + * <p> 1.536 + * This method traverses the base classes of the given object. 1.537 + * 1.538 + * @return null 1.539 + * if <tt>c</tt> isn't a JAXB-bound class and <tt>fatal==false</tt>. 1.540 + */ 1.541 + public final JaxBeanInfo getBeanInfo(Object o) { 1.542 + // don't allow xs:anyType beanInfo to handle all the unbound objects 1.543 + for( Class c=o.getClass(); c!=Object.class; c=c.getSuperclass()) { 1.544 + JaxBeanInfo bi = beanInfoMap.get(c); 1.545 + if(bi!=null) return bi; 1.546 + } 1.547 + if(o instanceof Element) 1.548 + return beanInfoMap.get(Object.class); // return the BeanInfo for xs:anyType 1.549 + for( Class c : o.getClass().getInterfaces()) { 1.550 + JaxBeanInfo bi = beanInfoMap.get(c); 1.551 + if(bi!=null) return bi; 1.552 + } 1.553 + return null; 1.554 + } 1.555 + 1.556 + /** 1.557 + * Gets the {@link JaxBeanInfo} object that can handle 1.558 + * the given JAXB-bound object. 1.559 + * 1.560 + * @param fatal 1.561 + * if true, the failure to look up will throw an exception. 1.562 + * Otherwise it will just return null. 1.563 + */ 1.564 + public final JaxBeanInfo getBeanInfo(Object o,boolean fatal) throws JAXBException { 1.565 + JaxBeanInfo bi = getBeanInfo(o); 1.566 + if(bi!=null) return bi; 1.567 + if(fatal) { 1.568 + if(o instanceof Document) 1.569 + throw new JAXBException(Messages.ELEMENT_NEEDED_BUT_FOUND_DOCUMENT.format(o.getClass())); 1.570 + throw new JAXBException(Messages.UNKNOWN_CLASS.format(o.getClass())); 1.571 + } 1.572 + return null; 1.573 + } 1.574 + 1.575 + /** 1.576 + * Gets the {@link JaxBeanInfo} object that can handle 1.577 + * the given JAXB-bound class. 1.578 + * 1.579 + * <p> 1.580 + * This method doesn't look for base classes. 1.581 + * 1.582 + * @return null 1.583 + * if <tt>c</tt> isn't a JAXB-bound class and <tt>fatal==false</tt>. 1.584 + */ 1.585 + public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) { 1.586 + return (JaxBeanInfo<T>)beanInfoMap.get(clazz); 1.587 + } 1.588 + 1.589 + /** 1.590 + * Gets the {@link JaxBeanInfo} object that can handle 1.591 + * the given JAXB-bound class. 1.592 + * 1.593 + * @param fatal 1.594 + * if true, the failure to look up will throw an exception. 1.595 + * Otherwise it will just return null. 1.596 + */ 1.597 + public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz,boolean fatal) throws JAXBException { 1.598 + JaxBeanInfo<T> bi = getBeanInfo(clazz); 1.599 + if(bi!=null) return bi; 1.600 + if(fatal) 1.601 + throw new JAXBException(clazz.getName()+" is not known to this context"); 1.602 + return null; 1.603 + } 1.604 + 1.605 + /** 1.606 + * Based on the tag name, determine what object to unmarshal, 1.607 + * and then set a new object and its loader to the current unmarshaller state. 1.608 + * 1.609 + * @return 1.610 + * null if the given name pair is not recognized. 1.611 + */ 1.612 + public final Loader selectRootLoader( UnmarshallingContext.State state, TagName tag ) { 1.613 + JaxBeanInfo beanInfo = rootMap.get(tag.uri,tag.local); 1.614 + if(beanInfo==null) 1.615 + return null; 1.616 + 1.617 + return beanInfo.getLoader(this,true); 1.618 + } 1.619 + 1.620 + /** 1.621 + * Gets the {@link JaxBeanInfo} for the given named XML Schema type. 1.622 + * 1.623 + * @return 1.624 + * null if the type name is not recognized. For schema 1.625 + * languages other than XML Schema, this method always 1.626 + * returns null. 1.627 + */ 1.628 + public JaxBeanInfo getGlobalType(QName name) { 1.629 + return typeMap.get(name); 1.630 + } 1.631 + 1.632 + /** 1.633 + * Finds a type name that this context recognizes which is 1.634 + * "closest" to the given type name. 1.635 + * 1.636 + * <p> 1.637 + * This method is used for error recovery. 1.638 + */ 1.639 + public String getNearestTypeName(QName name) { 1.640 + String[] all = new String[typeMap.size()]; 1.641 + int i=0; 1.642 + for (QName qn : typeMap.keySet()) { 1.643 + if(qn.getLocalPart().equals(name.getLocalPart())) 1.644 + return qn.toString(); // probably a match, as people often gets confused about namespace. 1.645 + all[i++] = qn.toString(); 1.646 + } 1.647 + 1.648 + String nearest = EditDistance.findNearest(name.toString(), all); 1.649 + 1.650 + if(EditDistance.editDistance(nearest,name.toString())>10) 1.651 + return null; // too far apart. 1.652 + 1.653 + return nearest; 1.654 + } 1.655 + 1.656 + /** 1.657 + * Returns the set of valid root tag names. 1.658 + * For diagnostic use. 1.659 + */ 1.660 + public Set<QName> getValidRootNames() { 1.661 + Set<QName> r = new TreeSet<QName>(QNAME_COMPARATOR); 1.662 + for (QNameMap.Entry e : rootMap.entrySet()) { 1.663 + r.add(e.createQName()); 1.664 + } 1.665 + return r; 1.666 + } 1.667 + 1.668 + /** 1.669 + * Cache of UTF-8 encoded local names to improve the performance for the marshalling. 1.670 + */ 1.671 + private Encoded[] utf8nameTable; 1.672 + 1.673 + public synchronized Encoded[] getUTF8NameTable() { 1.674 + if(utf8nameTable==null) { 1.675 + Encoded[] x = new Encoded[nameList.localNames.length]; 1.676 + for( int i=0; i<x.length; i++ ) { 1.677 + Encoded e = new Encoded(nameList.localNames[i]); 1.678 + e.compact(); 1.679 + x[i] = e; 1.680 + } 1.681 + utf8nameTable = x; 1.682 + } 1.683 + return utf8nameTable; 1.684 + } 1.685 + 1.686 + public int getNumberOfLocalNames() { 1.687 + return nameList.localNames.length; 1.688 + } 1.689 + 1.690 + public int getNumberOfElementNames() { 1.691 + return nameList.numberOfElementNames; 1.692 + } 1.693 + 1.694 + public int getNumberOfAttributeNames() { 1.695 + return nameList.numberOfAttributeNames; 1.696 + } 1.697 + 1.698 + /** 1.699 + * Creates a new identity transformer. 1.700 + */ 1.701 + static Transformer createTransformer(boolean disableSecureProcessing) { 1.702 + try { 1.703 + SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing); 1.704 + return tf.newTransformer(); 1.705 + } catch (TransformerConfigurationException e) { 1.706 + throw new Error(e); // impossible 1.707 + } 1.708 + } 1.709 + 1.710 + /** 1.711 + * Creates a new identity transformer. 1.712 + */ 1.713 + public static TransformerHandler createTransformerHandler(boolean disableSecureProcessing) { 1.714 + try { 1.715 + SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing); 1.716 + return tf.newTransformerHandler(); 1.717 + } catch (TransformerConfigurationException e) { 1.718 + throw new Error(e); // impossible 1.719 + } 1.720 + } 1.721 + 1.722 + /** 1.723 + * Creates a new DOM document. 1.724 + */ 1.725 + static Document createDom(boolean disableSecurityProcessing) { 1.726 + synchronized(JAXBContextImpl.class) { 1.727 + if(db==null) { 1.728 + try { 1.729 + DocumentBuilderFactory dbf = XmlFactory.createDocumentBuilderFactory(disableSecurityProcessing); 1.730 + db = dbf.newDocumentBuilder(); 1.731 + } catch (ParserConfigurationException e) { 1.732 + // impossible 1.733 + throw new FactoryConfigurationError(e); 1.734 + } 1.735 + } 1.736 + return db.newDocument(); 1.737 + } 1.738 + } 1.739 + 1.740 + public MarshallerImpl createMarshaller() { 1.741 + return new MarshallerImpl(this,null); 1.742 + } 1.743 + 1.744 + public UnmarshallerImpl createUnmarshaller() { 1.745 + return new UnmarshallerImpl(this,null); 1.746 + } 1.747 + 1.748 + public Validator createValidator() { 1.749 + throw new UnsupportedOperationException(Messages.NOT_IMPLEMENTED_IN_2_0.format()); 1.750 + } 1.751 + 1.752 + @Override 1.753 + public JAXBIntrospector createJAXBIntrospector() { 1.754 + return new JAXBIntrospector() { 1.755 + public boolean isElement(Object object) { 1.756 + return getElementName(object)!=null; 1.757 + } 1.758 + 1.759 + public QName getElementName(Object jaxbElement) { 1.760 + try { 1.761 + return JAXBContextImpl.this.getElementName(jaxbElement); 1.762 + } catch (JAXBException e) { 1.763 + return null; 1.764 + } 1.765 + } 1.766 + }; 1.767 + } 1.768 + 1.769 + private NonElement<Type,Class> getXmlType(RuntimeTypeInfoSet tis, TypeReference tr) { 1.770 + if(tr==null) 1.771 + throw new IllegalArgumentException(); 1.772 + 1.773 + XmlJavaTypeAdapter xjta = tr.get(XmlJavaTypeAdapter.class); 1.774 + XmlList xl = tr.get(XmlList.class); 1.775 + 1.776 + Ref<Type,Class> ref = new Ref<Type,Class>(annotationReader, tis.getNavigator(), tr.type, xjta, xl ); 1.777 + 1.778 + return tis.getTypeInfo(ref); 1.779 + } 1.780 + 1.781 + @Override 1.782 + public void generateEpisode(Result output) { 1.783 + if(output==null) 1.784 + throw new IllegalArgumentException(); 1.785 + createSchemaGenerator().writeEpisodeFile(ResultFactory.createSerializer(output)); 1.786 + } 1.787 + 1.788 + @Override 1.789 + @SuppressWarnings("ThrowableInitCause") 1.790 + public void generateSchema(SchemaOutputResolver outputResolver) throws IOException { 1.791 + if(outputResolver==null) 1.792 + throw new IOException(Messages.NULL_OUTPUT_RESOLVER.format()); 1.793 + 1.794 + final SAXParseException[] e = new SAXParseException[1]; 1.795 + final SAXParseException[] w = new SAXParseException[1]; 1.796 + 1.797 + createSchemaGenerator().write(outputResolver, new ErrorListener() { 1.798 + public void error(SAXParseException exception) { 1.799 + e[0] = exception; 1.800 + } 1.801 + 1.802 + public void fatalError(SAXParseException exception) { 1.803 + e[0] = exception; 1.804 + } 1.805 + 1.806 + public void warning(SAXParseException exception) { 1.807 + w[0] = exception; 1.808 + } 1.809 + 1.810 + public void info(SAXParseException exception) {} 1.811 + }); 1.812 + 1.813 + if (e[0]!=null) { 1.814 + IOException x = new IOException(Messages.FAILED_TO_GENERATE_SCHEMA.format()); 1.815 + x.initCause(e[0]); 1.816 + throw x; 1.817 + } 1.818 + if (w[0]!=null) { 1.819 + IOException x = new IOException(Messages.ERROR_PROCESSING_SCHEMA.format()); 1.820 + x.initCause(w[0]); 1.821 + throw x; 1.822 + } 1.823 + } 1.824 + 1.825 + private XmlSchemaGenerator<Type,Class,Field,Method> createSchemaGenerator() { 1.826 + RuntimeTypeInfoSet tis; 1.827 + try { 1.828 + tis = getTypeInfoSet(); 1.829 + } catch (IllegalAnnotationsException e) { 1.830 + // this shouldn't happen because we've already 1.831 + throw new AssertionError(e); 1.832 + } 1.833 + 1.834 + XmlSchemaGenerator<Type,Class,Field,Method> xsdgen = 1.835 + new XmlSchemaGenerator<Type,Class,Field,Method>(tis.getNavigator(),tis); 1.836 + 1.837 + // JAX-RPC uses Bridge objects that collide with 1.838 + // @XmlRootElement. 1.839 + // we will avoid collision here 1.840 + Set<QName> rootTagNames = new HashSet<QName>(); 1.841 + for (RuntimeElementInfo ei : tis.getAllElements()) { 1.842 + rootTagNames.add(ei.getElementName()); 1.843 + } 1.844 + for (RuntimeClassInfo ci : tis.beans().values()) { 1.845 + if(ci.isElement()) 1.846 + rootTagNames.add(ci.asElement().getElementName()); 1.847 + } 1.848 + 1.849 + for (TypeReference tr : bridges.keySet()) { 1.850 + if(rootTagNames.contains(tr.tagName)) 1.851 + continue; 1.852 + 1.853 + if(tr.type==void.class || tr.type==Void.class) { 1.854 + xsdgen.add(tr.tagName,false,null); 1.855 + } else 1.856 + if(tr.type==CompositeStructure.class) { 1.857 + // this is a special class we introduced for JAX-WS that we *don't* want in the schema 1.858 + } else { 1.859 + NonElement<Type,Class> typeInfo = getXmlType(tis,tr); 1.860 + xsdgen.add(tr.tagName, !tis.getNavigator().isPrimitive(tr.type),typeInfo); 1.861 + } 1.862 + } 1.863 + return xsdgen; 1.864 + } 1.865 + 1.866 + public QName getTypeName(TypeReference tr) { 1.867 + try { 1.868 + NonElement<Type,Class> xt = getXmlType(getTypeInfoSet(),tr); 1.869 + if(xt==null) throw new IllegalArgumentException(); 1.870 + return xt.getTypeName(); 1.871 + } catch (IllegalAnnotationsException e) { 1.872 + // impossible given that JAXBRIContext has been successfully built in the first place 1.873 + throw new AssertionError(e); 1.874 + } 1.875 + } 1.876 + 1.877 + @Override 1.878 + public <T> Binder<T> createBinder(Class<T> domType) { 1.879 + if(domType==Node.class) 1.880 + return (Binder<T>)createBinder(); 1.881 + else 1.882 + return super.createBinder(domType); 1.883 + } 1.884 + 1.885 + @Override 1.886 + public Binder<Node> createBinder() { 1.887 + return new BinderImpl<Node>(this,new DOMScanner()); 1.888 + } 1.889 + 1.890 + public QName getElementName(Object o) throws JAXBException { 1.891 + JaxBeanInfo bi = getBeanInfo(o,true); 1.892 + if(!bi.isElement()) 1.893 + return null; 1.894 + return new QName(bi.getElementNamespaceURI(o),bi.getElementLocalName(o)); 1.895 + } 1.896 + 1.897 + public QName getElementName(Class o) throws JAXBException { 1.898 + JaxBeanInfo bi = getBeanInfo(o,true); 1.899 + if(!bi.isElement()) 1.900 + return null; 1.901 + return new QName(bi.getElementNamespaceURI(o),bi.getElementLocalName(o)); 1.902 + } 1.903 + 1.904 + public Bridge createBridge(TypeReference ref) { 1.905 + return bridges.get(ref); 1.906 + } 1.907 + 1.908 + public @NotNull BridgeContext createBridgeContext() { 1.909 + return new BridgeContextImpl(this); 1.910 + } 1.911 + 1.912 + public RawAccessor getElementPropertyAccessor(Class wrapperBean, String nsUri, String localName) throws JAXBException { 1.913 + JaxBeanInfo bi = getBeanInfo(wrapperBean,true); 1.914 + if(!(bi instanceof ClassBeanInfoImpl)) 1.915 + throw new JAXBException(wrapperBean+" is not a bean"); 1.916 + 1.917 + for( ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; cb!=null; cb=cb.superClazz) { 1.918 + for (Property p : cb.properties) { 1.919 + final Accessor acc = p.getElementPropertyAccessor(nsUri,localName); 1.920 + if(acc!=null) 1.921 + return new RawAccessor() { 1.922 + // Accessor.set/get are designed for unmarshaller/marshaller, and hence 1.923 + // they go through an adapter behind the scene. 1.924 + // this isn't desirable for JAX-WS, which essentially uses this method 1.925 + // just as a reflection library. So use the "unadapted" version to 1.926 + // achieve the desired semantics 1.927 + public Object get(Object bean) throws AccessorException { 1.928 + return acc.getUnadapted(bean); 1.929 + } 1.930 + 1.931 + public void set(Object bean, Object value) throws AccessorException { 1.932 + acc.setUnadapted(bean,value); 1.933 + } 1.934 + }; 1.935 + } 1.936 + } 1.937 + throw new JAXBException(new QName(nsUri,localName)+" is not a valid property on "+wrapperBean); 1.938 + } 1.939 + 1.940 + public List<String> getKnownNamespaceURIs() { 1.941 + return Arrays.asList(nameList.namespaceURIs); 1.942 + } 1.943 + 1.944 + public String getBuildId() { 1.945 + Package pkg = getClass().getPackage(); 1.946 + if(pkg==null) return null; 1.947 + return pkg.getImplementationVersion(); 1.948 + } 1.949 + 1.950 + @Override 1.951 + public String toString() { 1.952 + StringBuilder buf = new StringBuilder(Which.which(getClass()) + " Build-Id: " + getBuildId()); 1.953 + buf.append("\nClasses known to this context:\n"); 1.954 + 1.955 + Set<String> names = new TreeSet<String>(); // sort them so that it's easy to read 1.956 + 1.957 + for (Class key : beanInfoMap.keySet()) 1.958 + names.add(key.getName()); 1.959 + 1.960 + for(String name: names) 1.961 + buf.append(" ").append(name).append('\n'); 1.962 + 1.963 + return buf.toString(); 1.964 + } 1.965 + 1.966 + /** 1.967 + * Gets the value of the xmime:contentType attribute on the given object, or null 1.968 + * if for some reason it couldn't be found, including any error. 1.969 + */ 1.970 + public String getXMIMEContentType( Object o ) { 1.971 + JaxBeanInfo bi = getBeanInfo(o); 1.972 + if(!(bi instanceof ClassBeanInfoImpl)) 1.973 + return null; 1.974 + 1.975 + ClassBeanInfoImpl cb = (ClassBeanInfoImpl) bi; 1.976 + for (Property p : cb.properties) { 1.977 + if (p instanceof AttributeProperty) { 1.978 + AttributeProperty ap = (AttributeProperty) p; 1.979 + if(ap.attName.equals(WellKnownNamespace.XML_MIME_URI,"contentType")) 1.980 + try { 1.981 + return (String)ap.xacc.print(o); 1.982 + } catch (AccessorException e) { 1.983 + return null; 1.984 + } catch (SAXException e) { 1.985 + return null; 1.986 + } catch (ClassCastException e) { 1.987 + return null; 1.988 + } 1.989 + } 1.990 + } 1.991 + return null; 1.992 + } 1.993 + 1.994 + /** 1.995 + * Creates a {@link JAXBContextImpl} that includes the specified additional classes. 1.996 + */ 1.997 + public JAXBContextImpl createAugmented(Class<?> clazz) throws JAXBException { 1.998 + Class[] newList = new Class[classes.length+1]; 1.999 + System.arraycopy(classes,0,newList,0,classes.length); 1.1000 + newList[classes.length] = clazz; 1.1001 + 1.1002 + JAXBContextBuilder builder = new JAXBContextBuilder(this); 1.1003 + builder.setClasses(newList); 1.1004 + return builder.build(); 1.1005 + } 1.1006 + 1.1007 + private static final Comparator<QName> QNAME_COMPARATOR = new Comparator<QName>() { 1.1008 + public int compare(QName lhs, QName rhs) { 1.1009 + int r = lhs.getLocalPart().compareTo(rhs.getLocalPart()); 1.1010 + if(r!=0) return r; 1.1011 + 1.1012 + return lhs.getNamespaceURI().compareTo(rhs.getNamespaceURI()); 1.1013 + } 1.1014 + }; 1.1015 + 1.1016 + public static class JAXBContextBuilder { 1.1017 + 1.1018 + private boolean retainPropertyInfo = false; 1.1019 + private boolean supressAccessorWarnings = false; 1.1020 + private String defaultNsUri = ""; 1.1021 + private @NotNull RuntimeAnnotationReader annotationReader = new RuntimeInlineAnnotationReader(); 1.1022 + private @NotNull Map<Class,Class> subclassReplacements = Collections.emptyMap(); 1.1023 + private boolean c14nSupport = false; 1.1024 + private Class[] classes; 1.1025 + private Collection<TypeReference> typeRefs; 1.1026 + private boolean xmlAccessorFactorySupport = false; 1.1027 + private boolean allNillable; 1.1028 + private boolean improvedXsiTypeHandling = true; 1.1029 + private boolean disableSecurityProcessing = true; 1.1030 + 1.1031 + public JAXBContextBuilder() {}; 1.1032 + 1.1033 + public JAXBContextBuilder(JAXBContextImpl baseImpl) { 1.1034 + this.supressAccessorWarnings = baseImpl.supressAccessorWarnings; 1.1035 + this.retainPropertyInfo = baseImpl.retainPropertyInfo; 1.1036 + this.defaultNsUri = baseImpl.defaultNsUri; 1.1037 + this.annotationReader = baseImpl.annotationReader; 1.1038 + this.subclassReplacements = baseImpl.subclassReplacements; 1.1039 + this.c14nSupport = baseImpl.c14nSupport; 1.1040 + this.classes = baseImpl.classes; 1.1041 + this.typeRefs = baseImpl.bridges.keySet(); 1.1042 + this.xmlAccessorFactorySupport = baseImpl.xmlAccessorFactorySupport; 1.1043 + this.allNillable = baseImpl.allNillable; 1.1044 + this.disableSecurityProcessing = baseImpl.disableSecurityProcessing; 1.1045 + } 1.1046 + 1.1047 + public JAXBContextBuilder setRetainPropertyInfo(boolean val) { 1.1048 + this.retainPropertyInfo = val; 1.1049 + return this; 1.1050 + } 1.1051 + 1.1052 + public JAXBContextBuilder setSupressAccessorWarnings(boolean val) { 1.1053 + this.supressAccessorWarnings = val; 1.1054 + return this; 1.1055 + } 1.1056 + 1.1057 + public JAXBContextBuilder setC14NSupport(boolean val) { 1.1058 + this.c14nSupport = val; 1.1059 + return this; 1.1060 + } 1.1061 + 1.1062 + public JAXBContextBuilder setXmlAccessorFactorySupport(boolean val) { 1.1063 + this.xmlAccessorFactorySupport = val; 1.1064 + return this; 1.1065 + } 1.1066 + 1.1067 + public JAXBContextBuilder setDefaultNsUri(String val) { 1.1068 + this.defaultNsUri = val; 1.1069 + return this; 1.1070 + } 1.1071 + 1.1072 + public JAXBContextBuilder setAllNillable(boolean val) { 1.1073 + this.allNillable = val; 1.1074 + return this; 1.1075 + } 1.1076 + 1.1077 + public JAXBContextBuilder setClasses(Class[] val) { 1.1078 + this.classes = val; 1.1079 + return this; 1.1080 + } 1.1081 + 1.1082 + public JAXBContextBuilder setAnnotationReader(RuntimeAnnotationReader val) { 1.1083 + this.annotationReader = val; 1.1084 + return this; 1.1085 + } 1.1086 + 1.1087 + public JAXBContextBuilder setSubclassReplacements(Map<Class,Class> val) { 1.1088 + this.subclassReplacements = val; 1.1089 + return this; 1.1090 + } 1.1091 + 1.1092 + public JAXBContextBuilder setTypeRefs(Collection<TypeReference> val) { 1.1093 + this.typeRefs = val; 1.1094 + return this; 1.1095 + } 1.1096 + 1.1097 + public JAXBContextBuilder setImprovedXsiTypeHandling(boolean val) { 1.1098 + this.improvedXsiTypeHandling = val; 1.1099 + return this; 1.1100 + } 1.1101 + 1.1102 + public JAXBContextBuilder setDisableSecurityProcessing(boolean val) { 1.1103 + this.disableSecurityProcessing = val; 1.1104 + return this; 1.1105 + } 1.1106 + 1.1107 + public JAXBContextImpl build() throws JAXBException { 1.1108 + 1.1109 + // fool-proof 1.1110 + if (this.defaultNsUri == null) { 1.1111 + this.defaultNsUri = ""; 1.1112 + } 1.1113 + 1.1114 + if (this.subclassReplacements == null) { 1.1115 + this.subclassReplacements = Collections.emptyMap(); 1.1116 + } 1.1117 + 1.1118 + if (this.annotationReader == null) { 1.1119 + this.annotationReader = new RuntimeInlineAnnotationReader(); 1.1120 + } 1.1121 + 1.1122 + if (this.typeRefs == null) { 1.1123 + this.typeRefs = Collections.<TypeReference>emptyList(); 1.1124 + } 1.1125 + 1.1126 + return new JAXBContextImpl(this); 1.1127 + } 1.1128 + 1.1129 + } 1.1130 + 1.1131 +}