You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by suresh <su...@vergiltech.com> on 2001/12/04 10:26:38 UTC

RE: XERCES EXCEPTION HELP

hi all,

	I have a JNI application running on PIII win2000.The java application loads
a runtime vc dll that parses the content.


i pick up the a message from the queue and call dispatcher(java) which loads
the parser dll and returns back info.
this all happens fine for the first time but on receiving data for the
second time


try{
        m_parser = XMLReaderFactory::createXMLReader();

	catch(...)
    {
             cout << "Error during initialization! :\n";
    }


	this part of the code seems to throw up an exception . plz help me out .



**********************************************************
/* onMessage is called when message arrives in the queue */
*********************************************************

public void onMessage(Message msg)
	{
			if (!(msg instanceof TextMessage))
				{
					return;
				}

				try
				{
					TextMessage txtMsg = (TextMessage)msg;
					String str = txtMsg.getText();
					System.out.println("Received:"+str);


				------------------------------------------------------------
					i create a dispatch object here and call methods of it
				--------------------------------------------------------------

					objDispatch.Initialize();
					objDispatch.xmlData = str;
					System.out.println("here");
					objDispatch.DispatchPPT();
					System.out.println("here");

				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
	}

-----------------
Dispatcher class
-----------------




public class Dispatcher
{
	private native void init();
	private native void cppParser(String xmlData);
    	private native String getText();
	private native void cleanUp();
	private int ptr;
	public String xmlData = "";
	public IPowerpoint objPowerPoint;
	public IXlsXml	objIXlsXml;
	public  boolean ppt;
	private DurableSubscriber objDurableSubscriber;


	public void Initialize()
	{
		init();
	}


	public String getXmlData()
	{
		return xmlData;
	}


	Dispatcher(String Data)
	{
			xmlData = Data;
			init();
	}

	public Dispatcher(DurableSubscriber refDurableSubscriber)
	{
			System.out.println("INITIALIZED...............n\n\n\n");
			init();
			objDurableSubscriber = refDurableSubscriber;
	}

	void DispatchPPT()
	{
						String Text = "must get it from xml";

						cppParser(xmlData);

						System.out.println(Text);
	}


	public static void main(String arg[])
	{
		String Text;

		Dispatcher objDispatcher  = new Dispatcher("");

		objDispatcher.xmlData = arg[0];

       if	(objDispatcher.xmlData.indexOf ("xls",0)  == -1)
		{
			System.out.println("true");
			objDispatcher.ppt = true;
		}
		else
		{
			System.out.println("false");
			objDispatcher.ppt = false;
		}
		objDispatcher.DispatchPPT();
	}

	 static {
		System.loadLibrary("LoadParser");
	}

	}

----------------
End of dispatcher
----------------


----------------------
Native implementation
----------------------


JNIEXPORT void JNICALL Java_Dispatcher_init
                (JNIEnv * m_environment,jobject jobj)
{
    try
    {

            XMLParser* objParser = new XMLParser();
            cout<<"THE value of add of the parser is"<<objParser<<endl;
            jclass cls = m_environment->GetObjectClass(jobj);

            jfieldID memberId = m_environment->GetFieldID(cls, "ptr", "I");
            jint ptr = m_environment->GetIntField(jobj,memberId);

            //stores the pointer value of objParser into a java class
            //member ptr(int)

             m_environment->SetIntField(jobj,memberId,(long) objParser);


    }catch(...)
    {
         cout<<"Exception Here0"<<endl;
    }
}

//native implementation of cppParser() method

//functions uses the object created in init and
//parses the string passed in and stores the result
//in a message format object

JNIEXPORT void JNICALL Java_Dispatcher_cppParser
  (JNIEnv * m_environment, jobject jobj, jstring m_jxmlData)
{
    try
    {

        jclass cls = m_environment->GetObjectClass(jobj);
        jfieldID memberId = m_environment->GetFieldID(cls, "ptr", "I");
        XMLParser* objParser = (XMLParser*)
m_environment->GetIntField(jobj,memberId);
        const char* m_xmlData = m_environment->GetStringUTFChars(m_jxmlData,
0);
        MessageFormat objMessageFormat;
        objMessageFormat.setpptName(m_xmlData);
        m_xmlData  = (objMessageFormat.getXmlData()).c_str();
        cout<<m_xmlData;
        objMessageFormat = objParser->parse(m_xmlData);
    }catch(...)
    {
	-------------------------------------------------------

		An exception is caught here
	-----------------------------------------------------------


        cout<<"Exception Here1"<<endl;
    }

}

*************************************************************8888
xerces implementation

********************************************************************88


MessageFormat XMLParser::parse(string strParseBuffer)
{

	try {
        XMLPlatformUtils::Initialize();
    }
    catch (const XMLException& toCatch) {
             cout << "Error during initialization! :\n"
                     << toCatch.getMessage() << "\n";
    }

	SAXParser::ValSchemes    valScheme = SAXParser::Val_Auto;
    bool doNamespaces    = false;
    bool doSchema        = false;

    **************************************************************88
	Exception caught here when called second time from the queue
*************************************************************************8
    try{
        m_parser = XMLReaderFactory::createXMLReader();
    }catch (const XMLException& toCatch) {
             cout << "Error during initialization! :\n"
                     << toCatch.getMessage() << "\n";
    }
    catch(...)
    {
             cout << "Error during initialization! :\n";
    }


    cout<<"Parsing.......4"<<endl;

    XmlFunctionHandler m_Handler;

	m_parser->setContentHandler(&m_Handler);
	m_parser->setLexicalHandler(&m_Handler);
    m_parser->setErrorHandler(&m_Handler);

    cout<<"Parsing.......5"<<endl;

	m_DataBuf = strParseBuffer.c_str();

	m_ParseBuf = new MemBufInputSource (
		(const XMLByte*)m_DataBuf
        ,strlen(m_DataBuf)
        ,m_MemBufId
        ,true
    );
        cout<<"Parsing.......6"<<endl;

    try {

             cout<<"Parsing......."<<endl;

		m_parser->parse(*m_ParseBuf);

        //     cout<<"Parse Complete......."<<endl;

		}
    catch (const XMLException& toCatch) {
             cout << "\nFile not found: '" <<"'\n"
                 << "Exception message is: \n"
             << toCatch.getMessage() << "\n" ;
    }
	 catch (...)
    {
        cerr << "\nUnexpected exception during parsing: '"<< "'\n";
    }

    XMLPlatformUtils::Terminate();

	m_objMessageFormat = m_Handler.getMessageFormat();

    return m_objMessageFormat;

}







---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: XERCES EXCEPTION HELP

Posted by suresh <su...@vergiltech.com>.
Thanks a million erik.I struggled for two days without knowing this.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: XERCES EXCEPTION HELP

Posted by Erik Rydgren <er...@mandarinen.se>.
It looks like that you call XMLPlatformUtils::Initialize() and
XMLPlatformUtils::Terminate() several times (in XMLParser::parse).
Once you have called Terminate you can't Initialize again. I'm not sure but
it might be fixed in the newest version. Check it out
or just do not call terminate until it is really time to unload the Xerces
dll.

Regards

Erik Rydgren
Mandarinen systems AB
Sweden


-----Original Message-----
From: suresh [mailto:suresh.n@vergiltech.com]
Sent: den 4 december 2001 10:27
To: xerces-c-dev@xml.apache.org
Subject: RE: XERCES EXCEPTION HELP


hi all,

	I have a JNI application running on PIII win2000.The java application loads
a runtime vc dll that parses the content.


i pick up the a message from the queue and call dispatcher(java) which loads
the parser dll and returns back info.
this all happens fine for the first time but on receiving data for the
second time


try{
        m_parser = XMLReaderFactory::createXMLReader();

	catch(...)
    {
             cout << "Error during initialization! :\n";
    }


	this part of the code seems to throw up an exception . plz help me out .



**********************************************************
/* onMessage is called when message arrives in the queue */
*********************************************************

public void onMessage(Message msg)
	{
			if (!(msg instanceof TextMessage))
				{
					return;
				}

				try
				{
					TextMessage txtMsg = (TextMessage)msg;
					String str = txtMsg.getText();
					System.out.println("Received:"+str);


				------------------------------------------------------------
					i create a dispatch object here and call methods of it
				--------------------------------------------------------------

					objDispatch.Initialize();
					objDispatch.xmlData = str;
					System.out.println("here");
					objDispatch.DispatchPPT();
					System.out.println("here");

				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
	}

-----------------
Dispatcher class
-----------------




public class Dispatcher
{
	private native void init();
	private native void cppParser(String xmlData);
    	private native String getText();
	private native void cleanUp();
	private int ptr;
	public String xmlData = "";
	public IPowerpoint objPowerPoint;
	public IXlsXml	objIXlsXml;
	public  boolean ppt;
	private DurableSubscriber objDurableSubscriber;


	public void Initialize()
	{
		init();
	}


	public String getXmlData()
	{
		return xmlData;
	}


	Dispatcher(String Data)
	{
			xmlData = Data;
			init();
	}

	public Dispatcher(DurableSubscriber refDurableSubscriber)
	{
			System.out.println("INITIALIZED...............n\n\n\n");
			init();
			objDurableSubscriber = refDurableSubscriber;
	}

	void DispatchPPT()
	{
						String Text = "must get it from xml";

						cppParser(xmlData);

						System.out.println(Text);
	}


	public static void main(String arg[])
	{
		String Text;

		Dispatcher objDispatcher  = new Dispatcher("");

		objDispatcher.xmlData = arg[0];

       if	(objDispatcher.xmlData.indexOf ("xls",0)  == -1)
		{
			System.out.println("true");
			objDispatcher.ppt = true;
		}
		else
		{
			System.out.println("false");
			objDispatcher.ppt = false;
		}
		objDispatcher.DispatchPPT();
	}

	 static {
		System.loadLibrary("LoadParser");
	}

	}

----------------
End of dispatcher
----------------


----------------------
Native implementation
----------------------


JNIEXPORT void JNICALL Java_Dispatcher_init
                (JNIEnv * m_environment,jobject jobj)
{
    try
    {

            XMLParser* objParser = new XMLParser();
            cout<<"THE value of add of the parser is"<<objParser<<endl;
            jclass cls = m_environment->GetObjectClass(jobj);

            jfieldID memberId = m_environment->GetFieldID(cls, "ptr", "I");
            jint ptr = m_environment->GetIntField(jobj,memberId);

            //stores the pointer value of objParser into a java class
            //member ptr(int)

             m_environment->SetIntField(jobj,memberId,(long) objParser);


    }catch(...)
    {
         cout<<"Exception Here0"<<endl;
    }
}

//native implementation of cppParser() method

//functions uses the object created in init and
//parses the string passed in and stores the result
//in a message format object

JNIEXPORT void JNICALL Java_Dispatcher_cppParser
  (JNIEnv * m_environment, jobject jobj, jstring m_jxmlData)
{
    try
    {

        jclass cls = m_environment->GetObjectClass(jobj);
        jfieldID memberId = m_environment->GetFieldID(cls, "ptr", "I");
        XMLParser* objParser = (XMLParser*)
m_environment->GetIntField(jobj,memberId);
        const char* m_xmlData = m_environment->GetStringUTFChars(m_jxmlData,
0);
        MessageFormat objMessageFormat;
        objMessageFormat.setpptName(m_xmlData);
        m_xmlData  = (objMessageFormat.getXmlData()).c_str();
        cout<<m_xmlData;
        objMessageFormat = objParser->parse(m_xmlData);
    }catch(...)
    {
	-------------------------------------------------------

		An exception is caught here
	-----------------------------------------------------------


        cout<<"Exception Here1"<<endl;
    }

}

*************************************************************8888
xerces implementation

********************************************************************88


MessageFormat XMLParser::parse(string strParseBuffer)
{

	try {
        XMLPlatformUtils::Initialize();
    }
    catch (const XMLException& toCatch) {
             cout << "Error during initialization! :\n"
                     << toCatch.getMessage() << "\n";
    }

	SAXParser::ValSchemes    valScheme = SAXParser::Val_Auto;
    bool doNamespaces    = false;
    bool doSchema        = false;

    **************************************************************88
	Exception caught here when called second time from the queue
*************************************************************************8
    try{
        m_parser = XMLReaderFactory::createXMLReader();
    }catch (const XMLException& toCatch) {
             cout << "Error during initialization! :\n"
                     << toCatch.getMessage() << "\n";
    }
    catch(...)
    {
             cout << "Error during initialization! :\n";
    }


    cout<<"Parsing.......4"<<endl;

    XmlFunctionHandler m_Handler;

	m_parser->setContentHandler(&m_Handler);
	m_parser->setLexicalHandler(&m_Handler);
    m_parser->setErrorHandler(&m_Handler);

    cout<<"Parsing.......5"<<endl;

	m_DataBuf = strParseBuffer.c_str();

	m_ParseBuf = new MemBufInputSource (
		(const XMLByte*)m_DataBuf
        ,strlen(m_DataBuf)
        ,m_MemBufId
        ,true
    );
        cout<<"Parsing.......6"<<endl;

    try {

             cout<<"Parsing......."<<endl;

		m_parser->parse(*m_ParseBuf);

        //     cout<<"Parse Complete......."<<endl;

		}
    catch (const XMLException& toCatch) {
             cout << "\nFile not found: '" <<"'\n"
                 << "Exception message is: \n"
             << toCatch.getMessage() << "\n" ;
    }
	 catch (...)
    {
        cerr << "\nUnexpected exception during parsing: '"<< "'\n";
    }

    XMLPlatformUtils::Terminate();

	m_objMessageFormat = m_Handler.getMessageFormat();

    return m_objMessageFormat;

}







---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org