4848import org .exist .Namespaces ;
4949import org .exist .dom .QName ;
5050
51+ import javax .annotation .Nullable ;
52+
5153/**
5254 *
5355 * @author aretter
@@ -291,14 +293,14 @@ public class ErrorCodes {
291293 public static class ErrorCode {
292294
293295 private final QName errorQName ;
294- private final String description ;
296+ private @ Nullable final String description ;
295297
296- public ErrorCode (String code , String description ) {
298+ public ErrorCode (final String code , @ Nullable final String description ) {
297299 this .errorQName = new QName (code , Namespaces .EXIST_XQUERY_XPATH_ERROR_NS , Namespaces .EXIST_XQUERY_XPATH_ERROR_PREFIX );
298300 this .description = description ;
299301 }
300302
301- public ErrorCode (QName errorQName , String description ) {
303+ public ErrorCode (final QName errorQName , final String description ) {
302304 this .errorQName = errorQName ;
303305 this .description = description ;
304306 }
@@ -309,10 +311,10 @@ public QName getErrorQName() {
309311
310312 @ Override
311313 public String toString () {
312- return "(" + errorQName .getNamespaceURI () + "#" + errorQName . getLocalPart () + "): " + description ;
314+ return "(" + errorQName .toString () + "): " + description ;
313315 }
314316
315- public String getDescription (){
317+ public @ Nullable String getDescription (){
316318 return description ;
317319 }
318320 }
@@ -333,12 +335,21 @@ private EXistErrorCode(String code, String description) {
333335
334336 public static class JavaErrorCode extends ErrorCode {
335337
336- public JavaErrorCode (final Throwable throwable ) {
337- super (new QName (
338- throwable .getClass ().getName (),
339- Namespaces .EXIST_JAVA_BINDING_NS ,
340- Namespaces .EXIST_JAVA_BINDING_NS_PREFIX ),
341- throwable .getMessage () != null ? throwable .getMessage () : throwable .getCause ().getMessage ());
338+ private JavaErrorCode (final QName errorQName , @ Nullable final String description ) {
339+ super (errorQName , description );
340+ }
341+
342+ public static JavaErrorCode fromThrowable (final Throwable throwable ) {
343+ final QName errorQName = new QName (throwable .getClass ().getName (), Namespaces .EXIST_JAVA_BINDING_NS , Namespaces .EXIST_JAVA_BINDING_NS_PREFIX );
344+ @ Nullable final String description ;
345+ if (throwable .getMessage () != null ) {
346+ description = throwable .getMessage ();
347+ } else if (throwable .getCause () != null ) {
348+ description = throwable .getCause ().getMessage ();
349+ } else {
350+ description = null ;
351+ }
352+ return new JavaErrorCode (errorQName , description );
342353 }
343354 }
344355}
0 commit comments