Thursday, May 17th 2012, 4:45pm UTC+2

You are not logged in.

  • Login
  • Register

Manuel

Administrator

Posts: 255

Location: Erlangen, Germany

Occupation: Software Developer

1

Friday, August 22nd 2008, 1:51am

Using Java-Framework's 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. I have googled for Java XML and found javax.xml.parsers.DocumentBuilderFactory. That sounds good and so i have a look to http://java.sun.com/j2se/1.4.2/docs/api/…derFactory.html

Ok, this Class is abstract and have a static method "newInstance()". This is a singleton pattern (don't know what that is? Have a look to http://en.wikipedia.org/wiki/Singleton_pattern). There are some syntax-differents from Java to Jabaco. For Jabaco you have to replace the "." to "#" in the namespace.

Jabaco Source

1
2
Dim tmpFactory As javax#xml#parsers#DocumentBuilderFactory = javax#xml#parsers#DocumentBuilderFactory.newInstance()
'Same in Java: javax.xml.parsers.DocumentBuilderFactory tmpFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();


Now we should have a new Instance of the document factory and could create a DocumentBuilder (http://java.sun.com/j2se/1.4.2/docs/api/…entBuilder.html). There is the next interesting method "parse()" which returns a instance that is compatible to the "org.w3c.dom.document"-interface (http://java.sun.com/j2se/1.4.2/docs/api/…m/Document.html). That's what we want:

Jabaco Source

1
2
3
Dim tmpFactory As javax#xml#parsers#DocumentBuilderFactory = javax#xml#parsers#DocumentBuilderFactory.newInstance()
   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:

Jabaco Source

1
2
3
4
Dim tmpFactory As javax#xml#parsers#DocumentBuilderFactory = javax#xml#parsers#DocumentBuilderFactory.newInstance()
   Dim tmpDocument As org#w3c#dom#Document 
   tmpDocument = tmpFactory.newDocumentBuilder().parse("c:\test.xml")
   MsgBox tmpDocument.getDocumentElement().getTagName

Rate this thread
WoltLab Burning Board