4.3. Using v-q from Java

Java language is one of most popular languages used in enterprise systems.

Java includes support for CORBA. You don't need any additional software, all you need is Java SDK.

To start using v-q from Java you need to translate IDL files into Java classes. To do it execute:

idlj vq.idl

This will generate some files and directories:


vq
vq/exceptHelper.java
vq/exceptHolder.java
vq/except.java
vq/db_errorHelper.java
vq/db_errorHolder.java
vq/db_error.java
vq/null_errorHelper.java
vq/null_errorHolder.java
vq/null_error.java
vq/_ivqStub.java
vq/ivqHolder.java
vq/ivqHelper.java
vq/ivq.java
vq/ivqPackage
vq/ivqPackage/quota_typeHelper.java
vq/ivqPackage/size_typeHelper.java
vq/ivqPackage/uif_typeHelper.java
vq/ivqPackage/user_conf_typeHelper.java
vq/ivqPackage/string_listHolder.java
vq/ivqPackage/string_listHelper.java
vq/ivqPackage/gid_typeHelper.java
vq/ivqPackage/uid_typeHelper.java
vq/ivqPackage/err_codeHolder.java
vq/ivqPackage/err_codeHelper.java
vq/ivqPackage/err_code.java
vq/ivqPackage/errorHelper.java
vq/ivqPackage/errorHolder.java
vq/ivqPackage/error.java
vq/ivqPackage/user_infoHelper.java
vq/ivqPackage/user_infoHolder.java
vq/ivqPackage/user_info.java
vq/ivqPackage/user_conf_infoHelper.java
vq/ivqPackage/user_conf_infoHolder.java
vq/ivqPackage/user_conf_info.java
vq/ivqPackage/user_conf_info_listHolder.java
vq/ivqPackage/user_conf_info_listHelper.java
vq/ivqPackage/email_bannedHelper.java
vq/ivqPackage/email_bannedHolder.java
vq/ivqPackage/email_banned.java
vq/ivqPackage/email_banned_listHolder.java
vq/ivqPackage/email_banned_listHelper.java
vq/ivqPackage/domain_infoHelper.java
vq/ivqPackage/domain_infoHolder.java
vq/ivqPackage/domain_info.java
vq/ivqPackage/domain_info_listHolder.java
vq/ivqPackage/domain_info_listHelper.java
vq/ivqOperations.java

Here's an example I created, it calls vq::ivq::dom_val function to validate domain's name:


/**
 * Simple example of using v-q from Java
 * @author Paweł Niewiadomski
 */
import com.foo_baz.v_q.*;
import com.foo_baz.v_q.ivqPackage.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;

public class DomVal {

	static public void main( String [] args ) throws Exception {
		ORB orb = ORB.init(args, null);

		org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService");

		NamingContext rootCtx = NamingContextHelper.narrow(obj);
		if( rootCtx == null ) {
			System.out.println("Failed to narrow the root naming context");
			System.exit(1);
		}

		NameComponent name = new NameComponent("VQ.ivq", "");
		NameComponent [] path = { name };
		ivq vqo = ivqHelper.narrow(rootCtx.resolve(path));
		
		String dom = "123123.asd.com.pl";
		error err = vqo.dom_val(dom);
		if( err.ec == err_code.err_no ) {
			System.out.println("It's a valid domain name");
		} else {
			System.out.println("It's an invalid domain name");
		}
		System.exit(0);
	}
}

Following script executes omniNames (name server), iauth (pgsqlauthd) and ivq (qmailvqd), then DomVal (above example). It is also located in examples/java.


#!/bin/sh
export BASE=../..
export VQ_HOME=.

export LD_LIBRARY_PATH="/tmp" 
cp -f $BASE/lib*/*.so* /tmp

host=localhost

echo "starting Naming Service daemon ..."
rm -f /tmp/omninames-*
omniNames -start 12456 -logdir /tmp &
nsd_pid=$!

trap "kill $nsd_pid" 0
sleep 2

echo "starting iauth(pgsqlauthd) server ..."
$BASE/base/pgsql/pgsqlauthd \
-ORBIIOPAddr inet:$host:44444 \
-ORBInitRef NameService=corbaloc::$host:12456/NameService . &
iauth_pid=$!
trap "kill $nsd_pid $iauth_pid" 0
sleep 2

echo -ORBInitRef NameService=corbaloc::$host:12453/NameService > etc/ivq/auth
echo "starting ivq(qmailvqd) server ..."
$BASE/base/qmailvqd/qmailvqd \
-ORBIIOPAddr inet:$host:33333 \
-ORBInitRef NameService=corbaloc::$host:12456/NameService . &
ivq_pid=$!

trap "kill $nsd_pid $iauth_pid $ivq_pid" 0
sleep 2

echo "running client ..."
java DomVal -ORBInitRef NameService=corbaloc::$host:12456/NameService

Note: qmailvqd and pgsqlauthd were compiled using MICO, name service was represented by omniORB omniNames and client was written in Java. So, it's also an example of interoperability :-)

Hosted by: BerliOS Logo SourceForge.net Logo