Hi Vincent, Thanks for sharing this snippet. The idea of leverage the WADL metadata at runtime to more easily manipulate a request/resource is very interesting.
However, in this case, how do you deal with the fact that you could have several parameters with the same name but different type? Best regards, Jérôme Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -----Message d'origine----- De : Bora [mailto:[EMAIL PROTECTED] Envoyé : vendredi 29 août 2008 21:37 À : [email protected] Objet : Re: [RFC] WadlResource, get a param value according to the description Thanks Vincent This was actually helpful for me -------------------------------------------------- From: "Vincent Ricard" <[EMAIL PROTECTED]> Sent: Thursday, August 28, 2008 9:49 AM To: <[email protected]> Subject: [RFC] WadlResource, get a param value according to the description > Hi, > > Here is what i added to my WadlResource subclass (and the super class of > all my resources): [see below]. > > I think it would be nice (in a future version) to have a similar method > directly available in WadlResource. > > For now, this code just fulfills my needs: > - it does not handle multi-valued param (but can be easily added: split > into a getFirstParam and a getParam methods) > - it does not handle the "plain" type (which requires a more complex code > for the xpath stuff) > - it does not handle the conversion to the correct type (as declared by > the "type" attribute) (add a "Converter" object in the method signature?) > - it does not handle the "required" attribute (we could add a > WadlRequiredException in the extension or something like that) > - it does not handle the "header" type because i dont need ;-) and because > i dont know if there is an abstract layer to reach the HTTP headers > without creating a strong dependency with another extension (like > ServerServlet, or an other). > > Despite of all that, now i can just call: > getParam(getRequestInfo(), "service"); > > Any comments are welcome (and anyone can reuse this code :-). > > --- snip --- > > protected String getParam(RequestInfo requestInfo, String parameterName) { > List<ParameterInfo> parameters = requestInfo.getParameters(); > for (ParameterInfo parameter : parameters) { > if (parameterName.equals(parameter.getName())) { > return getParam(parameter); > } > } > return null; > } > > protected String getParam(ParameterInfo parameterInfo) { > if (parameterInfo.getFixed() != null) { > return parameterInfo.getFixed(); > } > > String value = null; > if (ParameterStyle.HEADER.equals(parameterInfo.getStyle())) { > // not yet implemented > } else if (ParameterStyle.TEMPLATE.equals(parameterInfo.getStyle())) { > Object parameter = > getRequest().getAttributes().get(parameterInfo.getName()); > value = (parameter == null) ? null : Reference.decode((String) parameter); > } else if (ParameterStyle.MATRIX.equals(parameterInfo.getStyle())) { > Parameter parameter = getMatrix().getFirst(parameterInfo.getName()); > value = (parameter == null) ? null : parameter.getValue(); > } else if (ParameterStyle.QUERY.equals(parameterInfo.getStyle())) { > Parameter parameter = getQuery().getFirst(parameterInfo.getName()); > value = (parameter == null) ? null : parameter.getValue(); > } else if (ParameterStyle.PLAIN.equals(parameterInfo.getStyle())) { > // not yet implemented > } > > if (value == null) { > value = parameterInfo.getDefaultValue(); > } > > return value; > } > > --- snip --- > -- > Vincent Ricard > >

