|
From: Keith D. <kd...@cs...> - 2004-03-10 20:18:02
|
I was browsing Ben and Cameron's new security stuff (looks great) and I =
like
how they did the attribute markup for the security roles required for
certain methods:
=20
/**
* @@SecurityConfig("ROLE_TELLER")
* @@SecurityConfig("ROLE_SUPERVISOR")
* @@SecurityConfig("BANKSECURITY_CUSTOMER")
* @@SecurityConfig("RUN_AS_SERVER")
*/
public float getBalance(int id);
Specifically, I like how they didn't use a qualified class name, which =
makes
the attribute more compact & easier to type out. Also I liked how they =
went
with a generic "SecurityConfig" attribute. I was thinking of applying
something similiar to the validator attributes markup. So instead of
instantating the rule classes directly, you just instantiate a
ValidationRule attribute metadata class, with a String identifier for =
the
rule, and then a string list for any rule-specific properties. =
Something
like this:
=20
/**
* @@ValidationRule("required")
* @@ValidationRule("range", "minimum=3D0.0, maximum=3D100,000.0")
*/
public float getBalance(int id);
The question I have regarding this is with commons-attributes:
=20
1. Does it let you instantiate arbitrary objects using their =
constructors
within an attribute declaration? For example, can I say something like:
* @@ValidationRule("range", new NumberRange(0.0, 100,000.0))?
Somehow I doubt it, but I was curious how extensive its support was for
instantating objects declared as attributes (I mean obviously it can =
handle
Strings, but does it do type conversion too?)
=20
What I am thinking abut doing is just having something like this:
* @@ValidationRule("range", "minimum=3D0.0, maximum=3D100,000.0")
.. where the first parameter is a String identifier for the rule, whose
backing PropertyValidationRule instance is looked up using a rule =
factory
configured by Spring, and the second parameter is a string-separated =
list of
bean property->value pairs where I'll likely just use BeanWrapper or =
OGNL
later on...
=20
Keith
|