You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Aaron Robinson <aa...@hotmail.com> on 2003/06/14 12:20:43 UTC
Generating Java constants class from message resources
The most common approach I've seen to using error messages in code is set up
a bunch of constants somewhere and then use these in the code...
public class blah
{
private static int ERROR_CREATING_CLIENT = 1234;
public void doThis()
{
raiseError(ERROR_CREATING_CLIENT)
}
}
As Struts has an application resources file with all the error messages as
properties it would be nice if I could derive a bunch of constants from the
properties file so that I have one definition of the errors.
my idea is to write some code that will create a class that contains
constants based on the application resource file. This will allow compile
time checking of the error messages used in code.
So if the message resources file has
exception.clientexists="this client already exists"
A class would be generated that has
public class messages
{
public static string CLIENTEXISTS = "exception.clientexists";
}
And the code would
public void doThis()
{
raiseError(messages.CLIENTEXISTS);
}
Does anyone know of a better way of doing this? Has something like this
already been done?
_________________________________________________________________
Hotmail messages direct to your mobile phone http://www.msn.co.uk/msnmobile
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Generating Java constants class from message resources
Posted by Sandeep Takhar <sa...@yahoo.com>.
I haven't done anything like that, but it seems to me
that this is XDoclet's arena.
sandeep
--- Aaron Robinson <aa...@hotmail.com>
wrote:
> The most common approach I've seen to using error
> messages in code is set up
> a bunch of constants somewhere and then use these in
> the code...
>
> public class blah
> {
> private static int ERROR_CREATING_CLIENT = 1234;
>
> public void doThis()
> {
> raiseError(ERROR_CREATING_CLIENT)
> }
> }
>
> As Struts has an application resources file with all
> the error messages as
> properties it would be nice if I could derive a
> bunch of constants from the
> properties file so that I have one definition of the
> errors.
>
> my idea is to write some code that will create a
> class that contains
> constants based on the application resource file.
> This will allow compile
> time checking of the error messages used in code.
>
> So if the message resources file has
>
> exception.clientexists="this client already exists"
>
> A class would be generated that has
>
> public class messages
> {
> public static string CLIENTEXISTS =
> "exception.clientexists";
> }
>
> And the code would
>
> public void doThis()
> {
> raiseError(messages.CLIENTEXISTS);
> }
>
> Does anyone know of a better way of doing this? Has
> something like this
> already been done?
>
>
_________________________________________________________________
> Hotmail messages direct to your mobile phone
> http://www.msn.co.uk/msnmobile
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
>
__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org