[libinline-java-perl] 21/398: *** empty log message ***
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:42:38 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 142fc1999da3faff4000ce7247133e905effea62
Author: patrick <>
Date: Thu Mar 8 15:36:51 2001 +0000
*** empty log message ***
---
Java.pm | 25 ++++++++++++++---
Java/Class.pm | 81 ++++++++++++++++++++++++++++++++-----------------------
Java/Object.pm | 16 ++++++++---
Java/Protocol.pm | 16 ++++++++---
t/02_primitives.t | 13 ++++++++-
t/03_objects.t | 38 +++++++++++++++++++++++++-
6 files changed, 144 insertions(+), 45 deletions(-)
diff --git a/Java.pm b/Java.pm
index a063ea9..20bfde8 100644
--- a/Java.pm
+++ b/Java.pm
@@ -696,6 +696,7 @@ sub bind_jdat {
package $o->{pkg}::$class ;
\@$o->{pkg}::$class$c:ISA = qw(Inline::Java::Object) ;
\$$o->{pkg}::$class$c:EXISTS = 1 ;
+use Carp ;
CODE
@@ -714,7 +715,13 @@ sub new {
my \@new_args = \$class->__validate_prototype('new', [\@args], [$signature]) ;
- return \$class->__new('$java_class', \$Inline::Java::INLINE->{'$modfname'}, -1, \@new_args) ;
+ my \$ret = undef ;
+ eval {
+ \$ret = \$class->__new('$java_class', \$Inline::Java::INLINE->{'$modfname'}, -1, \@new_args) ;
+ } ;
+ croak \$@ if \$@ ;
+
+ return \$ret ;
}
@@ -743,7 +750,13 @@ sub $method {
my \$proto = new Inline::Java::Protocol(undef, \$Inline::Java::INLINE->{'$modfname'}) ;
- return \$proto->CallStaticJavaMethod('$java_class', '$method', \@new_args) ;
+ my \$ret = undef ;
+ eval {
+ \$ret = \$proto->CallStaticJavaMethod('$java_class', '$method', \@new_args) ;
+ } ;
+ croak \$@ if \$@ ;
+
+ return \$ret ;
}
CODE
@@ -764,7 +777,13 @@ sub $method {
my \@new_args = \$this->__validate_prototype('$method', [\@args], [$signature]) ;
- return \$this->{private}->{proto}->CallJavaMethod('$method', \@new_args) ;
+ my \$ret = undef ;
+ eval {
+ \$ret = \$this->{private}->{proto}->CallJavaMethod('$method', \@new_args) ;
+ } ;
+ croak \$@ if \$@ ;
+
+ return \$ret ;
}
CODE
diff --git a/Java/Class.pm b/Java/Class.pm
index e187c19..c2cacef 100644
--- a/Java/Class.pm
+++ b/Java/Class.pm
@@ -58,17 +58,27 @@ $RANGE->{double} = $RANGE->{'java.lang.Double'} ;
sub ValidateClass {
my $class = shift ;
- if ($class !~ /^(\w+)((\.(\w+))+)?/){
- croak "Protocol: Invalid Java class name $class" ;
- }
+ my $ret = ValidateClassSplit($class) ;
+
+ return $ret ;
+}
+
+
+sub ValidateClassSplit {
+ my $class = shift ;
- return $class ;
+ my $cre = '([\w$]+)(((\.([\w$]+))+)?)' ;
+ if (($class =~ /^($cre)()()()$/)||
+ ($class =~ /^(\[+)([BCDFIJSZ])()()$/)||
+ ($class =~ /^(\[+)([L])($cre)(;)$/)){
+ return (wantarray ? ($1, $2, $3, $4) : $class) ;
+ }
+
+ croak "Invalid Java class name $class" ;
}
sub CastArguments {
- my $class = shift ;
- my $method = shift ;
my $args = shift ;
my $proto = shift ;
@@ -76,12 +86,12 @@ sub CastArguments {
Inline::Java::debug_obj($proto) ;
if (scalar(@{$args}) != scalar(@{$proto})){
- croak "Wrong number of arguments for method $method of class $class" ;
+ croak "Wrong number of arguments" ;
}
my $ret = [] ;
for (my $i = 0 ; $i < scalar(@{$args}) ; $i++){
- $ret->[$i] = CastArgument($class, $method, $args->[$i], $proto->[$i]) ;
+ $ret->[$i] = CastArgument($args->[$i], $proto->[$i]) ;
}
return $ret ;
@@ -89,16 +99,16 @@ sub CastArguments {
sub CastArgument {
- my $class = shift ;
- my $method = shift ;
my $arg = shift ;
my $proto = shift ;
+ ValidateClass($proto) ;
+
if ((ClassIsReference($proto))&&(! UNIVERSAL::isa($arg, "Inline::Java::Object"))){
- croak "Can't convert $arg to $proto in method $method of class $class" ;
+ croak "Can't convert $arg to object $proto" ;
}
if ((ClassIsPrimitive($proto))&&(ref($arg))){
- croak "Can't convert $arg to $proto in method $method of class $class" ;
+ croak "Can't convert $arg to primitive $proto" ;
}
if (ClassIsNumeric($proto)){
@@ -113,9 +123,9 @@ sub CastArgument {
if (($arg >= $min)&&($arg <= $max)){
return $arg ;
}
- croak "$arg out of range for type $proto in method $method of class $class" ;
+ croak "$arg out of range for type $proto" ;
}
- croak "Can't convert $arg to $proto in method $method of class $class" ;
+ croak "Can't convert $arg to $proto" ;
}
elsif (ClassIsChar($proto)){
if (! defined($arg)){
@@ -124,7 +134,7 @@ sub CastArgument {
if (length($arg) == 1){
return $arg ;
}
- croak "Can't convert $arg to $proto in method $method of class $class" ;
+ croak "Can't convert $arg to $proto" ;
}
elsif (ClassIsBool($proto)){
if ($arg){
@@ -250,6 +260,17 @@ sub ClassIsReference {
}
+sub ClassIsArray {
+ my $class = shift ;
+
+ if ((ClassIsReference($class))&&($class =~ /^(\[+)(.*)$/)){
+ return 1 ;
+ }
+
+ return 0 ;
+}
+
+
1 ;
@@ -282,19 +303,16 @@ class InlineJavaClass {
/*
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 [] CastArguments (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()) ;
- ret[i] = CastArgument(class_name, method_name, p, (String)args.get(i)) ;
+ ret[i] = CastArgument(p, (String)args.get(i)) ;
}
return ret ;
@@ -304,12 +322,9 @@ class InlineJavaClass {
/*
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 CastArgument (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++){
@@ -343,11 +358,11 @@ class InlineJavaClass {
ijs.debug(" result is " + ret.toString()) ;
}
catch (NumberFormatException e){
- throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName()) ;
}
}
else{
- throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't convert reference to " + p.getName()) ;
}
}
else if (ClassIsBool(p)){
@@ -369,7 +384,7 @@ class InlineJavaClass {
ijs.debug(" result is " + ret.toString()) ;
}
else{
- throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't convert reference to " + p.getName()) ;
}
}
else if (ClassIsChar(p)){
@@ -386,13 +401,13 @@ class InlineJavaClass {
c = arg.toCharArray()[0] ;
}
else if (arg.length() > 1){
- throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't convert " + arg + " to " + p.getName()) ;
}
ret = new Character(c) ;
ijs.debug(" result is " + ret.toString()) ;
}
else{
- throw new InlineJavaCastException("Can't convert reference to " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't convert reference to " + p.getName()) ;
}
}
else {
@@ -410,7 +425,7 @@ class InlineJavaClass {
ret = arg ;
}
else{
- throw new InlineJavaCastException("Can't convert primitive type to " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't convert primitive type to " + p.getName()) ;
}
}
else{
@@ -434,17 +449,17 @@ class InlineJavaClass {
}
if (got_it){
- ijs.debug(" " + c.getName() + " is a kind of " + p.getName() + msg) ;
+ ijs.debug(" " + c.getName() + " is a kind of " + p.getName()) ;
// 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) ;
+ throw new InlineJavaException("Object " + oid.toString() + " of type " + c_name + " is not in object table ") ;
}
ret = o ;
}
else{
- throw new InlineJavaCastException("Can't cast a " + c.getName() + " to a " + p.getName() + msg) ;
+ throw new InlineJavaCastException("Can't cast a " + c.getName() + " to a " + p.getName()) ;
}
}
}
diff --git a/Java/Object.pm b/Java/Object.pm
index 34bcab2..3b9ccd0 100644
--- a/Java/Object.pm
+++ b/Java/Object.pm
@@ -41,7 +41,11 @@ sub __new {
$this->{private}->{module} = $inline->{modfname} ;
$this->{private}->{proto} = new Inline::Java::Protocol($this->{private}, $inline) ;
if ($objid <= 0){
- $this->{private}->{proto}->CreateJavaObject($java_class, @args) ;
+ eval {
+ $this->{private}->{proto}->CreateJavaObject($java_class, @args) ;
+ } ;
+ croak "In method new of class $class: $@" if $@ ;
+
Inline::Java::debug("Object created in perl script ($class):") ;
}
else{
@@ -64,9 +68,10 @@ sub __validate_prototype {
my $new_args = undef ;
eval {
- $new_args = Inline::Java::Class::CastArguments($class, $method, $args, $proto) ;
+ $new_args = Inline::Java::Class::CastArguments($args, $proto) ;
} ;
- croak $@ if $@ ;
+ my $name = (ref($class) ? $class->{private}->{class} : $class) ;
+ croak "In method $method of class $name: $@" if $@ ;
return @{$new_args} ;
}
@@ -96,7 +101,10 @@ sub DESTROY {
if (! $this->{private}->{deleted}){
$this->{private}->{deleted} = 1 ;
- $this->{private}->{proto}->DeleteJavaObject() ;
+ eval {
+ $this->{private}->{proto}->DeleteJavaObject() ;
+ } ;
+ croak "In method DESTROY of class $this->{private}->{class}: $@" if $@ ;
}
else{
Inline::Java::debug("Object destructor called more than once!") ;
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index 30696cd..4207309 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -447,9 +447,19 @@ class InlineJavaProtocol {
else{
params = ((Method)m).getParameterTypes() ;
}
- ret.add(0, m) ;
- ret.add(1, ijc.CastArguments(c.getName(), name, params, args)) ;
- ret.add(2, params) ;
+
+ String msg = "In method " + name + " of class " + c.getName() + ": " ;
+ try {
+ ret.add(0, m) ;
+ ret.add(1, ijc.CastArguments(params, args)) ;
+ ret.add(2, params) ;
+ }
+ catch (InlineJavaCastException e){
+ throw new InlineJavaCastException(msg + e.getMessage()) ;
+ }
+ catch (InlineJavaException e){
+ throw new InlineJavaException(msg + e.getMessage()) ;
+ }
}
else{
throw new InlineJavaException("Automatic method selection when multiple signatures are found not yet implemented") ;
diff --git a/t/02_primitives.t b/t/02_primitives.t
index aa6cd01..a674767 100644
--- a/t/02_primitives.t
+++ b/t/02_primitives.t
@@ -10,7 +10,7 @@ use Inline(
BEGIN {
- plan(tests => 18) ;
+ plan(tests => 20) ;
}
@@ -35,6 +35,9 @@ ok($t->_Boolean("0"), 0) ;
ok($t->_char("1"), '1') ;
ok($t->_Character("1"), '1') ;
+ok($t->_String("string"), 'string') ;
+ok($t->_StringBuffer("string_buffer"), 'string_buffer') ;
+
__END__
@@ -107,6 +110,14 @@ class types {
public Character _Character(Character c){
return c ;
}
+
+ public String _String(String s){
+ return s ;
+ }
+
+ public StringBuffer _StringBuffer(StringBuffer sb){
+ return sb ;
+ }
}
diff --git a/t/03_objects.t b/t/03_objects.t
index caf57e3..2bac0eb 100644
--- a/t/03_objects.t
+++ b/t/03_objects.t
@@ -10,7 +10,7 @@ use Inline(
BEGIN {
- plan(tests => 14) ;
+ plan(tests => 15) ;
}
@@ -46,6 +46,12 @@ $o1->set_arraylist($al, "array data") ;
ok($o1->get_arraylist($al), "array data") ;
+my $so3 = new sub_obj_test(100) ;
+my $ow = new obj_wrap($so3) ;
+my $do = new obj_do($ow) ;
+$do->get_obj()->set_obj($so2) ;
+ok($do->get_obj_data()->get_number(), 6) ;
+
__END__
__Java__
@@ -115,3 +121,33 @@ class sub_obj_test extends obj_test {
number = num ;
}
}
+
+
+/* Has an object as a member variable */
+class obj_wrap {
+ public sub_obj_test obj ;
+
+ public obj_wrap(sub_obj_test o){
+ obj = o ;
+ }
+
+ public void set_obj(sub_obj_test o){
+ obj = o ;
+ }
+}
+
+
+class obj_do {
+ public obj_wrap obj ;
+
+ public obj_do(obj_wrap o){
+ obj = o ;
+ }
+
+ public obj_wrap get_obj(){
+ return obj ;
+ }
+ public sub_obj_test get_obj_data(){
+ return obj.obj ;
+ }
+}
--
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