OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to let StarBasic and Java work together?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Cosmic P
OOo Enthusiast
OOo Enthusiast


Joined: 23 Mar 2005
Posts: 186

PostPosted: Fri Apr 22, 2005 12:04 pm    Post subject: How to let StarBasic and Java work together? Reply with quote

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
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Apr 22, 2005 12:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Cosmic P
OOo Enthusiast
OOo Enthusiast


Joined: 23 Mar 2005
Posts: 186

PostPosted: Sat Apr 23, 2005 9:31 am    Post subject: Reply with quote

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
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 23, 2005 10:40 am    Post subject: Reply with quote

Read the Developer's Guide, particularly the chapters about how to write an UNO component.

Alternately, as I mentioned previously, you could write a Java program as a command line tool, and call it from Basic using the Shell function.

I wrote a Calc Add in over here...
http://kosh.datateam.com/~danny/OOo/Java-OOo/DannysCalcAddInFunctions/PRERELEASE/
It is written in Java and includes source code.
It is a true OpenOffice.org component.
Only works on OOo 1.1.x.
Because it is a Calc Add-In, it has to conform to a lot of additional rules beyond just being a component and registering itself.
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
Cosmic P
OOo Enthusiast
OOo Enthusiast


Joined: 23 Mar 2005
Posts: 186

PostPosted: Sat Apr 23, 2005 10:58 am    Post subject: Reply with quote

A similar question along the way: is it possible for StarBasic to pass parameter to a Java Applet?
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Sat Apr 23, 2005 12:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
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