< prev index next >

src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/internalizer/DOMForest.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2014, 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
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.xjc.reader.internalizer;
  27 
  28 import com.sun.istack.internal.NotNull;
  29 import com.sun.istack.internal.XMLStreamReaderToContentHandler;
  30 import com.sun.tools.internal.xjc.ErrorReceiver;
  31 import com.sun.tools.internal.xjc.Options;
  32 import com.sun.tools.internal.xjc.reader.Const;

  33 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
  34 import com.sun.xml.internal.bind.marshaller.DataWriter;
  35 import com.sun.xml.internal.bind.v2.util.XmlFactory;
  36 import com.sun.xml.internal.xsom.parser.JAXPParser;
  37 import com.sun.xml.internal.xsom.parser.XMLParser;
  38 import org.w3c.dom.Document;
  39 import org.w3c.dom.Element;
  40 import org.xml.sax.*;
  41 import org.xml.sax.helpers.XMLFilterImpl;
  42 
  43 import javax.xml.parsers.DocumentBuilder;
  44 import javax.xml.parsers.DocumentBuilderFactory;
  45 import javax.xml.parsers.ParserConfigurationException;
  46 import javax.xml.parsers.SAXParserFactory;
  47 import javax.xml.stream.XMLStreamException;
  48 import javax.xml.stream.XMLStreamReader;
  49 import javax.xml.transform.Source;
  50 import javax.xml.transform.Transformer;
  51 import javax.xml.transform.TransformerException;
  52 import javax.xml.transform.TransformerFactory;


  66 /**
  67  * Builds a DOM forest and maintains association from
  68  * system IDs to DOM trees.
  69  *
  70  * <p>
  71  * A forest is a transitive reflexive closure of referenced documents.
  72  * IOW, if a document is in a forest, all the documents referenced from
  73  * it is in a forest, too. To support this semantics, {@link DOMForest}
  74  * uses {@link InternalizationLogic} to find referenced documents.
  75  *
  76  * <p>
  77  * Some documents are marked as "root"s, meaning those documents were
  78  * put into a forest explicitly, not because it is referenced from another
  79  * document. (However, a root document can be referenced from other
  80  * documents, too.)
  81  *
  82  * @author
  83  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
  84  */
  85 public final class DOMForest {
  86     /** actual data storage map&lt;SystemId,Document>. */
  87     private final Map<String,Document> core = new HashMap<String,Document>();
  88 
  89     /**
  90      * To correctly feed documents to a schema parser, we need to remember
  91      * which documents (of the forest) were given as the root
  92      * documents, and which of them are read as included/imported
  93      * documents.
  94      *
  95      * <p>
  96      * Set of system ids as strings.
  97      */
  98     private final Set<String> rootDocuments = new LinkedHashSet<String>();
  99 
 100     /** Stores location information for all the trees in this forest. */
 101     public final LocatorTable locatorTable = new LocatorTable();
 102 
 103     /** Stores all the outer-most &lt;jaxb:bindings> customizations. */
 104     public final Set<Element> outerMostBindings = new HashSet<Element>();
 105 
 106     /** Used to resolve references to other schema documents. */
 107     private EntityResolver entityResolver = null;
 108 
 109     /** Errors encountered during the parsing will be sent to this object. */
 110     private ErrorReceiver errorReceiver = null;
 111 
 112     /** Schema language dependent part of the processing. */
 113     protected final InternalizationLogic logic;
 114 
 115     private final SAXParserFactory parserFactory;
 116     private final DocumentBuilder documentBuilder;
 117 
 118     private final Options options;
 119 
 120     public DOMForest(
 121         SAXParserFactory parserFactory, DocumentBuilder documentBuilder,
 122         InternalizationLogic logic ) {
 123 


   1 /*
   2  * Copyright (c) 1997, 2015, 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
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.xjc.reader.internalizer;
  27 
  28 import com.sun.istack.internal.NotNull;
  29 import com.sun.istack.internal.XMLStreamReaderToContentHandler;
  30 import com.sun.tools.internal.xjc.ErrorReceiver;
  31 import com.sun.tools.internal.xjc.Options;
  32 import com.sun.tools.internal.xjc.reader.Const;
  33 import com.sun.tools.internal.xjc.reader.xmlschema.parser.SchemaConstraintChecker;
  34 import com.sun.tools.internal.xjc.util.ErrorReceiverFilter;
  35 import com.sun.xml.internal.bind.marshaller.DataWriter;
  36 import com.sun.xml.internal.bind.v2.util.XmlFactory;
  37 import com.sun.xml.internal.xsom.parser.JAXPParser;
  38 import com.sun.xml.internal.xsom.parser.XMLParser;
  39 import org.w3c.dom.Document;
  40 import org.w3c.dom.Element;
  41 import org.xml.sax.*;
  42 import org.xml.sax.helpers.XMLFilterImpl;
  43 
  44 import javax.xml.parsers.DocumentBuilder;
  45 import javax.xml.parsers.DocumentBuilderFactory;
  46 import javax.xml.parsers.ParserConfigurationException;
  47 import javax.xml.parsers.SAXParserFactory;
  48 import javax.xml.stream.XMLStreamException;
  49 import javax.xml.stream.XMLStreamReader;
  50 import javax.xml.transform.Source;
  51 import javax.xml.transform.Transformer;
  52 import javax.xml.transform.TransformerException;
  53 import javax.xml.transform.TransformerFactory;


  67 /**
  68  * Builds a DOM forest and maintains association from
  69  * system IDs to DOM trees.
  70  *
  71  * <p>
  72  * A forest is a transitive reflexive closure of referenced documents.
  73  * IOW, if a document is in a forest, all the documents referenced from
  74  * it is in a forest, too. To support this semantics, {@link DOMForest}
  75  * uses {@link InternalizationLogic} to find referenced documents.
  76  *
  77  * <p>
  78  * Some documents are marked as "root"s, meaning those documents were
  79  * put into a forest explicitly, not because it is referenced from another
  80  * document. (However, a root document can be referenced from other
  81  * documents, too.)
  82  *
  83  * @author
  84  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
  85  */
  86 public final class DOMForest {
  87     /** actual data storage {@code map<SystemId,Document>}. */
  88     private final Map<String,Document> core = new HashMap<String,Document>();
  89 
  90     /**
  91      * To correctly feed documents to a schema parser, we need to remember
  92      * which documents (of the forest) were given as the root
  93      * documents, and which of them are read as included/imported
  94      * documents.
  95      *
  96      * <p>
  97      * Set of system ids as strings.
  98      */
  99     private final Set<String> rootDocuments = new LinkedHashSet<String>();
 100 
 101     /** Stores location information for all the trees in this forest. */
 102     public final LocatorTable locatorTable = new LocatorTable();
 103 
 104     /** Stores all the outer-most {@code <jaxb:bindings>} customizations. */
 105     public final Set<Element> outerMostBindings = new HashSet<Element>();
 106 
 107     /** Used to resolve references to other schema documents. */
 108     private EntityResolver entityResolver = null;
 109 
 110     /** Errors encountered during the parsing will be sent to this object. */
 111     private ErrorReceiver errorReceiver = null;
 112 
 113     /** Schema language dependent part of the processing. */
 114     protected final InternalizationLogic logic;
 115 
 116     private final SAXParserFactory parserFactory;
 117     private final DocumentBuilder documentBuilder;
 118 
 119     private final Options options;
 120 
 121     public DOMForest(
 122         SAXParserFactory parserFactory, DocumentBuilder documentBuilder,
 123         InternalizationLogic logic ) {
 124 


< prev index next >