aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes configuration dialog restart when error in constructing the application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "configuration dialog restart when error in constructing the application" Watch "configuration dialog restart when error in constructing the application" New topic
Author

configuration dialog restart when error in constructing the application

Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
hi

I'm not far from being done with coding of my SCJD app, but there's something I don't manage to get clean: what to do in case of bad configuration. For example if the file given for the db is not a proper db file. In fact, what to do is easy: to relaunch the dialog

the question is how to that nicely.

Up to now, I've a enum handling the various modes (figuring the proper one from the main arguments). Something like:


however, if the config is broken, how to rerun it ?

I could have a "protected boolean doRun()" un LaunchMode, expecting a boolean to say whether it was successful or not (and restart if not) but I really find it ugly (comes from nowhere => hard to get for a newcomer imho).

The run() could call itself again in case of configuration failure, but it could lead to a stackoverflow. It's unlikely I agree but still I find it not nice neither...

someone with a better option ?

Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Howdy, Nono. Still struggling with the exceptions?

The thing is that you don't have to rerun anything. How about doing something like this:



Please take a look at that and let me know if it helps!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5407
    
  13

Hi Norbert,

I kept it simple: wrong configuration settings will result in an appropriate error message and the application exits (after user clicks 'ok' in the error message dialog).

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
David Byron
Rancher

Joined: Jan 20, 2009
Posts: 172

Norbert Lebenthal wrote:what to do in case of bad configuration. For example if the file given for the db is not a proper db file. In fact, what to do is easy: to relaunch the dialog

the question is how to that nicely.


I implemented a dialog restart by doing something like this:



Code like this occurs in a promptForClientOptions() method that builds my ClientOptionsDialog (called "options"). So if (for example) the database chosen is invalid, the exception handling code offers a warning, nukes the existing dialog, and calls promptForClientOptions(), the method in which it resides.

Norbert Lebenthal wrote:The run() could call itself again in case of configuration failure, but it could lead to a stackoverflow. It's unlikely I agree but still I find it not nice neither...


Sure, it replaces an existing dialog with a new one on each iteration, but that's (a) simple, and (b) no more strange than constructing a new TableModel every time a value in its state changes. ;)

Anyone who restarts a simple dialog enough times to max out the stack probably shouldn't be allowed into the app anyhow. ;)


SCJD 6, OCPJP7, Baroque Potion, G+
Norbert Lebenthal
Ranch Hand

Joined: Sep 23, 2010
Posts: 74
thanks all for your answers and especially Roberto Perillo: your solution is so damn clean !!! lovely It makes me wonder what I've been thinking about all this time, even if it looks like David Byron was quite close from my thinking path (I thought as well of exceptions, but I found them even less clean: handling exceptions by displaying message and then sending some other again, doesn't feel this clean).

thanks again

it's now all implemented and running fine
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

Cool, Nono! Glad I could help!

Norbert Lebenthal wrote:it's now all implemented and running fine


Alright! So you're pretty close to being a SCJD! Good luck, champion!
 
jQuery in Action, 2nd edition
 
subject: configuration dialog restart when error in constructing the application