Hi Ben,

The Validator can contain any number of validations or just one for a single 
attribute. 

To declare separate validators for each router route, you could attach the 
validators to the router and then the target resource class to each 
corresponding validator:

router.attach("pathA", validatorA);
router.attach("pathB", validatorB);
router.attach("pathC", validatorC);

validatorA.setNext(MyServerResourceA.class);
validatorB.setNext(MyServerResourceA.class);
validatorC.setNext(MyServerResourceA.class);

For your second example, you can't reuse the same Validator instance as the 
target resource is different for each one. However, you could create a 
Validator subclass facilitating the configuration and reuse of your attributes' 
format.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com




-----Message d'origine-----
De : Ben R Vesco [mailto:[email protected]] 
Envoyé : mardi 24 novembre 2009 06:40
À : [email protected]
Objet : Re: Examples of org.restlet.routing.Validator?

Ah, very good, that protected method was confusing me since it made it
look like I was supposed to extend.

As a Filter, is it intended to hold a mapping of all validations for
all routes or does it wrap each individual validated route? I'm not
sure how to go from the basic

router.attach("pathA", MyServerResourceA.class);
router.attach("pathB", MyServerResourceB.class);
router.attach("pathC", MyServerResourceC.class);

to something that wraps MyServerResource in a Validator which is
different for each resource. Perhaps some quick pseudo code?

Additionally, what about a structure like:

router.attach("pathA/{ida}", MyServerResourceA.class);
router.attach("pathA/{ida}/pathB/{idb}", MyServerResourceB.class);
router.attach("pathA/{ida}/pathB/{idb}/pathC/{idc}", MyServerResourceC.class);

Is there a way to reuse the validator of {ida} in the two following routes?



On Mon, Nov 23, 2009 at 9:23 AM, Jerome Louvel
<[email protected]> wrote:
> Hi Ben,
>
> Not yet, but it is very straightforward. Actually this feature existed in
> Restlet 1.1 but was hidden in the Route class. Looking at the API again, I
> noticed an issue: the validate() method should be public instead of
> protected. This is fixed in SVN trunk.
>
> You just need to call this method for each request attribute that you want
> to check for presence and/or for format. You can provide its format as a
> Java Regex.
>
> Best regards,
> Jerome Louvel
> --
> Restlet ~ Founder and Lead developer ~ http://www.restlet.org
> Noelios Technologies ~ Co-founder ~ http://www.noelios.com
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2423668

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2424188

Reply via email to