org.apache.xml.dtm.ref

## Class DTMManagerDefault

- java.lang.Object
- - org.apache.xml.dtm.DTMManager
  - - org.apache.xml.dtm.ref.DTMManagerDefault

- Direct Known Subclasses:
    XSLTCDTMManager

      public class DTMManagerDefault
      extends DTMManager

  The default implementation for the DTMManager. %REVIEW% There is currently a reentrancy issue, since the finalizer for XRTreeFrag (which runs in the GC thread) wants to call DTMManager.release(), and may do so at the same time that the main transformation thread is accessing the manager. Our current solution is to make most of the manager's methods `synchronized`. Early tests suggest that doing so is not causing a significant performance hit in Xalan. However, it should be noted that there is a possible alternative solution: rewrite release() so it merely posts a request for release onto a threadsafe queue, and explicitly process that queue on an infrequent basis during main-thread activity (eg, when getDTM() is invoked). The downside of that solution would be a greater delay before the DTM's storage is actually released for reuse.

- - ### Field Summary

    - ### Fields inherited from class org.apache.xml.dtm.DTMManager

      `IDENT_DTM_DEFAULT, IDENT_DTM_NODE_BITS, IDENT_MAX_DTMS, IDENT_NODE_DEFAULT, m_incremental, m_source_location`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DTMManagerDefault()` Constructor DTMManagerDefault

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDTM(DTM dtm, int id)` Add a DTM to the DTM table.
    `void` | `addDTM(DTM dtm, int id, int offset)` Add a DTM to the DTM table.
    `DTM` | `createDocumentFragment()` Method createDocumentFragment NEEDSDOC (createDocumentFragment) @return
    `DTMIterator` | `createDTMIterator(int node)` NEEDSDOC Method createDTMIterator NEEDSDOC @param node NEEDSDOC (createDTMIterator) @return
    `DTMIterator` | `createDTMIterator(int whatToShow, DTMFilter filter, boolean entityReferenceExpansion)` NEEDSDOC Method createDTMIterator NEEDSDOC @param whatToShow NEEDSDOC @param filter NEEDSDOC @param entityReferenceExpansion NEEDSDOC (createDTMIterator) @return
    `DTMIterator` | `createDTMIterator(java.lang.Object xpathCompiler, int pos)` NEEDSDOC Method createDTMIterator NEEDSDOC @param xpathCompiler NEEDSDOC @param pos NEEDSDOC (createDTMIterator) @return
    `DTMIterator` | `createDTMIterator(java.lang.String xpathString, PrefixResolver presolver)` NEEDSDOC Method createDTMIterator NEEDSDOC @param xpathString NEEDSDOC @param presolver NEEDSDOC (createDTMIterator) @return
    `DTM` | `getDTM(int nodeHandle)` Return the DTM object containing a representation of this node.
    `DTM` | `getDTM(Source source, boolean unique, DTMWSFilter whiteSpaceFilter, boolean incremental, boolean doIndexing)` Get an instance of a DTM, loaded with the content from the specified source.
    `int` | `getDTMHandleFromNode(Node node)` Given a W3C DOM node, try and return a DTM handle.
    `int` | `getDTMIdentity(DTM dtm)` Given a DTM, find the ID number in the DTM tables which addresses the start of the document.
    `ExpandedNameTable` | `getExpandedNameTable(DTM dtm)` return the expanded name table.
    `int` | `getFirstFreeDTMID()` Get the first free DTM ID available.
    `XMLReader` | `getXMLReader(Source inputSource)` This method returns the SAX2 parser to use with the InputSource obtained from this URI.
    `boolean` | `release(DTM dtm, boolean shouldHardDelete)` Release the DTMManager's reference(s) to a DTM, making it unmanaged.
    `void` | `releaseXMLReader(XMLReader reader)` Indicates that the XMLReader object is no longer in use for the transform.

    - ### Methods inherited from class org.apache.xml.dtm.DTMManager

      `getDTMIdentityMask, getIncremental, getNodeIdentityMask, getSource_location, getXMLStringFactory, newInstance, setIncremental, setSource_location, setXMLStringFactory`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DTMManagerDefault

          public DTMManagerDefault()

      Constructor DTMManagerDefault

  - ### Method Detail

    - #### addDTM

          public void addDTM(DTM dtm,
                    int id)

      Add a DTM to the DTM table. This convenience call adds it as the "base DTM ID", with offset 0. The other version of addDTM should be used if you want to add "extended" DTM IDs with nonzero offsets.
      Parameters:
        `dtm` - Should be a valid reference to a DTM.
        `id` - Integer DTM ID to be bound to this DTM

    - #### addDTM

          public void addDTM(DTM dtm,
                    int id,
                    int offset)

      Add a DTM to the DTM table.
      Parameters:
        `dtm` - Should be a valid reference to a DTM.
        `id` - Integer DTM ID to be bound to this DTM.
        `offset` - Integer addressing offset. The internal DTM Node ID is obtained by adding this offset to the node-number field of the public DTM Handle. For the first DTM ID accessing each DTM, this is 0; for overflow addressing it will be a multiple of 1<

    - #### getFirstFreeDTMID

          public int getFirstFreeDTMID()

      Get the first free DTM ID available. %OPT% Linear search is inefficient!

    - #### getDTM

          public DTM getDTM(Source source,
                   boolean unique,
                   DTMWSFilter whiteSpaceFilter,
                   boolean incremental,
                   boolean doIndexing)

      Get an instance of a DTM, loaded with the content from the specified source. If the unique flag is true, a new instance will always be returned. Otherwise it is up to the DTMManager to return a new instance or an instance that it already created and may be being used by someone else. A bit of magic in this implementation: If the source is null, unique is true, and incremental and doIndexing are both false, we return an instance of SAX2RTFDTM, which see. (I think more parameters will need to be added for error handling, and entity resolution, and more explicit control of the RTF situation).
      Specified by:
        `getDTM` in class `DTMManager`
      Parameters:
        `source` - the specification of the source object.
        `unique` - true if the returned DTM must be unique, probably because it is going to be mutated.
        `whiteSpaceFilter` - Enables filtering of whitespace nodes, and may be null.
        `incremental` - true if the DTM should be built incrementally, if possible.
        `doIndexing` - true if the caller considers it worth it to use indexing schemes.
      Returns:
        a non-null DTM reference.

    - #### getDTMHandleFromNode

          public int getDTMHandleFromNode(Node node)

      Given a W3C DOM node, try and return a DTM handle. Note: calling this may be non-optimal, and there is no guarantee that the node will be found in any particular DTM.
      Specified by:
        `getDTMHandleFromNode` in class `DTMManager`
      Parameters:
        `node` - Non-null reference to a DOM node.
      Returns:
        a valid DTM handle.

    - #### getXMLReader

          public XMLReader getXMLReader(Source inputSource)

      This method returns the SAX2 parser to use with the InputSource obtained from this URI. It may return null if any SAX2-conformant XML parser can be used, or if getInputSource() will also return null. The parser must be free for use (i.e., not currently in use for another parse(). After use of the parser is completed, the releaseXMLReader(XMLReader) must be called.
      Parameters:
        `inputSource` - The value returned from the URIResolver.
      Returns:
        a SAX2 XMLReader to use to resolve the inputSource argument.

    - #### releaseXMLReader

          public void releaseXMLReader(XMLReader reader)

      Indicates that the XMLReader object is no longer in use for the transform. Note that the getXMLReader method may return an XMLReader that was specified on the SAXSource object by the application code. Such a reader should still be passed to releaseXMLReader, but the reader manager will only re-use XMLReaders that it created.
      Parameters:
        `reader` - The XMLReader to be released.

    - #### getDTM

          public DTM getDTM(int nodeHandle)

      Return the DTM object containing a representation of this node.
      Specified by:
        `getDTM` in class `DTMManager`
      Parameters:
        `nodeHandle` - DTM Handle indicating which node to retrieve
      Returns:
        a reference to the DTM object containing this node.

    - #### getDTMIdentity

          public int getDTMIdentity(DTM dtm)

      Given a DTM, find the ID number in the DTM tables which addresses the start of the document. If overflow addressing is in use, other DTM IDs may also be assigned to this DTM.
      Specified by:
        `getDTMIdentity` in class `DTMManager`
      Parameters:
        `dtm` - The DTM which (hopefully) contains this node.
      Returns:
        The DTM ID (as the high bits of a NodeHandle, not as our internal index), or -1 if the DTM doesn't belong to this manager.

    - #### release

          public boolean release(DTM dtm,
                        boolean shouldHardDelete)

      Release the DTMManager's reference(s) to a DTM, making it unmanaged. This is typically done as part of returning the DTM to the heap after we're done with it.
      Specified by:
        `release` in class `DTMManager`
      Parameters:
        `dtm` - the DTM to be released.
        `shouldHardDelete` - If false, this call is a suggestion rather than an order, and we may not actually release the DTM. This is intended to support intelligent caching of documents... which is not implemented in this version of the DTM manager.
      Returns:
        true if the DTM was released, false if shouldHardDelete was set and we decided not to.

    - #### createDocumentFragment

          public DTM createDocumentFragment()

      Method createDocumentFragment NEEDSDOC (createDocumentFragment) @return
      Specified by:
        `createDocumentFragment` in class `DTMManager`
      Returns:
        a non-null DTM reference.

    - #### createDTMIterator

          public DTMIterator createDTMIterator(int whatToShow,
                                      DTMFilter filter,
                                      boolean entityReferenceExpansion)

      NEEDSDOC Method createDTMIterator NEEDSDOC @param whatToShow NEEDSDOC @param filter NEEDSDOC @param entityReferenceExpansion NEEDSDOC (createDTMIterator) @return
      Specified by:
        `createDTMIterator` in class `DTMManager`
      Parameters:
        `whatToShow` - This flag specifies which node types may appear in the logical view of the tree presented by the iterator. See the description of `NodeFilter` for the set of possible `SHOW_` values.These flags can be combined using `OR`.
        `filter` - The `NodeFilter` to be used with this `DTMFilter`, or `null` to indicate no filter.
        `entityReferenceExpansion` - The value of this flag determines whether entity reference nodes are expanded.
      Returns:
        The newly created `DTMIterator`.

    - #### createDTMIterator

          public DTMIterator createDTMIterator(java.lang.String xpathString,
                                      PrefixResolver presolver)

      NEEDSDOC Method createDTMIterator NEEDSDOC @param xpathString NEEDSDOC @param presolver NEEDSDOC (createDTMIterator) @return
      Specified by:
        `createDTMIterator` in class `DTMManager`
      Parameters:
        `xpathString` - Must be a valid string expressing a UnionExpr.
        `presolver` - An object that can resolve prefixes to namespace URLs.
      Returns:
        The newly created `DTMIterator`.

    - #### createDTMIterator

          public DTMIterator createDTMIterator(int node)

      NEEDSDOC Method createDTMIterator NEEDSDOC @param node NEEDSDOC (createDTMIterator) @return
      Specified by:
        `createDTMIterator` in class `DTMManager`
      Parameters:
        `node` - The node handle that the DTMIterator will iterate to.
      Returns:
        The newly created `DTMIterator`.

    - #### createDTMIterator

          public DTMIterator createDTMIterator(java.lang.Object xpathCompiler,
                                      int pos)

      NEEDSDOC Method createDTMIterator NEEDSDOC @param xpathCompiler NEEDSDOC @param pos NEEDSDOC (createDTMIterator) @return
      Specified by:
        `createDTMIterator` in class `DTMManager`
      Parameters:
        `xpathCompiler` - ??? Somehow we need to pass in a subpart of the expression. I hate to do this with strings, since the larger expression has already been parsed.
        `pos` - The position in the expression.
      Returns:
        The newly created `DTMIterator`.

    - #### getExpandedNameTable

          public ExpandedNameTable getExpandedNameTable(DTM dtm)

      return the expanded name table. NEEDSDOC @param dtm NEEDSDOC ($objectName$) @return

Copyright © 2014 Apache XML Project. All Rights Reserved.