Operating system specific calls.

A

Andoni

Hello,

I am writing a web based application which allows the user to do some
configuration of their account on a mail server my company maintains. This
application in particular involves the use of quite a few different calls to
command scripts and the like on the operating system. I have decided to
make all the responses from the operating system come back in XML which has
made some of my job easier but now I am trying to think of a way to wrap the
outbound commands which are different on my windows system and the system
for which I am developing which is Linux. I want to take them all aside in
a separate class which can use the System.getProperty("os.name") property to
decide which version to call. Is this a bad Idea? Can you please suggest
architectures for making JNI calls flexible.

Kind regards,

Andoni.
 
G

Gordon Beaton

now I am trying to think of a way to wrap the outbound commands
which are different on my windows system and the system for which I
am developing which is Linux. I want to take them all aside in a
separate class which can use the System.getProperty("os.name")
property to decide which version to call. Is this a bad Idea? Can
you please suggest architectures for making JNI calls flexible.

If your native code provides a well definced and consistent interface
java, the Java code doesn't need to do anything special at all.

Consider that you call System.loadLibrary("foo") in your java code.
The actual filename ("libfoo.so" or "foo.dll"), its location and most
importantly its contents are all necessarily system dependent, but the
exact same Java code can be used to invoke them if the interface is
consistent.

I'd make an effort to keep the system specific parts in one place. In
your case, it seems that that's the native library. The class itself
doesn't need to change.

If you are doing other things differently on the two platforms (where
no native code is involved), I'd consider using an inner class to
provide the complete functionality for each of the platforms. When you
initialize your interface class, create an instance of the appropriate
inner "implementation" class. You shouldn't need to use
System.getProperty("os.name") more than once.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top