| View previous topic :: View next topic |
| Author |
Message |
Cosmic P OOo Enthusiast

Joined: 23 Mar 2005 Posts: 186
|
Posted: Fri Apr 22, 2005 12:04 pm Post subject: How to let StarBasic and Java work together? |
|
|
How can I in the middle of a StarBasic subroutine pass a parameter to a Java programm, proces it there and return in to StarBasic?
Any references to documentation? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Fri Apr 22, 2005 12:57 pm Post subject: |
|
|
Not sure exactly what you want to do.
Two ideas....
1. Write java program as a command line tool.
2. Write java program as an UNO Service and then install it into the office.
If your java program is a command line tool, then you could call it from basic using the Shell() function.
| Code: | Sub Main
Shell( "Notepad.exe" )
End Sub |
If your java program is written in the form of an UNO Component, then it is installed into the office, then from Basic you would use the createUnoService() function to create an instance of your class.
| Code: | Sub Main
oMyJavaObject = createUnoService( "name.DannyBrewer.OOoMisc.FooBar" )
oMyJavaObject.wizBang( 12, True, "Meow Mix" )
x = oMyJavaObject.bazzle( 23, 45 )
Print x
End Sub |
In this case, I would have installed an UNO Component. An UNO Component can install zero or more services. In this case, my UNO Component would have installed a new UNO Service named "name.DannyBrewer.OOoMisc.FooBar".
| Code: | import ....a bunch of stuff....
package name.DannyBrewer.OOoMisc;
class FooBar extends WeakBase implements XFooBar {
public void wizBang( int x, bool y, String z ) { ... }
public String bazzle( int x, int y ) { ... }
}
|
It would be necessary to write an UNO IDL description of the service. Then you would need to use the "idlc" compiler to compile it, use the "regmerge" command to create an ".rdb" file. Then in NetBeans, create a Jar file with your compiled class. It have a Manifest file that declares the registration class. In addition, your Jar must have a class that implements some additional UNO business such as "writeRegistryInfo", etc. Your class must also implement several other interfaces such as XServiceInfo, etc.
Now if I am programming in any language, I can create an instance of my service (which could be written in any language). In this case the service is written in Java, and I am calling it from Basic. But I could write the service in Python, and call it from Java.
To create the service, always use the createInstance() method of the XMultiServiceFactory of the Service Manager. In Basic, the global createUnoService() function is just a shortcut for doing that. I could have written the Basic code this way....
| Code: | Sub Main
oServiceManager = getProcessServiceManager()
oMyJavaObject = oServiceManager.createInstance( "name.DannyBrewer.OOoMisc.FooBar" )
oMyJavaObject.wizBang( 12, True, "Meow Mix" )
x = oMyJavaObject.bazzle( 23, 45 )
Print x
End Sub |
Can't write more right now. Gotta go. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
Cosmic P OOo Enthusiast

Joined: 23 Mar 2005 Posts: 186
|
Posted: Sat Apr 23, 2005 9:31 am Post subject: |
|
|
| I have a few small programs which I compiled with Visual J++. Can you explain more in detail how I implement them or give a reference? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
|
| Back to top |
|
 |
Cosmic P OOo Enthusiast

Joined: 23 Mar 2005 Posts: 186
|
Posted: Sat Apr 23, 2005 10:58 am Post subject: |
|
|
| A similar question along the way: is it possible for StarBasic to pass parameter to a Java Applet? |
|
| Back to top |
|
 |
DannyB Moderator


Joined: 02 Apr 2003 Posts: 3991 Location: Lawrence, Kansas, USA
|
Posted: Sat Apr 23, 2005 12:46 pm Post subject: |
|
|
I do not know of a way. A long time ago, it was something I was interested in. It occured to me that I could easily put an Applet into an office document. Writing java components for the office has a high learning curve. So I was interested in using an applet and communicating with it.
Once you know how to do it, components are the best way to put java software inside of the office in an integrated fashion. _________________ Want to make OOo Drawings like the colored flower design to the left? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|