SAX and JNI

I'm having problems using Java classes from C. I've managed to trace the problem as far as the SAX parser, but I have no idea why there's a problem at all.
With the -verbose:jni option on, there's a message: "Unable to read from file" and then the JVM stops (crashes actually.)
I create a VM as follows:
        JavaVM* jvm;
     JNIEnv* env;
     JavaVMInitArgs args;
     JavaVMOption options[3];
     int ret;
     args.version = JNI_VERSION_1_4;
     args.nOptions = 3;
     options[0].optionString = classPath;
     options[1].optionString = "-verbose:jni";
     options[2].optionString = "-Djavax.xml.transform.TransformerFactory=net.sf.saxon.TransformerFactoryImpl";
     args.options = options;
     args.ignoreUnrecognized = JNI_TRUE;
     if ((ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args)) < 0) {
            /* error */
        }classPath is just a char* that lists all the Jars the project uses. I wrote a Java main() to test my code and when you run it with the exact same classpath, it works.
The Java code that creates and starts the SAX parser looks like:
     XMLHandler handler = new XMLHandler ();
     SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        try {
             saxParser.parse(f, handler);
        } catch (java.io.IOException e) {
             e.printStackTrace ();
        } catch (Exception e) {
             e.printStackTrace ();
        }Is there something about JNI that SAX stuff won't work with it?
Any help is greatly appreciated.

D'oh!
The java test code that "worked" actually used the wrong file name so the file didn't exist so it didn't actually execute the broken code.
When I hard-code the absolute path to the file, I still get "Unable to read from file". So I guess the problem isn't with the JNI but somewhere else in my code.
Thanks.

Similar Messages

  • "Right" way to mix SAX and DOM in app

    I'm writing a standalone desktop application that reads and stores data as XML files. Eventually, it might be converted to use some web services, but it's not a priority right now.
    What I need to do is to use an XML file, which could be large, as kind of a database -- there are many entries, each with a unique identifier, and the application will query the file to find those it needs to match and returns those as objects I'm mapping.
    At the moment, because this is a personal project and I'm using it to learn more technologies, I'm trying to (somewhat artificially) restrict myself to the pure Sun APIs. So far, my investigations have pointed to JAXP (by including Java EE 5 libraries) with StAX (including JAX-WS). Which raises two questions:
    1) To do this "right", do I really need to bundle my app with the entire JaveEE+Metro stack?
    2) Is there a better solution than StAX that's fully Java 5 compliant, even if it means stepping out of the Sun box? I haven't found many references to other solutions that are more recent than 2004. Is parsing XML on an app that has nothing to do with an appserver that uncommon?

    More likely than not, I won't be abstracting to that degree. If the current structure isn't right, I'd update the app instead of storing that kind of information in more files.
    I imagine at this point an example would be more effective. The app is itself more of an inventory browser that can jump around different searches dynamically. As an illustration, imagine that it's an inventory for DVDs. One central file will be your collection (with each entry containing a movie ID, date of purchase, etc). Another file would be more static, a list of DVDs themselves. These entries would contain information about the package itself -- how many discs? What's the title of the package? Which special features does it have? It would also point to an entry in yet another file which would have information about the film, containing biographies of the people listed under the movie credits.
    Basically, I want a flatfile database that I can do joins on that are split up into different files. There are few files (here, one) that will be constantly updated by the user. The others could be modified if needed, but it's not going to be optimized for it. (For example, you could own a DVD that nobody's ever heard of, and put in the info yourself.) Periodically, one or more of the more static files is updated and will be downloaded into the app.
    One of the advantages I see for this is that, in the future, I could with few changes turn this into more of a web service. Instead of pushing changes in those few files, the app would look to a web service for the data it would now find in files on the user's hard drive. But for now, it also has to be one standalone package.
    To answer the question, the file that will most commonly be updated by the user is the one that I don't have problems loading into memory in full. It's the other data that it links to which I want to be able to search and load into objects dynamically. My current implementation is to run the file through SAX and grab the data as it sees it, but it's really ugly. That could very well be how I'm using it and not because I'm trying to shoehorn some functionality into a technique it doesn't fit, but I'd like to find that out. ;)

  • Swing GUI and JNI

    Hello
    I am facing a problem related to Swing and JNI. Actually I have to call a native function on the action of a button, so I am using Swing to develop GUI. When I use Jframe and Jbuttons and on the action event of JButton when I call the native function of a different class, then the function works fine but suddenly program gets terminated. Program does not get terminated when I click on other buttons but when I click on the button containing native method, after clicking, the whole GUI frame gets removed and the program terminates. While debugging it does not give any error, infact the function works perfectly fine and the only thing that I came to know is that the application gets terminated and it displays "terminated, exit value : - 1073741819"
    Please help me out and reply as soon as possible.

    I imagine it depends on what's in the JNI code. Is this a JNI that you've created? Is it a large program? Can you post the code? Are you sure that you're compiling the C/C++ code with the correct parameters? (you may need to ask some of this in the JNI forum) Is it thread-safe? Are you calling its methods on the EDT?

  • Difference between JNA and JNI ?

    Hi All ,
    I am very new to both of JNA and JNI . Could you please help me to find out the differences between them.
    Thanks and Regards,
    Allwyn

    Google ( [jni jna|http://www.google.com/search?q=java+jni+jna] ).

  • XML - 0112 Error on parsing using SAX and xml file in InputSource object.

    I need to parse a XML string and extract some information. I have to use SAX parser. I'm converting hte string to InputSource and then trying to parese.
    i'm getting XML-0112 error, my guess is that it is not able to locate DTD file but i tried hardcoding the whole path in DOCTYPE tag.
    i tried doing setSystemId also but no luck.
    null

    Can you post a simple test case to look at?

  • Setting up SAX and Crimson

    Hello.
    Thanks in advance for any help or advice.
    I am trying to parse XML. I have done a bit of background reading and made a few attempts - but i am stuck.
    I would like to parse XML using Crimson. I would like to use SAX as the API to that parser (hope i have got things correct so far?).
    I instanciate my parser as follows:
    import org.xml.sax.*;
    import org.xml.sax.helpers.XMLReaderFactory;
    import javax.xml.parsers.*;
    // this code is in a class called ClientXMLParser
    try
                   SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                   try
                        saxParser = saxParserFactory.newSAXParser();
                   catch( ParserConfigurationException e )
                        System.out.println( "Error: " + e );
                   gameXMLParser = new GameXMLParser();
                   xmlReader = XMLReaderFactory.createXMLReader();
              catch( SAXException e )
                   System.out.println( "Error: " + e );
              }I have another class that acts as my hanlder class:
    import org.xml.sax.helpers.DefaultHandler;
    public class GameXMLParser extends DefaultHandler
         public GameXMLParser()
              super();
         public void startDocument()
              System.out.println( "Start document" );
        public void endDocument()
             System.out.println( "End document" );
    }So this is pretty much all i have at the moment.
    I understand that i have to have:
    1) A SAX2-compatible XML parser installed on your Java class path.
    (I chose Crimson and just put the .jar in my jdk lib directory).
    How do i know that my SAX API knows about my XML parser.
    I am confused about the overall structure of how to set things up. I thought all i needed was SAX, Crimson and Java?
    I am not parsing a File - but i construct a file out of Strings and just want to parse the XML document as a string, (it is sent from Macromedia Flash):
    serverData += '<?xml version="1.0" encoding="utf-8"?>\n';
              serverData += '<flashClient id="' + 123456 + '">\n';
              serverData += '<getPlayers />\n';
              serverData += '</flashClient>\n';Regards, Sam

    Hello.
    Thanks in advance for any help or advice.
    I am trying to parse XML. I have done a bit of background reading and made a few attempts - but i am stuck.
    I would like to parse XML using Crimson. I would like to use SAX as the API to that parser (hope i have got things correct so far?).
    I instanciate my parser as follows:
    import org.xml.sax.*;
    import org.xml.sax.helpers.XMLReaderFactory;
    import javax.xml.parsers.*;
    // this code is in a class called ClientXMLParser
    try
                   SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                   try
                        saxParser = saxParserFactory.newSAXParser();
                   catch( ParserConfigurationException e )
                        System.out.println( "Error: " + e );
                   gameXMLParser = new GameXMLParser();
                   xmlReader = XMLReaderFactory.createXMLReader();
              catch( SAXException e )
                   System.out.println( "Error: " + e );
              }I have another class that acts as my hanlder class:
    import org.xml.sax.helpers.DefaultHandler;
    public class GameXMLParser extends DefaultHandler
         public GameXMLParser()
              super();
         public void startDocument()
              System.out.println( "Start document" );
        public void endDocument()
             System.out.println( "End document" );
    }So this is pretty much all i have at the moment.
    I understand that i have to have:
    1) A SAX2-compatible XML parser installed on your Java class path.
    (I chose Crimson and just put the .jar in my jdk lib directory).
    How do i know that my SAX API knows about my XML parser.
    I am confused about the overall structure of how to set things up. I thought all i needed was SAX, Crimson and Java?
    I am not parsing a File - but i construct a file out of Strings and just want to parse the XML document as a string, (it is sent from Macromedia Flash):
    serverData += '<?xml version="1.0" encoding="utf-8"?>\n';
              serverData += '<flashClient id="' + 123456 + '">\n';
              serverData += '<getPlayers />\n';
              serverData += '</flashClient>\n';Regards, Sam

  • How to Parse XML with SAX and Retrieving the Information?

    Hiya!
    I have written this code in one of my classes:
    /**Parse XML File**/
              SAXParserFactory factory = SAXParserFactory.newInstance();
              GameContentHandler gameCH = new GameContentHandler();
              try
                   SAXParser saxParser = factory.newSAXParser();
                   saxParser.parse(recentFiles[0], gameCH);
              catch(javax.xml.parsers.ParserConfigurationException e)
                   e.printStackTrace();
              catch(java.io.IOException e)
                   e.printStackTrace();
              catch(org.xml.sax.SAXException e)
                   e.printStackTrace();
              /**Parse XML File**/
              games = gameCH.getGames();And here is the content handler:
    import java.util.ArrayList;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    class GameContentHandler extends DefaultHandler
         private ArrayList<Game> games = new ArrayList<Game>();
         public void startDocument()
              System.out.println("Start document.");
         public void endDocument()
              System.out.println("End document.");
         public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
         public void characters(char[] ch, int start, int length) throws SAXException
              /**for (int i = start; i < start+length; i++)
                   System.out.print(ch);
         public ArrayList<Game> getGames()
              return games;
    }And here is the xml i am trying to parse:<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
    <Database>
         <Name></Name>
         <Description></Description>
         <CurrentGameID></CurrentGameID>
         <Game>
              <gameID></gameID>
              <name></name>
              <publisher></publisher>
              <platform></platform>
              <type></type>
              <subtype></subtype>
              <genre></genre>
              <serial></serial>
              <prodReg></prodReg>
              <expantionFor></expantionFor>
              <relYear></relYear>
              <expantion></expantion>
              <picPath></picPath>
              <notes></notes>
              <discType></discType>
              <owner></owner>
              <location></location>
              <borrower></borrower>
              <numDiscs></numDiscs>
              <discSize></discSize>
              <locFrom></locFrom>
              <locTo></locTo>
              <onLoan></onLoan>
              <borrowed></borrowed>
              <manual></manual>
              <update></update>
              <mods></mods>
              <guide></guide>
              <walkthrough></walkthrough>
              <cheats></cheats>
              <savegame></savegame>
              <completed></completed>
         </Game>
    </Database>I have been trying for ages and just can't get the content handler class to extract a gameID and instantiate a Game to add to my ArrayList! How do I extract the information from my file?
    I have tried so many things in the startElement() method that I can't actually remember what I've tried and what I haven't! If you need to know, the Game class instantiates with asnew Game(int gameID)and the rest of the variables are public.
    Please help someone...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    OK, how's this?
    public void startElement(String namespaceURI, String localName, String qualifiedName, Attributes atts) throws SAXException
              current = "";
         public void endElement(String namespaceURI, String localName, String qualifiedName) throws SAXException
              try
                   if(qualifiedName.equals("Game") || qualifiedName.equals("Database"))
                        {return;}
                   else if(qualifiedName.equals("gameID"))
                        {games.add(new Game(Integer.parseInt(current)));}
                   else if(qualifiedName.equals("name"))
                        {games.get(games.size()-1).name = current;}
                   else if(qualifiedName.equals("publisher"))
                        {games.get(games.size()-1).publisher = current;}
                   etc...
                   else
                        {System.out.println("ERROR - Qualified Name found in xml that does not exist as databse field: " + qualifiedName);}
              catch (Exception e) {} //Ignore
         public void characters(char[] ch, int start, int length) throws SAXException
              current += new String(ch, start, length);
         }

  • How can I maintain a single connection between Forms 9i and JNI?

    I am creating a JNI interface into a legacy application written in Pro C. Currently this legacy system is accessed from Forms 6i through userexits. Under this setup the Pro C application is able to share the connection to the DB established by forms. I want to mimic this functionality over the web using JNI as the link between my web components and the legacy application.
    ie. I want to share the DB connection established by my web components with my Pro C application.
    Thus far I have been unable to find any documentation on how to do this.
    Any ideas would be very helpful.
    Information about how Oracle Forms shares its connection with userexits would also be helpful.

    The Pro*C application is linked in to Forms, and runs in the same process space, which is how the session is shared.
    You can't share the Forms session outside of Forms. So it's not possible to do what you want.
    Regards,
    Robin Zimmermann
    Forms Product Management

  • Invocation JVM and JNI library communication

    How do I communicate between my application that creates a VM, and the JNI libraries (with native functions) loaded by classes within the invoked VM?

    -Global variablesI doubt global variables inside the C app can be >accessed from JNI native methods.Whoops! Correct.
    -Primitives passed as argumentsSure, but there is an whole API in C I wan't to make
    available in Java.
    -Primitives as attributes in a classExplain? Attributes in class?Basically the same as the previous one. So probably no more useful.
    -C/C++ pointers passed as arguments or as class
    attributes using a java long to hold it.Yes, this is probably the way!You will probably find this is best.
    -Function callbacks.Presumably you control the code base for both sides of this. A JNI shared library can have normal shared library method calls in it. So use normal shared library protocols to access it. (I haven't tried it so there might be some interesting problems with initially resolving the thunks or there might not.)

  • Servlets And JNI.. real urgent help.

    Hi all,
    I have the JNI code integrated to the servlet .The servlet works fine at first time.but when i modified some source code of servlet (not native library) and redeploy it,then reload the same servlet in web browser ,i get "Native library already loaded in another classloader java.lang.UnsatisfiedLinkError" error.
    Any solution to this ???
    Thanks
    jetdvk

    Have you fixed this?
    I presume you are hot deploying the servlet ? if so then i also presume that you have either some static code or some run once code that loads your native code when your class is used for the first time.
    This code is being ran again as the class is being reloaded, therefore you have two choices,
    1) wrap the call loading the native library, and just ignore the exception. Then call a check method in the native code to make sure that the library was loaded.
    2) Move the code that loads the native library out to another class that is not hot deployed. Your servlet can call this when it is first accessed, and the other class will know whether it has already loaded the dll and will not attempt to load it again.

  • Servlets and JNI

    Hi,
    We have a C library which does financial computations and some of our customers have expressed the need to access our library from their servlets.
    This is why we have developed a JNI wrapper which encapsulates all functionality of our library.
    Now, do the specs allow using JNI in conjunction with servlets? I've studied the Java EE, JSP and servlet specs but JNI isn't mentioned anywhere...
    I've also found this thread with a quite similar question but without a clear answer whether it's allowed or not.
    -- Vincent

    yes, if the server's security policy allows it. In a basic server environment you can do just about anything you can do in a regular java application.

  • Map the XCreateWindow to Frame or window in C and JNI

    I am having a window which is created in C++ using 'XcreateWindow' function
    I am using JNI as a interface
    How do i get the Window Id / handle to java frame.
    If I am giving any actionlistener to my frame that has to be reflected in C window
    Anybody can send me the full source code too.

    Linux_Java wrote:
    How do i get the Window Id / handle to java frame.You can't get it from within Java, that much I know, and in fact since it is an OS construct it is meaningless in java. If you are working with MS Windows, I'm guessing that your best bet is to play with some of the functions in the User32 library, such as enumerateWindows and such, and by doing this you'll find out how to get a handle on the JFrame. If it's unix/linux (and given your name, that is a reasonable assumption) then I have no idea.
    If I am giving any actionlistener to my frame that has to be reflected in C windowNo idea what you mean here.
    Anybody can send me the full source code too.Doesn't this kind of go against the philosophy of these forums?
    Also, consider posting this sort of question in the JNI forum where you will have a much better chance of getting a JNI guru who actually knows what he's talking about instead of, well, me.

  • SAX and DOM - treating encoding differently ??

    Hello!
    I have run into a strange problem - I was parsing my xml document using
    WebLogic's DOM and SAX parsers to compare their performance, and I found
    that while using their DOM parser I was able to parse the document just
    fine, using the SAX parser gave me an error:
    org.xml.sax.SAXParseException: Declared encoding "UTF-8" does not match
    actual one "ISO8859_1"
    I don't use any extended characters in the xml document, and even if I
    did - I'm puzzled as to why DOM parser would process it without
    complaining but the SAX paser would not??
    Thanks,
    Marina

    Hello!
    I have run into a strange problem - I was parsing my xml document using
    WebLogic's DOM and SAX parsers to compare their performance, and I found
    that while using their DOM parser I was able to parse the document just
    fine, using the SAX parser gave me an error:
    org.xml.sax.SAXParseException: Declared encoding "UTF-8" does not match
    actual one "ISO8859_1"
    I don't use any extended characters in the xml document, and even if I
    did - I'm puzzled as to why DOM parser would process it without
    complaining but the SAX paser would not??
    Thanks,
    Marina

  • Can I Use  SAX  and DOM in same application?

    Hi,
    Here is my requirement. I am using Apache's SAX parser for my appliaction. The below xml is the sample xml i am processing.How can I know the parent of element 'C' using sax? Is there any way i can differentiate the element under <B> and under <A>? Or do i need to use DOM, when you encouter <C> and find out it's parent.?
    If any one had this situation,Please respond with some code examples.
    <A>
    <B>
    <C>aa</C>
    </B>
    <C>bb</C>
    </A>
    Thanx

    When using SAX, your application is notified about nodes as the parser encounters them, sequentially. There is no concept of a parent/child relationship for elements. When using SAX, you must develop this logic yourself.
    When using DOM, the contents of the XML file are read into a tree structure. If you have a reference to the node object that represents "C", you can get a reference to its parent by calling getParentNode().
    Hope this helps.
    Greg
    >
    Hi,
    Here is my requirement. I am using Apache's SAX parser
    for my appliaction. The below xml is the sample xml i
    am processing.How can I know the parent of element 'C'
    using sax? Is there any way i can differentiate the
    element under <B> and under <A>? Or do i need to
    use DOM, when you encouter <C> and find out it's
    parent.?
    If any one had this situation,Please respond with
    some code examples.
    <A>
    <B>
    <C>aa</C>
    </B>
    <C>bb</C>
    </A>
    Thanx

  • SAX and XML file, how to?

    Hi,
    I'm going to use JAXP and SAX to read my application XML config file.
    But I'm lost, I don't know how to read the elements.
    How does it function, do I have to put in the startElement() method as many "if" as entitys I need to process?
    And how can I guess if an element belongs (is inside) one element or another?
    Example:
    <program>
    <printer id="xx" type="aa">
    <path> /aa/cc </path>
    </printer>
    <source>
    <path> /aa/bb </path>
    </source>
    </program>
    for this XML, how would you code it? this way?
    startElement (String uri, String localName, String qName, Attributes attributes) {
    if (localname.equals("printer")) {
    //get printer attributes
    } else if (localname.equals("source")) {
    //get source attributes
    thanks!

    i have one sample code through which u can read the elements from xml file.
    // File SaxLister.java
    import java.io.IOException;
    import org.xml.sax.Attributes;
    import org.xml.sax.SAXException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.DefaultHandler;
    import org.xml.sax.helpers.XMLReaderFactory;
    public class SAXLister {
    public static void main(String[] args) throws Exception
    new SAXLister(args);
    public SAXLister(String[] args) throws SAXException, IOException
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    // should load properties rather than hardcoding class name
    parser.setContentHandler(new PeopleHandler( ));
    parser.parse(args.length == 1 ? args[0] : "parents.xml");
    /** Inner class provides DocumentHandler
    class PeopleHandler extends DefaultHandler
    boolean parent = false;
    boolean kids = false;
    public void startElement(String nsURI, String localName,
    String rawName, Attributes attributes) throws SAXException {
    // System.out.println("docEvents" + "startElement: " + localName + ","
    // + rawName);
    // Consult rawName since we aren't using xmlns prefixes here.
    if (rawName.equalsIgnoreCase("name"))
    parent = true;
    if (rawName.equalsIgnoreCase("children"))
    kids = true;
    public void characters(char[] ch, int start, int length) {
    if (parent) {
    System.out.println("Parent: " + new String(ch, start, length));
    parent = false;
    } else if (kids) {
    System.out.println("Children: " + new String(ch, start, length));
    kids = false;
    /** Needed for parent constructor */
    public PeopleHandler( ) throws org.xml.sax.SAXException {
    super( );
    // File people.xml
    <?xml version="1.0"?>
    <people>
    <person>
         <name>Ian Darwin</name>
         <email>http://www.darwinsys.com/</email>
         <country>Canada</country>
    </person>
    <person>
         <name>Another Darwin</name>
         <email type="intranet">afd@node1</email>
         <country>Canada</country>
    </person>
    </people>
    I hope this gives u a better understanding of how SAX parser works..
    Kindly note u need xml.jar and xerces.jar in ur classpath to run above program.
    Regards,
    Nikunj

Maybe you are looking for

  • SAP Client to the SAP Server: internal Error (-1102)[Message 131-183]

    Hi, We are using Windows 2008 Server R2, SQL 2008 Standard, SAP B1 8.81 PL08. When we trying to connect SAP Client to the SAP Server. There has internal Error (-1102) occurred. We can view the database on client, but we always get the same error mess

  • How to change the Apple ID associated with an iPhone4s

    My husband has bought my daughter a new iPhone 5s to replace her iPhone 4s which she has handed on to me, in to which we have now installed a new SIM. We have created a new Apple ID in my name but now need to change the Apple ID on the 4S handset to

  • How to convert oracle forms to adf

    I want to convert oracle forms to adf Edited by: user4435615 on 2013-3-22 下午8:23

  • Unable to access designer in odi

    Hi, I am new to odi.I have already configured the master repository and i am able to access it throuhg topology manager.Then i created 2 work repositories from the same 1) development type 2) execution type.But when i access the designer, and i am tr

  • Using Instrument I/O Assistant

    trying to use Instrument I/O Assistant with my rs232 connection but i dosnt pick up a respone from my device can anyone help!!