xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkess...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xpath SourceTreeManager.java
Date Wed, 10 Oct 2001 18:42:08 GMT
jkesselm    01/10/10 11:42:08

  Modified:    java/src/org/apache/xalan/processor
                        ProcessorStylesheetElement.java
                        StylesheetHandler.java
               java/src/org/apache/xalan/templates ElemForEach.java
               java/src/org/apache/xalan/transformer ResultTreeHandler.java
               java/src/org/apache/xml/dtm/ref DTMManagerDefault.java
               java/src/org/apache/xml/utils NamespaceSupport2.java
               java/src/org/apache/xpath SourceTreeManager.java
  Log:
  Restoring support for the (highly limited) <?xalan:doc-cache-off?>
  processing instruction. This can _only_ be used within an
  <xsl:for-each> whose select is based on a document() call, but
  within that limited case can be useful for minimizing memory use
  by discarding each document after you're done with it. You can think
  of this as being a kind of "pruning" for the DTMManager, as
  opposed to pruning subtrees out of individual documents.
  
  The current implementation isn't safe, which is why it isn't published as a Xalan feature.
  Use _entirely_ at your own risk.
  
  The Right Answer here involves merging the SourceTreeManager
  logic directly into the DTMManager (rather than having two separate
  caches of open documents), and developing some heuristics that
  enable us to determine when a DTM can/should be discarded. I
  expect that's going to involve explicitly managing reference counts
  and the like, whch may in turn push us toward developing a "smart
  pointer" flyweight object to replace the current integer DTM Node
  Handle. We need to do a lot more design work in this area.
  
  Revision  Changes    Path
  1.10      +1 -0      xml-xalan/java/src/org/apache/xalan/processor/ProcessorStylesheetElement.java
  
  Index: ProcessorStylesheetElement.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/ProcessorStylesheetElement.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ProcessorStylesheetElement.java	2001/03/29 22:39:32	1.9
  +++ ProcessorStylesheetElement.java	2001/10/10 18:42:07	1.10
  @@ -133,6 +133,7 @@
   
         stylesheet.setDOMBackPointer(handler.getOriginatingNode());
         stylesheet.setLocaterInfo(handler.getLocator());
  +
         stylesheet.setPrefixes(handler.getNamespaceSupport());
         handler.pushStylesheet(stylesheet);
         setPropertiesFromAttributes(handler, rawName, attributes,
  
  
  
  1.47      +60 -1     xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java
  
  Index: StylesheetHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/processor/StylesheetHandler.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- StylesheetHandler.java	2001/10/05 14:56:22	1.46
  +++ StylesheetHandler.java	2001/10/10 18:42:07	1.47
  @@ -72,6 +72,7 @@
   import org.apache.xalan.templates.Constants;
   import org.apache.xalan.templates.ElemTemplateElement;
   import org.apache.xalan.templates.ElemUnknown;
  +import org.apache.xalan.templates.ElemForEach;
   import org.apache.xalan.templates.StylesheetRoot;
   import org.apache.xalan.templates.Stylesheet;
   import org.apache.xml.utils.NodeConsumer;
  @@ -609,6 +610,7 @@
       nssupport.pushContext();
       
       int n = m_prefixMappings.size();
  +
       for (int i = 0; i < n; i++) 
       {
         String prefix = (String)m_prefixMappings.elementAt(i++);
  @@ -757,6 +759,14 @@
     /**
      * Receive notification of a processing instruction.
      *
  +   * <p>The Parser will invoke this method once for each processing
  +   * instruction found: note that processing instructions may occur
  +   * before or after the main document element.</p>
  +   *
  +   * <p>A SAX parser should never report an XML declaration (XML 1.0,
  +   * section 2.8) or a text declaration (XML 1.0, section 4.3.1)
  +   * using this method.</p>
  +   *
      * <p>By default, do nothing.  Application writers may override this
      * method in a subclass to take specific actions for each
      * processing instruction, such as setting status variables or
  @@ -773,9 +783,58 @@
     public void processingInstruction(String target, String data)
             throws org.xml.sax.SAXException
     {
  -
       if (!m_shouldProcess)
         return;
  +
  +    // Recreating Scott's kluge:
  +    // A xsl:for-each or xsl:apply-templates may have a special 
  +    // PI that tells us not to cache the document.  This PI 
  +    // should really be namespaced.
  +    //    String localName = getLocalName(target);
  +    //    String ns = m_stylesheet.getNamespaceFromStack(target);
  +    //
  +    // %REVIEW%: We need a better PI architecture
  +    
  +    String prefix="",ns="", localName=target;
  +    int colon=target.indexOf(':');
  +    if(colon>=0)
  +    {
  +      ns=getNamespaceForPrefix(prefix=target.substring(0,colon));
  +      localName=target.substring(colon+1);
  +    }
  +
  +    try
  +    {
  +      // A xsl:for-each or xsl:apply-templates may have a special 
  +      // PI that tells us not to cache the document.  This PI 
  +      // should really be namespaced... but since the XML Namespaces
  +      // spec never defined namespaces as applying to PI's, and since
  +      // the testcase we're trying to support is inconsistant in whether
  +      // it binds the prefix, I'm going to make this sloppy for
  +      // testing purposes.
  +      if(
  +	 "xalan:doc-cache-off".equals(target) ||
  +	   ("doc-cache-off".equals(localName) &&
  +	    ns.equals("org.apache.xalan.xslt.extensions.Redirect") )
  +	 )
  +      {
  +	if(!(m_elems.peek() instanceof ElemForEach))
  +          throw new TransformerException
  +	    ("xalan:doc-cache-off not allowed here!", 
  +	     getLocator());
  +        ElemForEach elem = (ElemForEach)m_elems.peek();
  +
  +        elem.m_doc_cache_off = true;
  +
  +	//System.out.println("JJK***** Recognized <? {"+ns+"}"+prefix+":"+localName+" "+data+"?>");
  +      }
  +    }
  +    catch(Exception e)
  +    {
  +      // JJK: Officially, unknown PIs can just be ignored.
  +      // Do we want to issue a warning?
  +    }
  +
   
       flushCharacters();
       getCurrentProcessor().processingInstruction(this, target, data);
  
  
  
  1.23      +32 -1     xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java
  
  Index: ElemForEach.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemForEach.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- ElemForEach.java	2001/06/19 21:31:40	1.22
  +++ ElemForEach.java	2001/10/10 18:42:07	1.23
  @@ -105,7 +105,19 @@
    */
   public class ElemForEach extends ElemTemplateElement
   {
  -
  +  /** Set true to request some basic status reports */
  +  static final boolean DEBUG = false;
  +  
  +  /**
  +   * This is set by an "xalan:doc-cache-off" pi.  It tells the engine that
  +   * documents created in the location paths executed by this element
  +   * will not be reparsed. It's set by StylesheetHandler during
  +   * construction. Note that this feature applies _only_ to xsl:for-each
  +   * elements in its current incarnation; a more general cache management
  +   * solution is desperately needed.
  +   */
  +  public boolean m_doc_cache_off=false;
  +  
     /**
      * Construct a element representing xsl:for-each.
      */
  @@ -425,6 +437,25 @@
             transformer.setCurrentElement(t);
             t.execute(transformer);
           }
  +
  +	// KLUGE: Implement <?xalan:doc_cache_off?> 
  +	// ASSUMPTION: This will be set only when the XPath was indeed
  +	// a call to the Document() function. Calling it in other
  +	// situations is likely to fry Xalan.
  +	//
  +	// %REVIEW% We need a MUCH cleaner solution -- one that will
  +	// handle cleaning up after document() and getDTM() in other
  +	// contexts. The whole SourceTreeManager mechanism should probably
  +	// be moved into DTMManager rather than being explicitly invoked in
  +	// FuncDocument and here.
  +	if(m_doc_cache_off)
  +	{
  +	  if(DEBUG)
  +	    System.out.println("JJK***** CACHE RELEASE *****\n"+
  +			       "\tdtm="+dtm.getDocumentBaseURI());
  +	  xctxt.getSourceTreeManager().removeDocumentFromCache(dtm.getDocument());
  +	  xctxt.release(dtm,false);
  +	}
         }
       }
       finally
  
  
  
  1.48      +1 -1      xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java
  
  Index: ResultTreeHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/ResultTreeHandler.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- ResultTreeHandler.java	2001/09/12 20:05:12	1.47
  +++ ResultTreeHandler.java	2001/10/10 18:42:07	1.48
  @@ -1058,7 +1058,7 @@
     }
   
     /**
  -   * JJK: Combination of sendStartPrefixMappings and
  +   * Combination of sendStartPrefixMappings and
      * addNSDeclsToAttrs() (which it mostly replaces).  Merging the two
      * loops is significantly more efficient.
      *
  
  
  
  1.25      +2 -2      xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java
  
  Index: DTMManagerDefault.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- DTMManagerDefault.java	2001/10/10 16:04:08	1.24
  +++ DTMManagerDefault.java	2001/10/10 18:42:07	1.25
  @@ -605,10 +605,10 @@
       {
         System.out.println("Releasing "+
   			 (shouldHardDelete ? "HARD" : "soft")+
  -			 " systemID="+
  +			 " dtm="+
   			 // Following shouldn't need a nodeHandle, but does...
   			 // and doesn't seem to report the intended value
  -			 dtm.getDocumentSystemIdentifier(dtm.getDocument())
  +			 dtm.getDocumentBaseURI()
   			 );
       }
   
  
  
  
  1.7       +1 -1      xml-xalan/java/src/org/apache/xml/utils/NamespaceSupport2.java
  
  Index: NamespaceSupport2.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/utils/NamespaceSupport2.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- NamespaceSupport2.java	2001/08/06 18:38:28	1.6
  +++ NamespaceSupport2.java	2001/10/10 18:42:07	1.7
  @@ -129,7 +129,7 @@
        */
       public void reset ()
       {
  -        // JJK: Discarding the whole stack doesn't save us a lot versus
  +        // Discarding the whole stack doesn't save us a lot versus
           // creating a new NamespaceSupport. Do we care, or should we
           // change this to just reset the root context?
           currentContext = new Context2(null);
  
  
  
  1.29      +22 -0     xml-xalan/java/src/org/apache/xpath/SourceTreeManager.java
  
  Index: SourceTreeManager.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/SourceTreeManager.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- SourceTreeManager.java	2001/06/20 14:02:37	1.28
  +++ SourceTreeManager.java	2001/10/10 18:42:07	1.29
  @@ -194,6 +194,28 @@
       return source;
     }
   
  +  /** JJK: Support  <?xalan:doc_cache_off?> kluge in ElemForEach.
  +   * TODO: This function is highly dangerous. Cache management must be improved.
  +   *
  +   * @param n The node to remove.
  +   */
  +  public void removeDocumentFromCache(int n)
  +  {
  +    if(DTM.NULL ==n)
  +      return;
  +    for(int i=m_sourceTree.size()-1;i>=0;--i)
  +    {
  +      SourceTree st=(SourceTree)m_sourceTree.elementAt(i);
  +      if(st!=null && st.m_root==n)
  +      {
  +	m_sourceTree.removeElementAt(i);
  +	return;
  +      }
  +    }
  +  }
  +  
  +
  +
     /**
      * Put the source tree root node in the document cache.
      * TODO: This function needs to be a LOT more sophisticated.
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message