src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -69,21 +69,21 @@
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Pool;
+import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import com.sun.xml.internal.bind.api.AccessorException;
import com.sun.xml.internal.bind.api.Bridge;
import com.sun.xml.internal.bind.api.BridgeContext;
import com.sun.xml.internal.bind.api.CompositeStructure;
import com.sun.xml.internal.bind.api.ErrorListener;
import com.sun.xml.internal.bind.api.JAXBRIContext;
import com.sun.xml.internal.bind.api.RawAccessor;
import com.sun.xml.internal.bind.api.TypeReference;
import com.sun.xml.internal.bind.unmarshaller.DOMScanner;
import com.sun.xml.internal.bind.util.Which;
-import com.sun.xml.internal.bind.v2.WellKnownNamespace;
import com.sun.xml.internal.bind.v2.model.annotation.RuntimeAnnotationReader;
import com.sun.xml.internal.bind.v2.model.annotation.RuntimeInlineAnnotationReader;
import com.sun.xml.internal.bind.v2.model.core.Adapter;
import com.sun.xml.internal.bind.v2.model.core.NonElement;
import com.sun.xml.internal.bind.v2.model.core.Ref;
@@ -108,10 +108,11 @@
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallingContext;
import com.sun.xml.internal.bind.v2.schemagen.XmlSchemaGenerator;
import com.sun.xml.internal.bind.v2.util.EditDistance;
import com.sun.xml.internal.bind.v2.util.QNameMap;
+import com.sun.xml.internal.bind.v2.util.XmlFactory;
import com.sun.xml.internal.txw2.output.ResultFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -218,28 +219,33 @@
* Store properties, so that they can be recovered in the run (is here because of JSON encoding of Jersey).
*/
public final boolean retainPropertyInfo;
/**
- * Supress reflection accessor warnings.
+ * Suppress reflection accessor warnings.
*/
public final boolean supressAccessorWarnings;
/**
* Improved xsi type handling.
*/
public final boolean improvedXsiTypeHandling;
+ /**
+ * Disable security processing.
+ */
+ public final boolean disableSecurityProcessing;
+
private WeakReference<RuntimeTypeInfoSet> typeInfoSetCache;
private @NotNull RuntimeAnnotationReader annotationReader;
private /*almost final*/ boolean hasSwaRef;
private final @NotNull Map<Class,Class> subclassReplacements;
/**
- * If true, we aim for faster {@link JAXBContext} instanciation performance,
+ * If true, we aim for faster {@link JAXBContext} instantiation performance,
* instead of going after efficient sustained unmarshalling/marshalling performance.
*
* @since 2.0.4
*/
public final boolean fastBoot;
@@ -265,10 +271,11 @@
this.classes = builder.classes;
this.xmlAccessorFactorySupport = builder.xmlAccessorFactorySupport;
this.allNillable = builder.allNillable;
this.supressAccessorWarnings = builder.supressAccessorWarnings;
this.improvedXsiTypeHandling = builder.improvedXsiTypeHandling;
+ this.disableSecurityProcessing = builder.disableSecurityProcessing;
Collection<TypeReference> typeRefs = builder.typeRefs;
boolean fastB;
try {
@@ -276,12 +283,10 @@
} catch (SecurityException e) {
fastB = false;
}
this.fastBoot = fastB;
- System.arraycopy(classes,0,this.classes,0,classes.length);
-
RuntimeTypeInfoSet typeSet = getTypeInfoSet();
// at least prepare the empty table so that we don't have to check for null later
elements.put(null,new LinkedHashMap<QName, ElementBeanInfoImpl>());
@@ -699,16 +704,16 @@
}
/**
* Creates a new identity transformer.
*/
- static Transformer createTransformer() {
+ static Transformer createTransformer(boolean disableSecureProcessing) {
try {
if (tf==null) {
synchronized(JAXBContextImpl.class) {
if (tf==null) {
- tf = (SAXTransformerFactory)TransformerFactory.newInstance();
+ tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
}
}
}
return tf.newTransformer();
} catch (TransformerConfigurationException e) {
@@ -717,16 +722,16 @@
}
/**
* Creates a new identity transformer.
*/
- public static TransformerHandler createTransformerHandler() {
+ public static TransformerHandler createTransformerHandler(boolean disableSecureProcessing) {
try {
if (tf==null) {
synchronized(JAXBContextImpl.class) {
if (tf==null) {
- tf = (SAXTransformerFactory)TransformerFactory.newInstance();
+ tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
}
}
}
return tf.newTransformerHandler();
} catch (TransformerConfigurationException e) {
@@ -735,16 +740,15 @@
}
/**
* Creates a new DOM document.
*/
- static Document createDom() {
+ static Document createDom(boolean disableSecurityProcessing) {
synchronized(JAXBContextImpl.class) {
if(db==null) {
try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
+ DocumentBuilderFactory dbf = XmlFactory.createDocumentBuilderFactory(disableSecurityProcessing);
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// impossible
throw new FactoryConfigurationError(e);
}
@@ -1053,10 +1057,11 @@
private Class[] classes;
private Collection<TypeReference> typeRefs;
private boolean xmlAccessorFactorySupport = false;
private boolean allNillable;
private boolean improvedXsiTypeHandling = true;
+ private boolean disableSecurityProcessing = true;
public JAXBContextBuilder() {};
public JAXBContextBuilder(JAXBContextImpl baseImpl) {
this.supressAccessorWarnings = baseImpl.supressAccessorWarnings;
@@ -1067,10 +1072,11 @@
this.c14nSupport = baseImpl.c14nSupport;
this.classes = baseImpl.classes;
this.typeRefs = baseImpl.bridges.keySet();
this.xmlAccessorFactorySupport = baseImpl.xmlAccessorFactorySupport;
this.allNillable = baseImpl.allNillable;
+ this.disableSecurityProcessing = baseImpl.disableSecurityProcessing;
}
public JAXBContextBuilder setRetainPropertyInfo(boolean val) {
this.retainPropertyInfo = val;
return this;
@@ -1124,10 +1130,15 @@
public JAXBContextBuilder setImprovedXsiTypeHandling(boolean val) {
this.improvedXsiTypeHandling = val;
return this;
}
+ public JAXBContextBuilder setDisableSecurityProcessing(boolean val) {
+ this.disableSecurityProcessing = val;
+ return this;
+ }
+
public JAXBContextImpl build() throws JAXBException {
// fool-proof
if (this.defaultNsUri == null) {
this.defaultNsUri = "";