Skip to content

Commit 1330860

Browse files
Merge pull request #10 from relogiclabs/develop
Add Scripting Functionalities
2 parents 4f3d1bd + e40b325 commit 1330860

File tree

304 files changed

+16895
-6233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

304 files changed

+16895
-6233
lines changed

src/main/java/com/relogiclabs/json/schema/JsonAssert.java renamed to src/main/java/com/relogiclabs/jschema/JsonAssert.java

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
package com.relogiclabs.json.schema;
1+
package com.relogiclabs.jschema;
22

3-
import com.relogiclabs.json.schema.internal.util.DebugUtilities;
4-
import com.relogiclabs.json.schema.tree.DataTree;
5-
import com.relogiclabs.json.schema.tree.JsonTree;
6-
import com.relogiclabs.json.schema.tree.RuntimeContext;
7-
import com.relogiclabs.json.schema.tree.SchemaTree;
8-
import com.relogiclabs.json.schema.tree.TreeType;
3+
import com.relogiclabs.jschema.internal.util.LogHelper;
4+
import com.relogiclabs.jschema.tree.DataTree;
5+
import com.relogiclabs.jschema.tree.JsonTree;
6+
import com.relogiclabs.jschema.tree.RuntimeContext;
7+
import com.relogiclabs.jschema.tree.SchemaTree;
8+
import com.relogiclabs.jschema.tree.TreeType;
99
import lombok.Getter;
1010

11-
import static com.relogiclabs.json.schema.message.MessageFormatter.JSON_ASSERTION;
12-
import static com.relogiclabs.json.schema.message.MessageFormatter.SCHEMA_ASSERTION;
13-
import static com.relogiclabs.json.schema.tree.TreeType.JSON_TREE;
14-
import static com.relogiclabs.json.schema.tree.TreeType.SCHEMA_TREE;
11+
import static com.relogiclabs.jschema.message.MessageFormatter.JSON_ASSERTION;
12+
import static com.relogiclabs.jschema.message.MessageFormatter.SCHEMA_ASSERTION;
13+
import static com.relogiclabs.jschema.tree.TreeType.JSON_TREE;
14+
import static com.relogiclabs.jschema.tree.TreeType.SCHEMA_TREE;
1515

1616
/**
1717
* The class provides assertion functionalities to validate JSON documents against
18-
* a Schema or JSON.
18+
* a JSchema or JSON document.
1919
*/
2020
@Getter
2121
public class JsonAssert {
@@ -24,19 +24,19 @@ public class JsonAssert {
2424

2525
/**
2626
* Initializes a new instance of the {@link JsonAssert} class for the
27-
* specified Schema string.
28-
* @param schema A Schema string for validation or conformation
27+
* specified JSchema string.
28+
* @param schema A JSchema string for validation or conformation
2929
*/
3030
public JsonAssert(String schema) {
3131
this(schema, SCHEMA_TREE);
3232
}
3333

3434
/**
3535
* Initializes a new instance of the {@link JsonAssert} class for the specified
36-
* {@code expected} string, which can be either a Schema or a JSON representation.
37-
* @param expected An expected Schema or JSON string for validation or conformation
36+
* {@code expected} string, which can be either a JSchema or a JSON representation.
37+
* @param expected An expected JSchema or JSON string for validation or conformation
3838
* @param type The type of string provided by {@code expected}, indicating whether it represents
39-
* a Schema or JSON. Use {@link TreeType#SCHEMA_TREE} for Schema and {@link TreeType#JSON_TREE}
39+
* a JSchema or JSON. Use {@link TreeType#SCHEMA_TREE} for JSchema and {@link TreeType#JSON_TREE}
4040
* for JSON.
4141
*/
4242
public JsonAssert(String expected, TreeType type) {
@@ -50,22 +50,22 @@ public JsonAssert(String expected, TreeType type) {
5050
}
5151

5252
/**
53-
* Tests whether the input JSON string conforms to the expected Schema or JSON
53+
* Tests whether the input JSON string conforms to the expected JSchema or JSON
5454
* specified in the {@link JsonAssert} constructor.
5555
* @param json The actual input JSON to conform or validate
5656
*/
5757
public void isValid(String json) {
5858
runtime.clear();
5959
var jsonTree = new JsonTree(runtime, json);
60-
DebugUtilities.print(expectedTree, jsonTree);
60+
LogHelper.debug(expectedTree, jsonTree);
6161
if(!expectedTree.match(jsonTree))
6262
throw new IllegalStateException("Invalid runtime state");
6363
}
6464

6565
/**
66-
* Tests whether the specified JSON string conforms to the given Schema string
67-
* and throws an exception if the JSON string does not conform to the Schema.
68-
* @param schema The expected Schema to conform or validate
66+
* Tests whether the specified JSON string conforms to the given JSchema string
67+
* and throws an exception if the JSON string does not conform to the JSchema.
68+
* @param schema The expected JSchema to conform or validate
6969
* @param json The actual JSON to conform or validate
7070
*/
7171
public static void isValid(String schema, String json) {

src/main/java/com/relogiclabs/json/schema/JsonSchema.java renamed to src/main/java/com/relogiclabs/jschema/JsonSchema.java

+23-20
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
package com.relogiclabs.json.schema;
1+
package com.relogiclabs.jschema;
22

3-
import com.relogiclabs.json.schema.internal.util.DebugUtilities;
4-
import com.relogiclabs.json.schema.tree.ExceptionRegistry;
5-
import com.relogiclabs.json.schema.tree.JsonTree;
6-
import com.relogiclabs.json.schema.tree.RuntimeContext;
7-
import com.relogiclabs.json.schema.tree.SchemaTree;
3+
import com.relogiclabs.jschema.internal.util.LogHelper;
4+
import com.relogiclabs.jschema.tree.ExceptionRegistry;
5+
import com.relogiclabs.jschema.tree.JsonTree;
6+
import com.relogiclabs.jschema.tree.RuntimeContext;
7+
import com.relogiclabs.jschema.tree.SchemaTree;
88
import lombok.Getter;
99

10-
import static com.relogiclabs.json.schema.message.MessageFormatter.SCHEMA_VALIDATION;
10+
import static com.relogiclabs.jschema.message.MessageFormatter.SCHEMA_VALIDATION;
1111

1212
/**
13-
* {@code JsonSchema} provides Schema validation functionalities for JSON document.
13+
* {@code JsonSchema} provides JSchema validation functionalities for JSON document.
1414
*/
1515
@Getter
1616
public class JsonSchema {
@@ -20,8 +20,8 @@ public class JsonSchema {
2020

2121
/**
2222
* Initializes a new instance of the {@link JsonSchema} class for the
23-
* specified Schema string.
24-
* @param schema A Schema string for validation
23+
* specified JSchema string.
24+
* @param schema A JSchema string for validation
2525
*/
2626
public JsonSchema(String schema) {
2727
runtime = new RuntimeContext(SCHEMA_VALIDATION, false);
@@ -30,32 +30,35 @@ public JsonSchema(String schema) {
3030
}
3131

3232
/**
33-
* Indicates whether the input JSON string conforms to the Schema specified
33+
* Indicates whether the input JSON string conforms to the JSchema specified
3434
* in the {@link JsonSchema} constructor.
35-
* @param json The JSON to validate with Schema
36-
* @return Returns {@code true} if the JSON string conforms to the Schema and {@code false} otherwise.
35+
* @param json The JSON to validate with JSchema
36+
* @return Returns {@code true} if the JSON string conforms to the JSchema and {@code false} otherwise.
3737
*/
3838
public boolean isValid(String json) {
3939
runtime.clear();
4040
var jsonTree = new JsonTree(runtime, json);
41-
DebugUtilities.print(schemaTree, jsonTree);
41+
LogHelper.debug(schemaTree, jsonTree);
4242
return schemaTree.match(jsonTree);
4343
}
4444

4545
/**
46-
* Writes error messages that occur during Schema validation process, to the
46+
* Writes error messages that occur during JSchema validation process, to the
4747
* standard error output stream.
4848
*/
4949
public void writeError() {
50-
for(var exception : exceptions)
51-
System.err.println(exception.getMessage());
50+
if(exceptions.getCount() == 0) {
51+
System.out.println("No error has occurred");
52+
return;
53+
}
54+
for(var exception : exceptions) System.err.println(exception.getMessage());
5255
}
5356

5457
/**
55-
* Indicates whether the input JSON string conforms to the given Schema string.
56-
* @param schema The Schema string to conform or validate
58+
* Indicates whether the input JSON string conforms to the given JSchema string.
59+
* @param schema The JSchema string to conform or validate
5760
* @param json The JSON string to conform or validate
58-
* @return Returns {@code true} if the JSON string conforms to the Schema and {@code false} otherwise.
61+
* @return Returns {@code true} if the JSON string conforms to the JSchema and {@code false} otherwise.
5962
*/
6063
public static boolean isValid(String schema, String json) {
6164
var jsonSchema = new JsonSchema(schema);

src/main/java/com/relogiclabs/json/schema/collection/IndexMap.java renamed to src/main/java/com/relogiclabs/jschema/collection/IndexMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.relogiclabs.json.schema.collection;
1+
package com.relogiclabs.jschema.collection;
22

33
import java.util.Collection;
44
import java.util.Set;

src/main/java/com/relogiclabs/json/schema/collection/Keyable.java renamed to src/main/java/com/relogiclabs/jschema/collection/Keyable.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.relogiclabs.json.schema.collection;
1+
package com.relogiclabs.jschema.collection;
22

33
public interface Keyable<TK> {
44
TK getKey();
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class ClassInstantiationException extends CommonException {
66
public ClassInstantiationException(ErrorDetail detail, Throwable cause) {
77
super(detail, cause);
88
}
9-
}
9+
}

src/main/java/com/relogiclabs/json/schema/exception/CommonException.java renamed to src/main/java/com/relogiclabs/jschema/exception/CommonException.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44
import lombok.Getter;
55

66
import java.util.HashMap;
77
import java.util.Map;
88

9+
import static java.util.Arrays.copyOfRange;
10+
911
public class CommonException extends RuntimeException {
12+
private static final String FAIL_METHOD_PREFIX = "fail";
1013
@Getter private final String code;
1114
private Map<String, String> attributes;
1215

1316
public CommonException(String code, String message, Throwable cause) {
1417
super(message, cause);
1518
this.code = code;
19+
formatStackTrace();
1620
}
1721

1822
public CommonException(String code, String message) {
@@ -36,4 +40,20 @@ public void setAttribute(String name, String value) {
3640
if(attributes == null) attributes = new HashMap<>(5);
3741
attributes.put(name, value);
3842
}
43+
44+
@Override
45+
public synchronized Throwable fillInStackTrace() {
46+
var result = super.fillInStackTrace();
47+
formatStackTrace();
48+
return result;
49+
}
50+
51+
private void formatStackTrace() {
52+
StackTraceElement[] stackTrace = getStackTrace();
53+
int offset = 0;
54+
for(var e : stackTrace)
55+
if(e.getMethodName().startsWith(FAIL_METHOD_PREFIX)) offset++;
56+
else break;
57+
setStackTrace(copyOfRange(stackTrace, offset, stackTrace.length));
58+
}
3959
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

33
public class DateTimeLexerException extends CommonException {
44
public DateTimeLexerException(String code, String message, Throwable cause) {
55
super(code, message, cause);
66
}
7-
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class DefinitionNotFoundException extends CommonException {
66
public DefinitionNotFoundException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class DuplicateDefinitionException extends CommonException {
66
public DuplicateDefinitionException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
5+
public class DuplicateImportException extends CommonException {
6+
public DuplicateImportException(ErrorDetail detail) {
7+
super(detail);
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class DuplicatePragmaException extends CommonException {
66
public DuplicatePragmaException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class DuplicatePropertyKeyException extends CommonException {
66
public DuplicatePropertyKeyException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class FunctionNotFoundException extends CommonException {
66
public FunctionNotFoundException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class InvalidDataTypeException extends CommonException {
66
public InvalidDataTypeException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

33
public class InvalidDateTimeException extends CommonException {
44
public InvalidDateTimeException(String code, String message) {
55
super(code, message);
66
}
7-
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class InvalidFunctionException extends CommonException {
66
public InvalidFunctionException(String code, String message) {
@@ -10,4 +10,4 @@ public InvalidFunctionException(String code, String message) {
1010
public InvalidFunctionException(ErrorDetail detail) {
1111
super(detail);
1212
}
13-
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
5+
public class InvalidImportException extends CommonException {
6+
public InvalidImportException(ErrorDetail detail) {
7+
super(detail);
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package com.relogiclabs.json.schema.exception;
1+
package com.relogiclabs.jschema.exception;
22

3-
import com.relogiclabs.json.schema.message.ErrorDetail;
3+
import com.relogiclabs.jschema.message.ErrorDetail;
44

55
public class InvalidPragmaValueException extends CommonException {
66
public InvalidPragmaValueException(ErrorDetail detail) {
77
super(detail);
88
}
9-
}
9+
}

0 commit comments

Comments
 (0)