LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 11 Jun 2007 04:16:48 -0700
Reply-To:     "Richard A. DeVenezia" <>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "Richard A. DeVenezia" <>
Subject:      Re: How to check, if a Java Class exists out of sas data step
Comments: To:
In-Reply-To:  <>
Content-Type: text/plain; charset="us-ascii"

On Jun 11, 5:04 am, sasu...@CODE2BE.DE (Michael Weiss) wrote: > Hello, > 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; > run; > > data checkResults(keep=className exists); > > Declare javaObj class('java/lang/Class'); > class.exceptionDescribe(1); > do until (last1); > set checkClasses end = last1; > class.callStaticVoidMethod('forName', className); > class.exceptionCheck(ex); > if ex eq 1 then do; > exists=0; > class.exceptionClear(); > end; else do; > exists=1; > end; > end; > class.delete(); > run; > > 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 JNI)

Back to: Top of message | Previous page | Main SAS-L page