com.github.fge.jsonschema.core.load.uri
Class URITranslatorConfigurationBuilder

java.lang.Object
  extended by com.github.fge.jsonschema.core.load.uri.URITranslatorConfigurationBuilder
All Implemented Interfaces:
Thawed<URITranslatorConfiguration>

public final class URITranslatorConfigurationBuilder
extends Object
implements Thawed<URITranslatorConfiguration>

Builder for a URITranslatorConfiguration

Example:

     final URITranslatorConfiguration cfg
         = URITranslatorConfiguration.newBuilder()
         .setNamespace("http://my.site/myschemas/")
         .addPathRedirect("http://my.site/myschemas/", "resource:/com/foo/myschemas")
         .addSchemaRedirect("http://some.other.site/schema.json", "resource:/com/foo/externalsite/schema.json")
         .freeze();
 

When feeding this configuration into a LoadingConfiguration (using LoadingConfigurationBuilder.setURITranslatorConfiguration(URITranslatorConfiguration)), the following will take place for URI schema1.json#/definitions/def1:

If URI http://some.other.site/schema.json#bar is encountered, a schema redirect triggers and will yield URI resource:/com/foo/externalsite/schema.json#bar.

See Also:
URITranslatorConfiguration, SchemaLoader, LoadingConfigurationBuilder.setURITranslatorConfiguration(URITranslatorConfiguration), SchemaLoader.SchemaLoader(LoadingConfiguration)

Method Summary
 URITranslatorConfigurationBuilder addPathRedirect(String from, String to)
          Convenience method for adding a path URI redirection
 URITranslatorConfigurationBuilder addPathRedirect(URI from, URI to)
          Add a path redirection
 URITranslatorConfigurationBuilder addSchemaRedirect(String from, String to)
          Convenience method for schema redirections
 URITranslatorConfigurationBuilder addSchemaRedirect(URI from, URI to)
          Add a schema redirection
 URITranslatorConfiguration freeze()
          Obtain a frozen configuration from this builder
 URITranslatorConfigurationBuilder setNamespace(String uri)
          Set the namespace for this configuration (convenience method)
 URITranslatorConfigurationBuilder setNamespace(URI uri)
          Set the namespace for this configuration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setNamespace

public URITranslatorConfigurationBuilder setNamespace(URI uri)
Set the namespace for this configuration

All schema loading via URIs (using SchemaLoader.get(URI) or when encountering a JSON Reference in a schema) will be resolved against the provided namespace.

Parameters:
uri - the URI
Returns:
this
Throws:
NullPointerException - URI is null
IllegalArgumentException - URI is not absolute, or is not a path URI (ie, does not end with /)

setNamespace

public URITranslatorConfigurationBuilder setNamespace(String uri)
Set the namespace for this configuration (convenience method)

This calls setNamespace(URI) after creating the URI using URI.create(String).

Parameters:
uri - the URI
Returns:
this
Throws:
NullPointerException - argument is null
IllegalArgumentException - URI.create(String) failed
See Also:
setNamespace(URI)

addSchemaRedirect

public URITranslatorConfigurationBuilder addSchemaRedirect(URI from,
                                                           URI to)
Add a schema redirection

Schema redirection occurs after namespace resolution and after path redirection.

Parameters:
from - the URI to redirect from
to - the URI to redirect to
Returns:
this
Throws:
NullPointerException - one, or both, argument(s) is/are null
IllegalArgumentException - one, or both, URI(s) are not absolute JSON References; or a redirection already exists for URI from; or from and to are the same URI after normalization.

addSchemaRedirect

public URITranslatorConfigurationBuilder addSchemaRedirect(String from,
                                                           String to)
Convenience method for schema redirections

This calls addSchemaRedirect(URI, URI) after converting its string arguments to URIs using URI.create(String).

Parameters:
from - the URI to redirect from
to - the URI to redirect to
Returns:
this
Throws:
NullPointerException - one, or both, argument(s) is/are null
IllegalArgumentException - URI.create(String) failed for one or both argument(s)

addPathRedirect

public URITranslatorConfigurationBuilder addPathRedirect(URI from,
                                                         URI to)
Add a path redirection

What is called a "path URI" here is a URI which is absolute, hierarchical, has no fragment part and whose path component ends with a /.

Parameters:
from - the "path URI" to redirect
to - the target "path URI"
Returns:
this
Throws:
NullPointerException - one, or both, argument(s) is/are null
IllegalArgumentException - one, or both, argument(s) is/are not valid path URIs; or a path redirection already exists for from; or from and to are the same URI after normalization.

addPathRedirect

public URITranslatorConfigurationBuilder addPathRedirect(String from,
                                                         String to)
Convenience method for adding a path URI redirection

This calls addPathRedirect(URI, URI) after performing URI.create(String) on both arguments.

Parameters:
from - the "path URI" to redirect
to - the target "path URI"
Returns:
this
Throws:
NullPointerException - one, or both, argument(s) is/are null
IllegalArgumentException - URI.create(String) failed
See Also:
addPathRedirect(URI, URI)

freeze

public URITranslatorConfiguration freeze()
Obtain a frozen configuration from this builder

Specified by:
freeze in interface Thawed<URITranslatorConfiguration>
Returns:
a new URITranslatorConfiguration