Results 1 to 2 of 2

Thread: XPath parameter binding

  1. #1
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default XPath parameter binding

    Following my post, I tried to think of ways to make XPath easier. In Java, this is the way to evaluate an XPath expression.

    Code:
    XPathFactory factory = XPathFactory.newInstance();
    XPath xpath = factory.newXPath();
    XPathExpression expression =
    xpath.compile("/Contacts/Contact/Name");
    String result = expression.evaluate(document);
    Clearly, this is too much plumbing to do each an every time. So I tried to make it easier, by using annotations. The end result looks something like this:

    Code:
    @Endpoint
    public class MyEndpoint {
      
      @SoapAction("http://mycompany.com/soapAction")
      public void handleContact(
        @XpathParam("/Contacts/Contact/Name") String name) {
          // do something with name
      }
     
    }
    The idea is to tag any object with @Endpoint, tag methods with @SoapAction to indicate that handleContact should be called for incoming messages with the "http://mycompany.com/soapAction" SOAPAction header. The parameters are bound to the result of the XPath expression. Besides String, other supported parameters types are boolean, double, Node, and NodeList (the supported types by XPath):

    Code:
        public void supportedTypes(@XPathParam("/root/child")boolean param1,
                                   @XPathParam("/root/child/number")double param2,
                                   @XPathParam("/root/child")Node param3,
                                   @XPathParam("/root/*")NodeList param4,
                                   @XPathParam("/root/child/text")String param5) {
    This programming model is a Java 5 alternative for PayloadEndpoint and MethodEndpoint (and it's subclasses). Besides using @XPathParam, you can also use a Marshaller:

    Code:
        @SoapAction("http://mycompany.com/soapAction")
        public MarshalledType response(UnmarshalledType type) {
            ...
        }
    This has not been submitted to SVN yet, because it requires a little more work. However, I would love to hear from your opinions on this feature. I like it, but I'm open for other or better thoughts .
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

  2. #2
    Join Date
    Jul 2005
    Location
    Rotterdam, the Netherlands
    Posts
    1,562

    Default

    I would really appreciate some feedback on this . If think I will push it into 1.0, if enough people like it.
    Arjen Poutsma

    Spring Web Services Dev Lead
    Please read the FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •