Package org.spdx.v3jsonldstore
Class JsonLDSchema
- java.lang.Object
-
- org.spdx.v3jsonldstore.JsonLDSchema
-
public class JsonLDSchema extends Object
Represents the JSON Schema for SPDX 3.X includes a number of convenience methods- Author:
- Gary O'Neall
-
-
Field Summary
Fields Modifier and Type Field Description static Set<String>BOOLEAN_TYPESstatic Set<String>DOUBLE_TYPESstatic Set<String>INTEGER_TYPESstatic Map<String,String>RESERVED_JAVA_WORDSstatic Map<String,String>REVERSE_JAVA_WORDSstatic Set<String>STRING_TYPES
-
Constructor Summary
Constructors Constructor Description JsonLDSchema(String schemaFileName, String contextFileName, String modelFileName)Loads the SPDX JSON schema, JSON-LD context, and SHACL model from the given resource files
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Collection<net.jimblackler.jsonschemafriend.Schema>getAllClasses()Returns all class schemas defined in the SPDX JSON schemaList<String>getAnyLicenseInfoTypes()Returns all AnyLicenseInfo type namesOptional<net.jimblackler.jsonschemafriend.Schema>getClassSchema(String className)Returns the schema for the named SPDX class, if definedList<String>getElementTypes()Returns all SPDX element type namesOptional<org.spdx.storage.PropertyDescriptor>getPropertyDescriptor(String fieldName)Returns the SPDX modelPropertyDescriptorfor the given JSON field nameOptional<String>getPropertyType(String propertyName)Returns the JSON-LD@typefor the named property from the contextOptional<String>getType(net.jimblackler.jsonschemafriend.Schema classSchema)Returns the JSON schema type name for the given class schemaOptional<URI>getTypeUri(net.jimblackler.jsonschemafriend.Schema classSchema)Resolves the type URI for a class schema using the JSON-LD contextOptional<String>getVocab(String propertyName)Returns the@vocabURI for the named property from the JSON-LD contextbooleanhasProperty(String propertyName, net.jimblackler.jsonschemafriend.Schema schema)Returns true if the given schema requires the named propertybooleanisEnum(String propertyName)Returns true if the property is an enumeration type in the SPDX vocabularybooleanisIndividual(String propertyName, String propertyValue)Returns true if the property value is a named individual from the SPDX vocabularybooleanisSpdxObject(String propertyName)Returns true if the property value is an ID referencing an SPDX objectbooleanisSubclassOf(String superClassType, net.jimblackler.jsonschemafriend.Schema subClass)Returns true if the given schema is a subclass of the specified superclass typebooleanvalidate(com.fasterxml.jackson.databind.JsonNode root)Validates a JSON node against the SPDX JSON schemabooleanvalidate(File spdxJsonFile)Validates a file against the SPDX JSON schemabooleanvalidate(InputStream is)Validates an input stream against the SPDX JSON schema
-
-
-
Constructor Detail
-
JsonLDSchema
public JsonLDSchema(String schemaFileName, String contextFileName, String modelFileName) throws net.jimblackler.jsonschemafriend.GenerationException
Loads the SPDX JSON schema, JSON-LD context, and SHACL model from the given resource files- Parameters:
schemaFileName- File name for the schema file in the resources directorycontextFileName- File name for the context file in the resources directorymodelFileName- File name for the model file in the resources directory- Throws:
net.jimblackler.jsonschemafriend.GenerationException- on schema loading error
-
-
Method Detail
-
getAllClasses
public Collection<net.jimblackler.jsonschemafriend.Schema> getAllClasses()
Returns all class schemas defined in the SPDX JSON schema- Returns:
- a list of schemas for all classes defined in the SPDX schema
-
isSubclassOf
public boolean isSubclassOf(String superClassType, net.jimblackler.jsonschemafriend.Schema subClass) throws URISyntaxException
Returns true if the given schema is a subclass of the specified superclass type- Parameters:
superClassType- superclass typesubClass- schema for the subclass- Returns:
- true if the subClass schema contains the property restrictions for the superclass types
- Throws:
URISyntaxException- on a bad superClassType string
-
hasProperty
public boolean hasProperty(String propertyName, net.jimblackler.jsonschemafriend.Schema schema)
Returns true if the given schema requires the named property- Parameters:
propertyName- name of the property to checkschema- schema containing property restrictions- Returns:
- true if the schema requires a property named propertyName via properties, subSchemas, or allOf
-
getClassSchema
public Optional<net.jimblackler.jsonschemafriend.Schema> getClassSchema(String className)
Returns the schema for the named SPDX class, if defined- Parameters:
className- name of the class- Returns:
- schema for the class if it exists
-
getTypeUri
public Optional<URI> getTypeUri(net.jimblackler.jsonschemafriend.Schema classSchema)
Resolves the type URI for a class schema using the JSON-LD context- Parameters:
classSchema- schema for a class- Returns:
- type URI for the type of the class from the JSON-LD context
-
getType
public Optional<String> getType(net.jimblackler.jsonschemafriend.Schema classSchema)
Returns the JSON schema type name for the given class schema- Parameters:
classSchema- Schema for the class- Returns:
- JSON Schema type name for the class
-
validate
public boolean validate(com.fasterxml.jackson.databind.JsonNode root)
Validates a JSON node against the SPDX JSON schema- Parameters:
root- Root JSON node of the JSON representation of an SPDX serialization- Returns:
- true if the JSON node is valid
-
validate
public boolean validate(File spdxJsonFile) throws IOException
Validates a file against the SPDX JSON schema- Parameters:
spdxJsonFile- file containing SPDX JSON-LD serialized content- Returns:
- true if the JSON in the file is valid according to the schema
- Throws:
IOException- on file IO errors
-
validate
public boolean validate(InputStream is) throws IOException
Validates an input stream against the SPDX JSON schema- Parameters:
is- input stream containing SPDX JSON-LD serialized content- Returns:
- true if the JSON in the input stream is valid according to the schema
- Throws:
IOException- on input stream IO errors
-
getElementTypes
public List<String> getElementTypes()
Returns all SPDX element type names- Returns:
- the elementTypes
-
getAnyLicenseInfoTypes
public List<String> getAnyLicenseInfoTypes()
Returns all AnyLicenseInfo type names- Returns:
- the anyLicenseInfoTypes
-
getPropertyType
public Optional<String> getPropertyType(String propertyName)
Returns the JSON-LD@typefor the named property from the context- Parameters:
propertyName- name of the property- Returns:
- the JSON property type if it exists in the JSON-LD context
-
getVocab
public Optional<String> getVocab(String propertyName)
Returns the@vocabURI for the named property from the JSON-LD context- Parameters:
propertyName- name of a property in the JSON-LD schema- Returns:
- the vocab definition
-
getPropertyDescriptor
public Optional<org.spdx.storage.PropertyDescriptor> getPropertyDescriptor(String fieldName)
Returns the SPDX modelPropertyDescriptorfor the given JSON field name- Parameters:
fieldName- name of a JSON field / property- Returns:
- the SPDX model property descriptor for the JSON property
-
isSpdxObject
public boolean isSpdxObject(String propertyName)
Returns true if the property value is an ID referencing an SPDX object- Parameters:
propertyName- Name of the property- Returns:
- true if the value associated with the property is an ID representing an SPDX Object
-
isIndividual
public boolean isIndividual(String propertyName, String propertyValue)
Returns true if the property value is a named individual from the SPDX vocabulary- Parameters:
propertyName- Name of the propertypropertyValue- property value- Returns:
- true if the propertyValue represents an Individual from the vocabulary
-
isEnum
public boolean isEnum(String propertyName)
Returns true if the property is an enumeration type in the SPDX vocabulary- Parameters:
propertyName- Name of the property- Returns:
- true if the propertyValue represents an enumeration
-
-