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

Jonas Smedegaard dr at jones.dk
Thu Feb 26 11:42:35 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 db12b96b0ba66f95b4805f4e31a681ff17254b3d
Author: patrick <>
Date:   Thu Mar 1 20:45:49 2001 +0000

    *** empty log message ***
---
 Java/Protocol.pm | 303 +++++++++++++++++++++++++++----------------------------
 1 file changed, 147 insertions(+), 156 deletions(-)

diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 6f841f3..3411cf7 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -3,32 +3,26 @@ package Inline::Java::Protocol ;
 
 use strict ;
 
+$Inline::Java::Protocol::VERSION = '0.01' ;
 
 use Carp ;
-use Data::Dumper ;
-
-
-# This will be set when the code is loaded.
-$Inline::Java::Protocol::socket = {} ;
 
 
 sub new {
 	my $class = shift ;
 	my $obj = shift ;
-	my $module = shift ;
+	my $inline = shift ;
 
 	my $this = {} ;
 	$this->{obj_priv} = $obj || {} ;
-	if ($obj){
-		$this->{pkg} = $obj->{pkg} ;
-	}
-	$this->{module} = $module ;
+	$this->{module} = $inline->{modfname} ;
 
 	bless($this, $class) ;
 	return $this ;
 }
 
 
+# Called to create a Java object
 sub CreateJavaObject {
 	my $this = shift ;
 	my $class = shift ;
@@ -48,15 +42,13 @@ sub CreateJavaObject {
 }
 
 
+# Called to call a static Java method
 sub CallStaticJavaMethod {
 	my $this = shift ;
 	my $class = shift ;
-	my $pkg = shift ;
 	my $method = shift ;
 	my @args = @_ ;
 
-	$this->{pkg} = $pkg ;
-
 	Inline::Java::debug("calling $class.$method(" . join(", ", @args) . ")") ;
 
 	my $data = join(" ", 
@@ -72,13 +64,14 @@ sub CallStaticJavaMethod {
 }
 
 
+# Calls a regular Java method.
 sub CallJavaMethod {
 	my $this = shift ;
 	my $method = shift ;
 	my @args = @_ ;
 
 	my $id = $this->{obj_priv}->{id} ;
-	my $class = $this->{obj_priv}->{class} ;
+	my $class = $this->{obj_priv}->{java_class} ;
 	Inline::Java::debug("calling object($id).$method(" . join(", ", @args) . ")") ;
 
 	my $data = join(" ", 
@@ -95,12 +88,13 @@ sub CallJavaMethod {
 }
 
 
+# Deletes a Java object
 sub DeleteJavaObject {
 	my $this = shift ;
 
 	if (defined($this->{obj_priv}->{id})){
 		my $id = $this->{obj_priv}->{id} ;
-		my $class = $this->{obj_priv}->{class} ;
+		my $class = $this->{obj_priv}->{java_class} ;
 
 		Inline::Java::debug("deleting object $this $id ($class)") ;
 
@@ -116,30 +110,35 @@ 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 "Invalid Java class name $class" ;
+		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 {
 	my $this = shift ;
 	my $method = shift ;
 
 	if ($method !~ /^(\w+)$/){
-		croak "Invalid Java method name $method" ;
+		croak "Protocol: Invalid Java method name $method" ;
 	}	
 
 	return $method ;
 }
 
 
+# Validates the arguments to be used in a method call.
 sub ValidateArgs {
 	my $this = shift ;
 	my @args = @_ ;
@@ -151,9 +150,9 @@ sub ValidateArgs {
 		}
 		elsif (ref($arg)){
 			if (! UNIVERSAL::isa($arg, "Inline::Java::Object")){
-				croak "A Java method can only have Java objects or scalars as arguments" ;
+				croak "Protocol: A Java method can only have Java objects or scalars as arguments" ;
 			}
-			my $class = $arg->{private}->{class} ;
+			my $class = $arg->{private}->{java_class} ;
 			my $id = $arg->{private}->{id} ;
 			push @ret, "object:$class:$id" ;
 		}
@@ -166,12 +165,15 @@ sub ValidateArgs {
 }
 
 
+# This actually sends the request to the Java program. It also takes
+# care of registering the returned object (if any)
 sub Send {
 	my $this = shift ;
 	my $data = shift ;
 	my $const = shift ;
 
-	my $sock = $Inline::Java::Protocol::socket->{$this->{module}} ;
+	my $inline = $Inline::Java::INLINE->{$this->{module}} ;
+	my $sock = $inline->{Java}->{socket} ;
 	print $sock $data . "\n" or
 		croak "Can't send packet over socket: $!" ;
 
@@ -195,24 +197,24 @@ sub Send {
 		my $id = $1 ;
 		my $class = $2 ;
 		if ($const){
-			$this->{obj_priv}->{class} = $class ;
+			$this->{obj_priv}->{java_class} = $class ;
 			$this->{obj_priv}->{id} = $id ;
 		}
 		else{
 			my $perl_class = $class ;
 			$perl_class =~ s/[.\$]/::/g ;
-			my $pkg = $this->{pkg} ;
+			my $pkg = $inline->{pkg} ;
 			$perl_class = $pkg . "::" . $perl_class ;
 			Inline::Java::debug($perl_class) ;
 
 			my $obj = undef ;
 			if (defined(${$perl_class . "::" . "EXISTS"})){
 				Inline::Java::debug("  returned class exists!") ;
-				$obj = $perl_class->__new($class, $pkg, $this->{module}, $id) ;
+				$obj = $perl_class->__new($class, $inline, $id) ;
 			}
 			else{
 				Inline::Java::debug("  returned class doesn't exist!") ;
-				$obj = Inline::Java::Object->__new($class, $pkg, $this->{module}, $id) ;
+				$obj = Inline::Java::Object->__new($class, $inline, $id) ;
 			}
 			return $obj ;
 		}
@@ -227,17 +229,24 @@ sub Send {
 __DATA__
 
 
+/*
+	This is where most of the work of Inline Java is done. Here determine
+	the request type and then we proceed to serve it.
+*/
 class InlineJavaProtocol {
-	InlineJavaServer main ;
+	InlineJavaServer ijs ;
 	String cmd ;
 	String response ;
 
-	InlineJavaProtocol(InlineJavaServer _m, String _cmd) {
-		main = _m ;
+	InlineJavaProtocol(InlineJavaServer _ijs, String _cmd) {
+		ijs = _ijs ;
 		cmd = _cmd ;
 	}
 
 
+	/*
+		Starts the analysis of the command line
+	*/
 	void Do() throws InlineJavaException {
 		StringTokenizer st = new StringTokenizer(cmd, " ") ;
 		String c = st.nextToken() ;
@@ -257,6 +266,9 @@ class InlineJavaProtocol {
 	}
 
 
+	/*
+		Calls a static Java method
+	*/
 	void CallStaticJavaMethod(StringTokenizer st) throws InlineJavaException {
 		String class_name = st.nextToken() ;
 		String method = st.nextToken() ;
@@ -271,21 +283,24 @@ class InlineJavaProtocol {
 			SetResponse(ret) ;
 		}
 		catch (IllegalAccessException e){
-			throw new InlineJavaException("You are not allowed to invoke static method " + name) ;
+			throw new InlineJavaException("You are not allowed to invoke static method " + name + " in class " + class_name) ;
 		}
 		catch (IllegalArgumentException e){
-			throw new InlineJavaException("Arguments for static method " + name + " are incompatible:" + e.getMessage()) ;
+			throw new InlineJavaException("Arguments for static method " + name + " in class " + class_name + " are incompatible: " + e.getMessage()) ;
 		}
 		catch (InvocationTargetException e){
 			Throwable t = e.getTargetException() ;
 			String type = t.getClass().getName() ;
 			String msg = t.getMessage() ;
 			throw new InlineJavaException(
-				"Method " + name + " threw exception " + type + ": " + msg) ;
+				"Static method " + name + " in class " + class_name + " threw exception " + type + ": " + msg) ;
 		}
 	}
 
 
+	/*
+		Calls a regular Java method
+	*/
 	void CallJavaMethod(StringTokenizer st) throws InlineJavaException {
 		int id = Integer.parseInt(st.nextToken()) ;
 		String class_name = st.nextToken() ;
@@ -296,7 +311,7 @@ class InlineJavaProtocol {
 		Method m = (Method)f.get(0) ;
 		String name = m.getName() ;
 		Integer oid = new Integer(id) ;
-		Object o = main.objects.get(oid) ;
+		Object o = ijs.objects.get(oid) ;
 		if (o == null){
 			throw new InlineJavaException("Object " + oid.toString() + " is not in HashMap!") ;
 		}
@@ -306,21 +321,24 @@ class InlineJavaProtocol {
 			SetResponse(ret) ;
 		}
 		catch (IllegalAccessException e){
-			throw new InlineJavaException("You are not allowed to invoke method " + name) ;
+			throw new InlineJavaException("You are not allowed to invoke method " + name + " in class " + class_name) ;
 		}
 		catch (IllegalArgumentException e){
-			throw new InlineJavaException("Arguments for static " + name + " are incompatible:" + e.getMessage()) ;
+			throw new InlineJavaException("Arguments for method " + name + " in class " + class_name + " are incompatible: " + e.getMessage()) ;
 		}
 		catch (InvocationTargetException e){
 			Throwable t = e.getTargetException() ;
 			String type = t.getClass().getName() ;
 			String msg = t.getMessage() ;
 			throw new InlineJavaException(
-				"Method " + name + " threw exception " + type + ": " + msg) ;
+				"Method " + name + " in class " + class_name + " threw exception " + type + ": " + msg) ;
 		}
 	}
 
 
+	/*
+		Creates a Java Object with the specified arguments.
+	*/
 	void CreateJavaObject(StringTokenizer st) throws InlineJavaException {
 		String class_name = st.nextToken() ;
 		Class c = ValidateClass(class_name) ;
@@ -336,16 +354,22 @@ class InlineJavaProtocol {
 	}
 
 
+	/*
+		Deletes a Java object
+	*/
 	void DeleteJavaObject(StringTokenizer st) throws InlineJavaException {
 		int id = Integer.parseInt(st.nextToken()) ;
 
 		Integer oid = new Integer(id) ;
-		Object o = main.objects.remove(oid) ;
+		Object o = ijs.objects.remove(oid) ;
 
 		SetResponse(null) ;
 	}
 
 	
+	/*
+		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++){
@@ -361,29 +385,32 @@ class InlineJavaProtocol {
 			ret = con.newInstance(args) ;
 		}
 		catch (NoSuchMethodException e){
-			throw new InlineJavaException("Constructor for class " + name + " with specified signature not found") ;
+			throw new InlineJavaException("Constructor for class " + name + " with signature " + ijs.CreateSignature(clist) + " not found") ;
 		}
 		catch (InstantiationException e){
 			throw new InlineJavaException("You are not allowed to instantiate object of class " + name) ;
 		}
 		catch (IllegalAccessException e){
-			throw new InlineJavaException("You are not allowed to instantiate object of class " + name + " using the specified constructor") ;
+			throw new InlineJavaException("You are not allowed to instantiate object of class " + name + " using the constructor with signature " + ijs.CreateSignature(clist)) ;
 		}
 		catch (IllegalArgumentException e){
-			throw new InlineJavaException("Arguments to constructor are incompatible for class " + name) ;
+			throw new InlineJavaException("Arguments to constructor for class " + name + " with signature " + ijs.CreateSignature(clist) + " 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 + " threw exception " + type + ": " + msg) ;
+				"Constructor for class " + name + " with signature " + ijs.CreateSignature(clist) + " threw exception " + type + ": " + msg) ;
 		}
 
 		return ret ;
 	}
 
 
+	/*
+		Makes sure a class exists
+	*/
 	Class ValidateClass(String name) throws InlineJavaException {
 		try {
 			Class c = Class.forName(name) ;
@@ -395,6 +422,9 @@ class InlineJavaProtocol {
 	}
 
 
+	/*
+		Makes sure a method exists
+	*/
 	ArrayList ValidateMethod(boolean constructor, Class c, String name, StringTokenizer st) throws InlineJavaException {
 		Member ma[] = (constructor ? (Member [])c.getConstructors() : (Member [])c.getMethods()) ;
 		ArrayList ret = new ArrayList(ma.length) ;
@@ -406,12 +436,12 @@ class InlineJavaProtocol {
 		}
 
 		ArrayList ml = new ArrayList(ma.length) ;
+		Class params[] = null ;
 		for (int i = 0 ; i < ma.length ; i++){
 			Member m = ma[i] ;
 			if (m.getName().equals(name)){
-				main.debug("found a " + name + (constructor ? " constructor" : " method")) ;
+				ijs.debug("found a " + name + (constructor ? " constructor" : " method")) ;
 
-				Class params[] = null ;
 				if (constructor){
 					params = ((Constructor)m).getParameterTypes() ;
 				}
@@ -421,7 +451,7 @@ class InlineJavaProtocol {
 			 	if (params.length == args.size()){
 					// We have the same number of arguments
 					ml.add(ml.size(), m) ;
-					main.debug("  has the correct number of params (" +  String.valueOf(args.size()) + ") and signature is " + CreateSignature(params)) ;
+					ijs.debug("  has the correct number of params (" +  String.valueOf(args.size()) + ") and signature is " + ijs.CreateSignature(params)) ;
 				}
 			}
 		}
@@ -431,13 +461,13 @@ class InlineJavaProtocol {
 		if (ml.size() == 0){
 			throw new InlineJavaException(
 				(constructor ? "Constructor " : "Method ") + 
-				name + " with " + String.valueOf(args.size()) + " parameters not found in class " + c.getName()) ;
+				name + " for class " + c.getName() + " with signature " +
+				ijs.CreateSignature(params) + " not found") ;
 		}
 		else if (ml.size() == 1){
 			// Now we need to force the arguments received to match
 			// the methods signature.
 			Member m = (Member)ml.get(0) ;
-			Class params[] = null ;
 			if (constructor){
 				params = ((Constructor)m).getParameterTypes() ;
 			}
@@ -445,24 +475,30 @@ class InlineJavaProtocol {
 				params = ((Method)m).getParameterTypes() ;
 			}
 			ret.add(0, m) ;
-			ret.add(1, CastArguments(params, args)) ;
+			ret.add(1, CastArguments(c.getName(), name, params, args)) ;
 		}
 		else{
-			throw new InlineJavaException("Don't know which signature of " + name + " to call") ;
+			throw new InlineJavaException("Automatic method selection when multiple signatures are found not yet implemented") ;
 		}
 
 		return ret ;
 	}
 
 
-	Object [] CastArguments (Class [] params, ArrayList args) throws InlineJavaException {
+	/*
+		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] ;
-			main.debug("    arg " + String.valueOf(i) + " of signature is " + p.getName()) ;
+			ijs.debug("    arg " + String.valueOf(i) + " of signature is " + p.getName()) ;
 
 			ArrayList tokens = new ArrayList() ;
 			StringTokenizer st = new StringTokenizer((String)args.get(i), ":") ;
@@ -478,106 +514,104 @@ class InlineJavaProtocol {
 			// reference types.
 			boolean num = ClassIsNumeric(p) ;
 			if ((num)||(ClassIsString(p))){
-				String text = "string" ;
-				if (num){
-					text = "number" ;
-				}
 				if (type.equals("undef")){
-					main.debug("  args is undef -> forcing to " + text + " 0") ;
+					ijs.debug("  args is undef -> forcing to " + p.getName() + " 0") ;
 					ret[i] = CreateObject(p, new Object [] {"0"}) ;
-					main.debug("    result is " + ret[i].toString()) ;
+					ijs.debug("    result is " + ret[i].toString()) ;
 				}
 				else if (type.equals("scalar")){
 					String arg = pack((String)tokens.get(1)) ;
-					main.debug("  args is scalar -> forcing to " + text) ;
+					ijs.debug("  args is scalar -> forcing to " + p.getName()) ;
 					try	{							
 						ret[i] = CreateObject(p, new Object [] {arg}) ;
-						main.debug("    result is " + ret[i].toString()) ;
+						ijs.debug("    result is " + ret[i].toString()) ;
 					}
 					catch (NumberFormatException e){
-						throw new InlineJavaCastException("Can't convert " + arg + " to some primitive " + text) ;
+						throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
 					}
 				}
 				else{
-					throw new InlineJavaCastException("Can't convert reference to primitive " + text) ;
+					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
 				}
 			}
 			else if ((p == java.lang.Boolean.class)||(p == boolean.class)){
-				main.debug("  class java.lang.Boolean is primitive bool") ;
+				ijs.debug("  class java.lang.Boolean is primitive bool") ;
 				if (type.equals("undef")){
-					main.debug("  args is undef -> forcing to bool false") ;
+					ijs.debug("  args is undef -> forcing to bool false") ;
 					ret[i] = new Boolean("false") ;
-					main.debug("    result is " + ret[i].toString()) ;
+					ijs.debug("    result is " + ret[i].toString()) ;
 				}
 				else if (type.equals("scalar")){
 					String arg = pack(((String)tokens.get(1)).toLowerCase()) ;
-					main.debug("  args is scalar -> forcing to bool") ;
-					if ((arg.equals(""))||(arg.equals("0"))||(arg.equals("false"))){
+					ijs.debug("  args is scalar -> forcing to bool") ;
+					if ((arg.equals(""))||(arg.equals("0"))){
 						arg = "false" ;
 					}
 					else{
 						arg = "true" ;
 					}
 					ret[i] = new Boolean(arg) ;
-					main.debug("    result is " + ret[i].toString()) ;
+					ijs.debug("    result is " + ret[i].toString()) ;
 				}
 				else{
-					throw new InlineJavaCastException("Can't convert reference to primitive bool") ;
+					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
 				}
 			}
 			else if ((p == java.lang.Character.class)||(p == char.class)){
-				main.debug("  class java.lang.Character is primitive char") ;
+				ijs.debug("  class java.lang.Character is primitive char") ;
 				if (type.equals("undef")){
-					main.debug("  args is undef -> forcing to char '\0'") ;
+					ijs.debug("  args is undef -> forcing to char '\0'") ;
 					ret[i] = new Character('\0') ;
-					main.debug("    result is " + ret[i].toString()) ;
+					ijs.debug("    result is " + ret[i].toString()) ;
 				}
 				else if (type.equals("scalar")){
 					String arg = pack((String)tokens.get(1)) ;
-					main.debug("  args is scalar -> forcing to char") ;
+					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 primitive char") ;
+						throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
 					}
 					ret[i] = new Character(c) ;
-					main.debug("    result is " + ret[i].toString()) ;
+					ijs.debug("    result is " + ret[i].toString()) ;
 				}
 				else{
-					throw new InlineJavaCastException("Can't convert reference to primitive char") ;
+					throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
 				}
 			}
 			else {
-				main.debug("  class " + p.getName() + " is reference") ;
+				ijs.debug("  class " + p.getName() + " is reference") ;
 				// We know that what we expect here is a real object
 				if (type.equals("undef")){
-					main.debug("  args is undef -> forcing to null") ;
+					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 to reference") ;
+						throw new InlineJavaCastException("Can't convert primitive type to " + p.getName() + msg) ;
 					}
 				}
 				else{
 					// We need an object and we got an object...
-					main.debug("  class " + p.getName() + " is reference") ;
+					ijs.debug("  class " + p.getName() + " is reference") ;
 
-					String class_name = (String)tokens.get(1) ;
+					String c_name = (String)tokens.get(1) ;
 					String objid = (String)tokens.get(2) ;
 
-					Class c = ValidateClass(class_name) ;
+					Class c = ValidateClass(c_name) ;
 					// We need to check if c extends p
 					Class parent = c ;
 					boolean got_it = false ;
 					while (parent != null){
-						main.debug("    parent is " + parent.getName()) ;
+						ijs.debug("    parent is " + parent.getName()) ;
 						if (parent == p){
 							got_it = true ;
 							break ;
@@ -586,17 +620,17 @@ class InlineJavaProtocol {
 					}
 
 					if (got_it){
-						main.debug("    " + c.getName() + " is a kind of " + p.getName()) ;
+						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 = main.objects.get(oid) ;
+						Object o = ijs.objects.get(oid) ;
 						if (o == null){
-							throw new InlineJavaException("Object " + oid.toString() + " is not in HashMap!") ;
+							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()) ;
+						throw new InlineJavaCastException("Can't cast a " + c.getName() + " to a " + p.getName() + msg) ;
 					}
 				}
 			}			
@@ -606,19 +640,9 @@ class InlineJavaProtocol {
 	}
 
 
-	String CreateSignature (Class param[]){
-		StringBuffer ret = new StringBuffer() ;
-		for (int i = 0 ; i < param.length ; i++){
-			if (i > 0){
-				ret.append(", ") ;
-			}
-			ret.append(param[i].getName()) ;
-		}
-
-		return "(" + ret.toString() + ")" ;
-	}
-
-
+	/*
+		Finds the wrapper class for the passed primitive type.
+	*/
 	Class FindWrapper (Class p){
 		Class [] list = {
 			byte.class,
@@ -629,7 +653,6 @@ class InlineJavaProtocol {
 			double.class,
 			boolean.class,
 			char.class,
-			void.class,
 		} ;
 		Class [] listw = {
 			java.lang.Byte.class,
@@ -640,7 +663,6 @@ class InlineJavaProtocol {
 			java.lang.Double.class,
 			java.lang.Boolean.class,
 			java.lang.Character.class,
-			java.lang.Void.class,
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
@@ -663,25 +685,26 @@ class InlineJavaProtocol {
 		Class [] list = {
 			java.lang.Boolean.class,
 			java.lang.Character.class,
-			java.lang.Void.class,
 			boolean.class,
 			char.class,
-			void.class,
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			main.debug("  comparing " + name + " with " + list[i].getName()) ;
+			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
-				main.debug("  class " + name + " is primitive") ;
+				ijs.debug("  class " + name + " is primitive") ;
 				return true ;
 			}
 		}
 
-		main.debug("  class " + name + " is reference") ;
+		ijs.debug("  class " + name + " is reference") ;
 		return false ;
 	}
 
 
+	/*
+		Determines if class is of numerical type.
+	*/
 	boolean ClassIsNumeric (Class p){
 		String name = p.getName() ;
 
@@ -701,9 +724,9 @@ class InlineJavaProtocol {
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			main.debug("  comparing " + name + " with " + list[i].getName()) ;
+			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
-				main.debug("  class " + name + " is primitive numeric") ;
+				ijs.debug("  class " + name + " is primitive numeric") ;
 				return true ;
 			}
 		}
@@ -712,6 +735,9 @@ class InlineJavaProtocol {
 	}
 
 
+	/*
+		Class is String or StringBuffer
+	*/
 	boolean ClassIsString (Class p){
 		String name = p.getName() ;
 
@@ -721,9 +747,9 @@ class InlineJavaProtocol {
 		} ;
 
 		for (int i = 0 ; i < list.length ; i++){
-			main.debug("  comparing " + name + " with " + list[i].getName()) ;
+			ijs.debug("  comparing " + name + " with " + list[i].getName()) ;
 			if (p == list[i]){
-				main.debug("  class " + name + " is primitive string") ;
+				ijs.debug("  class " + name + " is primitive string") ;
 				return true ;
 			}
 		}
@@ -732,6 +758,10 @@ class InlineJavaProtocol {
 	}
 
 	
+	/*
+		Determines if a class is not of a primitive type or of a 
+		wrapper class.
+	*/
 	boolean ClassIsReference (Class p){
 		String name = p.getName() ;
 
@@ -739,31 +769,35 @@ class InlineJavaProtocol {
 			return false ;
 		}
 
-		main.debug("  class " + name + " is reference") ;
+		ijs.debug("  class " + name + " is reference") ;
 
 		return true ;
 	}
 
 
+	/*
+		This sets the response that will be returned to the Perl
+		script
+	*/
 	void SetResponse (Object o){
 		if (o == null){
 			response = "ok undef:" ;
 		}
-		// Split between Numeric, String, Boolean and Character and Void
 		else if (ClassIsPrimitive(o.getClass())){
 			response = "ok scalar:" + unpack(o.toString()) ;
 		}
 		else {
 			// Here we need to register the object in order to send
 			// it back to the Perl script.
-			main.objects.put(new Integer(main.objid), o) ;
-			response = "ok object:" + String.valueOf(main.objid) +
+			ijs.objects.put(new Integer(ijs.objid), o) ;
+			response = "ok object:" + String.valueOf(ijs.objid) +
 				":" + o.getClass().getName() ;
-			main.objid++ ;
+			ijs.objid++ ;
 		}
 	}
 
 
+	/* Equivalent to Perl pack */
 	public String pack(String s){
 		StringTokenizer st = new StringTokenizer(s, ".") ;
 		StringBuffer sb = new StringBuffer() ;
@@ -777,6 +811,7 @@ class InlineJavaProtocol {
 	}
 
 
+	/* Equivalent to Perl unpack */
 	public String unpack(String s){
 		byte b[] = s.getBytes() ;
 		StringBuffer sb = new StringBuffer() ;
@@ -789,49 +824,5 @@ class InlineJavaProtocol {
 
 		return sb.toString() ;
 	}
-
-
-	public void test(String argv[]){
-		Class list[] = {
-			java.lang.Exception.class,
-//			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.String.class,
-//			java.lang.StringBuffer.class,
-//			java.lang.Boolean.class,
-//			java.lang.Character.class,
-		} ;
-
-		ArrayList args[] = new ArrayList [1] ;
-		for (int j = 0 ; j < 1 ; j++){
-			args[j] = new ArrayList(1) ;
-		}
-		args[0].add(0, "object:666:java.lang.Exception") ;
-//		args[0].add(0, "undef:") ;
-//		args[1].add(0, "scalar:66") ;
-//		args[2].add(0, "scalar:666") ;
-//		args[3].add(0, "scalar:a") ;
-//		args[4].add(0, "scalar:AB") ;
-//		args[5].add(0, "scalar:1") ;
-//		args[6].add(0, "scalar:") ;
-
-		for (int j = 0 ; j < args.length ; j++){
-			for (int i = 0; i < list.length ; i++){
-				Class proto[] = new Class[1] ;
-				proto[0] = list[i] ;
-				try	{
-					CastArguments(proto, args[j]) ;
-				}
-				catch (InlineJavaException e){
-					main.debug("InlineJavaException caught: " + e.getMessage()) ;
-				}			
-			}
-			main.debug("") ;
-		}
-	}
 }
 

-- 
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