src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  54 import javax.xml.bind.annotation.XmlAttachmentRef;
  55 import javax.xml.bind.annotation.XmlList;
  56 import javax.xml.bind.annotation.XmlNs;
  57 import javax.xml.bind.annotation.XmlSchema;
  58 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
  59 import javax.xml.namespace.QName;
  60 import javax.xml.parsers.DocumentBuilder;
  61 import javax.xml.parsers.DocumentBuilderFactory;
  62 import javax.xml.parsers.FactoryConfigurationError;
  63 import javax.xml.parsers.ParserConfigurationException;
  64 import javax.xml.transform.Result;
  65 import javax.xml.transform.Transformer;
  66 import javax.xml.transform.TransformerConfigurationException;
  67 import javax.xml.transform.TransformerFactory;
  68 import javax.xml.transform.sax.SAXResult;
  69 import javax.xml.transform.sax.SAXTransformerFactory;
  70 import javax.xml.transform.sax.TransformerHandler;
  71 
  72 import com.sun.istack.internal.NotNull;
  73 import com.sun.istack.internal.Pool;

  74 import com.sun.xml.internal.bind.api.AccessorException;
  75 import com.sun.xml.internal.bind.api.Bridge;
  76 import com.sun.xml.internal.bind.api.BridgeContext;
  77 import com.sun.xml.internal.bind.api.CompositeStructure;
  78 import com.sun.xml.internal.bind.api.ErrorListener;
  79 import com.sun.xml.internal.bind.api.JAXBRIContext;
  80 import com.sun.xml.internal.bind.api.RawAccessor;
  81 import com.sun.xml.internal.bind.api.TypeReference;
  82 import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
  83 import com.sun.xml.internal.bind.util.Which;
  84 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
  85 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader;
  86 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader;
  87 import com.sun.xml.internal.bind.v2.model.core.Adapter;
  88 import com.sun.xml.internal.bind.v2.model.core.NonElement;
  89 import com.sun.xml.internal.bind.v2.model.core.Ref;
  90 import com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl;
  91 import com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder;
  92 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
  93 import com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator;
  94 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeArrayInfo;
  95 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeBuiltinLeafInfo;
  96 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeClassInfo;
  97 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementInfo;
  98 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeEnumLeafInfo;
  99 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeLeafInfo;
 100 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfo;
 101 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet;
 102 import com.sun.xml.internal.bind.v2.runtime.output.Encoded;
 103 import com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty;
 104 import com.sun.xml.internal.bind.v2.runtime.property.Property;
 105 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
 106 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
 107 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName;
 108 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl;
 109 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
 110 import com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator;
 111 import com.sun.xml.internal.bind.v2.util.EditDistance;
 112 import com.sun.xml.internal.bind.v2.util.QNameMap;

 113 import com.sun.xml.internal.txw2.output.ResultFactory;
 114 
 115 import org.w3c.dom.Document;
 116 import org.w3c.dom.Element;
 117 import org.w3c.dom.Node;
 118 import org.xml.sax.SAXException;
 119 import org.xml.sax.SAXParseException;
 120 import org.xml.sax.helpers.DefaultHandler;
 121 
 122 /**
 123  * This class provides the implementation of JAXBContext.
 124  *
 125  */
 126 public final class JAXBContextImpl extends JAXBRIContext {
 127 
 128     /**
 129      * All the bridge classes.
 130      */
 131     private final Map<TypeReference,Bridge> bridges = new LinkedHashMap<TypeReference,Bridge>();
 132 


 203      * true to reorder attributes lexicographically in preparation of the c14n support.
 204      */
 205     protected final boolean c14nSupport;
 206 
 207     /**
 208      * Flag that user has provided a custom AccessorFactory for JAXB to use
 209      */
 210     public final boolean xmlAccessorFactorySupport;
 211 
 212     /**
 213      * @see JAXBRIContext#TREAT_EVERYTHING_NILLABLE
 214      */
 215     public final boolean allNillable;
 216 
 217     /**
 218      * Store properties, so that they can be recovered in the run (is here because of JSON encoding of Jersey).
 219      */
 220     public final boolean retainPropertyInfo;
 221 
 222     /**
 223      * Supress reflection accessor warnings.
 224      */
 225     public final boolean supressAccessorWarnings;
 226 
 227     /**
 228      * Improved xsi type handling.
 229      */
 230     public final boolean improvedXsiTypeHandling;
 231 





 232     private WeakReference<RuntimeTypeInfoSet> typeInfoSetCache;
 233 
 234     private @NotNull RuntimeAnnotationReader annotationReader;
 235 
 236     private /*almost final*/ boolean hasSwaRef;
 237     private final @NotNull Map<Class,Class> subclassReplacements;
 238 
 239     /**
 240      * If true, we aim for faster {@link JAXBContext} instanciation performance,
 241      * instead of going after efficient sustained unmarshalling/marshalling performance.
 242      *
 243      * @since 2.0.4
 244      */
 245     public final boolean fastBoot;
 246 
 247     private Set<XmlNs> xmlNsSet = null;
 248 
 249     /**
 250      * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 251      *
 252      * @return set of all present XmlNs annotations
 253      */
 254     public Set<XmlNs> getXmlNsSet() {
 255         return xmlNsSet;
 256     }
 257 
 258     private JAXBContextImpl(JAXBContextBuilder builder) throws JAXBException {
 259 
 260         this.defaultNsUri = builder.defaultNsUri;
 261         this.retainPropertyInfo = builder.retainPropertyInfo;
 262         this.annotationReader = builder.annotationReader;
 263         this.subclassReplacements = builder.subclassReplacements;
 264         this.c14nSupport = builder.c14nSupport;
 265         this.classes = builder.classes;
 266         this.xmlAccessorFactorySupport = builder.xmlAccessorFactorySupport;
 267         this.allNillable = builder.allNillable;
 268         this.supressAccessorWarnings = builder.supressAccessorWarnings;
 269         this.improvedXsiTypeHandling = builder.improvedXsiTypeHandling;

 270 
 271         Collection<TypeReference> typeRefs = builder.typeRefs;
 272 
 273         boolean fastB;
 274         try {
 275             fastB = Boolean.getBoolean(JAXBContextImpl.class.getName()+".fastBoot");
 276         } catch (SecurityException e) {
 277             fastB = false;
 278         }
 279         this.fastBoot = fastB;
 280 
 281         System.arraycopy(classes,0,this.classes,0,classes.length);
 282 
 283         RuntimeTypeInfoSet typeSet = getTypeInfoSet();
 284 
 285         // at least prepare the empty table so that we don't have to check for null later
 286         elements.put(null,new LinkedHashMap<QName, ElementBeanInfoImpl>());
 287 
 288         // recognize leaf bean infos
 289         for( RuntimeBuiltinLeafInfo leaf : RuntimeBuiltinLeafInfoImpl.builtinBeanInfos ) {
 290             LeafBeanInfoImpl<?> bi = new LeafBeanInfoImpl(this,leaf);
 291             beanInfoMap.put(leaf.getClazz(),bi);
 292             for( QName t : bi.getTypeNames() )
 293                 typeMap.put(t,bi);
 294         }
 295 
 296         for (RuntimeEnumLeafInfo e : typeSet.enums().values()) {
 297             JaxBeanInfo<?> bi = getOrCreate(e);
 298             for (QName qn : bi.getTypeNames())
 299                 typeMap.put( qn, bi );
 300             if(e.isElement())
 301                 rootMap.put( e.getElementName(), bi );
 302         }


 684             utf8nameTable = x;
 685         }
 686         return utf8nameTable;
 687     }
 688 
 689     public int getNumberOfLocalNames() {
 690         return nameList.localNames.length;
 691     }
 692 
 693     public int getNumberOfElementNames() {
 694         return nameList.numberOfElementNames;
 695     }
 696 
 697     public int getNumberOfAttributeNames() {
 698         return nameList.numberOfAttributeNames;
 699     }
 700 
 701     /**
 702      * Creates a new identity transformer.
 703      */
 704     static Transformer createTransformer() {
 705         try {
 706             if (tf==null) {
 707                 synchronized(JAXBContextImpl.class) {
 708                     if (tf==null) {
 709                         tf = (SAXTransformerFactory)TransformerFactory.newInstance();
 710                     }
 711                 }
 712             }
 713             return tf.newTransformer();
 714         } catch (TransformerConfigurationException e) {
 715             throw new Error(e); // impossible
 716         }
 717     }
 718 
 719     /**
 720      * Creates a new identity transformer.
 721      */
 722     public static TransformerHandler createTransformerHandler() {
 723         try {
 724             if (tf==null) {
 725                 synchronized(JAXBContextImpl.class) {
 726                     if (tf==null) {
 727                         tf = (SAXTransformerFactory)TransformerFactory.newInstance();
 728                     }
 729                 }
 730             }
 731             return tf.newTransformerHandler();
 732         } catch (TransformerConfigurationException e) {
 733             throw new Error(e); // impossible
 734         }
 735     }
 736 
 737     /**
 738      * Creates a new DOM document.
 739      */
 740     static Document createDom() {
 741         synchronized(JAXBContextImpl.class) {
 742             if(db==null) {
 743                 try {
 744                     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 745                     dbf.setNamespaceAware(true);
 746                     db = dbf.newDocumentBuilder();
 747                 } catch (ParserConfigurationException e) {
 748                     // impossible
 749                     throw new FactoryConfigurationError(e);
 750                 }
 751             }
 752             return db.newDocument();
 753         }
 754     }
 755 
 756     public MarshallerImpl createMarshaller() {
 757         return new MarshallerImpl(this,null);
 758     }
 759 
 760     public UnmarshallerImpl createUnmarshaller() {
 761         return new UnmarshallerImpl(this,null);
 762     }
 763 
 764     public Validator createValidator() {
 765         throw new UnsupportedOperationException(Messages.NOT_IMPLEMENTED_IN_2_0.format());


1038             int r = lhs.getLocalPart().compareTo(rhs.getLocalPart());
1039             if(r!=0)    return r;
1040 
1041             return lhs.getNamespaceURI().compareTo(rhs.getNamespaceURI());
1042         }
1043     };
1044 
1045     public static class JAXBContextBuilder {
1046 
1047         private boolean retainPropertyInfo = false;
1048         private boolean supressAccessorWarnings = false;
1049         private String defaultNsUri = "";
1050         private @NotNull RuntimeAnnotationReader annotationReader = new RuntimeInlineAnnotationReader();
1051         private @NotNull Map<Class,Class> subclassReplacements = Collections.emptyMap();
1052         private boolean c14nSupport = false;
1053         private Class[] classes;
1054         private Collection<TypeReference> typeRefs;
1055         private boolean xmlAccessorFactorySupport = false;
1056         private boolean allNillable;
1057         private boolean improvedXsiTypeHandling = true;

1058 
1059         public JAXBContextBuilder() {};
1060 
1061         public JAXBContextBuilder(JAXBContextImpl baseImpl) {
1062             this.supressAccessorWarnings = baseImpl.supressAccessorWarnings;
1063             this.retainPropertyInfo = baseImpl.retainPropertyInfo;
1064             this.defaultNsUri = baseImpl.defaultNsUri;
1065             this.annotationReader = baseImpl.annotationReader;
1066             this.subclassReplacements = baseImpl.subclassReplacements;
1067             this.c14nSupport = baseImpl.c14nSupport;
1068             this.classes = baseImpl.classes;
1069             this.typeRefs = baseImpl.bridges.keySet();
1070             this.xmlAccessorFactorySupport = baseImpl.xmlAccessorFactorySupport;
1071             this.allNillable = baseImpl.allNillable;

1072         }
1073 
1074         public JAXBContextBuilder setRetainPropertyInfo(boolean val) {
1075             this.retainPropertyInfo = val;
1076             return this;
1077         }
1078 
1079         public JAXBContextBuilder setSupressAccessorWarnings(boolean val) {
1080             this.supressAccessorWarnings = val;
1081             return this;
1082         }
1083 
1084         public JAXBContextBuilder setC14NSupport(boolean val) {
1085             this.c14nSupport = val;
1086             return this;
1087         }
1088 
1089         public JAXBContextBuilder setXmlAccessorFactorySupport(boolean val) {
1090             this.xmlAccessorFactorySupport = val;
1091             return this;


1106             return this;
1107         }
1108 
1109         public JAXBContextBuilder setAnnotationReader(RuntimeAnnotationReader val) {
1110             this.annotationReader = val;
1111             return this;
1112         }
1113 
1114         public JAXBContextBuilder setSubclassReplacements(Map<Class,Class> val) {
1115             this.subclassReplacements = val;
1116             return this;
1117         }
1118 
1119         public JAXBContextBuilder setTypeRefs(Collection<TypeReference> val) {
1120             this.typeRefs = val;
1121             return this;
1122         }
1123 
1124         public JAXBContextBuilder setImprovedXsiTypeHandling(boolean val) {
1125             this.improvedXsiTypeHandling = val;





1126             return this;
1127         }
1128 
1129         public JAXBContextImpl build() throws JAXBException {
1130 
1131             // fool-proof
1132             if (this.defaultNsUri == null) {
1133                 this.defaultNsUri = "";
1134             }
1135 
1136             if (this.subclassReplacements == null) {
1137                 this.subclassReplacements = Collections.emptyMap();
1138             }
1139 
1140             if (this.annotationReader == null) {
1141                 this.annotationReader = new RuntimeInlineAnnotationReader();
1142             }
1143 
1144             if (this.typeRefs == null) {
1145                 this.typeRefs = Collections.<TypeReference>emptyList();
   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  54 import javax.xml.bind.annotation.XmlAttachmentRef;
  55 import javax.xml.bind.annotation.XmlList;
  56 import javax.xml.bind.annotation.XmlNs;
  57 import javax.xml.bind.annotation.XmlSchema;
  58 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
  59 import javax.xml.namespace.QName;
  60 import javax.xml.parsers.DocumentBuilder;
  61 import javax.xml.parsers.DocumentBuilderFactory;
  62 import javax.xml.parsers.FactoryConfigurationError;
  63 import javax.xml.parsers.ParserConfigurationException;
  64 import javax.xml.transform.Result;
  65 import javax.xml.transform.Transformer;
  66 import javax.xml.transform.TransformerConfigurationException;
  67 import javax.xml.transform.TransformerFactory;
  68 import javax.xml.transform.sax.SAXResult;
  69 import javax.xml.transform.sax.SAXTransformerFactory;
  70 import javax.xml.transform.sax.TransformerHandler;
  71 
  72 import com.sun.istack.internal.NotNull;
  73 import com.sun.istack.internal.Pool;
  74 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
  75 import com.sun.xml.internal.bind.api.AccessorException;
  76 import com.sun.xml.internal.bind.api.Bridge;
  77 import com.sun.xml.internal.bind.api.BridgeContext;
  78 import com.sun.xml.internal.bind.api.CompositeStructure;
  79 import com.sun.xml.internal.bind.api.ErrorListener;
  80 import com.sun.xml.internal.bind.api.JAXBRIContext;
  81 import com.sun.xml.internal.bind.api.RawAccessor;
  82 import com.sun.xml.internal.bind.api.TypeReference;
  83 import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
  84 import com.sun.xml.internal.bind.util.Which;

  85 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader;
  86 import com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader;
  87 import com.sun.xml.internal.bind.v2.model.core.Adapter;
  88 import com.sun.xml.internal.bind.v2.model.core.NonElement;
  89 import com.sun.xml.internal.bind.v2.model.core.Ref;
  90 import com.sun.xml.internal.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl;
  91 import com.sun.xml.internal.bind.v2.model.impl.RuntimeModelBuilder;
  92 import com.sun.xml.internal.bind.v2.model.nav.Navigator;
  93 import com.sun.xml.internal.bind.v2.model.nav.ReflectionNavigator;
  94 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeArrayInfo;
  95 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeBuiltinLeafInfo;
  96 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeClassInfo;
  97 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeElementInfo;
  98 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeEnumLeafInfo;
  99 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeLeafInfo;
 100 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfo;
 101 import com.sun.xml.internal.bind.v2.model.runtime.RuntimeTypeInfoSet;
 102 import com.sun.xml.internal.bind.v2.runtime.output.Encoded;
 103 import com.sun.xml.internal.bind.v2.runtime.property.AttributeProperty;
 104 import com.sun.xml.internal.bind.v2.runtime.property.Property;
 105 import com.sun.xml.internal.bind.v2.runtime.reflect.Accessor;
 106 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.Loader;
 107 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.TagName;
 108 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl;
 109 import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
 110 import com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator;
 111 import com.sun.xml.internal.bind.v2.util.EditDistance;
 112 import com.sun.xml.internal.bind.v2.util.QNameMap;
 113 import com.sun.xml.internal.bind.v2.util.XmlFactory;
 114 import com.sun.xml.internal.txw2.output.ResultFactory;
 115 
 116 import org.w3c.dom.Document;
 117 import org.w3c.dom.Element;
 118 import org.w3c.dom.Node;
 119 import org.xml.sax.SAXException;
 120 import org.xml.sax.SAXParseException;
 121 import org.xml.sax.helpers.DefaultHandler;
 122 
 123 /**
 124  * This class provides the implementation of JAXBContext.
 125  *
 126  */
 127 public final class JAXBContextImpl extends JAXBRIContext {
 128 
 129     /**
 130      * All the bridge classes.
 131      */
 132     private final Map<TypeReference,Bridge> bridges = new LinkedHashMap<TypeReference,Bridge>();
 133 


 204      * true to reorder attributes lexicographically in preparation of the c14n support.
 205      */
 206     protected final boolean c14nSupport;
 207 
 208     /**
 209      * Flag that user has provided a custom AccessorFactory for JAXB to use
 210      */
 211     public final boolean xmlAccessorFactorySupport;
 212 
 213     /**
 214      * @see JAXBRIContext#TREAT_EVERYTHING_NILLABLE
 215      */
 216     public final boolean allNillable;
 217 
 218     /**
 219      * Store properties, so that they can be recovered in the run (is here because of JSON encoding of Jersey).
 220      */
 221     public final boolean retainPropertyInfo;
 222 
 223     /**
 224      * Suppress reflection accessor warnings.
 225      */
 226     public final boolean supressAccessorWarnings;
 227 
 228     /**
 229      * Improved xsi type handling.
 230      */
 231     public final boolean improvedXsiTypeHandling;
 232 
 233     /**
 234      * Disable security processing.
 235      */
 236     public final boolean disableSecurityProcessing;
 237 
 238     private WeakReference<RuntimeTypeInfoSet> typeInfoSetCache;
 239 
 240     private @NotNull RuntimeAnnotationReader annotationReader;
 241 
 242     private /*almost final*/ boolean hasSwaRef;
 243     private final @NotNull Map<Class,Class> subclassReplacements;
 244 
 245     /**
 246      * If true, we aim for faster {@link JAXBContext} instantiation performance,
 247      * instead of going after efficient sustained unmarshalling/marshalling performance.
 248      *
 249      * @since 2.0.4
 250      */
 251     public final boolean fastBoot;
 252 
 253     private Set<XmlNs> xmlNsSet = null;
 254 
 255     /**
 256      * Returns declared XmlNs annotations (from package-level annotation XmlSchema
 257      *
 258      * @return set of all present XmlNs annotations
 259      */
 260     public Set<XmlNs> getXmlNsSet() {
 261         return xmlNsSet;
 262     }
 263 
 264     private JAXBContextImpl(JAXBContextBuilder builder) throws JAXBException {
 265 
 266         this.defaultNsUri = builder.defaultNsUri;
 267         this.retainPropertyInfo = builder.retainPropertyInfo;
 268         this.annotationReader = builder.annotationReader;
 269         this.subclassReplacements = builder.subclassReplacements;
 270         this.c14nSupport = builder.c14nSupport;
 271         this.classes = builder.classes;
 272         this.xmlAccessorFactorySupport = builder.xmlAccessorFactorySupport;
 273         this.allNillable = builder.allNillable;
 274         this.supressAccessorWarnings = builder.supressAccessorWarnings;
 275         this.improvedXsiTypeHandling = builder.improvedXsiTypeHandling;
 276         this.disableSecurityProcessing = builder.disableSecurityProcessing;
 277 
 278         Collection<TypeReference> typeRefs = builder.typeRefs;
 279 
 280         boolean fastB;
 281         try {
 282             fastB = Boolean.getBoolean(JAXBContextImpl.class.getName()+".fastBoot");
 283         } catch (SecurityException e) {
 284             fastB = false;
 285         }
 286         this.fastBoot = fastB;
 287 


 288         RuntimeTypeInfoSet typeSet = getTypeInfoSet();
 289 
 290         // at least prepare the empty table so that we don't have to check for null later
 291         elements.put(null,new LinkedHashMap<QName, ElementBeanInfoImpl>());
 292 
 293         // recognize leaf bean infos
 294         for( RuntimeBuiltinLeafInfo leaf : RuntimeBuiltinLeafInfoImpl.builtinBeanInfos ) {
 295             LeafBeanInfoImpl<?> bi = new LeafBeanInfoImpl(this,leaf);
 296             beanInfoMap.put(leaf.getClazz(),bi);
 297             for( QName t : bi.getTypeNames() )
 298                 typeMap.put(t,bi);
 299         }
 300 
 301         for (RuntimeEnumLeafInfo e : typeSet.enums().values()) {
 302             JaxBeanInfo<?> bi = getOrCreate(e);
 303             for (QName qn : bi.getTypeNames())
 304                 typeMap.put( qn, bi );
 305             if(e.isElement())
 306                 rootMap.put( e.getElementName(), bi );
 307         }


 689             utf8nameTable = x;
 690         }
 691         return utf8nameTable;
 692     }
 693 
 694     public int getNumberOfLocalNames() {
 695         return nameList.localNames.length;
 696     }
 697 
 698     public int getNumberOfElementNames() {
 699         return nameList.numberOfElementNames;
 700     }
 701 
 702     public int getNumberOfAttributeNames() {
 703         return nameList.numberOfAttributeNames;
 704     }
 705 
 706     /**
 707      * Creates a new identity transformer.
 708      */
 709     static Transformer createTransformer(boolean disableSecureProcessing) {
 710         try {
 711             if (tf==null) {
 712                 synchronized(JAXBContextImpl.class) {
 713                     if (tf==null) {
 714                         tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
 715                     }
 716                 }
 717             }
 718             return tf.newTransformer();
 719         } catch (TransformerConfigurationException e) {
 720             throw new Error(e); // impossible
 721         }
 722     }
 723 
 724     /**
 725      * Creates a new identity transformer.
 726      */
 727     public static TransformerHandler createTransformerHandler(boolean disableSecureProcessing) {
 728         try {
 729             if (tf==null) {
 730                 synchronized(JAXBContextImpl.class) {
 731                     if (tf==null) {
 732                         tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
 733                     }
 734                 }
 735             }
 736             return tf.newTransformerHandler();
 737         } catch (TransformerConfigurationException e) {
 738             throw new Error(e); // impossible
 739         }
 740     }
 741 
 742     /**
 743      * Creates a new DOM document.
 744      */
 745     static Document createDom(boolean disableSecurityProcessing) {
 746         synchronized(JAXBContextImpl.class) {
 747             if(db==null) {
 748                 try {
 749                     DocumentBuilderFactory dbf = XmlFactory.createDocumentBuilderFactory(disableSecurityProcessing);

 750                     db = dbf.newDocumentBuilder();
 751                 } catch (ParserConfigurationException e) {
 752                     // impossible
 753                     throw new FactoryConfigurationError(e);
 754                 }
 755             }
 756             return db.newDocument();
 757         }
 758     }
 759 
 760     public MarshallerImpl createMarshaller() {
 761         return new MarshallerImpl(this,null);
 762     }
 763 
 764     public UnmarshallerImpl createUnmarshaller() {
 765         return new UnmarshallerImpl(this,null);
 766     }
 767 
 768     public Validator createValidator() {
 769         throw new UnsupportedOperationException(Messages.NOT_IMPLEMENTED_IN_2_0.format());


1042             int r = lhs.getLocalPart().compareTo(rhs.getLocalPart());
1043             if(r!=0)    return r;
1044 
1045             return lhs.getNamespaceURI().compareTo(rhs.getNamespaceURI());
1046         }
1047     };
1048 
1049     public static class JAXBContextBuilder {
1050 
1051         private boolean retainPropertyInfo = false;
1052         private boolean supressAccessorWarnings = false;
1053         private String defaultNsUri = "";
1054         private @NotNull RuntimeAnnotationReader annotationReader = new RuntimeInlineAnnotationReader();
1055         private @NotNull Map<Class,Class> subclassReplacements = Collections.emptyMap();
1056         private boolean c14nSupport = false;
1057         private Class[] classes;
1058         private Collection<TypeReference> typeRefs;
1059         private boolean xmlAccessorFactorySupport = false;
1060         private boolean allNillable;
1061         private boolean improvedXsiTypeHandling = true;
1062         private boolean disableSecurityProcessing = true;
1063 
1064         public JAXBContextBuilder() {};
1065 
1066         public JAXBContextBuilder(JAXBContextImpl baseImpl) {
1067             this.supressAccessorWarnings = baseImpl.supressAccessorWarnings;
1068             this.retainPropertyInfo = baseImpl.retainPropertyInfo;
1069             this.defaultNsUri = baseImpl.defaultNsUri;
1070             this.annotationReader = baseImpl.annotationReader;
1071             this.subclassReplacements = baseImpl.subclassReplacements;
1072             this.c14nSupport = baseImpl.c14nSupport;
1073             this.classes = baseImpl.classes;
1074             this.typeRefs = baseImpl.bridges.keySet();
1075             this.xmlAccessorFactorySupport = baseImpl.xmlAccessorFactorySupport;
1076             this.allNillable = baseImpl.allNillable;
1077             this.disableSecurityProcessing = baseImpl.disableSecurityProcessing;
1078         }
1079 
1080         public JAXBContextBuilder setRetainPropertyInfo(boolean val) {
1081             this.retainPropertyInfo = val;
1082             return this;
1083         }
1084 
1085         public JAXBContextBuilder setSupressAccessorWarnings(boolean val) {
1086             this.supressAccessorWarnings = val;
1087             return this;
1088         }
1089 
1090         public JAXBContextBuilder setC14NSupport(boolean val) {
1091             this.c14nSupport = val;
1092             return this;
1093         }
1094 
1095         public JAXBContextBuilder setXmlAccessorFactorySupport(boolean val) {
1096             this.xmlAccessorFactorySupport = val;
1097             return this;


1112             return this;
1113         }
1114 
1115         public JAXBContextBuilder setAnnotationReader(RuntimeAnnotationReader val) {
1116             this.annotationReader = val;
1117             return this;
1118         }
1119 
1120         public JAXBContextBuilder setSubclassReplacements(Map<Class,Class> val) {
1121             this.subclassReplacements = val;
1122             return this;
1123         }
1124 
1125         public JAXBContextBuilder setTypeRefs(Collection<TypeReference> val) {
1126             this.typeRefs = val;
1127             return this;
1128         }
1129 
1130         public JAXBContextBuilder setImprovedXsiTypeHandling(boolean val) {
1131             this.improvedXsiTypeHandling = val;
1132             return this;
1133         }
1134 
1135         public JAXBContextBuilder setDisableSecurityProcessing(boolean val) {
1136             this.disableSecurityProcessing = val;
1137             return this;
1138         }
1139 
1140         public JAXBContextImpl build() throws JAXBException {
1141 
1142             // fool-proof
1143             if (this.defaultNsUri == null) {
1144                 this.defaultNsUri = "";
1145             }
1146 
1147             if (this.subclassReplacements == null) {
1148                 this.subclassReplacements = Collections.emptyMap();
1149             }
1150 
1151             if (this.annotationReader == null) {
1152                 this.annotationReader = new RuntimeInlineAnnotationReader();
1153             }
1154 
1155             if (this.typeRefs == null) {
1156                 this.typeRefs = Collections.<TypeReference>emptyList();