mkwan       2003/03/12 09:44:13

  Modified:    java/src/org/apache/xalan/xsltc Tag: XSLTC_DTM DOM.java
               java/src/org/apache/xalan/xsltc/compiler Tag: XSLTC_DTM
                        SyntaxTreeNode.java
               java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
                        DOMAdapter.java DOMImpl.java MultiDOM.java
                        SAXImpl.java SimpleResultTreeImpl.java
  Added:       java/src/org/apache/xalan/xsltc/dom Tag: XSLTC_DTM
                        AdaptiveResultTreeImpl.java
  Log:
  XSLTC_DTM performance work
  
  Design a light-weight DOM model (AdaptiveResultTreeImpl) for RTFs with 
xsl:call-template.
  
  AdaptiveResultTreeImpl is a adaptive DOM model for result tree fragments 
(RTF). It is
  used in the case where the RTF is likely to be pure text yet it can still be 
a DOM tree.
  It is designed for RTFs which have <xsl:call-template> or 
<xsl:apply-templates> in
  the contents. Example:
  
      <xsl:variable name = "x">
        <xsl:call-template name = "test">
           <xsl:with-param name="a" select="."/>
        </xsl:call-template>
      </xsl:variable>
  
  In this example the result produced by <xsl:call-template> is likely to be a 
single
  Text node. But it can also be a DOM tree. This kind of RTF cannot be modelled 
by
  SimpleResultTreeImpl.
  
  AdaptiveResultTreeImpl can be considered as a smart switcher between 
SimpleResultTreeImpl
  and SAXImpl. It treats the RTF as simple Text and uses the 
SimpleResultTreeImpl model
  at the beginning. However, if it receives a call which indicates that this is 
a DOM tree
  (e.g. startElement), it will automatically transform itself into a wrapper 
around a
  SAXImpl. In this way we can have a light-weight model when the result only 
contains
  simple text, while at the same time it still works when the RTF is a DOM tree.
  
  All methods in this class are overridden to delegate the action to the 
wrapped SAXImpl object
  if it is non-null, or delegate the action to the SimpleResultTreeImpl if 
there is no
  wrapped SAXImpl.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.9.10.13 +7 -2      xml-xalan/java/src/org/apache/xalan/xsltc/DOM.java
  
  Index: DOM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/DOM.java,v
  retrieving revision 1.9.10.12
  retrieving revision 1.9.10.13
  diff -u -r1.9.10.12 -r1.9.10.13
  --- DOM.java  5 Mar 2003 19:22:59 -0000       1.9.10.12
  +++ DOM.java  12 Mar 2003 17:44:11 -0000      1.9.10.13
  @@ -81,6 +81,11 @@
       public final static int RETURN_CURRENT = 0;
       public final static int RETURN_PARENT  = 1;
       
  +    // Constants used by getResultTreeFrag to indicate the types of the RTFs.
  +    public final static int SIMPLE_RTF   = 0;
  +    public final static int ADAPTIVE_RTF = 1;
  +    public final static int TREE_RTF     = 2;
  +    
       /** returns singleton iterator containg the document root */
       public DTMAxisIterator getIterator();
       public String getStringValue();
  @@ -126,7 +131,7 @@
        throws TransletException;
       public int getNodeIdent(final int nodehandle);
       public int getNodeHandle(final int nodeId);
  -    public DOM getResultTreeFrag(int initialSize, boolean isSimple);
  +    public DOM getResultTreeFrag(int initialSize, int rtfType);
       public TransletOutputHandler getOutputDomBuilder();
       public int getNSType(int node);
       public int getDocument();
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.19.2.9  +51 -11    
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java
  
  Index: SyntaxTreeNode.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/SyntaxTreeNode.java,v
  retrieving revision 1.19.2.8
  retrieving revision 1.19.2.9
  diff -u -r1.19.2.8 -r1.19.2.9
  --- SyntaxTreeNode.java       5 Mar 2003 19:22:59 -0000       1.19.2.8
  +++ SyntaxTreeNode.java       12 Mar 2003 17:44:11 -0000      1.19.2.9
  @@ -88,6 +88,7 @@
   import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
   import org.apache.xalan.xsltc.compiler.util.Type;
   import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
  +import org.apache.xalan.xsltc.DOM;
   
   import org.xml.sax.Attributes;
   
  @@ -553,31 +554,58 @@
           Vector contents = node.getContents();
           for (int i = 0; i < contents.size(); i++) {
               SyntaxTreeNode item = (SyntaxTreeNode)contents.elementAt(i);
  -            if (!isTextElement(item))
  +            if (!isTextElement(item, false))
                   return false;
           }
           
           return true;
       }
  -    
  + 
  +     /**
  +     * Return true if the node represents an adaptive RTF.
  +     *
  +     * A node is an adaptive RTF if each children is a Text element
  +     * or it is <xsl:call-template> or <xsl:apply-templates>.
  +     *
  +     * @param node A node
  +     * @return true if the node content can be considered as an adaptive RTF.
  +     */
  +    private boolean isAdaptiveRTF(SyntaxTreeNode node) {
  +        
  +        Vector contents = node.getContents();
  +        for (int i = 0; i < contents.size(); i++) {
  +            SyntaxTreeNode item = (SyntaxTreeNode)contents.elementAt(i);
  +            if (!isTextElement(item, true))
  +                return false;
  +        }
  +        
  +        return true;
  +    }
  +   
       /**
        * Return true if the node only produces Text content.
        *
  -     * A node is a Text element if it is Text, xsl:value-of or xsl:number.
  -     * It can also be an xsl:if or xsl:choose whose content body are pure
  -     * Text.
  +     * A node is a Text element if it is Text, xsl:value-of, xsl:number, 
  +     * or a combination of these nested in a control instruction (xsl:if or
  +     * xsl:choose).
  +     *
  +     * If the doExtendedCheck flag is true, xsl:call-template and 
xsl:apply-templates
  +     * are also considered as Text elements.
        *
        * @param node A node
  +     * @param doExtendedCheck If this flag is true, <xsl:call-template> and 
  +     * <xsl:apply-templates> are also considered as Text elements.
  +     *
        * @return true if the node of Text type
        */
  -    private boolean isTextElement(SyntaxTreeNode node) {
  +    private boolean isTextElement(SyntaxTreeNode node, boolean 
doExtendedCheck) {
           if (node instanceof ValueOf || node instanceof Number
               || node instanceof Text)
           {
               return true;
           }
           else if (node instanceof If) {
  -            return isSimpleRTF(node);
  +            return doExtendedCheck ? isAdaptiveRTF(node) : isSimpleRTF(node);
           }
           else if (node instanceof Choose) {
               Vector contents = node.getContents();
  @@ -585,13 +613,18 @@
                   SyntaxTreeNode item = (SyntaxTreeNode)contents.elementAt(i);
                   if (item instanceof Text || 
                        ((item instanceof When || item instanceof Otherwise)
  -                     && isSimpleRTF(item)))
  +                     && ((doExtendedCheck && isAdaptiveRTF(item))
  +                         || (!doExtendedCheck && isSimpleRTF(item)))))
                       continue;
                   else
                       return false;
               }
               return true;
           }
  +        else if (doExtendedCheck && 
  +                  (node instanceof CallTemplate
  +                   || node instanceof ApplyTemplates))
  +            return true;
           else
               return false;
       }
  @@ -609,6 +642,13 @@
        final Stylesheet stylesheet = classGen.getStylesheet();
   
        boolean isSimple = isSimpleRTF(this);
  +     boolean isAdaptive = false;
  +     if (!isSimple) {
  +         isAdaptive = isAdaptiveRTF(this);
  +     }
  +     
  +     int rtfType = isSimple ? DOM.SIMPLE_RTF
  +                            : (isAdaptive ? DOM.ADAPTIVE_RTF : DOM.TREE_RTF);
        
        // Save the current handler base on the stack
        il.append(methodGen.loadHandler());
  @@ -622,9 +662,9 @@
        il.append(methodGen.loadDOM());
        int index = cpg.addInterfaceMethodref(DOM_INTF,
                                 "getResultTreeFrag",
  -                              "(IZ)" + DOM_INTF_SIG);
  +                              "(II)" + DOM_INTF_SIG);
        il.append(new PUSH(cpg, RTF_INITIAL_SIZE));
  -     il.append(new PUSH(cpg, isSimple));
  +     il.append(new PUSH(cpg, rtfType));
        il.append(new INVOKEINTERFACE(index,3));
   
        
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.11.10.18 +12 -4     
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java
  
  Index: DOMAdapter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java,v
  retrieving revision 1.11.10.17
  retrieving revision 1.11.10.18
  diff -u -r1.11.10.17 -r1.11.10.18
  --- DOMAdapter.java   7 Mar 2003 18:36:31 -0000       1.11.10.17
  +++ DOMAdapter.java   12 Mar 2003 17:44:11 -0000      1.11.10.18
  @@ -115,6 +115,14 @@
           _namespaceArray = namespaces;
       }
       
  +    public String[] getNamesArray() {
  +        return _namesArray;
  +    }
  +    
  +    public String[] getNamespaceArray() {
  +        return _namespaceArray;
  +    }
  +    
       public DOM getDOMImpl() {
        //return (_domImpl != null) ? (DOM)_domImpl : (DOM)_saxImpl;
        return _dom;
  @@ -488,13 +496,13 @@
       /**
        * Return a instance of a DOM class to be used as an RTF
        */ 
  -    public DOM getResultTreeFrag(int initSize, boolean isSimple)
  +    public DOM getResultTreeFrag(int initSize, int rtfType)
       {
        if (_saxImpl != null) {
  -         return _saxImpl.getResultTreeFrag(initSize, isSimple);
  +         return _saxImpl.getResultTreeFrag(initSize, rtfType);
        }
        else {
  -         return _dom.getResultTreeFrag(initSize, isSimple);
  +         return _dom.getResultTreeFrag(initSize, rtfType);
        }
       }
       
  
  
  
  1.68.2.27 +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
  
  Index: DOMImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
  retrieving revision 1.68.2.26
  retrieving revision 1.68.2.27
  diff -u -r1.68.2.26 -r1.68.2.27
  --- DOMImpl.java      5 Mar 2003 19:22:59 -0000       1.68.2.26
  +++ DOMImpl.java      12 Mar 2003 17:44:11 -0000      1.68.2.27
  @@ -1839,7 +1839,7 @@
       /**
        * Return a instance of a DOM class to be used as an RTF
        */ 
  -    public DOM getResultTreeFrag(int initSize, boolean isSimple)
  +    public DOM getResultTreeFrag(int initSize, int rtfType)
       {
           return (SAXImpl) ((XSLTCDTMManager)m_mgr).getDTM(null, true, 
m_wsfilter,
                                                            true, false, false,
  
  
  
  1.16.10.16 +22 -11    
xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java
  
  Index: MultiDOM.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/MultiDOM.java,v
  retrieving revision 1.16.10.15
  retrieving revision 1.16.10.16
  diff -u -r1.16.10.15 -r1.16.10.16
  --- MultiDOM.java     6 Mar 2003 20:42:31 -0000       1.16.10.15
  +++ MultiDOM.java     12 Mar 2003 17:44:12 -0000      1.16.10.16
  @@ -300,16 +300,13 @@
           DOM dom = adapter.getDOMImpl();
           
           DTMManager dtmManager = null;
  -        if (dom instanceof DTMDefaultBase)
  +        if (dom instanceof DTMDefaultBase) {
               dtmManager = ((DTMDefaultBase)dom).m_mgr;
  -        else if (dom instanceof SimpleResultTreeImpl)
  +        }
  +        else if (dom instanceof SimpleResultTreeImpl) {
               dtmManager = ((SimpleResultTreeImpl)dom).getDTMManager();
  -        
  -        /*
  -        DTMManager dtmManager =
  -                      ((DTMDefaultBase)((DOMAdapter)dom).getDOMImpl()).m_mgr;
  -        */
  -        
  +        }
  +                
           final int domNo =
                dtmManager.getDTMIdentity((DTM)dom)
                      >>> DTMManager.IDENT_DTM_NODE_BITS;
  @@ -332,6 +329,20 @@
               _documents.put(uri, new Integer(domNo));
           }
           
  +        // If the dom is an AdaptiveResultTreeImpl, we need to create a
  +        // DOMAdapter around its nested dom object (if it is non-null) and
  +        // add the DOMAdapter to the list.
  +        if (dom instanceof AdaptiveResultTreeImpl) {
  +            AdaptiveResultTreeImpl adaptiveRTF = (AdaptiveResultTreeImpl)dom;
  +            DOM nestedDom = adaptiveRTF.getNestedDOM();
  +            if (nestedDom != null) {
  +                DOMAdapter newAdapter = new DOMAdapter(nestedDom, 
  +                                                       
adapter.getNamesArray(),
  +                                                       
adapter.getNamespaceArray());
  +                addDOMAdapter(newAdapter);  
  +            } 
  +        }
  +        
           // Store mask in DOMAdapter
           adapter.setMultiDOMMask(domNo << 24);
           return (domNo << 24);
  @@ -599,9 +610,9 @@
           return _adapters[nodeId>>>24].getNodeHandle(nodeId & CLR);
       }
       
  -    public DOM getResultTreeFrag(int initSize, boolean isSimple)
  +    public DOM getResultTreeFrag(int initSize, int rtfType)
       {
  -        return _adapters[0].getResultTreeFrag(initSize, isSimple);
  +        return _adapters[0].getResultTreeFrag(initSize, rtfType);
       }
       
       public DOM getMain()
  
  
  
  1.1.2.42  +12 -3     
xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/SAXImpl.java
  
  Index: SAXImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/SAXImpl.java,v
  retrieving revision 1.1.2.41
  retrieving revision 1.1.2.42
  diff -u -r1.1.2.41 -r1.1.2.42
  --- SAXImpl.java      7 Mar 2003 18:36:31 -0000       1.1.2.41
  +++ SAXImpl.java      12 Mar 2003 17:44:12 -0000      1.1.2.42
  @@ -2122,14 +2122,23 @@
       /**
        * Return a instance of a DOM class to be used as an RTF
        */ 
  -    public DOM getResultTreeFrag(int initSize, boolean isSimple)
  +    public DOM getResultTreeFrag(int initSize, int rtfType)
       {
  -     if (isSimple) {
  +     if (rtfType == DOM.SIMPLE_RTF) {
               int dtmPos = _dtmManager.getFirstFreeDTMID();
            SimpleResultTreeImpl rtf = new SimpleResultTreeImpl(_dtmManager,
                                       dtmPos << 
DTMManager.IDENT_DTM_NODE_BITS);
            _dtmManager.addDTM(rtf, dtmPos, 0);
            return rtf;
  +     }
  +     else if (rtfType == DOM.ADAPTIVE_RTF) {
  +            int dtmPos = _dtmManager.getFirstFreeDTMID();
  +         AdaptiveResultTreeImpl rtf = new AdaptiveResultTreeImpl(_dtmManager,
  +                                    dtmPos << DTMManager.IDENT_DTM_NODE_BITS,
  +                                    m_wsfilter, initSize, m_buildIdIndex);
  +         _dtmManager.addDTM(rtf, dtmPos, 0);
  +         return rtf;
  +     
        }
        else
            return (SAXImpl) _dtmManager.getDTM(null, true, m_wsfilter,
  
  
  
  1.1.2.2   +6 -6      
xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/SimpleResultTreeImpl.java
  
  Index: SimpleResultTreeImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/SimpleResultTreeImpl.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- SimpleResultTreeImpl.java 5 Mar 2003 19:24:29 -0000       1.1.2.1
  +++ SimpleResultTreeImpl.java 12 Mar 2003 17:44:12 -0000      1.1.2.2
  @@ -285,13 +285,13 @@
       // The array of Text items, which is built by the characters() call.
       // The characters() interface can be called multiple times. Each 
character item
       // can have different escape settings.
  -    private String[] _textArray;
  +    protected String[] _textArray;
       
       // The DTMManager
  -    private XSLTCDTMManager _dtmManager;
  +    protected XSLTCDTMManager _dtmManager;
       
       // Number of character items
  -    private int _size = 0;
  +    protected int _size = 0;
       
       // The document ID
       private int _documentID;
  @@ -594,7 +594,7 @@
       /**
        * Return the node identity from a node handle.
        */
  -    public final int getNodeIdent(final int nodehandle)
  +    public int getNodeIdent(final int nodehandle)
       {
           return (nodehandle != DTM.NULL) ? (nodehandle - _documentID) : 
DTM.NULL;
       }
  @@ -602,12 +602,12 @@
       /**
        * Return the node handle from a node identity.
        */
  -    public final int getNodeHandle(final int nodeId)
  +    public int getNodeHandle(final int nodeId)
       {
           return (nodeId != DTM.NULL) ? (nodeId + _documentID) : DTM.NULL;
       }
       
  -    public DOM getResultTreeFrag(int initialSize, boolean isSimple)
  +    public DOM getResultTreeFrag(int initialSize, int rtfType)
       {
           return null;
       }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +1402 -0   
xml-xalan/java/src/org/apache/xalan/xsltc/dom/Attic/AdaptiveResultTreeImpl.java
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to