1 /*
2 * Copyright (c) 1997, 2013, 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
225 public final boolean disableSecurityProcessing;
226
227 private WeakReference<RuntimeTypeInfoSet> typeInfoSetCache;
228
229 private @NotNull RuntimeAnnotationReader annotationReader;
230
231 private /*almost final*/ boolean hasSwaRef;
232 private final @NotNull Map<Class,Class> subclassReplacements;
233
234 /**
235 * If true, we aim for faster {@link JAXBContext} instantiation performance,
236 * instead of going after efficient sustained unmarshalling/marshalling performance.
237 *
238 * @since 2.0.4
239 */
240 public final boolean fastBoot;
241
242 private Set<XmlNs> xmlNsSet = null;
243
244 /**
245 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
246 *
247 * @return set of all present XmlNs annotations
248 */
249 public Set<XmlNs> getXmlNsSet() {
250 return xmlNsSet;
251 }
252
253 private JAXBContextImpl(JAXBContextBuilder builder) throws JAXBException {
254
255 this.defaultNsUri = builder.defaultNsUri;
256 this.retainPropertyInfo = builder.retainPropertyInfo;
257 this.annotationReader = builder.annotationReader;
258 this.subclassReplacements = builder.subclassReplacements;
259 this.c14nSupport = builder.c14nSupport;
260 this.classes = builder.classes;
261 this.xmlAccessorFactorySupport = builder.xmlAccessorFactorySupport;
262 this.allNillable = builder.allNillable;
263 this.supressAccessorWarnings = builder.supressAccessorWarnings;
264 this.improvedXsiTypeHandling = builder.improvedXsiTypeHandling;
265 this.disableSecurityProcessing = builder.disableSecurityProcessing;
266
267 Collection<TypeReference> typeRefs = builder.typeRefs;
268
269 boolean fastB;
270 try {
271 fastB = Boolean.getBoolean(JAXBContextImpl.class.getName()+".fastBoot");
272 } catch (SecurityException e) {
273 fastB = false;
274 }
275 this.fastBoot = fastB;
276
277 RuntimeTypeInfoSet typeSet = getTypeInfoSet();
278
279 // at least prepare the empty table so that we don't have to check for null later
280 elements.put(null,new LinkedHashMap<QName, ElementBeanInfoImpl>());
281
282 // recognize leaf bean infos
283 for( RuntimeBuiltinLeafInfo leaf : RuntimeBuiltinLeafInfoImpl.builtinBeanInfos ) {
284 LeafBeanInfoImpl<?> bi = new LeafBeanInfoImpl(this,leaf);
285 beanInfoMap.put(leaf.getClazz(),bi);
1007 if(r!=0) return r;
1008
1009 return lhs.getNamespaceURI().compareTo(rhs.getNamespaceURI());
1010 }
1011 };
1012
1013 public static class JAXBContextBuilder {
1014
1015 private boolean retainPropertyInfo = false;
1016 private boolean supressAccessorWarnings = false;
1017 private String defaultNsUri = "";
1018 private @NotNull RuntimeAnnotationReader annotationReader = new RuntimeInlineAnnotationReader();
1019 private @NotNull Map<Class,Class> subclassReplacements = Collections.emptyMap();
1020 private boolean c14nSupport = false;
1021 private Class[] classes;
1022 private Collection<TypeReference> typeRefs;
1023 private boolean xmlAccessorFactorySupport = false;
1024 private boolean allNillable;
1025 private boolean improvedXsiTypeHandling = true;
1026 private boolean disableSecurityProcessing = true;
1027
1028 public JAXBContextBuilder() {};
1029
1030 public JAXBContextBuilder(JAXBContextImpl baseImpl) {
1031 this.supressAccessorWarnings = baseImpl.supressAccessorWarnings;
1032 this.retainPropertyInfo = baseImpl.retainPropertyInfo;
1033 this.defaultNsUri = baseImpl.defaultNsUri;
1034 this.annotationReader = baseImpl.annotationReader;
1035 this.subclassReplacements = baseImpl.subclassReplacements;
1036 this.c14nSupport = baseImpl.c14nSupport;
1037 this.classes = baseImpl.classes;
1038 this.typeRefs = baseImpl.bridges.keySet();
1039 this.xmlAccessorFactorySupport = baseImpl.xmlAccessorFactorySupport;
1040 this.allNillable = baseImpl.allNillable;
1041 this.disableSecurityProcessing = baseImpl.disableSecurityProcessing;
1042 }
1043
1044 public JAXBContextBuilder setRetainPropertyInfo(boolean val) {
1045 this.retainPropertyInfo = val;
1046 return this;
1047 }
1048
1049 public JAXBContextBuilder setSupressAccessorWarnings(boolean val) {
1050 this.supressAccessorWarnings = val;
1051 return this;
1052 }
1053
1054 public JAXBContextBuilder setC14NSupport(boolean val) {
1055 this.c14nSupport = val;
1056 return this;
1057 }
1058
1059 public JAXBContextBuilder setXmlAccessorFactorySupport(boolean val) {
1060 this.xmlAccessorFactorySupport = val;
1061 return this;
1081 return this;
1082 }
1083
1084 public JAXBContextBuilder setSubclassReplacements(Map<Class,Class> val) {
1085 this.subclassReplacements = val;
1086 return this;
1087 }
1088
1089 public JAXBContextBuilder setTypeRefs(Collection<TypeReference> val) {
1090 this.typeRefs = val;
1091 return this;
1092 }
1093
1094 public JAXBContextBuilder setImprovedXsiTypeHandling(boolean val) {
1095 this.improvedXsiTypeHandling = val;
1096 return this;
1097 }
1098
1099 public JAXBContextBuilder setDisableSecurityProcessing(boolean val) {
1100 this.disableSecurityProcessing = val;
1101 return this;
1102 }
1103
1104 public JAXBContextImpl build() throws JAXBException {
1105
1106 // fool-proof
1107 if (this.defaultNsUri == null) {
1108 this.defaultNsUri = "";
1109 }
1110
1111 if (this.subclassReplacements == null) {
1112 this.subclassReplacements = Collections.emptyMap();
1113 }
1114
1115 if (this.annotationReader == null) {
1116 this.annotationReader = new RuntimeInlineAnnotationReader();
1117 }
1118
1119 if (this.typeRefs == null) {
1120 this.typeRefs = Collections.<TypeReference>emptyList();
|
1 /*
2 * Copyright (c) 1997, 2017, 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
225 public final boolean disableSecurityProcessing;
226
227 private WeakReference<RuntimeTypeInfoSet> typeInfoSetCache;
228
229 private @NotNull RuntimeAnnotationReader annotationReader;
230
231 private /*almost final*/ boolean hasSwaRef;
232 private final @NotNull Map<Class,Class> subclassReplacements;
233
234 /**
235 * If true, we aim for faster {@link JAXBContext} instantiation performance,
236 * instead of going after efficient sustained unmarshalling/marshalling performance.
237 *
238 * @since 2.0.4
239 */
240 public final boolean fastBoot;
241
242 private Set<XmlNs> xmlNsSet = null;
243
244 /**
245 * If true, despite the specification, unmarshall child element with parent namespace, if child namespace is not specified.
246 * The default value is null for System {code}com.sun.xml.internal.bind.backupWithParentNamespace{code} property to be used,
247 * and false is assumed if it's not set either.
248 *
249 * Boolean
250 * @since 2.3.0
251 */
252 public Boolean backupWithParentNamespace = null;
253
254 /**
255 * Returns declared XmlNs annotations (from package-level annotation XmlSchema
256 *
257 * @return set of all present XmlNs annotations
258 */
259 public Set<XmlNs> getXmlNsSet() {
260 return xmlNsSet;
261 }
262
263 private JAXBContextImpl(JAXBContextBuilder builder) throws JAXBException {
264
265 this.defaultNsUri = builder.defaultNsUri;
266 this.retainPropertyInfo = builder.retainPropertyInfo;
267 this.annotationReader = builder.annotationReader;
268 this.subclassReplacements = builder.subclassReplacements;
269 this.c14nSupport = builder.c14nSupport;
270 this.classes = builder.classes;
271 this.xmlAccessorFactorySupport = builder.xmlAccessorFactorySupport;
272 this.allNillable = builder.allNillable;
273 this.supressAccessorWarnings = builder.supressAccessorWarnings;
274 this.improvedXsiTypeHandling = builder.improvedXsiTypeHandling;
275 this.disableSecurityProcessing = builder.disableSecurityProcessing;
276 this.backupWithParentNamespace = builder.backupWithParentNamespace;
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);
1018 if(r!=0) return r;
1019
1020 return lhs.getNamespaceURI().compareTo(rhs.getNamespaceURI());
1021 }
1022 };
1023
1024 public static class JAXBContextBuilder {
1025
1026 private boolean retainPropertyInfo = false;
1027 private boolean supressAccessorWarnings = false;
1028 private String defaultNsUri = "";
1029 private @NotNull RuntimeAnnotationReader annotationReader = new RuntimeInlineAnnotationReader();
1030 private @NotNull Map<Class,Class> subclassReplacements = Collections.emptyMap();
1031 private boolean c14nSupport = false;
1032 private Class[] classes;
1033 private Collection<TypeReference> typeRefs;
1034 private boolean xmlAccessorFactorySupport = false;
1035 private boolean allNillable;
1036 private boolean improvedXsiTypeHandling = true;
1037 private boolean disableSecurityProcessing = true;
1038 private Boolean backupWithParentNamespace = null; // null for System property to be used
1039
1040 public JAXBContextBuilder() {};
1041
1042 public JAXBContextBuilder(JAXBContextImpl baseImpl) {
1043 this.supressAccessorWarnings = baseImpl.supressAccessorWarnings;
1044 this.retainPropertyInfo = baseImpl.retainPropertyInfo;
1045 this.defaultNsUri = baseImpl.defaultNsUri;
1046 this.annotationReader = baseImpl.annotationReader;
1047 this.subclassReplacements = baseImpl.subclassReplacements;
1048 this.c14nSupport = baseImpl.c14nSupport;
1049 this.classes = baseImpl.classes;
1050 this.typeRefs = baseImpl.bridges.keySet();
1051 this.xmlAccessorFactorySupport = baseImpl.xmlAccessorFactorySupport;
1052 this.allNillable = baseImpl.allNillable;
1053 this.disableSecurityProcessing = baseImpl.disableSecurityProcessing;
1054 this.backupWithParentNamespace = baseImpl.backupWithParentNamespace;
1055 }
1056
1057 public JAXBContextBuilder setRetainPropertyInfo(boolean val) {
1058 this.retainPropertyInfo = val;
1059 return this;
1060 }
1061
1062 public JAXBContextBuilder setSupressAccessorWarnings(boolean val) {
1063 this.supressAccessorWarnings = val;
1064 return this;
1065 }
1066
1067 public JAXBContextBuilder setC14NSupport(boolean val) {
1068 this.c14nSupport = val;
1069 return this;
1070 }
1071
1072 public JAXBContextBuilder setXmlAccessorFactorySupport(boolean val) {
1073 this.xmlAccessorFactorySupport = val;
1074 return this;
1094 return this;
1095 }
1096
1097 public JAXBContextBuilder setSubclassReplacements(Map<Class,Class> val) {
1098 this.subclassReplacements = val;
1099 return this;
1100 }
1101
1102 public JAXBContextBuilder setTypeRefs(Collection<TypeReference> val) {
1103 this.typeRefs = val;
1104 return this;
1105 }
1106
1107 public JAXBContextBuilder setImprovedXsiTypeHandling(boolean val) {
1108 this.improvedXsiTypeHandling = val;
1109 return this;
1110 }
1111
1112 public JAXBContextBuilder setDisableSecurityProcessing(boolean val) {
1113 this.disableSecurityProcessing = val;
1114 return this;
1115 }
1116
1117 public JAXBContextBuilder setBackupWithParentNamespace(Boolean backupWithParentNamespace) {
1118 this.backupWithParentNamespace = backupWithParentNamespace;
1119 return this;
1120 }
1121
1122 public JAXBContextImpl build() throws JAXBException {
1123
1124 // fool-proof
1125 if (this.defaultNsUri == null) {
1126 this.defaultNsUri = "";
1127 }
1128
1129 if (this.subclassReplacements == null) {
1130 this.subclassReplacements = Collections.emptyMap();
1131 }
1132
1133 if (this.annotationReader == null) {
1134 this.annotationReader = new RuntimeInlineAnnotationReader();
1135 }
1136
1137 if (this.typeRefs == null) {
1138 this.typeRefs = Collections.<TypeReference>emptyList();
|