com.github.fge.jsonschema.core.tree
Class BaseSchemaTree

java.lang.Object
  extended by com.github.fge.jsonschema.core.tree.BaseSchemaTree
All Implemented Interfaces:
SchemaTree, SimpleTree, AsJson
Direct Known Subclasses:
CanonicalSchemaTree, InlineSchemaTree

@Immutable
public abstract class BaseSchemaTree
extends Object
implements SchemaTree

Base implementation of a SchemaTree

See Also:
CanonicalSchemaTree, InlineSchemaTree

Field Summary
protected  JsonNode baseNode
          The initial node
protected  JsonRef loadingRef
          The JSON Reference from which this node has been loaded
protected  JsonPointer pointer
          The current JSON Pointer into the node.
 
Constructor Summary
protected BaseSchemaTree(BaseSchemaTree other, JsonPointer newPointer)
           
protected BaseSchemaTree(JsonRef loadingRef, JsonNode baseNode, JsonPointer pointer)
           
 
Method Summary
 JsonNode asJson()
          Return a JSON representation of this object
 JsonNode getBaseNode()
          Return the node this tree was created with
 JsonRef getContext()
          Get the current resolution context
 JsonRef getDollarSchema()
          Return the metaschema URI for that schema (ie, $schema)
 long getId()
           
 JsonRef getLoadingRef()
          Get the loading URI for that schema
 JsonNode getNode()
          Get the node at the current path
 JsonPointer getPointer()
          Get the current path into the document
protected static JsonRef idFromNode(JsonNode node)
          Build a JSON Reference from a node
 JsonRef resolve(JsonRef other)
          Resolve a JSON Reference against the current resolution context
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.github.fge.jsonschema.core.tree.SchemaTree
append, containsRef, matchingPointer, setPointer
 

Field Detail

baseNode

protected final JsonNode baseNode
The initial node


pointer

protected final JsonPointer pointer
The current JSON Pointer into the node. Starts empty.


loadingRef

protected final JsonRef loadingRef
The JSON Reference from which this node has been loaded

If loaded without a URI, this will be the empty reference.

Constructor Detail

BaseSchemaTree

protected BaseSchemaTree(JsonRef loadingRef,
                         JsonNode baseNode,
                         JsonPointer pointer)

BaseSchemaTree

protected BaseSchemaTree(BaseSchemaTree other,
                         JsonPointer newPointer)
Method Detail

getId

public final long getId()
Specified by:
getId in interface SchemaTree

getBaseNode

public final JsonNode getBaseNode()
Description copied from interface: SimpleTree
Return the node this tree was created with

Note: in current Jackson versions, this node is unfortunately mutable, so be careful...

Specified by:
getBaseNode in interface SimpleTree
Returns:
the node

getPointer

public final JsonPointer getPointer()
Description copied from interface: SimpleTree
Get the current path into the document

Specified by:
getPointer in interface SimpleTree
Returns:
the path as a JSON Pointer

getNode

public final JsonNode getNode()
Description copied from interface: SimpleTree
Get the node at the current path

Specified by:
getNode in interface SimpleTree
Returns:
the matching node (a MissingNode if there is no matching node at that pointer)

resolve

public final JsonRef resolve(JsonRef other)
Resolve a JSON Reference against the current resolution context

Specified by:
resolve in interface SchemaTree
Parameters:
other - the JSON Reference to resolve
Returns:
the resolved reference
See Also:
JsonRef.resolve(JsonRef)

getDollarSchema

public final JsonRef getDollarSchema()
Description copied from interface: SchemaTree
Return the metaschema URI for that schema (ie, $schema)

Note: it is required that if present, $schema be an absolute JSON Reference. If this keyword is not present and/or is malformed, an empty reference is returned.

Specified by:
getDollarSchema in interface SchemaTree
Returns:
the contents of $schema as a JsonRef

getLoadingRef

public final JsonRef getLoadingRef()
Get the loading URI for that schema

Specified by:
getLoadingRef in interface SchemaTree
Returns:
the loading URI as a JsonRef

getContext

public final JsonRef getContext()
Get the current resolution context

Specified by:
getContext in interface SchemaTree
Returns:
the context as a JsonRef

asJson

public final JsonNode asJson()
Description copied from interface: AsJson
Return a JSON representation of this object

Specified by:
asJson in interface AsJson
Returns:
a JsonNode

toString

public final String toString()
Overrides:
toString in class Object

idFromNode

protected static JsonRef idFromNode(JsonNode node)
Build a JSON Reference from a node

This will return null if the reference could not be built. The conditions for a successful build are as follows:

Parameters:
node - the node
Returns:
a JSON Reference, or null