src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/DOMForest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1997, 2011, 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
--- 1,7 ----
/*
! * Copyright (c) 1997, 2013, 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
*** 55,67 ****
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.XMLStreamReaderToContentHandler;
import com.sun.tools.internal.xjc.ErrorReceiver;
import com.sun.tools.internal.xjc.Options;
import com.sun.tools.internal.xjc.reader.Const;
- import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker;
import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
import com.sun.xml.internal.bind.marshaller.DataWriter;
import com.sun.xml.internal.xsom.parser.JAXPParser;
import com.sun.xml.internal.xsom.parser.XMLParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
--- 55,67 ----
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.XMLStreamReaderToContentHandler;
import com.sun.tools.internal.xjc.ErrorReceiver;
import com.sun.tools.internal.xjc.Options;
import com.sun.tools.internal.xjc.reader.Const;
import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
import com.sun.xml.internal.bind.marshaller.DataWriter;
+ import com.sun.xml.internal.bind.v2.util.XmlFactory;
import com.sun.xml.internal.xsom.parser.JAXPParser;
import com.sun.xml.internal.xsom.parser.XMLParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
*** 124,151 ****
protected final InternalizationLogic logic;
private final SAXParserFactory parserFactory;
private final DocumentBuilder documentBuilder;
public DOMForest(
SAXParserFactory parserFactory, DocumentBuilder documentBuilder,
InternalizationLogic logic ) {
this.parserFactory = parserFactory;
this.documentBuilder = documentBuilder;
this.logic = logic;
}
! public DOMForest( InternalizationLogic logic ) {
try {
! DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
! dbf.setNamespaceAware(true);
this.documentBuilder = dbf.newDocumentBuilder();
!
! this.parserFactory = SAXParserFactory.newInstance();
! this.parserFactory.setNamespaceAware(true);
} catch( ParserConfigurationException e ) {
throw new AssertionError(e);
}
this.logic = logic;
--- 124,154 ----
protected final InternalizationLogic logic;
private final SAXParserFactory parserFactory;
private final DocumentBuilder documentBuilder;
+ private final Options options;
public DOMForest(
SAXParserFactory parserFactory, DocumentBuilder documentBuilder,
InternalizationLogic logic ) {
this.parserFactory = parserFactory;
this.documentBuilder = documentBuilder;
this.logic = logic;
+ this.options = null;
}
! public DOMForest( InternalizationLogic logic, Options opt ) {
!
! if (opt == null) throw new AssertionError("Options object null");
! this.options = opt;
!
try {
! DocumentBuilderFactory dbf = XmlFactory.createDocumentBuilderFactory(opt.disableXmlSecurity);
this.documentBuilder = dbf.newDocumentBuilder();
! this.parserFactory = XmlFactory.createParserFactory(opt.disableXmlSecurity);
} catch( ParserConfigurationException e ) {
throw new AssertionError(e);
}
this.logic = logic;
*** 186,197 ****
/**
* Strips off the leading 'file:///' portion from an URL.
*/
private String getPath(String key) {
key = key.substring(5); // skip 'file:'
! while(key.length()>0 && key.charAt(0)=='/')
key = key.substring(1);
return key;
}
/**
* Returns a read-only set of root document system IDs.
--- 189,201 ----
/**
* Strips off the leading 'file:///' portion from an URL.
*/
private String getPath(String key) {
key = key.substring(5); // skip 'file:'
! while(key.length()>0 && key.charAt(0)=='/') {
key = key.substring(1);
+ }
return key;
}
/**
* Returns a read-only set of root document system IDs.
*** 223,233 ****
*
* @see SchemaConstraintChecker
*/
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
try {
! SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
sf.setErrorHandler(filter);
Set<String> roots = getRootDocuments();
Source[] sources = new Source[roots.size()];
int i=0;
--- 227,241 ----
*
* @see SchemaConstraintChecker
*/
public boolean checkSchemaCorrectness(ErrorReceiver errorHandler) {
try {
! boolean disableXmlSecurity = false;
! if (options != null) {
! disableXmlSecurity = options.disableXmlSecurity;
! }
! SchemaFactory sf = XmlFactory.createSchemaFactory(W3C_XML_SCHEMA_NS_URI, disableXmlSecurity);
ErrorReceiverFilter filter = new ErrorReceiverFilter(errorHandler);
sf.setErrorHandler(filter);
Set<String> roots = getRootDocuments();
Source[] sources = new Source[roots.size()];
int i=0;
*** 422,432 ****
* @return
* the returned bindings need to be applied after schema
* components are built.
*/
public SCDBasedBindingSet transform(boolean enableSCD) {
! return Internalizer.transform(this,enableSCD);
}
/**
* Performs the schema correctness check by using JAXP 1.3.
*
--- 430,440 ----
* @return
* the returned bindings need to be applied after schema
* components are built.
*/
public SCDBasedBindingSet transform(boolean enableSCD) {
! return Internalizer.transform(this, enableSCD, options.disableXmlSecurity);
}
/**
* Performs the schema correctness check by using JAXP 1.3.
*
*** 464,483 ****
try {
sf.newSchema(sources.toArray(new SAXSource[0]));
} catch (SAXException e) {
// error should have been reported.
! } catch (RuntimeException e) {
// JAXP RI isn't very trustworthy when it comes to schema error check,
// and we know some cases where it just dies with NPE. So handle it gracefully.
// this masks a bug in the JAXP RI, but we need a release that we have to make.
try {
sf.getErrorHandler().warning(
new SAXParseException(Messages.format(
! Messages.ERR_GENERAL_SCHEMA_CORRECTNESS_ERROR,e.getMessage()),
! null,null,-1,-1,e));
! } catch (SAXException _) {
// ignore
}
}
}
--- 472,491 ----
try {
sf.newSchema(sources.toArray(new SAXSource[0]));
} catch (SAXException e) {
// error should have been reported.
! } catch (RuntimeException re) {
// JAXP RI isn't very trustworthy when it comes to schema error check,
// and we know some cases where it just dies with NPE. So handle it gracefully.
// this masks a bug in the JAXP RI, but we need a release that we have to make.
try {
sf.getErrorHandler().warning(
new SAXParseException(Messages.format(
! Messages.ERR_GENERAL_SCHEMA_CORRECTNESS_ERROR,re.getMessage()),
! null,null,-1,-1,re));
! } catch (SAXException e) {
// ignore
}
}
}
*** 487,500 ****
--- 495,510 ----
*/
public @NotNull SAXSource createSAXSource(String systemId) {
ContentHandlerNamespacePrefixAdapter reader = new ContentHandlerNamespacePrefixAdapter(new XMLFilterImpl() {
// XMLReader that uses XMLParser to parse. We need to use XMLFilter to indrect
// handlers, since SAX allows handlers to be changed while parsing.
+ @Override
public void parse(InputSource input) throws SAXException, IOException {
createParser().parse(input, this, this, this);
}
+ @Override
public void parse(String systemId) throws SAXException, IOException {
parse(new InputSource(systemId));
}
});
*** 507,521 ****
*
* The net effect is that XSOM will read transformed XML Schemas
* instead of the original documents.
*/
public XMLParser createParser() {
! return new DOMForestParser(this,new JAXPParser());
}
-
-
public EntityResolver getEntityResolver() {
return entityResolver;
}
public void setEntityResolver(EntityResolver entityResolver) {
--- 517,529 ----
*
* The net effect is that XSOM will read transformed XML Schemas
* instead of the original documents.
*/
public XMLParser createParser() {
! return new DOMForestParser(this, new JAXPParser(XmlFactory.createParserFactory(options.disableXmlSecurity)));
}
public EntityResolver getEntityResolver() {
return entityResolver;
}
public void setEntityResolver(EntityResolver entityResolver) {
*** 547,560 ****
/**
* Dumps the contents of the forest to the specified stream.
*
* This is a debug method. As such, error handling is sloppy.
*/
public void dump( OutputStream out ) throws IOException {
try {
// create identity transformer
! Transformer it = TransformerFactory.newInstance().newTransformer();
for (Map.Entry<String, Document> e : core.entrySet()) {
out.write( ("---<< "+e.getKey()+'\n').getBytes() );
DataWriter dw = new DataWriter(new OutputStreamWriter(out),null);
--- 555,574 ----
/**
* Dumps the contents of the forest to the specified stream.
*
* This is a debug method. As such, error handling is sloppy.
*/
+ @SuppressWarnings("CallToThreadDumpStack")
public void dump( OutputStream out ) throws IOException {
try {
// create identity transformer
! boolean disableXmlSecurity = false;
! if (options != null) {
! disableXmlSecurity = options.disableXmlSecurity;
! }
! TransformerFactory tf = XmlFactory.createTransformerFactory(disableXmlSecurity);
! Transformer it = tf.newTransformer();
for (Map.Entry<String, Document> e : core.entrySet()) {
out.write( ("---<< "+e.getKey()+'\n').getBytes() );
DataWriter dw = new DataWriter(new OutputStreamWriter(out),null);