You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Voytenko, Dimitry" <DV...@SECTORBASE.COM> on 2000/10/18 05:44:58 UTC

Thread safe

Hi,
I use functions from XPathApi. Everything works great. But I wanna optimize
some code. So I need to know if some parts of this code is not thread-safe.
So I want to move variables xpathSupport, parser and may be some more to
static variables so all invokes of eval(...) will use them so no need to
recreate them each time. So can someone say me which of this objects are
thread-safe in this case

Thank you

  public static XObject eval(Node contextNode, String str, Node
namespaceNode)
    throws SAXException
  {
    XPathSupport xpathSupport = new XMLParserLiaisonDefault(); //
<-----------------------
    
    if(null == namespaceNode)
      namespaceNode = contextNode;

    PrefixResolverDefault prefixResolver = new
PrefixResolverDefault((namespaceNode.getNodeType() == Node.DOCUMENT_NODE)
                                                         ?
((Document)namespaceNode).getDocumentElement() :
                                                           namespaceNode);

    // Create the XPath object.
    XPath xpath = new XPath();

    // Create a XPath parser.
    XPathProcessorImpl parser = new XPathProcessorImpl(xpathSupport);    //
<-----------------------
    parser.initXPath(xpath, str, prefixResolver);

    // Execute the XPath, and have it return the result
    return xpath.execute(xpathSupport, contextNode, prefixResolver);
  }