-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Deep property path validation?
PostPosted: Tue Jun 09, 2009 1:07 pm 
Newbie

Joined: Tue Nov 21, 2006 6:46 pm
Posts: 6
Let’s say I have classes A and B.
A and B have properties/fields ‘a’ and ‘b’ respectively of the same class C which in turn has some property/field ‘c’.
Now the class A is valid only if a.c < N and B is valid only if b.c < M

As you can see we cannot put validation directly to the class C.
Also there could be arbitrary large number of classes that use class C and each could have its own restrictions on value c.

I do not see how this could be done gracefully unless some kind of expression (ideally the unified expression language, JSR-245) is introduced. Something like this:

class A {
@NotNull
@Max(value=N, expression=”c”)
C a;
}

class B {
@NotNull
@Max(value=M, expression=”c”)
C b;
}

class C {
private int c;
public int getC() { return c; }
}

Obviously expression could be arbitrary deep, could only be applied to Object targets, and a target object would become a root context for expression evaluation
So something like this becomes possible:

class X {
@NotNull
@Max(value=100, expression="z.map['some-key']")
Y y;
}

class Y {
@NotNull
private Z z;
public Z getZ() { return z; }
}

class Z {
@NotNull
private Map<String,Integer> map;
public Map<String,Integer> getMap() { return map; }
}


Any thoughts?


Top
 Profile  
 
 Post subject: Re: Deep property path validation?
PostPosted: Tue Jun 09, 2009 8:41 pm 
Newbie

Joined: Tue Jun 09, 2009 8:35 pm
Posts: 1
Very interested on this topic, I hope some can show more info about this.

_________________
my software


Top
 Profile  
 
 Post subject: Re: Deep property path validation?
PostPosted: Mon Jun 22, 2009 3:18 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I am not a big fan of the EL approach as it encourages un-typesafe code (at least in Java).
The way you handle that in today's spec is to write a custom annotation that can go and navigate the graph to validate what's needed. In essence you could write your custom annotation that supports the contract you describe, I will not promote it in the spec though.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.