Date: Mon, 11 Jun 2007 04:16:48 -0700
Reply-To: "Richard A. DeVenezia" <richard.google@DEVENEZIA.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <richard.google@DEVENEZIA.COM>
Subject: Re: How to check, if a Java Class exists out of sas data step
Content-Type: text/plain; charset="us-ascii"
On Jun 11, 5:04 am, sasu...@CODE2BE.DE (Michael Weiss) wrote:
> I'm a bit new in SAS and have not as much knowledge about how to invoke java
> out of saa.
> To complain to our guidelines, I need to check if the class, I want to use
> is accessible or not.
> For that I would like to do something like:
> data checkClasses;
> className='com/mypath/MyClass'; output;
> className='com/mypath/MyClass2'; output;
> data checkResults(keep=className exists);
> Declare javaObj class('java/lang/Class');
> do until (last1);
> set checkClasses end = last1;
> class.callStaticVoidMethod('forName', className);
> if ex eq 1 then do;
> end; else do;
> Unfortunately I can't instantiate the Class java.lang.Class. Is there any
> way to access a static method of this class? Or is there any other way to
> check, if a class can be used? I need to catch the error, if it is not
> possible to use the class.
As you found out, javaobj can only instantiate a class that has a
public constructor. Additionally, javaobj interact with a method that
returns an object. Is there a reason you can not try to instantiate
MyClass directly ?
In general, to deal with any method that returns an object, you need
to write an adapter class that has a series of javaobj accessible
methods for interacting with a delegate. Perhaps some future version
of SAS will have a fully realized javaobj (would require an update of
the Component Object technology that deals with object returns, in
particular, a javaobj implementation that accomodates all aspects of