#################################################################################
# Abstract: This script overcomes a bug in the autogenerated build.cmd		#
#		created by Blazix 1.2.5 This error seems to be caused by 	#
#		Java 1.5+ not creating skeltons for RMI communication.		#
# Alternatives : Use the Java 1.4 SDK to avoid this problem. Of course this	#
#		is not always possible thus this script.			#
# Usage : Use this script instead of the autogenerated build.cmd		#
# Platform : Linux/Bash								#
# Author: Ronan Barrett								#
# Date: 27/09/05								#
#################################################################################

#Set these variables to determine how the script parameters - TODO:Might want to make these comamnd parameters
package_name="stocks"
ejb_name="StockQuotes"
temp_dir="ejbtemp"
home_dir="`pwd`/" #store the current directory and append a trailing slash

#compile the Home, the Bean and the Interface
javac -d "$home_dir" "$home_dir$ejb_name"Home.java "$home_dir$ejb_name".java "$home_dir$ejb_name"Bean.java

#roll up all the complied files to a jar
jar -cvf "$ejb_name".jar -C "$home_dir" META-INF/ejb-jar.xml  "$package_name"/"$ejb_name"Home.class "$package_name"/"$ejb_name".class "$package_name"/"$ejb_name"Bean.class

#prepare a temporary directory
rm -ifr "$temp_dir" > /dev/null
mkdir "$temp_dir"

#perform the Blazix specific EJB work - This causes an error which we ignore
echo "**************  Ignore errors  ***************"
java desisoft.ejbtools.EjbCompiler -keepgenerated "$ejb_name".jar "$ejb_name"Ejb.jar
echo "**************  Stop ignoring  ***************"

#compile the source files created by desisoft.ejbtools.EjbCompiler
cd "$temp_dir"
javac -classpath "$CLASSPATH":.:../"$ejb_name".jar *.java

#clean up and move the compiled EjbCompiler files so we can generate some Skeletons
rm -ifr "$package_name" > /dev/null
mkdir "$package_name"
mv *.class "$package_name"

#Java 1.5 doesn't be default create Skeletons so we force RMIC todo it for us
rmic -v1.1 -classpath $CLASSPATH:.:../"$ejb_name".jar "$package_name"."$ejb_name"HomeCtx
rmic -v1.1 -classpath $CLASSPATH:.:../"$ejb_name".jar "$package_name"."$ejb_name"BeanCtx
cd ..

#finally roll up all the required plumming into a jar file
jar cf "$ejb_name"Ejb.jar "$package_name"/*.class META-INF/*

#finally, finally, clean up
rm -ifr "$temp_dir" > /dev/null

