This is another concrete example of how you carry forward location
information.
The following code is taken from the JAX-WS RI. This code parses
sun-jaxws.xml. At some point we read a class name from the descriptor,
but when we can't load that class, we report an error:
> protected Class getImplementorClass(String name) {
> try {
> return Class.forName(name, true, classLoader);
> } catch (ClassNotFoundException e) {
> logger.log(Level.SEVERE, e.getMessage(), e);
> throw new ServerRtException(
> "runtime.parser.classNotFound", name);
> }
> }
The problem here is that when you report an error, the user doesn't know
where in the sun-jaxws.xml file the error exists. By using the newly
added classes, you can now do this:
> private Class getImplementorClass(String name, XMLStreamReader xsr) {
> try {
> return Class.forName(name, true, classLoader);
> } catch (ClassNotFoundException e) {
> logger.log(Level.SEVERE, e.getMessage(), e);
> throw new LocatableWebServiceException(
> ServerMessages.RUNTIME_PARSER_CLASS_NOT_FOUND(name), e, xsr );
> }
> }
The XMLStreamReader is automatically turned into the proper location
information. With this, you now get an error message like:
> Caused by: com.sun.xml.ws.util.exception.LocatableWebServiceException: class not found in runtime descriptor: fromjava.server.AddNumbersImpl
> at line 4 of file:///c:/kohsuke/Sun/jax-ws/test-harness/test/testcases/jaxws/fromjava/work/services/server/war/WEB-INF/sun-jaxws.xml
Much better.
--
Kohsuke Kawaguchi
Sun Microsystems kohsuke.kawaguchi_at_sun.com