View Single Post
  #1 (permalink)  
Old November 10th, 2005, 05:13 PM
dleal dleal is offline
Registered User
 
Join Date: Oct 2005
Location: Madrid, M, Spain.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to dleal Send a message via MSN to dleal Send a message via Yahoo to dleal
Default Exception design on Boxoffice Sample Application?

Dear Members,

Looking in to the BoxOffice sample Aplication the exception messages are written in "hard code", they don't use any ResourceBundle for that.

For example (From NotEnoughSeatsException):

Code:
public NotEnoughSeatsException(long classId, int available, int requested) {
        super(ERROR_CODE, "Requested " + requested + " seats in class " + classId + "; only " + available + " are free");
        this.classId = classId;
        this.requested = requested;
        this.available = available;
    }


Every exception is designed on a similar way. There is no constructor with message as input argument.

How to implement a language independent way for defining the message exceptions?

In think in two possibilities:

1. Add a ResourceBundle attribute on the ApplicationException (base exception for all possible application exceptions)

2. Defining the exception constructors with a message attribute in order to be filled on places the exceptions will be thrown. With this solutions we need only a few exceptions, because ApplicationException with different message could apply for most cases (Probably a poor design strategy)

I am assuming the Application Exception police should consider that the exceptions are not only caught by the web side client, that is why each tier should be independ, so if I want also to run my application on console mode I would like that my exception will be treated property on language independ way (at least user exceptions)

So what is the purpose of the bean:

Code:
 
    <bean id="messageSource"        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename">
            <value>error-messages</value>
        </property>
    </bean>


Is is correct to desing an Exception policy creating dependence with such bean, how can we do that?, or it is better the solution I have propoused (1).

How can I unify this exception police using error-messages.properties from my web client side and also for throwing the exception could be caught on non web application.

If you take a look on BookSeatsController class from BoxOffice application, the exception are catch, in the form:

Code:
try {
            reservation = boxOffice.allocateSeats(request);
        } catch (RequestedSeatNotAvailableException e) {
            errors.reject(e.getErrorCode(), "Requested seats are not available");
        } catch (NotEnoughSeatsException e) {
            errors.reject(e.getErrorCode(), "Could not allocate the number of seats requested");
        }


So were goes this message in english????, should it be language independent? For example the error code: "seatNotAvailable" is not used at other places on the source code and there is no information on the error-message.properties of such error code, so it is not used as resource key for getting the translatated message.

As far as I remember on the Expert one-on-one J2EE book there is comment about the user error message and detailed error message (goes for log files) the first one should be language independent and the second one (log file) could be in english for example. I don't see very clear how to implement that on language indepent way and also independently of tier.

Thanks in advance,

David

Reply With Quote