Skip to content

Commit e573ff0

Browse files
Continued to refactor the Metapath runtime exception hierarchy. Created a RuntimeMetapathError exception class that all runtime exceptions are now children of. Moved function-related exceptions to their own branch in the Metapath runtime error tree.
1 parent e5f93b7 commit e573ff0

40 files changed

+291
-209
lines changed

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/DynamicMetapathError.java

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,18 @@
66
package gov.nist.secauto.metaschema.core.metapath;
77

88
import edu.umd.cs.findbugs.annotations.NonNull;
9-
import edu.umd.cs.findbugs.annotations.Nullable;
109

1110
/**
1211
* This Metapath exception base class is used for all exceptions that have a
1312
* defined error code family and value.
1413
*/
1514
public class DynamicMetapathError
16-
extends MetapathException {
15+
extends RuntimeMetapathError {
1716

1817
/**
1918
* the serial version UID.
2019
*/
2120
private static final long serialVersionUID = 1L;
22-
/**
23-
* The error prefix which identifies what kind of error it is.
24-
*/
25-
@NonNull
26-
private final IErrorCode errorCode;
2721

2822
/**
2923
* Constructs a new Metapath exception with the provided {@code code},
@@ -35,8 +29,7 @@ public class DynamicMetapathError
3529
* the exception message
3630
*/
3731
public DynamicMetapathError(@NonNull IErrorCode errorCode, String message) {
38-
super(message);
39-
this.errorCode = errorCode;
32+
super(errorCode, message);
4033
}
4134

4235
/**
@@ -51,8 +44,7 @@ public DynamicMetapathError(@NonNull IErrorCode errorCode, String message) {
5144
* the original exception cause
5245
*/
5346
protected DynamicMetapathError(@NonNull IErrorCode errorCode, String message, Throwable cause) {
54-
super(message, cause);
55-
this.errorCode = errorCode;
47+
super(errorCode, message, cause);
5648
}
5749

5850
/**
@@ -65,32 +57,6 @@ protected DynamicMetapathError(@NonNull IErrorCode errorCode, String message, Th
6557
* the original exception cause
6658
*/
6759
public DynamicMetapathError(@NonNull IErrorCode errorCode, Throwable cause) {
68-
super(cause);
69-
this.errorCode = errorCode;
70-
}
71-
72-
@Override
73-
public final String getMessage() {
74-
String message = getMessageText();
75-
return String.format("%s%s", getErrorCode().toString(), message == null ? "" : ": " + message);
76-
}
77-
78-
/**
79-
* Get the message text without the error code prefix.
80-
*
81-
* @return the message text or {@code null}
82-
*/
83-
@Nullable
84-
public final String getMessageText() {
85-
return super.getMessage();
86-
}
87-
88-
/**
89-
* Get the error code, which indicates what type of error it is.
90-
*
91-
* @return the error code
92-
*/
93-
public final IErrorCode getErrorCode() {
94-
return errorCode;
60+
super(errorCode, cause);
9561
}
9662
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/IMetapathExpression.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
1515
import gov.nist.secauto.metaschema.core.metapath.item.atomic.INumericItem;
1616
import gov.nist.secauto.metaschema.core.metapath.type.InvalidTypeMetapathException;
17-
import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathException;
17+
import gov.nist.secauto.metaschema.core.metapath.type.TypeMetapathError;
1818
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
1919

2020
import java.math.BigDecimal;
@@ -82,7 +82,7 @@ public Class<?> expectedClass() {
8282
* @param sequence
8383
* the Metapath result sequence to convert
8484
* @return the converted sequence as the expected type
85-
* @throws TypeMetapathException
85+
* @throws TypeMetapathError
8686
* if the provided sequence is incompatible with the expected result
8787
* type
8888
*/
@@ -113,7 +113,7 @@ interface ConversionFunction {
113113
*/
114114
@NonNull
115115
static IMetapathExpression contextNode() {
116-
return MetapathExpression.CONTEXT_NODE;
116+
return MetapathExpression.CONTEXT_METAPATH;
117117
}
118118

119119
/**
@@ -127,7 +127,7 @@ static IMetapathExpression contextNode() {
127127
*/
128128
@NonNull
129129
static IMetapathExpression compile(@NonNull String path) {
130-
return MetapathExpression.compile(path, StaticContext.instance());
130+
return compile(path, StaticContext.instance());
131131
}
132132

133133
/**
@@ -188,7 +188,7 @@ static IMetapathExpression lazyCompile(@NonNull String path, @NonNull StaticCont
188188
* @param resultType
189189
* the type of result to produce
190190
* @return the converted result
191-
* @throws TypeMetapathException
191+
* @throws TypeMetapathError
192192
* if the provided sequence is incompatible with the requested result
193193
* type
194194
* @throws MetapathException
@@ -212,7 +212,7 @@ default <T> T evaluateAs(@NonNull ResultType resultType) {
212212
* @param resultType
213213
* the type of result to produce
214214
* @return the converted result
215-
* @throws TypeMetapathException
215+
* @throws TypeMetapathError
216216
* if the provided sequence is incompatible with the requested result
217217
* type
218218
* @throws MetapathException
@@ -243,7 +243,7 @@ default <T> T evaluateAs(
243243
* @param dynamicContext
244244
* the dynamic context to use for evaluation
245245
* @return the converted result
246-
* @throws TypeMetapathException
246+
* @throws TypeMetapathError
247247
* if the provided sequence is incompatible with the requested result
248248
* type
249249
* @throws MetapathException
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* SPDX-FileCopyrightText: none
3+
* SPDX-License-Identifier: CC0-1.0
4+
*/
5+
6+
package gov.nist.secauto.metaschema.core.metapath;
7+
8+
import edu.umd.cs.findbugs.annotations.NonNull;
9+
import edu.umd.cs.findbugs.annotations.Nullable;
10+
11+
public class RuntimeMetapathError
12+
extends MetapathException {
13+
14+
/**
15+
* the serial version UID.
16+
*/
17+
private static final long serialVersionUID = 1L;
18+
/**
19+
* The error prefix which identifies what kind of error it is.
20+
*/
21+
@NonNull
22+
private final IErrorCode errorCode;
23+
24+
/**
25+
* Constructs a new Metapath exception with the provided {@code code},
26+
* {@code message}, and no cause.
27+
*
28+
* @param errorCode
29+
* the error code that identifies the type of error
30+
* @param message
31+
* the exception message
32+
*/
33+
// TODO: Make protected?
34+
public RuntimeMetapathError(@NonNull IErrorCode errorCode, String message) {
35+
super(message);
36+
this.errorCode = errorCode;
37+
}
38+
39+
/**
40+
* Constructs a new Metapath exception with the provided {@code code},
41+
* {@code message}, and {@code cause}.
42+
*
43+
* @param errorCode
44+
* the error code that identifies the type of error
45+
* @param message
46+
* the exception message
47+
* @param cause
48+
* the original exception cause
49+
*/
50+
public RuntimeMetapathError(@NonNull IErrorCode errorCode, String message, Throwable cause) {
51+
super(message, cause);
52+
this.errorCode = errorCode;
53+
}
54+
55+
/**
56+
* Constructs a new Metapath exception with a {@code null} message and the
57+
* provided {@code cause}.
58+
*
59+
* @param errorCode
60+
* the error code that identifies the type of error
61+
* @param cause
62+
* the original exception cause
63+
*/
64+
public RuntimeMetapathError(@NonNull IErrorCode errorCode, Throwable cause) {
65+
super(cause);
66+
this.errorCode = errorCode;
67+
}
68+
69+
@Override
70+
public final String getMessage() {
71+
String message = getMessageText();
72+
return String.format("%s%s", getErrorCode().toString(), message == null ? "" : ": " + message);
73+
}
74+
75+
/**
76+
* Get the message text without the error code prefix.
77+
*
78+
* @return the message text or {@code null}
79+
*/
80+
@Nullable
81+
public final String getMessageText() {
82+
return super.getMessage();
83+
}
84+
85+
/**
86+
* Get the error code, which indicates what type of error it is.
87+
*
88+
* @return the error code
89+
*/
90+
public final IErrorCode getErrorCode() {
91+
return errorCode;
92+
}
93+
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/StaticContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public IFunction lookupFunction(@NonNull String name, int arity) {
463463
* @param qname
464464
* the qualified name of the function
465465
* @param arity
466-
* the number of arguments <<<<<<< HEAD
466+
* the number of arguments
467467
* @return the function
468468
* @throws StaticMetapathError
469469
* with the code {@link StaticMetapathError#NO_FUNCTION_MATCH} if a

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/StaticMetapathError.java

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
package gov.nist.secauto.metaschema.core.metapath;
77

88
import edu.umd.cs.findbugs.annotations.NonNull;
9-
import edu.umd.cs.findbugs.annotations.Nullable;
109

1110
/**
1211
* MPST: Exceptions related to the Metapath static context and static
1312
* evaluation.
1413
*/
1514
@SuppressWarnings("PMD.DataClass")
1615
public class StaticMetapathError
17-
extends MetapathException {
16+
extends RuntimeMetapathError {
1817
@NonNull
1918
private static final String PREFIX = "MPST";
2019
/**
@@ -125,11 +124,6 @@ public class StaticMetapathError
125124
* the serial version UID.
126125
*/
127126
private static final long serialVersionUID = 2L;
128-
/**
129-
* The error prefix which identifies what kind of error it is.
130-
*/
131-
@NonNull
132-
private final IErrorCode errorCode;
133127

134128
/**
135129
* Constructs a new exception with the provided {@code code}, {@code message},
@@ -143,23 +137,7 @@ public class StaticMetapathError
143137
* the original exception cause
144138
*/
145139
public StaticMetapathError(int code, String message, Throwable cause) {
146-
this(IErrorCode.of(PREFIX, code), message, cause);
147-
}
148-
149-
/**
150-
* Constructs a new exception with the provided {@code code}, {@code message},
151-
* and {@code cause}.
152-
*
153-
* @param errorCode
154-
* the error code
155-
* @param message
156-
* the exception message
157-
* @param cause
158-
* the original exception cause
159-
*/
160-
public StaticMetapathError(@NonNull IErrorCode errorCode, String message, Throwable cause) {
161-
super(message, cause);
162-
this.errorCode = errorCode;
140+
super(IErrorCode.of(PREFIX, code), message, cause);
163141
}
164142

165143
/**
@@ -172,8 +150,7 @@ public StaticMetapathError(@NonNull IErrorCode errorCode, String message, Throwa
172150
* the exception message
173151
*/
174152
public StaticMetapathError(int code, String message) {
175-
super(message);
176-
this.errorCode = IErrorCode.of(PREFIX, code);
153+
super(IErrorCode.of(PREFIX, code), message);
177154
}
178155

179156
/**
@@ -186,32 +163,6 @@ public StaticMetapathError(int code, String message) {
186163
* the original exception cause
187164
*/
188165
public StaticMetapathError(int code, Throwable cause) {
189-
super(cause);
190-
this.errorCode = IErrorCode.of(PREFIX, code);
191-
}
192-
193-
@Override
194-
public final String getMessage() {
195-
String message = getMessageText();
196-
return String.format("%s%s", getErrorCode().toString(), message == null ? "" : ": " + message);
197-
}
198-
199-
/**
200-
* Get the message text without the error code prefix.
201-
*
202-
* @return the message text or {@code null}
203-
*/
204-
@Nullable
205-
public final String getMessageText() {
206-
return super.getMessage();
207-
}
208-
209-
/**
210-
* Get the error code, which indicates what type of error it is.
211-
*
212-
* @return the error code
213-
*/
214-
public final IErrorCode getErrorCode() {
215-
return errorCode;
166+
super(IErrorCode.of(PREFIX, code), cause);
216167
}
217168
}

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/ArithmeticFunctionException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package gov.nist.secauto.metaschema.core.metapath.function;
77

8-
import gov.nist.secauto.metaschema.core.metapath.DynamicMetapathError;
98
import gov.nist.secauto.metaschema.core.metapath.IErrorCode;
109

1110
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -14,7 +13,7 @@
1413
* Represents an error that occurred while performing mathematical operations.
1514
*/
1615
public class ArithmeticFunctionException
17-
extends DynamicMetapathError {
16+
extends FunctionMetapathError {
1817
@NonNull
1918
private static final String PREFIX = "FOAR";
2019
/**

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/CastFunctionException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package gov.nist.secauto.metaschema.core.metapath.function;
77

8-
import gov.nist.secauto.metaschema.core.metapath.DynamicMetapathError;
98
import gov.nist.secauto.metaschema.core.metapath.IErrorCode;
109
import gov.nist.secauto.metaschema.core.metapath.item.atomic.IAnyAtomicItem;
1110

@@ -15,7 +14,7 @@
1514
* FOCA: Exceptions related to type casting.
1615
*/
1716
public class CastFunctionException
18-
extends DynamicMetapathError {
17+
extends FunctionMetapathError {
1918
@NonNull
2019
private static final String PREFIX = "FOCA";
2120
/**

core/src/main/java/gov/nist/secauto/metaschema/core/metapath/function/DateTimeFunctionException.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
package gov.nist.secauto.metaschema.core.metapath.function;
77

8-
import gov.nist.secauto.metaschema.core.metapath.DynamicMetapathError;
98
import gov.nist.secauto.metaschema.core.metapath.IErrorCode;
109

1110
import edu.umd.cs.findbugs.annotations.NonNull;
@@ -14,7 +13,7 @@
1413
* FODT: Exceptions related to Date/Time/Duration errors.
1514
*/
1615
public class DateTimeFunctionException
17-
extends DynamicMetapathError {
16+
extends FunctionMetapathError {
1817
@NonNull
1918
private static final String PREFIX = "FODT";
2019
/**

0 commit comments

Comments
 (0)