sboag       99/12/16 07:00:37

  Modified:    src/org/apache/xalan/xslt ElemTemplate.java Stylesheet.java
                        XSLTEngineImpl.java
  Log:
  Fixed some major threading problems.  The stylesheet build is now threadsafe 
processor instance per thread, the stylesheet is safe to be shared over 
multiple threads.
  
  Revision  Changes    Path
  1.3       +1 -1      xml-xalan/src/org/apache/xalan/xslt/ElemTemplate.java
  
  Index: ElemTemplate.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/ElemTemplate.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElemTemplate.java 1999/12/15 16:25:13     1.2
  +++ ElemTemplate.java 1999/12/16 15:00:36     1.3
  @@ -90,7 +90,7 @@
         switch(tok)
         {
         case Constants.TATTRNAME_MATCH:
  -        m_matchPattern = m_stylesheet.m_xpathFactory.create();
  +        m_matchPattern = m_stylesheet.getXPathFactory().create();
           m_stylesheet.m_xpathProcessor.initMatchPattern(m_matchPattern, 
atts.getValue(i), this);
           break;
         case Constants.TATTRNAME_NAME:
  
  
  
  1.18      +9 -8      xml-xalan/src/org/apache/xalan/xslt/Stylesheet.java
  
  Index: Stylesheet.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/Stylesheet.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Stylesheet.java   1999/12/16 11:19:19     1.17
  +++ Stylesheet.java   1999/12/16 15:00:36     1.18
  @@ -1289,12 +1289,12 @@
     /**
      * Factory for creating xpaths.
      */
  -  static XPathFactory m_xpathFactory = null;
  +  private XPathFactory m_xpathFactory = null;
     
     /**
      * Statically init anything to do with XPath.
      */
  -  static void initXPath(XSLTEngineImpl processor)
  +  void initXPath(XSLTEngineImpl processor)
     {
       m_xpathFactory = 
processor.getXMLProcessorLiaison().getDefaultXPathFactory();
       
  @@ -1314,6 +1314,7 @@
       
       // m_parserLiaison.setProcessorOwner(this);
       m_xpathProcessor = new 
XPathProcessorImpl(processor.getXMLProcessorLiaison());
  +    
       m_xpath = m_xpathFactory.create();
       m_xpath.installFunction("document", new FuncDocument());
       m_xpath.installFunction("format-number", new FuncFormatNumb());
  @@ -1323,7 +1324,7 @@
     /**
      * The query/pattern-matcher object.
      */
  -  static XPathProcessor m_xpathProcessor = null;
  +  XPathProcessor m_xpathProcessor = null;
   
     /**
      * Evaluate an xpath string and return the result.
  @@ -1366,7 +1367,7 @@
     /**
      * Evaluate an xpath string and return the result.
      */
  -  public static XObject evalXPathStr(XPathSupport execContext, String str, 
  +  public XObject evalXPathStr(XPathSupport execContext, String str, 
                                 Node context, PrefixResolver nsNode)
       throws org.xml.sax.SAXException
     {
  @@ -1740,7 +1741,7 @@
     /**
      * Set the factory for making XPaths.
      */
  -  public static void setXPathFactory(XPathFactory factory)
  +  public void setXPathFactory(XPathFactory factory)
     {
       m_xpathFactory = factory;
     }
  @@ -1748,7 +1749,7 @@
     /**
      * Get the factory for making xpaths.
      */
  -  public static XPathFactory getXPathFactory()
  +  public XPathFactory getXPathFactory()
     {
       return m_xpathFactory;
     }
  @@ -1757,7 +1758,7 @@
      * Set the XPath processor object.
      * @param processor A XPathProcessor interface.
      */
  -  public static void setXPathProcessor(XPathProcessor processor)
  +  public void setXPathProcessor(XPathProcessor processor)
     {
       m_xpathProcessor = processor;
     }
  @@ -1766,7 +1767,7 @@
      * Get the XPath processor object.
      * @return The XPathProcessor interface being used.
      */
  -  public static XPathProcessor getXPathProcessor()
  +  public XPathProcessor getXPathProcessor()
     {
       return m_xpathProcessor;
     }  
  
  
  
  1.26      +42 -9     xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java
  
  Index: XSLTEngineImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/src/org/apache/xalan/xslt/XSLTEngineImpl.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- XSLTEngineImpl.java       1999/12/16 09:06:05     1.25
  +++ XSLTEngineImpl.java       1999/12/16 15:00:36     1.26
  @@ -648,8 +648,15 @@
           = new StylesheetHandler(this, m_stylesheetRoot);
         if(null != stylesheetSource.getNode())
         {
  -        TreeWalker tw = new TreeWalker(stylesheetProcessor);
  -        tw.traverse(stylesheetSource.getNode());
  +        if(stylesheetSource.getNode() instanceof StylesheetRoot)
  +        {
  +          m_stylesheetRoot = (StylesheetRoot)stylesheetSource.getNode();
  +        }
  +        else
  +        {
  +          TreeWalker tw = new TreeWalker(stylesheetProcessor);
  +          tw.traverse(stylesheetSource.getNode());
  +        }
         }
         else
         {
  @@ -862,26 +869,52 @@
         diag("Locating stylesheet from fragment identifier...");
         String fragID = xslURLString.substring(1);
         PrefixResolver nsNode = getExecContext().getNamespaceContext();
  +      
         // Try a bunch of really ugly stuff to find the fragment.
         // What's the right way to do this?
  -      if(null == Stylesheet.m_xpathFactory)
  -        Stylesheet.initXPath(this);
  +      
  +      // Create a XPath parser.
  +      XPathProcessorImpl parser = new XPathProcessorImpl();
  +      
  +      // Create the XPath object.
  +      XPath xpath = new XPath();
  +      
  +      // Parse the xpath
  +      parser.initXPath(xpath, "id("+fragID+")", nsNode);
  +      XObject xobj = xpath.execute(getExecContext(), fragBase, nsNode);
   
  -      XObject xobj = Stylesheet.evalXPathStr(getExecContext(), 
"id("+fragID+")",
  -                                             fragBase, nsNode);
         NodeList nl = xobj.nodeset();
         if(nl.getLength() == 0)
         {
  -        xobj = Stylesheet.evalXPathStr(getExecContext(), "//[EMAIL 
PROTECTED]'"+fragID+"']", fragBase, nsNode);
  +        // xobj = Stylesheet.evalXPathStr(getExecContext(), "//[EMAIL 
PROTECTED]'"+fragID+"']", fragBase, nsNode);
  +        // Create the XPath object.
  +        xpath = new XPath();
  +        
  +        // Parse the xpath
  +        parser.initXPath(xpath, "//[EMAIL PROTECTED]'"+fragID+"']", nsNode);
  +        xobj = xpath.execute(getExecContext(), fragBase, nsNode);
  +
           nl = xobj.nodeset();
           if(nl.getLength() == 0)
           {
  -          xobj = Stylesheet.evalXPathStr(getExecContext(), "//[EMAIL 
PROTECTED]'"+fragID+"']", fragBase, nsNode);
  +          // xobj = Stylesheet.evalXPathStr(getExecContext(), "//[EMAIL 
PROTECTED]'"+fragID+"']", fragBase, nsNode);
  +          // Create the XPath object.
  +          xpath = new XPath();
  +          
  +          // Parse the xpath
  +          parser.initXPath(xpath, "//[EMAIL PROTECTED]'"+fragID+"']", 
nsNode);
  +          xobj = xpath.execute(getExecContext(), fragBase, nsNode);
             nl = xobj.nodeset();
             if(nl.getLength() == 0)
             {
               // Well, hell, maybe it's an XPath...
  -            xobj = Stylesheet.evalXPathStr(getExecContext(), fragID, 
fragBase, nsNode);
  +            // xobj = Stylesheet.evalXPathStr(getExecContext(), fragID, 
fragBase, nsNode);
  +            // Create the XPath object.
  +            xpath = new XPath();
  +            
  +            // Parse the xpath
  +            parser.initXPath(xpath, fragID, nsNode);
  +            xobj = xpath.execute(getExecContext(), fragBase, nsNode);
               nl = xobj.nodeset();
             }
           }
  
  
  

Reply via email to