emmanuel wrote:
it would have to be isValid(object, metadata ...)
Otherwise you can have some multi threading issues I think, though I am not sure.
Multi threading is not an problem because meta data is injected once. And metadata is static info. As in the case of initialize method.
Quote:
You mean depending on the fact that it's a getter or a field? why does that matter? Java should have had a property feature anyway.
Java already has a property feature based in convention. Even it has meta property classes, for example:
http://java.sun.com/j2se/1.5.0/docs/api ... iptor.htmlBut, if field versus getter is a big problem, injecting the Member is enough for me:
http://java.sun.com/j2se/1.5.0/docs/api ... ember.htmlQuote:
Quote:
- Read other annotations of the same property. The the validation logic can depend on annotation combination.
Hum, I kind of don't like that I think :) Can you give a concrete example?
Of course:
Code:
@ManyToOne @Required
private EMail email;
@Required
private Email email;
In this case the @Required constraints does not behaves equals for a reference (@ManyToOne) and for a regular property.
Code:
@Hidden @Required
String code;
@Required
String code;
In this case the @Required constraint has a special behaviour for @Hidden members.
When you write concrete constraints (as build in constraint of Hibernate Validator) this is not an issue, even it could be bad. But when you write constraint with an higher level of abstraction (as @Required for example) this feature is needed.
Quote:
Quote:
- Using metadata from other part of the application that needs to be access from name of class/property.
I don't understand.
For example, we can have a properties as this:
Code:
@CreditLimit
private BigDecimal currentAmount;
@CreditLimit
private BigDecimal maxAmount;
And, in CreditLimit.properties we can have:
Code:
Customer.currentAmount=10000
Customer.maxAmount=30000
Partner.currentAmount=11000
Partner.maxAmount=35000
In addition of a properties file we also can use a xml file or even a database table.
That is we can configure the behaviour of the validation without recompile, and without redeploy. Application that can customize its logic in hot are VERY common, specially if you have your application deployed in several customers.
Quote:
Quote:
- Doing validation based on the name of the property, or container class.
Can you give an example where it is useful?
Yes.
For example:
Code:
@Required
String name;
The fact that this property is called 'name' means that is required at least 5 charecters in order to fulfil @Required constraint. We can regulate the semantic of the constraint based in the name of the member.
Really I don't like use this technique, but name convention are usual, remember the Java property feature itslef uses it.
I don't use my imagination for my proposals, instead I propose here things that already I am using for years.
Cheers