jaxp/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java
author dfuchs
Tue, 30 Jun 2015 12:04:27 +0200
changeset 31497 4a6b2e733c0d
parent 25868 686eef1e7a79
child 44797 8b3b3b911b8a
permissions -rw-r--r--
8130051: Cleanup usage of reflection in jaxp Summary: replaced usage of reflection with direct access where possible, removed obsolete code where possible. Reviewed-by: joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: DTMManagerDefault.java,v 1.2.4.1 2005/09/15 08:15:02 suresh_emailid Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xml.internal.dtm.ref;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
    25
import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.parsers.DocumentBuilder;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import javax.xml.parsers.DocumentBuilderFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import javax.xml.transform.Source;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import javax.xml.transform.dom.DOMSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import javax.xml.transform.sax.SAXSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import javax.xml.transform.stream.StreamSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xml.internal.dtm.DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xml.internal.dtm.DTMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xml.internal.dtm.DTMFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xml.internal.dtm.DTMIterator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
import com.sun.org.apache.xml.internal.dtm.DTMManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
import com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2RTFDTM;
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
import com.sun.org.apache.xml.internal.res.XMLErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
import com.sun.org.apache.xml.internal.res.XMLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
import org.w3c.dom.Document;
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
import org.xml.sax.InputSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
import org.xml.sax.SAXException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
import org.xml.sax.SAXNotRecognizedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
import org.xml.sax.SAXNotSupportedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
import org.xml.sax.XMLReader;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
import org.xml.sax.helpers.DefaultHandler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * The default implementation for the DTMManager.
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
 * %REVIEW% There is currently a reentrancy issue, since the finalizer
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * for XRTreeFrag (which runs in the GC thread) wants to call
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * DTMManager.release(), and may do so at the same time that the main
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 * transformation thread is accessing the manager. Our current solution is
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * to make most of the manager's methods <code>synchronized</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * Early tests suggest that doing so is not causing a significant
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * performance hit in Xalan. However, it should be noted that there
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * is a possible alternative solution: rewrite release() so it merely
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 * posts a request for release onto a threadsafe queue, and explicitly
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 * process that queue on an infrequent basis during main-thread
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
 * activity (eg, when getDTM() is invoked). The downside of that solution
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
 * would be a greater delay before the DTM's storage is actually released
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
 * for reuse.
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
 * */
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
public class DTMManagerDefault extends DTMManager
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  //static final boolean JKESS_XNI_EXPERIMENT=true;
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
  /** Set this to true if you want a dump of the DTM after creation. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  private static final boolean DUMPTREE = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  /** Set this to true if you want a basic diagnostics. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  private static final boolean DEBUG = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * Map from DTM identifier numbers to DTM objects that this manager manages.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   * One DTM may have several prefix numbers, if extended node indexing
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * is in use; in that case, m_dtm_offsets[] will used to control which
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   * prefix maps to which section of the DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * This array grows as necessary; see addDTM().
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * This array grows as necessary; see addDTM(). Growth is uncommon... but
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * access needs to be blindingly fast since it's used in node addressing.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  protected DTM m_dtms[] = new DTM[256];
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
  /** Map from DTM identifier numbers to offsets. For small DTMs with a
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   * single identifier, this will always be 0. In overflow addressing, where
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * additional identifiers are allocated to access nodes beyond the range of
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   * a single Node Handle, this table is used to map the handle's node field
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
   * into the actual node identifier.
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
   * This array grows as necessary; see addDTM().
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
   * This array grows as necessary; see addDTM(). Growth is uncommon... but
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
   * access needs to be blindingly fast since it's used in node addressing.
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * (And at the moment, that includes accessing it from DTMDefaultBase,
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * which is why this is not Protected or Private.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  int m_dtm_offsets[] = new int[256];
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   * The cache for XMLReader objects to be used if the user did not
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   * supply an XMLReader for a SAXSource or supplied a StreamSource.
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
  protected XMLReaderManager m_readerManager = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
   * The default implementation of ContentHandler, DTDHandler and ErrorHandler.
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
  protected DefaultHandler m_defaultHandler = new DefaultHandler();
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   * Add a DTM to the DTM table. This convenience call adds it as the
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * "base DTM ID", with offset 0. The other version of addDTM should
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   * be used if you want to add "extended" DTM IDs with nonzero offsets.
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   * @param dtm Should be a valid reference to a DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
   * @param id Integer DTM ID to be bound to this DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
  synchronized public void addDTM(DTM dtm, int id) {    addDTM(dtm,id,0); }
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   * Add a DTM to the DTM table.
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
   * @param dtm Should be a valid reference to a DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
   * @param id Integer DTM ID to be bound to this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * @param offset Integer addressing offset. The internal DTM Node ID is
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   * obtained by adding this offset to the node-number field of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * public DTM Handle. For the first DTM ID accessing each DTM, this is 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   * for overflow addressing it will be a multiple of 1<<IDENT_DTM_NODE_BITS.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  synchronized public void addDTM(DTM dtm, int id, int offset)
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
                if(id>=IDENT_MAX_DTMS)
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
                        // TODO: %REVIEW% Not really the right error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
            throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DTMIDS_AVAIL, null)); //"No more DTM IDs are available!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
                // We used to just allocate the array size to IDENT_MAX_DTMS.
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
                // But we expect to increase that to 16 bits, and I'm not willing
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                // to allocate that much space unless needed. We could use one of our
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
                // handy-dandy Fast*Vectors, but this will do for now.
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                // %REVIEW%
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                int oldlen=m_dtms.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                if(oldlen<=id)
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                        // Various growth strategies are possible. I think we don't want
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
                        // to over-allocate excessively, and I'm willing to reallocate
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
                        // more often to get that. See also Fast*Vector classes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
                        // %REVIEW% Should throw a more diagnostic error if we go over the max...
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                        int newlen=Math.min((id+256),IDENT_MAX_DTMS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
                        DTM new_m_dtms[] = new DTM[newlen];
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
                        System.arraycopy(m_dtms,0,new_m_dtms,0,oldlen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
                        m_dtms=new_m_dtms;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
                        int new_m_dtm_offsets[] = new int[newlen];
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
                        System.arraycopy(m_dtm_offsets,0,new_m_dtm_offsets,0,oldlen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
                        m_dtm_offsets=new_m_dtm_offsets;
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    m_dtms[id] = dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
                m_dtm_offsets[id]=offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    dtm.documentRegistration();
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
                // The DTM should have been told who its manager was when we created it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
                // Do we need to allow for adopting DTMs _not_ created by this manager?
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
   * Get the first free DTM ID available. %OPT% Linear search is inefficient!
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
  synchronized public int getFirstFreeDTMID()
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    int n = m_dtms.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    for (int i = 1; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
      if(null == m_dtms[i])
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
        return i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
                return n; // count on addDTM() to throw exception if out of range
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
   * The default table for exandedNameID lookups.
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
  private ExpandedNameTable m_expandedNameTable =
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    new ExpandedNameTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
   * Constructor DTMManagerDefault
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
  public DTMManagerDefault(){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
   * Get an instance of a DTM, loaded with the content from the
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
   * specified source.  If the unique flag is true, a new instance will
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
   * always be returned.  Otherwise it is up to the DTMManager to return a
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
   * new instance or an instance that it already created and may be being used
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
   * by someone else.
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
   * A bit of magic in this implementation: If the source is null, unique is true,
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
   * and incremental and doIndexing are both false, we return an instance of
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
   * SAX2RTFDTM, which see.
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
   * (I think more parameters will need to be added for error handling, and entity
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
   * resolution, and more explicit control of the RTF situation).
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
   * @param source the specification of the source object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
   * @param unique true if the returned DTM must be unique, probably because it
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
   * is going to be mutated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
   * @param whiteSpaceFilter Enables filtering of whitespace nodes, and may
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
   *                         be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
   * @param incremental true if the DTM should be built incrementally, if
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
   *                    possible.
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
   * @param doIndexing true if the caller considers it worth it to use
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
   *                   indexing schemes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
   * @return a non-null DTM reference.
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
  synchronized public DTM getDTM(Source source, boolean unique,
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
                                 DTMWSFilter whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
                                 boolean incremental, boolean doIndexing)
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
    if(DEBUG && null != source)
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
      System.out.println("Starting "+
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
                         (unique ? "UNIQUE" : "shared")+
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
                         " source: "+source.getSystemId()
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
                         );
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
    XMLStringFactory xstringFactory = m_xsf;
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    int dtmPos = getFirstFreeDTMID();
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    int documentID = dtmPos << IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
    if ((null != source) && source instanceof DOMSource)
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
      DOM2DTM dtm = new DOM2DTM(this, (DOMSource) source, documentID,
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
                                whiteSpaceFilter, xstringFactory, doIndexing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
      addDTM(dtm, dtmPos, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
      //      if (DUMPTREE)
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
      //      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
      //        dtm.dumpDTM();
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
      //      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
      return dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
      boolean isSAXSource = (null != source)
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
        ? (source instanceof SAXSource) : true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
      boolean isStreamSource = (null != source)
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        ? (source instanceof StreamSource) : false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
      if (isSAXSource || isStreamSource) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        XMLReader reader = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
        SAX2DTM dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
          InputSource xmlSource;
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
          if (null == source) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
            xmlSource = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
          } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
            reader = getXMLReader(source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
            xmlSource = SAXSource.sourceToInputSource(source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
            String urlOfSource = xmlSource.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
            if (null != urlOfSource) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
              try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
                urlOfSource = SystemIDResolver.getAbsoluteURI(urlOfSource);
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
              } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                // %REVIEW% Is there a better way to send a warning?
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
                System.err.println("Can not absolutize URL: " + urlOfSource);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
              xmlSource.setSystemId(urlOfSource);
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
          if (source==null && unique && !incremental && !doIndexing) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
            // Special case to support RTF construction into shared DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
            // It should actually still work for other uses,
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
            // but may be slightly deoptimized relative to the base
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
            // to allow it to deal with carrying multiple documents.
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
            //
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
            // %REVIEW% This is a sloppy way to request this mode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            // we need to consider architectural improvements.
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
            dtm = new SAX2RTFDTM(this, source, documentID, whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
                                 xstringFactory, doIndexing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
          /**************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
          // EXPERIMENTAL 3/22/02
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
          else if(JKESS_XNI_EXPERIMENT && m_incremental) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
            dtm = new XNI2DTM(this, source, documentID, whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
                              xstringFactory, doIndexing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
          **************************************************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
          // Create the basic SAX2DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
          else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
            dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
                              xstringFactory, doIndexing);
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
          // Go ahead and add the DTM to the lookup table.  This needs to be
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
          // done before any parsing occurs. Note offset 0, since we've just
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
          // created a new DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
          addDTM(dtm, dtmPos, 0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
          boolean haveXercesParser =
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                     (null != reader)
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                     && (reader.getClass()
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                               .getName()
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                               .equals("com.sun.org.apache.xerces.internal.parsers.SAXParser") );
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
          if (haveXercesParser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
            incremental = true;  // No matter what.  %REVIEW%
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
          // If the reader is null, but they still requested an incremental
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
          // build, then we still want to set up the IncrementalSAXSource stuff.
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
          if (m_incremental && incremental
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
               /* || ((null == reader) && incremental) */) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
            IncrementalSAXSource coParser=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
            if (haveXercesParser) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
              // IncrementalSAXSource_Xerces to avoid threading.
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
              try {
31497
4a6b2e733c0d 8130051: Cleanup usage of reflection in jaxp
dfuchs
parents: 25868
diff changeset
   351
                coParser = new com.sun.org.apache.xml.internal.dtm.ref.IncrementalSAXSource_Xerces();
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
              }  catch( Exception ex ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                ex.printStackTrace();
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
                coParser=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
            if (coParser==null ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
              // Create a IncrementalSAXSource to run on the secondary thread.
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
              if (null == reader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
                coParser = new IncrementalSAXSource_Filter();
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
              } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
                IncrementalSAXSource_Filter filter =
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                         new IncrementalSAXSource_Filter();
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
                filter.setXMLReader(reader);
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
                coParser=filter;
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
            /**************************************************************
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
            // EXPERIMENTAL 3/22/02
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
            if (JKESS_XNI_EXPERIMENT && m_incremental &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
                  dtm instanceof XNI2DTM &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
                  coParser instanceof IncrementalSAXSource_Xerces) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
                com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration xpc=
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
                      ((IncrementalSAXSource_Xerces)coParser)
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
                                           .getXNIParserConfiguration();
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
              if (xpc!=null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
                // Bypass SAX; listen to the XNI stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
                ((XNI2DTM)dtm).setIncrementalXNISource(xpc);
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
              } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
                  // Listen to the SAX stream (will fail, diagnostically...)
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
                dtm.setIncrementalSAXSource(coParser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
              }
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
            } else
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
            ***************************************************************/
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
            // Have the DTM set itself up as IncrementalSAXSource's listener.
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
            dtm.setIncrementalSAXSource(coParser);
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
            if (null == xmlSource) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
              // Then the user will construct it themselves.
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
              return dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
            if (null == reader.getErrorHandler()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
              reader.setErrorHandler(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
            reader.setDTDHandler(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
              // Launch parsing coroutine.  Launches a second thread,
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
              // if we're using IncrementalSAXSource.filter().
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
              coParser.startParse(xmlSource);
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
            } catch (RuntimeException re) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
              dtm.clearCoRoutine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
              throw re;
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
            } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
              dtm.clearCoRoutine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
              throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
          } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
            if (null == reader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
              // Then the user will construct it themselves.
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
              return dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
            // not incremental
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
            reader.setContentHandler(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
            reader.setDTDHandler(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
            if (null == reader.getErrorHandler()) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
              reader.setErrorHandler(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
              reader.setProperty(
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
                               "http://xml.org/sax/properties/lexical-handler",
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
                               dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
            } catch (SAXNotRecognizedException e){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
              catch (SAXNotSupportedException e){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
              reader.parse(xmlSource);
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
            } catch (RuntimeException re) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
              dtm.clearCoRoutine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
              throw re;
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
            } catch (Exception e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
              dtm.clearCoRoutine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
              throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
          if (DUMPTREE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
            System.out.println("Dumping SAX2DOM");
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
            dtm.dumpDTM(System.err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
          return dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
        } finally {
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
          // Reset the ContentHandler, DTDHandler, ErrorHandler to the DefaultHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
          // after creating the DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
          if (reader != null && !(m_incremental && incremental)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
            reader.setContentHandler(m_defaultHandler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
            reader.setDTDHandler(m_defaultHandler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
            reader.setErrorHandler(m_defaultHandler);
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
            // Reset the LexicalHandler to null after creating the DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
              reader.setProperty("http://xml.org/sax/properties/lexical-handler", null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
            catch (Exception e) {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
          releaseXMLReader(reader);
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
      } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
        // It should have been handled by a derived class or the caller
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
        // made a mistake.
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
        throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NOT_SUPPORTED, new Object[]{source})); //"Not supported: " + source);
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   * Given a W3C DOM node, try and return a DTM handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   * Note: calling this may be non-optimal, and there is no guarantee that
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
   * the node will be found in any particular DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
   * @param node Non-null reference to a DOM node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
   * @return a valid DTM handle.
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
  synchronized public int getDTMHandleFromNode(org.w3c.dom.Node node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
    if(null == node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
      throw new IllegalArgumentException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NODE_NON_NULL, null)); //"node must be non-null for getDTMHandleFromNode!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
    if (node instanceof com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy)
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
      return ((com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy) node).getDTMNodeNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
      // Find the DOM2DTMs wrapped around this Document (if any)
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
      // and check whether they contain the Node in question.
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
      //
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
      // NOTE that since a DOM2DTM may represent a subtree rather
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
      // than a full document, we have to be prepared to check more
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
      // than one -- and there is no guarantee that we will find
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
      // one that contains ancestors or siblings of the node we're
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
      // seeking.
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
      //
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
      // %REVIEW% We could search for the one which contains this
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
      // node at the deepest level, and thus covers the widest
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
      // subtree, but that's going to entail additional work
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
      // checking more DTMs... and getHandleOfNode is not a
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
      // cheap operation in most implementations.
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
                        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
                        // TODO: %REVIEW% If overflow addressing, we may recheck a DTM
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
                        // already examined. Ouch. But with the increased number of DTMs,
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
                        // scanning back to check this is painful.
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
                        // POSSIBLE SOLUTIONS:
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
                        //   Generate a list of _unique_ DTM objects?
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
                        //   Have each DTM cache last DOM node search?
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
                        int max = m_dtms.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
      for(int i = 0; i < max; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
          DTM thisDTM=m_dtms[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
          if((null != thisDTM) && thisDTM instanceof DOM2DTM)
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
            int handle=((DOM2DTM)thisDTM).getHandleOfNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
            if(handle!=DTM.NULL) return handle;
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
         }
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
                        // Not found; generate a new DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
                        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                        // %REVIEW% Is this really desirable, or should we return null
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
                        // and make folks explicitly instantiate from a DOMSource? The
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
                        // latter is more work but gives the caller the opportunity to
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
                        // explicitly add the DTM to a DTMManager... and thus to know when
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
                        // it can be discarded again, which is something we need to pay much
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
                        // more attention to. (Especially since only DTMs which are assigned
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
                        // to a manager can use the overflow addressing scheme.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
                        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
                        // %BUG% If the source node was a DOM2DTM$defaultNamespaceDeclarationNode
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
                        // and the DTM wasn't registered with this DTMManager, we will create
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
                        // a new DTM and _still_ not be able to find the node (since it will
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
                        // be resynthesized). Another reason to push hard on making all DTMs
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
                        // be managed DTMs.
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
                        // Since the real root of our tree may be a DocumentFragment, we need to
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
      // use getParent to find the root, instead of getOwnerDocument.  Otherwise
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
      // DOM2DTM#getHandleOfNode will be very unhappy.
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
      Node root = node;
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
      Node p = (root.getNodeType() == Node.ATTRIBUTE_NODE) ? ((org.w3c.dom.Attr)root).getOwnerElement() : root.getParentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
      for (; p != null; p = p.getParentNode())
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
        root = p;
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
      DOM2DTM dtm = (DOM2DTM) getDTM(new javax.xml.transform.dom.DOMSource(root),
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
                                                                                                                                                 false, null, true, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
      int handle;
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
      if(node instanceof com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
                                // Can't return the same node since it's unique to a specific DTM,
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
                                // but can return the equivalent node -- find the corresponding
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
                                // Document Element, then ask it for the xml: namespace decl.
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
                                handle=dtm.getHandleOfNode(((org.w3c.dom.Attr)node).getOwnerElement());
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
                                handle=dtm.getAttributeNode(handle,node.getNamespaceURI(),node.getLocalName());
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
                                handle = ((DOM2DTM)dtm).getHandleOfNode(node);
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
      if(DTM.NULL == handle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
        throw new RuntimeException(XMLMessages.createXMLMessage(XMLErrorResources.ER_COULD_NOT_RESOLVE_NODE, null)); //"Could not resolve the node to a handle!");
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
      return handle;
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
   * This method returns the SAX2 parser to use with the InputSource
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
   * obtained from this URI.
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
   * It may return null if any SAX2-conformant XML parser can be used,
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
   * or if getInputSource() will also return null. The parser must
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
   * be free for use (i.e., not currently in use for another parse().
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
   * After use of the parser is completed, the releaseXMLReader(XMLReader)
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
   * must be called.
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
   * @param inputSource The value returned from the URIResolver.
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
   * @return  a SAX2 XMLReader to use to resolve the inputSource argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
   * @return non-null XMLReader reference ready to parse.
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
  synchronized public XMLReader getXMLReader(Source inputSource)
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
      XMLReader reader = (inputSource instanceof SAXSource)
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
                         ? ((SAXSource) inputSource).getXMLReader() : null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
      // If user did not supply a reader, ask for one from the reader manager
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
      if (null == reader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
        if (m_readerManager == null) {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   609
            m_readerManager = XMLReaderManager.getInstance(super.useServicesMechnism());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
        reader = m_readerManager.getXMLReader();
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
      return reader;
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    } catch (SAXException se) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
      throw new DTMException(se.getMessage(), se);
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
   * Indicates that the XMLReader object is no longer in use for the transform.
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
   * Note that the getXMLReader method may return an XMLReader that was
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
   * specified on the SAXSource object by the application code.  Such a
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
   * reader should still be passed to releaseXMLReader, but the reader manager
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
   * will only re-use XMLReaders that it created.
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
   * @param reader The XMLReader to be released.
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
  synchronized public void releaseXMLReader(XMLReader reader) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
    if (m_readerManager != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
      m_readerManager.releaseXMLReader(reader);
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
   * Return the DTM object containing a representation of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
   * @param nodeHandle DTM Handle indicating which node to retrieve
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
   * @return a reference to the DTM object containing this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
  synchronized public DTM getDTM(int nodeHandle)
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
      // Performance critical function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
      return m_dtms[nodeHandle >>> IDENT_DTM_NODE_BITS];
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
    catch(java.lang.ArrayIndexOutOfBoundsException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
      if(nodeHandle==DTM.NULL)
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
                                return null;            // Accept as a special case.
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
                                throw e;                // Programming error; want to know about it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
   * Given a DTM, find the ID number in the DTM tables which addresses
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
   * the start of the document. If overflow addressing is in use, other
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
   * DTM IDs may also be assigned to this DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
   * @param dtm The DTM which (hopefully) contains this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
   * @return The DTM ID (as the high bits of a NodeHandle, not as our
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
   * internal index), or -1 if the DTM doesn't belong to this manager.
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
  synchronized public int getDTMIdentity(DTM dtm)
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
        // Shortcut using DTMDefaultBase's extension hooks
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
        // %REVIEW% Should the lookup be part of the basic DTM API?
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
        if(dtm instanceof DTMDefaultBase)
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
                DTMDefaultBase dtmdb=(DTMDefaultBase)dtm;
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
                if(dtmdb.getManager()==this)
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
                        return dtmdb.getDTMIDs().elementAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
                        return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
    int n = m_dtms.length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
    for (int i = 0; i < n; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
      DTM tdtm = m_dtms[i];
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
      if (tdtm == dtm && m_dtm_offsets[i]==0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
        return i << IDENT_DTM_NODE_BITS;
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
    return -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
   * Release the DTMManager's reference(s) to a DTM, making it unmanaged.
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
   * This is typically done as part of returning the DTM to the heap after
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
   * we're done with it.
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
   * @param dtm the DTM to be released.
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
   * @param shouldHardDelete If false, this call is a suggestion rather than an
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
   * order, and we may not actually release the DTM. This is intended to
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
   * support intelligent caching of documents... which is not implemented
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
   * in this version of the DTM manager.
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
   * @return true if the DTM was released, false if shouldHardDelete was set
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
   * and we decided not to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
  synchronized public boolean release(DTM dtm, boolean shouldHardDelete)
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
    if(DEBUG)
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
      System.out.println("Releasing "+
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
                         (shouldHardDelete ? "HARD" : "soft")+
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
                         " dtm="+
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
                         // Following shouldn't need a nodeHandle, but does...
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
                         // and doesn't seem to report the intended value
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
                         dtm.getDocumentBaseURI()
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
                         );
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
    if (dtm instanceof SAX2DTM)
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
      ((SAX2DTM) dtm).clearCoRoutine();
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
                // Multiple DTM IDs may be assigned to a single DTM.
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
                // The Right Answer is to ask which (if it supports
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
                // extension, the DTM will need a list anyway). The
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
                // Wrong Answer, applied if the DTM can't help us,
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
                // is to linearly search them all; this may be very
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
                // painful.
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
                //
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
                // %REVIEW% Should the lookup move up into the basic DTM API?
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
                if(dtm instanceof DTMDefaultBase)
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
                        com.sun.org.apache.xml.internal.utils.SuballocatedIntVector ids=((DTMDefaultBase)dtm).getDTMIDs();
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
                        for(int i=ids.size()-1;i>=0;--i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
                                m_dtms[ids.elementAt(i)>>>DTMManager.IDENT_DTM_NODE_BITS]=null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
                else
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
                {
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
                        int i = getDTMIdentity(dtm);
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
                    if (i >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
                        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
                                m_dtms[i >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
                        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
    dtm.documentRelease();
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
   * Method createDocumentFragment
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
   * NEEDSDOC (createDocumentFragment) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
  synchronized public DTM createDocumentFragment()
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
    {
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   768
      DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(super.useServicesMechnism());
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
      dbf.setNamespaceAware(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
      DocumentBuilder db = dbf.newDocumentBuilder();
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
      Document doc = db.newDocument();
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
      Node df = doc.createDocumentFragment();
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
      return getDTM(new DOMSource(df), true, null, false, false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
    catch (Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
      throw new DTMException(e);
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
   * NEEDSDOC Method createDTMIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
   * NEEDSDOC @param whatToShow
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
   * NEEDSDOC @param filter
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
   * NEEDSDOC @param entityReferenceExpansion
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
   * NEEDSDOC (createDTMIterator) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
  synchronized public DTMIterator createDTMIterator(int whatToShow, DTMFilter filter,
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
                                       boolean entityReferenceExpansion)
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
    /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
   * NEEDSDOC Method createDTMIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
   * NEEDSDOC @param xpathString
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
   * NEEDSDOC @param presolver
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
   * NEEDSDOC (createDTMIterator) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
  synchronized public DTMIterator createDTMIterator(String xpathString,
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
                                       PrefixResolver presolver)
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
    /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
   * NEEDSDOC Method createDTMIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
   * NEEDSDOC @param node
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
   * NEEDSDOC (createDTMIterator) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
  synchronized public DTMIterator createDTMIterator(int node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
    /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
   * NEEDSDOC Method createDTMIterator
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
   * NEEDSDOC @param xpathCompiler
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
   * NEEDSDOC @param pos
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
   * NEEDSDOC (createDTMIterator) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
  synchronized public DTMIterator createDTMIterator(Object xpathCompiler, int pos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
    /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
   * return the expanded name table.
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
   * NEEDSDOC @param dtm
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
   * NEEDSDOC ($objectName$) @return
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
  public ExpandedNameTable getExpandedNameTable(DTM dtm)
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
    return m_expandedNameTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
}