[libinline-java-perl] 10/398: *** empty log message ***

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:42:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.55
in repository libinline-java-perl.

commit 062dd4aa93ac3d0db917b087b48e53345d796f37
Author: patrick <>
Date:   Mon Mar 5 18:26:42 2001 +0000

    *** empty log message ***
---
 Java/Class.pm    | 275 +++++++++++++++++++++-------------------
 Java/Init.pm     |  11 +-
 Java/Object.pm   |  24 +++-
 Java/Protocol.pm | 375 +++++--------------------------------------------------
 MANIFEST         |  17 +--
 README           |   2 +-
 TODO             |   6 +-
 7 files changed, 216 insertions(+), 494 deletions(-)

diff --git a/Java/Class.pm b/Java/Class.pm
index a0bf43f..e187c19 100644
--- a/Java/Class.pm
+++ b/Java/Class.pm
@@ -8,34 +8,38 @@ $Inline::Java::Class::VERSION = '0.01' ;
 use Carp ;
 
 
+
+my $INT_RE = '^[+-]?\d+$' ;
+my $FLOAT_RE = '^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$' ;
+
 my $RANGE = {
 	'java.lang.Byte' => {
-		REGEXP => '^\d+$',
+		REGEXP => $INT_RE,
 		MAX => 127,
 		MIN => -128,
 	},
 	'java.lang.Short' => {
-		REGEXP => '^\d+$',
+		REGEXP => $INT_RE,
 		MAX => 32767,
 		MIN => -32768,
 	},
 	'java.lang.Integer' => {
-		REGEXP => '^\d+$',
+		REGEXP => $INT_RE,
 		MAX => 2147483647,
 		MIN => -2147483648,
 	},
 	'java.lang.Long' => {
-		REGEXP => '^\d+$',
+		REGEXP => $INT_RE,
 		MAX => 9223372036854775807,
 		MIN => -9223372036854775808,
 	},
 	'java.lang.Float' => {
-		REGEXP => '^\d+$',
+		REGEXP => $FLOAT_RE,
 		MAX => 3.4028235e38,
 		MIN => 1.4e-45,
 	},
 	'java.lang.Double' => {
-		REGEXP => '^\d+$',
+		REGEXP => $FLOAT_RE,
 		MAX => 1.7976931348623157e308,
 		MIN => 4.9e-324,
 	},
@@ -124,10 +128,10 @@ sub CastArgument {
 	}
 	elsif (ClassIsBool($proto)){
 		if ($arg){
-			return "true" ;
+			return 1 ;
 		}
 		else{
-			return "false" ;
+			return 0 ;
 		}
 	}
 	elsif (ClassIsString($proto)){
@@ -210,7 +214,7 @@ sub ClassIsBool {
 	my $class = shift ;
 
 	my @list = qw(
-		java.lang.Bolean
+		java.lang.Boolean
 		boolean
 	) ;
 
@@ -290,144 +294,159 @@ class InlineJavaClass {
 			Class p = params[i] ;
 			ijs.debug("    arg " + String.valueOf(i) + " of signature is " + p.getName()) ;
 
-			ArrayList tokens = new ArrayList() ;
-			StringTokenizer st = new StringTokenizer((String)args.get(i), ":") ;
-			for (int j = 0 ; st.hasMoreTokens() ; j++){
-				tokens.add(j, st.nextToken()) ;
-			}
-			if (tokens.size() == 1){
-				tokens.add(1, "") ;
-			}
-			String type = (String)tokens.get(0) ;
-			
-			// We need to separate the primitive types from the 
-			// reference types.
-			boolean num = ClassIsNumeric(p) ;
-			if ((num)||(ClassIsString(p))){
-				if (type.equals("undef")){
-					if (num){
-						ijs.debug("  args is undef -> forcing to " + p.getName() + " 0") ;
-						ret[i] = ijp.CreateObject(p, new Object [] {"0"}) ;
-					}
-					else{
-						ijs.debug("  args is undef -> forcing to " + p.getName() + " ''") ;
-						ret[i] = ijp.CreateObject(p, new Object [] {""}) ;
-					}
-					ijs.debug("    result is " + ret[i].toString()) ;
-				}
-				else if (type.equals("scalar")){
-					String arg = ijp.pack((String)tokens.get(1)) ;
-					ijs.debug("  args is scalar -> forcing to " + p.getName()) ;
-					try	{							
-						ret[i] = ijp.CreateObject(p, new Object [] {arg}) ;
-						ijs.debug("    result is " + ret[i].toString()) ;
-					}
-					catch (NumberFormatException e){
-						throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
-					}
+			ret[i] = CastArgument(class_name, method_name, p, (String)args.get(i)) ;
+		}
+
+		return ret ;
+	}
+
+
+	/*
+		This is the monster method that determines how to cast arguments
+	*/
+	Object CastArgument (String class_name, String method_name, Class p, String argument) throws InlineJavaException {
+		Object ret = null ;
+	
+		// Used for exceptions
+		String msg = " in method " + method_name + " of class " + class_name ;
+
+		ArrayList tokens = new ArrayList() ;
+		StringTokenizer st = new StringTokenizer(argument, ":") ;
+		for (int j = 0 ; st.hasMoreTokens() ; j++){
+			tokens.add(j, st.nextToken()) ;
+		}
+		if (tokens.size() == 1){
+			tokens.add(1, "") ;
+		}
+		String type = (String)tokens.get(0) ;
+		
+		// We need to separate the primitive types from the 
+		// reference types.
+		boolean num = ClassIsNumeric(p) ;
+		if ((num)||(ClassIsString(p))){
+			if (type.equals("undef")){
+				if (num){
+					ijs.debug("  args is undef -> forcing to " + p.getName() + " 0") ;
+					ret = ijp.CreateObject(p, new Object [] {"0"}, new Class [] {String.class}) ;
 				}
 				else{
-					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+					ijs.debug("  args is undef -> forcing to " + p.getName() + " ''") ;
+					ret = ijp.CreateObject(p, new Object [] {""}, new Class [] {String.class}) ;
 				}
+				ijs.debug("    result is " + ret.toString()) ;
 			}
-			else if (ClassIsBool(p)){
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to bool false") ;
-					ret[i] = new Boolean("false") ;
-					ijs.debug("    result is " + ret[i].toString()) ;
+			else if (type.equals("scalar")){
+				String arg = ijp.pack((String)tokens.get(1)) ;
+				ijs.debug("  args is scalar -> forcing to " + p.getName()) ;
+				try	{							
+					ret = ijp.CreateObject(p, new Object [] {arg}, new Class [] {String.class}) ;
+					ijs.debug("    result is " + ret.toString()) ;
 				}
-				else if (type.equals("scalar")){
-					String arg = ijp.pack(((String)tokens.get(1)).toLowerCase()) ;
-					ijs.debug("  args is scalar -> forcing to bool") ;
-					if ((arg.equals(""))||(arg.equals("0"))){
-						arg = "false" ;
-					}
-					else{
-						arg = "true" ;
-					}
-					ret[i] = new Boolean(arg) ;
-					ijs.debug("    result is " + ret[i].toString()) ;
+				catch (NumberFormatException e){
+					throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
+				}
+			}
+			else{
+				throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+			}
+		}
+		else if (ClassIsBool(p)){
+			if (type.equals("undef")){
+				ijs.debug("  args is undef -> forcing to bool false") ;
+				ret = new Boolean("false") ;
+				ijs.debug("    result is " + ret.toString()) ;
+			}
+			else if (type.equals("scalar")){
+				String arg = ijp.pack(((String)tokens.get(1)).toLowerCase()) ;
+				ijs.debug("  args is scalar -> forcing to bool") ;
+				if ((arg.equals(""))||(arg.equals("0"))){
+					arg = "false" ;
 				}
 				else{
-					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+					arg = "true" ;
 				}
+				ret = new Boolean(arg) ;
+				ijs.debug("    result is " + ret.toString()) ;
 			}
-			else if (ClassIsChar(p)){
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to char '\0'") ;
-					ret[i] = new Character('\0') ;
-					ijs.debug("    result is " + ret[i].toString()) ;
+			else{
+				throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+			}
+		}
+		else if (ClassIsChar(p)){
+			if (type.equals("undef")){
+				ijs.debug("  args is undef -> forcing to char '\0'") ;
+				ret = new Character('\0') ;
+				ijs.debug("    result is " + ret.toString()) ;
+			}
+			else if (type.equals("scalar")){
+				String arg = ijp.pack((String)tokens.get(1)) ;
+				ijs.debug("  args is scalar -> forcing to char") ;
+				char c = '\0' ;
+				if (arg.length() == 1){
+					c = arg.toCharArray()[0] ;
 				}
-				else if (type.equals("scalar")){
+				else if (arg.length() > 1){
+					throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
+				}
+				ret = new Character(c) ;
+				ijs.debug("    result is " + ret.toString()) ;
+			}
+			else{
+				throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+			}
+		}
+		else {
+			ijs.debug("  class " + p.getName() + " is reference") ;
+			// We know that what we expect here is a real object
+			if (type.equals("undef")){
+				ijs.debug("  args is undef -> forcing to null") ;
+				ret = null ;
+			}
+			else if (type.equals("scalar")){
+				// Here if we need a java.lang.Object.class, it's probably
+				// because we can store anything, so we use a String object.
+				if (p == java.lang.Object.class){
 					String arg = ijp.pack((String)tokens.get(1)) ;
-					ijs.debug("  args is scalar -> forcing to char") ;
-					char c = '\0' ;
-					if (arg.length() == 1){
-						c = arg.toCharArray()[0] ;
-					}
-					else if (arg.length() > 1){
-						throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
-					}
-					ret[i] = new Character(c) ;
-					ijs.debug("    result is " + ret[i].toString()) ;
+					ret = arg ;
 				}
 				else{
-					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+					throw new InlineJavaCastException("Can't convert primitive type to " + p.getName() + msg) ;
 				}
 			}
-			else {
+			else{
+				// We need an object and we got an object...
 				ijs.debug("  class " + p.getName() + " is reference") ;
-				// We know that what we expect here is a real object
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to null") ;
-					ret[i] = null ;
-				}
-				else if (type.equals("scalar")){
-					// Here if we need a java.lang.Object.class, it's probably
-					// because we can store anything, so we use a String object.
-					if (p == java.lang.Object.class){
-						String arg = ijp.pack((String)tokens.get(1)) ;
-						ret[i] = arg ;
-					}
-					else{
-						throw new InlineJavaCastException("Can't convert primitive type to " + p.getName() + msg) ;
+
+				String c_name = (String)tokens.get(1) ;
+				String objid = (String)tokens.get(2) ;
+
+				Class c = ValidateClass(c_name) ;
+				// We need to check if c extends p
+				Class parent = c ;
+				boolean got_it = false ;
+				while (parent != null){
+					ijs.debug("    parent is " + parent.getName()) ;
+					if (parent == p){
+						got_it = true ;
+						break ;
 					}
+					parent = parent.getSuperclass() ;
 				}
-				else{
-					// We need an object and we got an object...
-					ijs.debug("  class " + p.getName() + " is reference") ;
-
-					String c_name = (String)tokens.get(1) ;
-					String objid = (String)tokens.get(2) ;
-
-					Class c = ValidateClass(c_name) ;
-					// We need to check if c extends p
-					Class parent = c ;
-					boolean got_it = false ;
-					while (parent != null){
-						ijs.debug("    parent is " + parent.getName()) ;
-						if (parent == p){
-							got_it = true ;
-							break ;
-						}
-						parent = parent.getSuperclass() ;
-					}
 
-					if (got_it){
-						ijs.debug("    " + c.getName() + " is a kind of " + p.getName() + msg) ;
-						// get the object from the hash table
-						Integer oid = new Integer(objid) ;
-						Object o = ijs.objects.get(oid) ;
-						if (o == null){
-							throw new InlineJavaException("Object " + oid.toString() + " of type " + c_name + " is not in object table " + msg) ;
-						}
-						ret[i] = o ;
-					}
-					else{
-						throw new InlineJavaCastException("Can't cast a " + c.getName() + " to a " + p.getName() + msg) ;
+				if (got_it){
+					ijs.debug("    " + c.getName() + " is a kind of " + p.getName() + msg) ;
+					// get the object from the hash table
+					Integer oid = new Integer(objid) ;
+					Object o = ijs.objects.get(oid) ;
+					if (o == null){
+						throw new InlineJavaException("Object " + oid.toString() + " of type " + c_name + " is not in object table " + msg) ;
 					}
+					ret = o ;
 				}
-			}			
+				else{
+					throw new InlineJavaCastException("Can't cast a " + c.getName() + " to a " + p.getName() + msg) ;
+				}
+			}
 		}
 
 		return ret ;
@@ -504,7 +523,6 @@ class InlineJavaClass {
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
 				ijs.debug("  class " + name + " is primitive numeric") ;
 				return true ;
@@ -527,7 +545,6 @@ class InlineJavaClass {
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
 				ijs.debug("  class " + name + " is primitive string") ;
 				return true ;
@@ -550,7 +567,6 @@ class InlineJavaClass {
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
 				ijs.debug("  class " + name + " is primitive char") ;
 				return true ;
@@ -573,7 +589,6 @@ class InlineJavaClass {
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
 				ijs.debug("  class " + name + " is primitive bool") ;
 				return true ;
diff --git a/Java/Init.pm b/Java/Init.pm
index e1401b8..686ea3f 100644
--- a/Java/Init.pm
+++ b/Java/Init.pm
@@ -4,8 +4,10 @@ $Inline::Java::Init::VERSION = '0.01' ;
 
 my $DATA = join('', <DATA>) ;
 my $OBJECT_DATA = join('', <Inline::Java::Object::DATA>) ;
+my $CLASS_DATA = join('', <Inline::Java::Class::DATA>) ;
 my $PROTO_DATA = join('', <Inline::Java::Protocol::DATA>) ;
 
+
 sub DumpUserJavaCode {
 	my $fh = shift ;
 	my $modfname = shift ;
@@ -21,9 +23,11 @@ sub DumpServerJavaCode {
 
 	my $java = $DATA ;
 	my $java_obj = $OBJECT_DATA ;
+	my $java_class = $CLASS_DATA ;
 	my $java_proto = $PROTO_DATA ;
 
 	$java =~ s/<INLINE_JAVA_OBJECT>/$java_obj/g ;
+	$java =~ s/<INLINE_JAVA_CLASS>/$java_class/g ;
 	$java =~ s/<INLINE_JAVA_PROTOCOL>/$java_proto/g ;
 
 	print $fh $java ;
@@ -112,7 +116,7 @@ public class InlineJavaServer {
 		Returns a report on the Java classes, listing all public methods
 		and members
 	*/
-	void Report(String [] class_list, int idx){
+	void Report(String [] class_list, int idx) {
 		String module = class_list[idx] ;
 		idx++ ;
 
@@ -198,15 +202,12 @@ public class InlineJavaServer {
 		}
 	}
 
-
-
 	<INLINE_JAVA_OBJECT>
 
-
+	<INLINE_JAVA_CLASS>
 
 	<INLINE_JAVA_PROTOCOL>
 
-
 	/*
 		Exception thrown by this code.
 	*/
diff --git a/Java/Object.pm b/Java/Object.pm
index 0971fa5..34bcab2 100644
--- a/Java/Object.pm
+++ b/Java/Object.pm
@@ -57,6 +57,18 @@ sub __new {
 # Checks to make sure all the arguments can be "cast" to prototype
 # types.
 sub __validate_prototype {
+	my $class = shift ;
+	my $method = shift ;
+	my $args = shift ;
+	my $proto = shift ;
+
+	my $new_args = undef ;
+	eval {
+		$new_args = Inline::Java::Class::CastArguments($class, $method, $args, $proto) ;
+	} ;
+	croak $@ if $@ ;
+
+	return @{$new_args} ;
 }
 
 
@@ -76,7 +88,9 @@ sub AUTOLOAD {
 }
 
 
-# Here an object in destroyed
+# Here an object in destroyed. this function seems to be called twice
+# for each object. I think it's because the $this reference is both blessed
+# and tied to the same package.
 sub DESTROY {
 	my $this = shift ;
 
@@ -84,6 +98,9 @@ sub DESTROY {
 		$this->{private}->{deleted} = 1 ;
 		$this->{private}->{proto}->DeleteJavaObject() ;
 	}
+	else{
+		Inline::Java::debug("Object destructor called more than once!") ;
+	}
 }
 
 
@@ -181,6 +198,9 @@ sub CLEAR {
 
 
 
+1 ;
 
 
-1 ;
+
+__DATA__
+
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 3411cf7..0107dfb 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -32,7 +32,7 @@ sub CreateJavaObject {
 
 	my $data = join(" ", 
 		"create_object", 
-		$this->ValidateClass($class),
+		Inline::Java::Class::ValidateClass($class),
 		$this->ValidateArgs(@args),
 	) ;
 
@@ -53,7 +53,7 @@ sub CallStaticJavaMethod {
 
 	my $data = join(" ", 
 		"call_static_method", 
-		$this->ValidateClass($class),
+		Inline::Java::Class::ValidateClass($class),
 		$this->ValidateMethod($method),
 		$this->ValidateArgs(@args),
 	) ;
@@ -77,7 +77,7 @@ sub CallJavaMethod {
 	my $data = join(" ", 
 		"call_method", 
 		$id,		
-		$this->ValidateClass($class),
+		Inline::Java::Class::ValidateClass($class),
 		$this->ValidateMethod($method),
 		$this->ValidateArgs(@args),
 	) ;
@@ -110,20 +110,6 @@ sub DeleteJavaObject {
 }
 
 
-# This method makes sure that the class we are asking for
-# has the correct form for a Java class.
-sub ValidateClass {
-	my $this = shift ;
-	my $class = shift ;
-
-	if ($class !~ /^(\w+)((\.(\w+))+)?/){
-		croak "Protocol: Invalid Java class name $class" ;
-	}	
-
-	return $class ;
-}
-
-
 # This method makes sure that the method we are asking for
 # has the correct form for a Java method.
 sub ValidateMethod {
@@ -131,7 +117,7 @@ sub ValidateMethod {
 	my $method = shift ;
 
 	if ($method !~ /^(\w+)$/){
-		croak "Protocol: Invalid Java method name $method" ;
+		croak "Invalid Java method name $method" ;
 	}	
 
 	return $method ;
@@ -150,7 +136,7 @@ sub ValidateArgs {
 		}
 		elsif (ref($arg)){
 			if (! UNIVERSAL::isa($arg, "Inline::Java::Object")){
-				croak "Protocol: A Java method can only have Java objects or scalars as arguments" ;
+				croak "A Java method can only have Java objects or scalars as arguments" ;
 			}
 			my $class = $arg->{private}->{java_class} ;
 			my $id = $arg->{private}->{id} ;
@@ -235,12 +221,15 @@ __DATA__
 */
 class InlineJavaProtocol {
 	InlineJavaServer ijs ;
+	InlineJavaClass ijc ;
 	String cmd ;
 	String response ;
 
 	InlineJavaProtocol(InlineJavaServer _ijs, String _cmd) {
 		ijs = _ijs ;
-		cmd = _cmd ;
+		ijc = new InlineJavaClass(ijs, this) ;
+
+		cmd = _cmd ;		
 	}
 
 
@@ -272,7 +261,7 @@ class InlineJavaProtocol {
 	void CallStaticJavaMethod(StringTokenizer st) throws InlineJavaException {
 		String class_name = st.nextToken() ;
 		String method = st.nextToken() ;
-		Class c = ValidateClass(class_name) ;
+		Class c = ijc.ValidateClass(class_name) ;
 		ArrayList f = ValidateMethod(false, c, method, st) ;
 
 		Method m = (Method)f.get(0) ;
@@ -283,7 +272,7 @@ class InlineJavaProtocol {
 			SetResponse(ret) ;
 		}
 		catch (IllegalAccessException e){
-			throw new InlineJavaException("You are not allowed to invoke static method " + name + " in class " + class_name) ;
+			throw new InlineJavaException("You are not allowed to invoke static method " + name + " in class " + class_name + ": " + e.getMessage()) ;
 		}
 		catch (IllegalArgumentException e){
 			throw new InlineJavaException("Arguments for static method " + name + " in class " + class_name + " are incompatible: " + e.getMessage()) ;
@@ -305,7 +294,7 @@ class InlineJavaProtocol {
 		int id = Integer.parseInt(st.nextToken()) ;
 		String class_name = st.nextToken() ;
 		String method = st.nextToken() ;
-		Class c = ValidateClass(class_name) ;
+		Class c = ijc.ValidateClass(class_name) ;
 		ArrayList f = ValidateMethod(false, c, method, st) ;
 
 		Method m = (Method)f.get(0) ;
@@ -321,7 +310,7 @@ class InlineJavaProtocol {
 			SetResponse(ret) ;
 		}
 		catch (IllegalAccessException e){
-			throw new InlineJavaException("You are not allowed to invoke method " + name + " in class " + class_name) ;
+			throw new InlineJavaException("You are not allowed to invoke method " + name + " in class " + class_name + ": " + e.getMessage()) ;
 		}
 		catch (IllegalArgumentException e){
 			throw new InlineJavaException("Arguments for method " + name + " in class " + class_name + " are incompatible: " + e.getMessage()) ;
@@ -341,15 +330,16 @@ class InlineJavaProtocol {
 	*/
 	void CreateJavaObject(StringTokenizer st) throws InlineJavaException {
 		String class_name = st.nextToken() ;
-		Class c = ValidateClass(class_name) ;
+		Class c = ijc.ValidateClass(class_name) ;
 
 		ArrayList f = ValidateMethod(true, c, class_name, st) ;
 
 		Constructor con = (Constructor)f.get(0) ;
 		String name = class_name ;
 		Object p[] = (Object [])f.get(1) ;
+		Class clist[] = (Class [])f.get(2) ;
 
-		Object o = CreateObject(c, p) ;
+		Object o = CreateObject(c, p, clist) ;
 		SetResponse(o) ;
 	}
 
@@ -370,38 +360,34 @@ class InlineJavaProtocol {
 	/*
 		Creates a Java Object with the specified arguments.
 	*/
-	Object CreateObject(Class p, Object args[]) throws InlineJavaException {
-		Class clist[] = new Class [args.length] ;
-		for (int i = 0 ; i < args.length ; i++){
-			clist[i] = args[i].getClass() ;
-		}
+	Object CreateObject(Class p, Object args[], Class proto[]) throws InlineJavaException {
 
-		p = FindWrapper(p) ;
+		p = ijc.FindWrapper(p) ;
 
 		String name = p.getName() ;
 		Object ret = null ;
 		try {
-			Constructor con = (Constructor)p.getConstructor(clist) ;
+			Constructor con = (Constructor)p.getConstructor(proto) ;
 			ret = con.newInstance(args) ;
 		}
 		catch (NoSuchMethodException e){
-			throw new InlineJavaException("Constructor for class " + name + " with signature " + ijs.CreateSignature(clist) + " not found") ;
+			throw new InlineJavaException("Constructor for class " + name + " with signature " + ijs.CreateSignature(proto) + " not found: " + e.getMessage()) ;
 		}
 		catch (InstantiationException e){
-			throw new InlineJavaException("You are not allowed to instantiate object of class " + name) ;
+			throw new InlineJavaException("You are not allowed to instantiate object of class " + name + ": " + e.getMessage()) ;
 		}
 		catch (IllegalAccessException e){
-			throw new InlineJavaException("You are not allowed to instantiate object of class " + name + " using the constructor with signature " + ijs.CreateSignature(clist)) ;
+			throw new InlineJavaException("You are not allowed to instantiate object of class " + name + " using the constructor with signature " + ijs.CreateSignature(proto) + ": " + e.getMessage()) ;
 		}
 		catch (IllegalArgumentException e){
-			throw new InlineJavaException("Arguments to constructor for class " + name + " with signature " + ijs.CreateSignature(clist) + " are incompatible: " + e.getMessage()) ;
+			throw new InlineJavaException("Arguments to constructor for class " + name + " with signature " + ijs.CreateSignature(proto) + " are incompatible: " + e.getMessage()) ;
 		}
 		catch (InvocationTargetException e){
 			Throwable t = e.getTargetException() ;
 			String type = t.getClass().getName() ;
 			String msg = t.getMessage() ;
 			throw new InlineJavaException(
-				"Constructor for class " + name + " with signature " + ijs.CreateSignature(clist) + " threw exception " + type + ": " + msg) ;
+				"Constructor for class " + name + " with signature " + ijs.CreateSignature(proto) + " threw exception " + type + ": " + msg) ;
 		}
 
 		return ret ;
@@ -409,20 +395,6 @@ class InlineJavaProtocol {
 
 
 	/*
-		Makes sure a class exists
-	*/
-	Class ValidateClass(String name) throws InlineJavaException {
-		try {
-			Class c = Class.forName(name) ;
-			return c ;
-		}
-		catch (ClassNotFoundException e){
-			throw new InlineJavaException("Class " + name + " not found") ;
-		}
-	}
-
-
-	/*
 		Makes sure a method exists
 	*/
 	ArrayList ValidateMethod(boolean constructor, Class c, String name, StringTokenizer st) throws InlineJavaException {
@@ -475,7 +447,8 @@ class InlineJavaProtocol {
 				params = ((Method)m).getParameterTypes() ;
 			}
 			ret.add(0, m) ;
-			ret.add(1, CastArguments(c.getName(), name, params, args)) ;
+			ret.add(1, ijc.CastArguments(c.getName(), name, params, args)) ;
+			ret.add(2, params) ;
 		}
 		else{
 			throw new InlineJavaException("Automatic method selection when multiple signatures are found not yet implemented") ;
@@ -486,296 +459,6 @@ class InlineJavaProtocol {
 
 
 	/*
-		This is the monster method that determines how to cast arguments
-	*/
-	Object [] CastArguments (String class_name, String method_name, Class [] params, ArrayList args) throws InlineJavaException {
-		Object ret[] = new Object [params.length] ;
-	
-		// Used for exceptions
-		String msg = " in method " + method_name + " of class " + class_name ;
-
-		for (int i = 0 ; i < params.length ; i++){	
-			// Here the args are all strings or objects (or undef)
-			// we need to match them to the prototype.
-			Class p = params[i] ;
-			ijs.debug("    arg " + String.valueOf(i) + " of signature is " + p.getName()) ;
-
-			ArrayList tokens = new ArrayList() ;
-			StringTokenizer st = new StringTokenizer((String)args.get(i), ":") ;
-			for (int j = 0 ; st.hasMoreTokens() ; j++){
-				tokens.add(j, st.nextToken()) ;
-			}
-			if (tokens.size() == 1){
-				tokens.add(1, "") ;
-			}
-			String type = (String)tokens.get(0) ;
-			
-			// We need to separate the primitive types from the 
-			// reference types.
-			boolean num = ClassIsNumeric(p) ;
-			if ((num)||(ClassIsString(p))){
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to " + p.getName() + " 0") ;
-					ret[i] = CreateObject(p, new Object [] {"0"}) ;
-					ijs.debug("    result is " + ret[i].toString()) ;
-				}
-				else if (type.equals("scalar")){
-					String arg = pack((String)tokens.get(1)) ;
-					ijs.debug("  args is scalar -> forcing to " + p.getName()) ;
-					try	{							
-						ret[i] = CreateObject(p, new Object [] {arg}) ;
-						ijs.debug("    result is " + ret[i].toString()) ;
-					}
-					catch (NumberFormatException e){
-						throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
-					}
-				}
-				else{
-					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
-				}
-			}
-			else if ((p == java.lang.Boolean.class)||(p == boolean.class)){
-				ijs.debug("  class java.lang.Boolean is primitive bool") ;
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to bool false") ;
-					ret[i] = new Boolean("false") ;
-					ijs.debug("    result is " + ret[i].toString()) ;
-				}
-				else if (type.equals("scalar")){
-					String arg = pack(((String)tokens.get(1)).toLowerCase()) ;
-					ijs.debug("  args is scalar -> forcing to bool") ;
-					if ((arg.equals(""))||(arg.equals("0"))){
-						arg = "false" ;
-					}
-					else{
-						arg = "true" ;
-					}
-					ret[i] = new Boolean(arg) ;
-					ijs.debug("    result is " + ret[i].toString()) ;
-				}
-				else{
-					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
-				}
-			}
-			else if ((p == java.lang.Character.class)||(p == char.class)){
-				ijs.debug("  class java.lang.Character is primitive char") ;
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to char '\0'") ;
-					ret[i] = new Character('\0') ;
-					ijs.debug("    result is " + ret[i].toString()) ;
-				}
-				else if (type.equals("scalar")){
-					String arg = pack((String)tokens.get(1)) ;
-					ijs.debug("  args is scalar -> forcing to char") ;
-					char c = '\0' ;
-					if (arg.length() == 1){
-						c = arg.toCharArray()[0] ;
-					}
-					else if (arg.length() > 1){
-						throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
-					}
-					ret[i] = new Character(c) ;
-					ijs.debug("    result is " + ret[i].toString()) ;
-				}
-				else{
-					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
-				}
-			}
-			else {
-				ijs.debug("  class " + p.getName() + " is reference") ;
-				// We know that what we expect here is a real object
-				if (type.equals("undef")){
-					ijs.debug("  args is undef -> forcing to null") ;
-					ret[i] = null ;
-				}
-				else if (type.equals("scalar")){
-					// Here if we need a java.lang.Object.class, it's probably
-					// because we can store anything, so we use a String object.
-					if (p == java.lang.Object.class){
-						String arg = pack((String)tokens.get(1)) ;
-						ret[i] = arg ;
-					}
-					else{
-						throw new InlineJavaCastException("Can't convert primitive type to " + p.getName() + msg) ;
-					}
-				}
-				else{
-					// We need an object and we got an object...
-					ijs.debug("  class " + p.getName() + " is reference") ;
-
-					String c_name = (String)tokens.get(1) ;
-					String objid = (String)tokens.get(2) ;
-
-					Class c = ValidateClass(c_name) ;
-					// We need to check if c extends p
-					Class parent = c ;
-					boolean got_it = false ;
-					while (parent != null){
-						ijs.debug("    parent is " + parent.getName()) ;
-						if (parent == p){
-							got_it = true ;
-							break ;
-						}
-						parent = parent.getSuperclass() ;
-					}
-
-					if (got_it){
-						ijs.debug("    " + c.getName() + " is a kind of " + p.getName() + msg) ;
-						// get the object from the hash table
-						Integer oid = new Integer(objid) ;
-						Object o = ijs.objects.get(oid) ;
-						if (o == null){
-							throw new InlineJavaException("Object " + oid.toString() + " of type " + c_name + " is not in object table " + msg) ;
-						}
-						ret[i] = o ;
-					}
-					else{
-						throw new InlineJavaCastException("Can't cast a " + c.getName() + " to a " + p.getName() + msg) ;
-					}
-				}
-			}			
-		}
-
-		return ret ;
-	}
-
-
-	/*
-		Finds the wrapper class for the passed primitive type.
-	*/
-	Class FindWrapper (Class p){
-		Class [] list = {
-			byte.class,
-			short.class,
-			int.class,
-			long.class,
-			float.class,
-			double.class,
-			boolean.class,
-			char.class,
-		} ;
-		Class [] listw = {
-			java.lang.Byte.class,
-			java.lang.Short.class,
-			java.lang.Integer.class,
-			java.lang.Long.class,
-			java.lang.Float.class,
-			java.lang.Double.class,
-			java.lang.Boolean.class,
-			java.lang.Character.class,
-		} ;
-
-		for (int i = 0 ; i < list.length ; i++){
-			if (p == list[i]){
-				return listw[i] ;
-			}
-		}
-
-		return p ;
-	}
-
-
-	boolean ClassIsPrimitive (Class p){
-		String name = p.getName() ;
-
-		if ((ClassIsNumeric(p))||(ClassIsString(p))){
-			return true ;
-		}
-
-		Class [] list = {
-			java.lang.Boolean.class,
-			java.lang.Character.class,
-			boolean.class,
-			char.class,
-		} ;
-
-		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
-			if (p == list[i]){
-				ijs.debug("  class " + name + " is primitive") ;
-				return true ;
-			}
-		}
-
-		ijs.debug("  class " + name + " is reference") ;
-		return false ;
-	}
-
-
-	/*
-		Determines if class is of numerical type.
-	*/
-	boolean ClassIsNumeric (Class p){
-		String name = p.getName() ;
-
-		Class [] list = {
-			java.lang.Byte.class,
-			java.lang.Short.class,
-			java.lang.Integer.class,
-			java.lang.Long.class,
-			java.lang.Float.class,
-			java.lang.Double.class,
-			byte.class,
-			short.class,
-			int.class,
-			long.class,
-			float.class,
-			double.class,
-		} ;
-
-		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
-			if (p == list[i]){
-				ijs.debug("  class " + name + " is primitive numeric") ;
-				return true ;
-			}
-		}
-
-		return false ;
-	}
-
-
-	/*
-		Class is String or StringBuffer
-	*/
-	boolean ClassIsString (Class p){
-		String name = p.getName() ;
-
-		Class [] list = {
-			java.lang.String.class,
-			java.lang.StringBuffer.class,
-		} ;
-
-		for (int i = 0 ; i < list.length ; i++){
-			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
-			if (p == list[i]){
-				ijs.debug("  class " + name + " is primitive string") ;
-				return true ;
-			}
-		}
-
-		return false ;
-	}
-
-	
-	/*
-		Determines if a class is not of a primitive type or of a 
-		wrapper class.
-	*/
-	boolean ClassIsReference (Class p){
-		String name = p.getName() ;
-
-		if (ClassIsPrimitive(p)){
-			return false ;
-		}
-
-		ijs.debug("  class " + name + " is reference") ;
-
-		return true ;
-	}
-
-
-	/*
 		This sets the response that will be returned to the Perl
 		script
 	*/
@@ -783,9 +466,13 @@ class InlineJavaProtocol {
 		if (o == null){
 			response = "ok undef:" ;
 		}
-		else if (ClassIsPrimitive(o.getClass())){
+		else if ((ijc.ClassIsNumeric(o.getClass()))||(ijc.ClassIsChar(o.getClass()))||(ijc.ClassIsString(o.getClass()))){
 			response = "ok scalar:" + unpack(o.toString()) ;
 		}
+		else if (ijc.ClassIsBool(o.getClass())){
+			String b = o.toString() ;
+			response = "ok scalar:" + unpack((b.equals("true") ? "1" : "0")) ;
+		}
 		else {
 			// Here we need to register the object in order to send
 			// it back to the Perl script.
diff --git a/MANIFEST b/MANIFEST
index 82eff46..ca3d7f6 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,11 +1,14 @@
 CHANGES
-Java.pm
-Java.pod
 MANIFEST
-Makefile.PL
 README
-t/
-Java/private/Init.pm
-Java/private/Object.pm
-Java/private/Protocol.pm
+TODO
+Makefile.PL
+Java.pm
+Java.pod
+Java/Init.pm
+Java/Object.pm
+Java/Protocol.pm
+t/1_init.t
+t/2_primitives.t
+t/3_objects.t
 
diff --git a/README b/README
index 1442e4d..639c012 100644
--- a/README
+++ b/README
@@ -60,6 +60,6 @@ INFORMATION:
 The Inline::Java mailing list is inline at perl.org. 
 Send email to inline-subscribe at perl.org to subscribe.
 
-Please send questions and comments to "Patrick LeBoutillier" <patrick_leboutillier at hotmail.com>
+Please send questions and comments to "Patrick LeBoutillier" <patl at cpan.org>
 
 Copyright (c) 2001, Patrick LeBoutillier. All Rights Reserved.  
diff --git a/TODO b/TODO
index 4d12ca5..8402c62 100644
--- a/TODO
+++ b/TODO
@@ -1,11 +1,7 @@
-- Documentation
-- Code comments
-- Code cleanup
+CODE:
 - Arrays
-- Casting
 
 PORTABILITY ISSUES:
-- find_java_bin (getpwuid)
 - path sep ":"
 - fork, exec
 - makefile stuff

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git



More information about the Pkg-perl-cvs-commits mailing list