Path: csiph.com!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: "Richard Maher" Newsgroups: comp.lang.java.programmer Subject: Re: Packages and Reflection in an Applet Date: Mon, 7 May 2012 20:47:59 +0800 Organization: HTTP *is* The Box - Let's think outside Lines: 86 Message-ID: References: <4fa59c0e$0$285$14726298@news.sunsite.dk> NNTP-Posting-Host: jOhPn0KFjrxwuMc9OPMmCw.user.speranza.aioe.org X-Complaints-To: abuse@aioe.org X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Response X-Notice: Filtered by postfilter v. 0.8.2 X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-Priority: 3 X-MSMail-Priority: Normal Xref: csiph.com comp.lang.java.programmer:14358 Hi Arne, Thanks as always for your replies. "Arne Vajhøj" wrote in message news:4fa59c0e$0$285$14726298@news.sunsite.dk... > On 5/5/2012 1:25 AM, Richard Maher wrote: >> I have an unsigned Applet that needs to obtain a Username/Password from >> the >> user (via generic dialog boxes outside of the web-page) and optionally, >> on >> successful login, display some "welcome" info from the server. To that >> end, >> I have come up with a rudimentary AWT interface that pops-up a couple of >> modal dialogue boxes. (There is also a "status" window that has bytes >> received/sent etc). > > Why not use Swing instead of AWT? That's the whole point. If someone wants to use Swing then I'm happy to plug-in the results. (Or a localized/foreign-language version, or a.n.other) > > Or maybe even do it the Java 8 way with JavaFX? I'm sure JavaFX is appropriate for those who see fit to use it but it's a non-issue here. > >> So, I have the default, fallback, rough-as-guts option for obtaining user >> credentials but would like to allow the consumers of my Applet to >> override >> the default and supply their own much slicker +/- localized UI. So I have >> the simple interface below that each prospective UI class must implement >> but >> I don't know what part packages/protection play in this scenario as well >> as >> reflection. If there are any people here with direct experience of the >> following conditions/questions I would be very grateful for their >> advice: - >> >> 1) Can a class loaded via Reflection (eg: myInter localGUI = >> (myInter)(class.forName("appletParameter").newInstance())) be in the same >> Package, and enjoy the benefits/protection of same, as the caller? >> Ideally >> here, the methods/variables/properties of the newly loaded class (albeit >> under the restriction of being loaded from the same codebase) being >> package >> private and not public? Again ideally, I do not want the methods in this >> GUI >> to be accessible from JavaScript but obviously accessible from my applet. > > The loaded class can certainly be in the same package as the caller. Cool. So they just point their classpath at my interface bearing JAR an it should all be good/doable. I guess I'll have some Manifest issues getting the/my original JAR to look for the new gui.JAR or with the Multi-JAR codebase/archive Object attributes sort the classpath out automagically? > >> 2) I'd expect the "tier3Client" implementing class (and any additional >> classes) to be supplied in a separate archive/JAR file and this will be >> located via the "archive=a,b,c" specifier (with "codebase_lookup" set to >> false). My "understanding" is that class.forName() will use the same >> classloader as the Applet and therefore I'm hoping that it will happily >> search through all specified JAR files looking for the requested class? > > If you do not specify a classloader in the forName call (there is an > overload for that), then you will get the current classes classloader. > >> 3) Are there any other restrictions/requirements or wil this just not >> work? > > Will their jar and your jar be loaded from the same location? Yep. > > Arne > Cheers Richard Maher