views:

277

answers:

3

Hi All,

I'm about to embark on a new project within which we require the ability to re-use validations based on (preferably XML) on both the client and server.

We would setup a service to provide the XML validation configuration data to the client side.

The following is not meant to be inflammatory in any way.

The Enterprise library does have support for the validation of objects to be configured in XML but java developers would not have access to a java reader version of this XML interpretation.

There is also Spring.Net validation but again I think this may be tied too much to .net. Is the Spring.Net validation suite straight ported over from the java spring framework i.e. without changes to the xml config?

Is there any other frameworks for validation which are able to be used in both .Net and Java?

The project will be fully SOA and the validation is one of the last things I have to figure out.

EDIT:

To clarify the validation needs to occur within the language that the receiving client is using, i.e. if the client to the web service is Java then the validation would be read into java and validated within java so that error conditions could be reported to the UI for the user to rectify. Equally if it was a .net client the .net client would be able to read it in and provide the same functionality.

I don't want to validate within the xml, the xml will be a set of rules, i.e. Customer.Name will be a maximum 50 chars long and must be at least 5 chars, and is a required field.

Thanks Pete

A: 

Not sure what sort of validation your are trying to accomplish. If your business objects are going to be serialized in XML form, then aside from schema validation, you can augment that with additional business rules and checks using Schematron.

Schematron is an ISO standard and provides a way of encoding business rules, restrictions and validation that is not possible in XML Schema.

The Schematron differs in basic concept from other schema languages in that it not based on grammars but on finding tree patterns in the parsed document. This approach allows many kinds of structures to be represented which are inconvenient and difficult in grammar-based schema languages. If you know XPath or the XSLT expression language, you can start to use The Schematron immediately.

Mads Hansen
Thanks for the pointer towards schematron.I was actually hoping to do the validation in code. The reason for it is so that we can reduce the chattyness of the client with the web service layer by performing up front validation on the client.I want to validate in .net or in java so that the clients can access each objects properties and retrieve all of the errors for the object and display help messages to the user.
Peter
+3  A: 

How about trying the validation in a scripting language that can be run in both the jvm and by .net.

Scripting languages would be ideal for this kind of logic so maybe:

Ruby - http://www.ironruby.net/ and http://www.jruby.org/

or Perl.

This approach would allow use to the exact same code for validation and then call this from Java or .net.

Using jruby wouldn't be much of a performance overhead and it can integrate very closely with java. I've less experience with Ironruby but from what I've read once the code has been loaded and is running the performance is ok and it can be integrated well into the .net code - see: http://www.ironruby.net/Documentation/.NET/Hosting

Not to take away from my answer but regardless of how you do this it will involve introducing a new technology with all the associated overheads - dev environment etc. A better approach may be just to do it in .net and java seperately but maintain a very extensive test suite of examples to ensure that two validations remain in sync.

Pablojim
What is the performance like of these calls into these scripts? is there a large overhead on them? I know the amount of validation to be done will directly impact this but i mean the straight interop.The other thing is when using these script types can you still access all of the variables used within the script? Such as if we validate an object and then want to query the errors dictionary for errors for a specific property?thanks
Peter
updated my answer
Pablojim
+3  A: 

Have a look at DROOLS. There are .Net and Java versions of the rules engine. Java Link and .Net Link

I've not user the libraries, so cannot comment on how "seamlessly" the one set of rules could be used in both environments.

Aussie Craig