Using the Java-Framework inside Jabaco


There are millions of Frameworks based on Java. Jabaco is based on Java too - so it is very simple to use every Java-Library with Jabaco. You could use Frameworks like Hibernate, Java3D, eFace, ... Let's go.

I'll show you how to use the Java XML-Lib in this sample. I have googled for Java XML and found javax.xml.parsers.DocumentBuilderFactory. That sounds good and so i have a looked at

Ok, this Class is abstract and has a static method "newInstance()". There are some syntax differences between Java an Jabaco. For Jabaco you have to replace the "." with an "#" in the namespace.

' Create a new Factory-Instance:

Dim tmpFactory As javax#xml#parsers#DocumentBuilderFactory
tmpFactory = javax#xml#parsers#DocumentBuilderFactory.newInstance()

And the Java-version:

// Create a new Factory-Instance:
 
javax.xml.parsers.DocumentBuilderFactory tmpFactory;
tmpFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();

Now we should have a new Instance of the document factory and could create a DocumentBuilder (). There is the next interesting method "parse()" which returns a instance that is compatible to the "org.w3c.dom.document"-interface (). That's what we want:

' Create a new Factory-Instance
Dim tmpFactory As javax#xml#parsers#DocumentBuilderFactory
tmpFactory = javax#xml#parsers#DocumentBuilderFactory.newInstance()
 
' Create a new Document
Dim tmpDocument As org#w3c#dom#Document 
tmpDocument = tmpFactory.newDocumentBuilder().parse("c:\test.xml")

That's all you need to instance a Java-Class inside Jabaco. Now you can use it:

' Create a new Factory-Instance
Dim tmpFactory As javax#xml#parsers#DocumentBuilderFactory
tmpFactory = javax#xml#parsers#DocumentBuilderFactory.newInstance()
 
' Create a new Document
Dim tmpDocument As org#w3c#dom#Document 
tmpDocument = tmpFactory.newDocumentBuilder().parse("c:\test.xml")
 
' Get TagName from Document
MsgBox tmpDocument.getDocumentElement().getTagName

Retrieved from "http://www.jabaco.org/wiki/Using_the_Java-Framework_inside_Jabaco"

This page has been accessed 6,756 times. This page was last modified on 8 February 2010, at 07:45.



This page has been accessed 6,756 times. This page was last modified on 8 February 2010, at 07:45.