Package jmri.server.json.schema
Class JsonSchemaServiceCache
- java.lang.Object
-
- jmri.server.json.schema.JsonSchemaServiceCache
-
- All Implemented Interfaces:
InstanceManagerAutoDefault
public class JsonSchemaServiceCache extends java.lang.Object implements InstanceManagerAutoDefault
Cache for mappingJsonHttpServices to types for getting schemas.
-
-
Constructor Summary
Constructors Constructor Description JsonSchemaServiceCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.networknt.schema.JsonSchemagetClientSchema(java.lang.String type, JsonRequest request)Get the client schema for JSON messages or for specific JSON data schema.java.util.Set<java.lang.String>getClientTypes(java.lang.String version)Get the types of JSON messages expected from clients.com.networknt.schema.JsonSchemagetServerSchema(java.lang.String type, JsonRequest request)Get the server schema for JSON messages or for specific JSON data schema.java.util.Set<java.lang.String>getServerTypes(java.lang.String version)Get the types of JSON messages this application sends.java.util.Set<JsonHttpService>getServices(java.lang.String type, java.lang.String version)Get the services known to this cache that support a specific JSON type.java.util.Set<java.lang.String>getTypes(java.lang.String version)Get all types of JSON messages.voidvalidateData(java.lang.String type, com.fasterxml.jackson.databind.JsonNode data, boolean server, JsonRequest request)Validate a JSON data object against the schema for JSON messages and data.voidvalidateMessage(com.fasterxml.jackson.databind.JsonNode message, boolean server, JsonRequest request)Validate a JSON message against the schema for JSON messages and data.
-
-
-
Constructor Detail
-
JsonSchemaServiceCache
public JsonSchemaServiceCache()
-
-
Method Detail
-
getServices
@Nonnull public java.util.Set<JsonHttpService> getServices(@Nonnull java.lang.String type, @Nonnull java.lang.String version)
Get the services known to this cache that support a specific JSON type.- Parameters:
type- the JSON type requestedversion- the JSON protocol version requested- Returns:
- the supporting services or an empty set if none
- Throws:
java.lang.NullPointerException- if version is not a known version
-
getTypes
@Nonnull public java.util.Set<java.lang.String> getTypes(java.lang.String version)
Get all types of JSON messages.- Parameters:
version- the JSON protocol version- Returns:
- the union of the results from
getClientTypes(java.lang.String)andgetServerTypes(java.lang.String)
-
getClientTypes
@Nonnull public java.util.Set<java.lang.String> getClientTypes(java.lang.String version)
Get the types of JSON messages expected from clients.- Parameters:
version- the JSON protocol version- Returns:
- the message types
-
getServerTypes
@Nonnull public java.util.Set<java.lang.String> getServerTypes(java.lang.String version)
Get the types of JSON messages this application sends.- Parameters:
version- the JSON protocol version- Returns:
- the message types
-
getClientSchema
@Nonnull public com.networknt.schema.JsonSchema getClientSchema(@Nonnull java.lang.String type, @Nonnull JsonRequest request) throws JsonException
Get the client schema for JSON messages or for specific JSON data schema.- Parameters:
type- the type; useJSON.JSONto get the schema for messages, or any other value for a data schemarequest- the JSON request- Returns:
- the requested schema
- Throws:
JsonException- if unable to get schema due to errors processing schemajava.lang.IllegalArgumentException- if no JSON service provides schemas for type
-
getServerSchema
@Nonnull public com.networknt.schema.JsonSchema getServerSchema(@Nonnull java.lang.String type, @Nonnull JsonRequest request) throws JsonException
Get the server schema for JSON messages or for specific JSON data schema.- Parameters:
type- the type; useJSON.JSONto get the schema for messages, or any other value for a data schemarequest- the JSON request- Returns:
- the requested schema
- Throws:
JsonException- if unable to get schema due to errors processing schemajava.lang.IllegalArgumentException- if no JSON service provides schemas for type
-
validateMessage
public void validateMessage(@Nonnull com.fasterxml.jackson.databind.JsonNode message, boolean server, @Nonnull JsonRequest request) throws JsonException
Validate a JSON message against the schema for JSON messages and data.- Parameters:
message- the message to validateserver- true if message is from the JSON server; false otherwiserequest- the JSON request- Throws:
JsonException- if the message does not validate
-
validateData
public void validateData(@Nonnull java.lang.String type, @Nonnull com.fasterxml.jackson.databind.JsonNode data, boolean server, @Nonnull JsonRequest request) throws JsonException
Validate a JSON data object against the schema for JSON messages and data.- Parameters:
type- the type of data objectdata- the data object to validateserver- true if message is from the JSON server; false otherwiserequest- the JSON request- Throws:
JsonException- if the message does not validate
-
-