Following my post, I tried to think of ways to make XPath easier. In Java, this is the way to evaluate an XPath expression.
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:XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expression = xpath.compile("/Contacts/Contact/Name"); String result = expression.evaluate(document);
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:@Endpoint public class MyEndpoint { @SoapAction("http://mycompany.com/soapAction") public void handleContact( @XpathParam("/Contacts/Contact/Name") String name) { // do something with name } }
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: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 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 thoughtsCode:@SoapAction("http://mycompany.com/soapAction") public MarshalledType response(UnmarshalledType type) { ... }.


.
Reply With Quote