You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by au...@apache.org on 2001/04/27 22:01:24 UTC
cvs commit: xml-xalan/c/samples/ThreadSafe ThreadSafe.cpp
auriemma 01/04/27 13:01:24
Modified: c/samples/ThreadSafe ThreadSafe.cpp
Log:
Updated to use the XalanTransformer class.
Revision Changes Path
1.12 +96 -166 xml-xalan/c/samples/ThreadSafe/ThreadSafe.cpp
Index: ThreadSafe.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/samples/ThreadSafe/ThreadSafe.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ThreadSafe.cpp 2001/01/08 20:26:35 1.11
+++ ThreadSafe.cpp 2001/04/27 20:01:23 1.12
@@ -1,29 +1,20 @@
+// Base header file. Must be first.
+#include <Include/PlatformDefinitions.hpp>
+
+
+
#include <cassert>
#include <fstream>
#include <iostream>
#include <strstream>
-#include <util/PlatformUtils.hpp>
-
-#include <PlatformSupport/DOMStringHelper.hpp>
-#include <DOMSupport/DOMSupportDefault.hpp>
-#include <XPath/XObjectFactoryDefault.hpp>
-#include <XPath/XPathFactoryDefault.hpp>
-#include <XSLT/StylesheetConstructionContextDefault.hpp>
-#include <XSLT/StylesheetExecutionContextDefault.hpp>
-#include <XSLT/StylesheetRoot.hpp>
-#include <XSLT/XSLTEngineImpl.hpp>
-#include <XSLT/XSLTInit.hpp>
-#include <XSLT/XSLTInputSource.hpp>
-#include <XSLT/XSLTProcessorEnvSupportDefault.hpp>
-#include <XSLT/XSLTResultTarget.hpp>
+#include <util/PlatformUtils.hpp>
-#include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
-#include <XalanSourceTree/XalanSourceTreeParserLiaison.hpp>
+#include <XalanTransformer/XalanTransformer.hpp>
@@ -33,6 +24,8 @@
#include <winbase.h>
#define THREADFUNCTIONRETURN DWORD WINAPI
+
+
#if !defined(XALAN_NO_NAMESPACES)
using std::cerr;
using std::cout;
@@ -43,9 +36,12 @@
using std::string;
#endif
+
+
// Used to hold compiled stylesheet and XML source document.
-StylesheetRoot* glbStylesheetRoot;
-XalanNode* glbDocSource;
+XalanCompiledStylesheet* glbCompiledStylesheet = 0;
+XalanParsedSource* glbParsedSource = 0;
+int glbError = 0;
// Print messages tracking the progress of each thread, and the
// beginning and end of the entire operation.
@@ -61,49 +57,21 @@
THREADFUNCTIONRETURN theThread(LPVOID param)
{
-// This routine uses a compiled stylesheet (glbStylesheetRoot),
-// and a binary source tree (glbSourceDoc) to perform the
+// This routine uses a compiled stylesheet (glbCompiledStylesheet),
+// and a binary source tree (glbParsedSource) to perform the
// transformation.
+ int theResult = 0;
+
const int number = reinterpret_cast<int>(param);
+
const DWORD theThreadID = GetCurrentThreadId();
- // Create some support objects that are necessary for running the processor...
- XalanSourceTreeDOMSupport theDOMSupport;
- XalanSourceTreeParserLiaison theParserLiaison(theDOMSupport);
-
- // Hook the two together...
- theDOMSupport.setParserLiaison(&theParserLiaison);
-
- // Create some more support objects.
- XSLTProcessorEnvSupportDefault theXSLTProcessorEnvSupport;
- XObjectFactoryDefault theXObjectFactory;
- XPathFactoryDefault theXPathFactory;
-
- // Create a processor...and output the start message.
- XSLTEngineImpl theProcessor(
- theParserLiaison,
- theXSLTProcessorEnvSupport,
- theDOMSupport,
- theXObjectFactory,
- theXPathFactory);
outputMessage(theThreadID,"Starting ");
-
- // Connect the processor to the support object...
- theXSLTProcessorEnvSupport.setProcessor(&theProcessor);
- // The execution context uses the same factory support objects as
- // the processor, since those objects have the same lifetime as
- // other objects created as a result of the execution.
- StylesheetExecutionContextDefault ssExecutionContext(
- theProcessor,
- theXSLTProcessorEnvSupport,
- theDOMSupport,
- theXObjectFactory);
+ // Create a XalanTransformer.
+ XalanTransformer theXalanTransformer;
- // Set the XSLTInputSource...
- XSLTInputSource xslIn(glbDocSource);
-
// Generate the output file name for this thread.
ostrstream theFormatterOut;
theFormatterOut << "birds" << number << ".out" << '\0';
@@ -114,14 +82,23 @@
// Unfreeze the ostrstream, so memory is returned...
theFormatterOut.freeze(false);
- // Set the processor to use the compiled stylesheet. Then do the transform
- // with the process() method that uses the compiled stylesheet.
- // Report the start of the transformation and the termination of the thread.
- theProcessor.setStylesheetRoot(glbStylesheetRoot);
outputMessage(theThreadID,"Transforming");
- theProcessor.process(xslIn,theResultTarget,ssExecutionContext);
+
+ // Do the transform.
+ theResult = theXalanTransformer.transform(*glbParsedSource, glbCompiledStylesheet, theResultTarget);
+
+ if(theResult != 0)
+ {
+ cerr << "ThreadSafe Error: \n" << theXalanTransformer.getLastError()
+ << endl
+ << endl;
+
+ glbError = theResult;
+ }
+
outputMessage(theThreadID,"Finishing");
- return (0);
+
+ return (theResult);
}
// Create and run the threads...
@@ -136,48 +113,41 @@
std::vector<HANDLE> hThreads;
hThreads.reserve(nThreads);
- int i = 0;
-
- try
+ int i = 0;
+
+ cout << endl << "Clock before starting threads: " << clock() << endl;
+
+ for (i=0; i< nThreads; i++)
{
- cout << endl << "Clock before starting threads: " << clock() << endl;
+ HANDLE hThread;
+ DWORD threadID;
+
+ hThread = CreateThread(
+ 0,
+ dwStackSize,
+ lpStartAddress, // pointer to thread function
+ reinterpret_cast<LPVOID>(i), // argument for new thread
+ dwCreationFlags, // creation flags
+ &threadID);
- for (i=0; i< nThreads; i++)
- {
- HANDLE hThread;
- DWORD threadID;
-
- hThread = CreateThread(
- 0, dwStackSize,
- lpStartAddress, // pointer to thread function
- reinterpret_cast<LPVOID>(i), // argument for new thread
- dwCreationFlags, // creation flags
- &threadID);
- assert(hThread != 0);
- hThreads.push_back(hThread);
- }
-
- WaitForMultipleObjects(hThreads.size(), &hThreads[0], TRUE, INFINITE);
-
- cout << endl << "Clock after threads: " << clock() << endl;
-
- for (i = 0; i < nThreads; ++i)
- {
- CloseHandle(hThreads[i]);
- }
+ assert(hThread != 0);
+
+ hThreads.push_back(hThread);
}
- catch(...)
+
+ WaitForMultipleObjects(hThreads.size(), &hThreads[0], TRUE, INFINITE);
+
+ cout << endl << "Clock after threads: " << clock() << endl;
+
+ for (i = 0; i < nThreads; ++i)
{
- cerr << "Exception caught!!!"
- << endl
- << endl;
+ CloseHandle(hThreads[i]);
}
}
int main(int argc, const char* /* argv */[])
{
-
if (argc != 1)
{
cerr << "Usage: ThreadTest"
@@ -186,81 +156,41 @@
}
else
{
- try
- {
- // Call the static initializer for Xerces...
- XMLPlatformUtils::Initialize();
-
- {
- // Initialize the Xalan XSLT subsystem...
- XSLTInit theInit;
-
- // Create some support objects that are necessary for running the processor...
- XalanSourceTreeDOMSupport ssDOMSupport;
- XalanSourceTreeParserLiaison ssParserLiaison(ssDOMSupport);
-
- // Hook the two together...
- ssDOMSupport.setParserLiaison(&ssParserLiaison);
-
- // Create some more support objects.
- XSLTProcessorEnvSupportDefault ssXSLTProcessorEnvSupport;
- XObjectFactoryDefault ssXObjectFactory;
- XPathFactoryDefault ssXPathFactory;
-
- // Create a processor...
- // This processor is used to compile the stylesheet and the source document.
- // Each thread uses its own processor to perform a transformation.
-
- XSLTEngineImpl ssProcessor(
- ssParserLiaison,
- ssXSLTProcessorEnvSupport,
- ssDOMSupport,
- ssXObjectFactory,
- ssXPathFactory);
-
- // Create a stylesheet construction context, using the
- // stylesheet's factory support objects.
- StylesheetConstructionContextDefault ssConstructionContext(
- ssProcessor,
- ssXSLTProcessorEnvSupport,
- ssXPathFactory);
-
- const XalanDOMString theXSLFileName("birds.xsl");
- const XalanDOMString theXMLFileName("birds.xml");
-
- // Our stylesheet XML input document and XSL stylesheet
- XSLTInputSource xmlDocSource(c_wstr(theXMLFileName));
- XSLTInputSource xslStylesheetSource(c_wstr(theXSLFileName));
-
- // Use the processor to create a StylesheetRoot for the specified
- // input XSL. This is the compiled stylesheet. We don't have to
- // delete it, since it is owned by the StylesheetConstructionContext
- // instance.
- glbStylesheetRoot = ssProcessor.processStylesheet(xslStylesheetSource,
- ssConstructionContext);
- assert(glbStylesheetRoot != 0);
-
- // Compile the XML source document as well. All threads will use
- // this binary representation of the source tree.
- glbDocSource = ssProcessor.getSourceTreeFromInput(xmlDocSource);
- assert(glbDocSource != 0);
-
- // Create and run the threads...
- // Each thread uses the same XalanNode and
- // StylesheetRoot to perform a transformation.
- doThreads(10);
- }
-
- // Call the static terminator for Xerces...
- XMLPlatformUtils::Terminate();
- }
- catch(...)
- {
- cerr << "Exception caught!!!"
- << endl
- << endl;
- }
+ // Call the static initializer for Xerces.
+ XMLPlatformUtils::Initialize();
+
+ // Initialize Xalan.
+ XalanTransformer::initialize();
+
+ // Create a XalanTransformer.
+ XalanTransformer theXalanTransformer;
+
+ // Our input files...The assumption is that the executable will be run
+ // from same directory as the input files.
+ const char* theXSLFileName = "birds.xsl";
+ const char* theXMLFileName = "birds.xml";
+
+ glbCompiledStylesheet = theXalanTransformer.compileStylesheet(theXSLFileName);
+
+ assert(glbCompiledStylesheet != 0);
+
+ // Compile the XML source document as well. All threads will use
+ // this binary representation of the source tree.
+ glbParsedSource =theXalanTransformer.parseSource(theXMLFileName);
+
+ assert(glbParsedSource != 0);
+
+ // Create and run the threads...
+ // Each thread uses the same XalanNode and
+ // StylesheetRoot to perform a transformation.
+ doThreads(10);
+
+ // Terminate Xalan.
+ XalanTransformer::terminate();
+
+ // Call the static terminator for Xerces.
+ XMLPlatformUtils::Terminate();
}
- return 0;
+ return glbError;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org