A couple of alternatives spring to mind.
1. If you're able and prepared to use a signed applet, the security
issues may go away.
2. You could handle Logger initialisation in a static block, catch
exceptions and provide a dummy implementation of Logger so that the
remainder of your code doesn't throw NPEs.
e.g.
replace
static Logger cat = Logger.getLogger( "TimeStamp" );
with
static Logger cat;
static {
try {
cat = Logger.getLogger( "TimeStamp" );
}
catch (Exception e) {
cat = new NoOpLogger(); // you provide a subclass of Logger
that does nothing
}
}
Of course rather than have this code in every class you would
parametrise it and move it into a static factory class of some sort,
calling it from static blocks as required.
I'm sure there are more elegant solutions.
Hope this helps
Keith
-----Original Message-----
From: Jeff Drew [mailto:[EMAIL PROTECTED]
Sent: 20 February 2006 22:33
To: [email protected]
Subject: reusability and applet dilemma
I'm converting my desktop application to an applet. Due to browser
security, I can't read or write local files so I can neither use
.properties nor write logs. My dilemma is rooted in reusable classes.
My desktop application(now applet) uses some classes, such as a
timeStamp class, that are also used in my server. I'd prefer to retain
that class's logging capability when it is running in the server, but
disable the logging when running in the applet.
I see 3 alternatives:
1. move the logger instantiation to the constructor, then pass the
constructor a newly created boolean indicating whether it's running as
an applet. 2. subclass Logger, then have the subclass check some global
boolean indicating whether it's running as an applet 3. remove logging
from the reused classes altogether
I don't like any of these alternatives and wondered if there is another,
more appealing alternative. Here's a simple example that illustrates my
problem.
Thanks
Jeff
public class TimeStamp implements Serializable {
// the following line will cause a security exception
static Logger cat =
Logger.getLogger( "TimeStamp" );
public TimeStamp( long milliSeconds ) {
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]