Skip to content

Commit

Permalink
some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
redmitry committed Aug 23, 2024
1 parent d5cd2e1 commit 3824c99
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 62 deletions.
24 changes: 23 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2024 Spanish National Bioinformatics Institute (INB) and
Barcelona Supercomputing Center
Modifications to the initial code base are copyright of their respective
authors, or their employers as appropriate.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301 USA
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
Expand All @@ -8,7 +30,7 @@

<groupId>es.elixir.bsc.json.schema</groupId>
<artifactId>jaronuinga</artifactId>
<version>0.5.4</version>
<version>0.5.5-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle
vtype = type_value.getValueType();
switch(vtype) {
case STRING:
try {
type = JsonType.fromValue(((JsonString)type_value).getString());
} catch(IllegalArgumentException ex) {
throw new JsonSchemaException(new ParsingError(
ParsingMessage.UNKNOWN_OBJECT_TYPE, ((JsonString)type_value).getString()));
}
try {
type = JsonType.fromValue(((JsonString)type_value).getString());
} catch(IllegalArgumentException ex) {
throw new JsonSchemaException(new ParsingError(
ParsingMessage.UNKNOWN_OBJECT_TYPE, ((JsonString)type_value).getString()));
}
case ARRAY: break;
default:
throw new JsonSchemaException(new ParsingError(
Expand Down Expand Up @@ -151,17 +151,17 @@ public AbstractJsonSchema parse(JsonSchemaLocator locator, AbstractJsonSchemaEle

final AbstractJsonSchema schema;
switch(type) {
case OBJECT: schema = new JsonObjectSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case ARRAY: schema = new JsonArraySchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case STRING: schema = new JsonStringSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case NUMBER: schema = new JsonNumberSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case INTEGER: schema = new JsonIntegerSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case BOOLEAN: schema = new JsonBooleanSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case NULL: schema = new JsonNullSchemaImpl(parent, locator, jsonPointer).read(this, object); break;
case OBJECT: schema = new JsonObjectSchemaImpl(parent, locator, jsonPointer); break;
case ARRAY: schema = new JsonArraySchemaImpl(parent, locator, jsonPointer); break;
case STRING: schema = new JsonStringSchemaImpl(parent, locator, jsonPointer); break;
case NUMBER: schema = new JsonNumberSchemaImpl(parent, locator, jsonPointer); break;
case INTEGER: schema = new JsonIntegerSchemaImpl(parent, locator, jsonPointer); break;
case BOOLEAN: schema = new JsonBooleanSchemaImpl(parent, locator, jsonPointer); break;
case NULL: schema = new JsonNullSchemaImpl(parent, locator, jsonPointer); break;
default: return null;
}

return schema;
return schema.read(this, object);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public JsonAnyOfImpl read(JsonSubschemaParser parser, JsonObject object)
}
try {
final JsonType t = JsonType.fromValue(((JsonString)val).getString());
add(parser.parse(locator, parent, getJsonPointer(), object, t));
add(parser.parse(locator, this, getJsonPointer(), object, t));
} catch(IllegalArgumentException ex) {
throw new JsonSchemaException(
new ParsingError(ParsingMessage.UNKNOWN_OBJECT_TYPE, val));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public JsonObjectSchemaImpl read(JsonSubschemaParser parser, JsonObject object)

final JsonObject jpatternProperties = JsonSchemaUtil.check(object.get(PATTERN_PROPERTIES), ValueType.OBJECT);
if (jpatternProperties != null) {
patternProperties = new JsonPropertiesImpl(this, getScope(), getJsonPointer() + "/" + DEPENDENT_SCHEMAS)
patternProperties = new JsonPropertiesImpl(this, getScope(), getJsonPointer() + "/" + PATTERN_PROPERTIES)
.read(parser, jpatternProperties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,7 @@ public PrimitiveSchemaImpl read(JsonSubschemaParser parser, JsonObject object)
JsonSchema.DEFS, jdefs.getValueType().name(), JsonValue.ValueType.OBJECT.name()));
}
for (Map.Entry<String, JsonValue> entry : jdefs.asJsonObject().entrySet()) {
final JsonValue subschema = entry.getValue();
switch(subschema.getValueType()) {
case OBJECT:
case TRUE:
case FALSE: parser.parse(getScope(), parent, getJsonPointer() + "/" + JsonSchema.DEFS + "/" + entry.getKey(), subschema, null);
break;
default: throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE,
entry.getKey(), subschema.getValueType().name(), JsonValue.ValueType.OBJECT.name()));
}
parser.parse(getScope(), this, getJsonPointer() + "/" + JsonSchema.DEFS + "/" + entry.getKey(), entry.getValue(), null);
}
}

Expand All @@ -232,15 +224,7 @@ public PrimitiveSchemaImpl read(JsonSubschemaParser parser, JsonObject object)
"definitions", jdefinitions.getValueType().name(), JsonValue.ValueType.OBJECT.name()));
}
for (Map.Entry<String, JsonValue> entry : jdefinitions.asJsonObject().entrySet()) {
final JsonValue subschema = entry.getValue();
switch(subschema.getValueType()) {
case OBJECT:
case TRUE:
case FALSE: parser.parse(getScope(), this, getJsonPointer() + "/definitions/" + entry.getKey(), subschema, null);
break;
default: throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE,
entry.getKey(), subschema.getValueType().name(), JsonValue.ValueType.OBJECT.name()));
}
parser.parse(getScope(), this, getJsonPointer() + "/definitions/" + entry.getKey(), entry.getValue(), null);
}
}

Expand Down Expand Up @@ -284,41 +268,17 @@ public PrimitiveSchemaImpl read(JsonSubschemaParser parser, JsonObject object)

final JsonValue jif = object.get(IF);
if (jif != null) {
switch(jif.getValueType()) {
case OBJECT: _if = parser.parse(scope, this, getJsonPointer() + "/" + IF, jif, null);
break;
case TRUE:
case FALSE: _if = new BooleanJsonSchemaImpl(this, scope, getJsonPointer()).read(parser, jif);
break;
default: throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE,
IF, jif.getValueType().name(), "either object or boolean"));
}
_if = parser.parse(scope, this, getJsonPointer() + "/" + IF, jif, null);
}

final JsonValue jelse = object.get(ELSE);
if (jelse != null) {
switch(jelse.getValueType()) {
case OBJECT: _else = parser.parse(scope, this, getJsonPointer() + "/" + ELSE, jelse, null);
break;
case TRUE:
case FALSE: _else = new BooleanJsonSchemaImpl(this, scope, getJsonPointer()).read(parser, jelse);
break;
default: throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE,
ELSE, jelse.getValueType().name(), "either object or boolean"));
}
_else = parser.parse(scope, this, getJsonPointer() + "/" + ELSE, jelse, null);
}

final JsonValue jthen = object.get(THEN);
if (jthen != null) {
switch(jthen.getValueType()) {
case OBJECT: _then = parser.parse(scope, this, getJsonPointer() + "/" + THEN, jthen, null);
break;
case TRUE:
case FALSE: _then = new BooleanJsonSchemaImpl(this, scope, getJsonPointer()).read(parser, jthen);
break;
default: throw new JsonSchemaException(new ParsingError(ParsingMessage.INVALID_ATTRIBUTE_TYPE,
THEN, jthen.getValueType().name(), "either object or boolean"));
}
_then = parser.parse(scope, this, getJsonPointer() + "/" + THEN, jthen, null);
}

final JsonValue jref = object.get(JsonReference.REF);
Expand Down

0 comments on commit 3824c99

Please sign in to comment.