public class ModelBuilder extends Object
Model objects via a fluent interface. All methods returning
a ModelBuilder return an immutable reference to the current object, allowing method chaining.
Usage example:
ModelBuilder builder = new ModelBuilder();
// set some namespaces
builder.setNamespace("ex", "http://example.org/").setNamespace(FOAF.NS);
// add a new named graph to the model
builder.namedGraph("ex:graph1")
// add statements about resource ex:john
.subject("ex:john")
.add(FOAF.NAME, "John") // add the triple (ex:john, foaf:name "John") to the named graph
.add(FOAF.AGE, 42)
.add(FOAF.MBOX, "john@example.org");
// add a triple to the default graph
builder.defaultGraph().subject("ex:graph1").add(RDF.TYPE, "ex:Graph");
// return the Model object
Model m = builder.build();
| Constructor and Description |
|---|
ModelBuilder()
Create a new
ModelBuilder. |
ModelBuilder(Model model)
Create a new
ModelBuilder which will append to the supplied Model. |
| Modifier and Type | Method and Description |
|---|---|
ModelBuilder |
add(IRI predicate,
Object object)
Add an RDF statement with the predicate and object to the model, using the current subject and graph (either
named or default).
|
ModelBuilder |
add(Resource subject,
IRI predicate,
Object object)
Add an RDF statement with the given subject, predicate and object to the model, using the current graph (either
named or default).
|
ModelBuilder |
add(String subject,
IRI predicate,
Object object)
Add an RDF statement with the given subject, predicate and object to the model, using the current graph (either
named or default).
|
ModelBuilder |
add(String predicate,
Object object)
Add an RDF statement with the predicate and object to the model, using the current subject and graph (either
named or default).
|
ModelBuilder |
add(String subject,
String predicate,
Object object)
Add an RDF statement with the given subject, predicate and object to the model, using the current graph (either
named or default).
|
Model |
build()
Return the created
Model |
ModelBuilder |
defaultGraph()
Set the current graph in which to add new statements to the default graph.
|
ModelBuilder |
namedGraph(Resource namedGraph)
Set the current graph in which to add new statements to the supplied named graph.
|
ModelBuilder |
namedGraph(String prefixedNameOrIRI)
Set the current graph in which to add new statements to the supplied named graph.
|
ModelBuilder |
setNamespace(Namespace ns)
Set the supplied
Namespace mapping. |
ModelBuilder |
setNamespace(String prefix,
String namespace)
Set the namespace mapping defined by the supplied prefix and name
|
ModelBuilder |
subject(Resource subject)
Set the subject resource about which statements are to be added to the model.
|
ModelBuilder |
subject(String prefixedNameOrIri)
Set the subject about which statements are to be added to the model, defined by a prefixed name or an IRI
reference.
|
public ModelBuilder()
ModelBuilder.public ModelBuilder(Model model)
ModelBuilder which will append to the supplied Model.model - public ModelBuilder setNamespace(Namespace ns)
Namespace mapping.ns - a Namespace to add to the modelModelBuilderpublic ModelBuilder setNamespace(String prefix, String namespace)
prefix - prefix of the namespace to add to the model.namespace - namespace name to add to the model.ModelBuilderpublic ModelBuilder subject(Resource subject)
subject - the subject resource about which statements are to be added.ModelBuilderpublic ModelBuilder subject(String prefixedNameOrIri)
prefixedNameOrIri - the subject resource about which statements are to be added. This can be defined either
as a prefixed name string (e.g. "ex:john"), or as a full IRI (e.g.
"http://example.org/john"). If supplied as a prefixed name, the ModelBuilder
will need to have a namespace mapping for the prefix.ModelBuilderpublic ModelBuilder namedGraph(Resource namedGraph)
namedGraph - a named graph identifierModelBuilderpublic ModelBuilder namedGraph(String prefixedNameOrIRI)
prefixedNameOrIRI - a named graph identifier. This can be defined either as a prefixed name string (e.g.
"ex:john"), or as a full IRI (e.g. "http://example.org/john"). If supplied as a prefixed
name, the ModelBuilder will need to have a namespace mapping for the prefix.ModelBuilderpublic ModelBuilder defaultGraph()
ModelBuilderpublic ModelBuilder add(Resource subject, IRI predicate, Object object)
subject - the statement's subjectpredicate - the statement's predicateobject - the statement's object. If the supplied object is a BNode, IRI, or
Literal, the object is used directly. If it is a prefixed name String with a known
prefix, it is mapped to an IRI. Otherwise a typed Literal is created out of the supplied
object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping
is available, the method creates a literal with the string representation of the supplied object
as the value, and XSD.STRING as the datatype. Recognized types are Boolean ,
Byte, Double, Float, Integer, Long, Short,
XMLGregorianCalendar , and Date.ModelBuildernamedGraph(Resource),
defaultGraph(),
Literals.createLiteral(ValueFactory, Object)public ModelBuilder add(String subject, IRI predicate, Object object)
subject - the statement's subject. This can be defined either as a prefixed name string (e.g. "ex:john"),
or as a full IRI (e.g. "http://example.org/john"). If supplied as a prefixed name, the
ModelBuilder will need to have a namespace mapping for the prefix.predicate - the statement's predicateobject - the statement's object. If the supplied object is a BNode, IRI, or
Literal, the object is used directly. If it is a prefixed name String with a known
prefix, it is mapped to an IRI. Otherwise a typed Literal is created out of the supplied
object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping
is available, the method creates a literal with the string representation of the supplied object
as the value, and XSD.STRING as the datatype. Recognized types are Boolean ,
Byte, Double, Float, Integer, Long, Short,
XMLGregorianCalendar , and Date.ModelBuildernamedGraph(Resource),
defaultGraph(),
Literals.createLiteral(ValueFactory, Object)public ModelBuilder add(String subject, String predicate, Object object)
subject - the statement's subject. This can be defined either as a prefixed name string (e.g. "ex:john"),
or as a full IRI (e.g. "http://example.org/john"). If supplied as a prefixed name, the
ModelBuilder will need to have a namespace mapping for the prefix.predicate - the statement's predicate. This can be defined either as a prefixed name string (e.g.
"ex:john"), or as a full IRI (e.g. "http://example.org/john"). If supplied as a prefixed name,
the ModelBuilder will need to have a namespace mapping for the prefix.object - the statement's object. If the supplied object is a BNode, IRI, or
Literal, the object is used directly. If it is a prefixed name String with a known
prefix, it is mapped to an IRI. Otherwise a typed Literal is created out of the supplied
object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping
is available, the method creates a literal with the string representation of the supplied object
as the value, and XSD.STRING as the datatype. Recognized types are Boolean ,
Byte, Double, Float, Integer, Long, Short,
XMLGregorianCalendar , and Date.ModelBuildernamedGraph(Resource),
defaultGraph(),
Literals.createLiteral(ValueFactory, Object)public ModelBuilder add(IRI predicate, Object object)
predicate - the statement's predicate.object - the statement's object. If the supplied object is a BNode, IRI, or
Literal, the object is used directly. If it is a prefixed name String with a known
prefix, it is mapped to an IRI. Otherwise a typed Literal is created out of the supplied
object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping
is available, the method creates a literal with the string representation of the supplied object
as the value, and XSD.STRING as the datatype. Recognized types are Boolean ,
Byte, Double, Float, Integer, Long, Short,
XMLGregorianCalendar , and Date.ModelBuilderModelException - if the current subject is not set using subject(Resource) or
subject(String).public ModelBuilder add(String predicate, Object object)
predicate - the statement's predicate. This can be defined either as a prefixed name string (e.g.
"ex:john"), or as a full IRI (e.g. "http://example.org/john"). If supplied as a prefixed name,
the ModelBuilder will need to have a namespace mapping for the prefix.object - the statement's object. If the supplied object is a BNode, IRI, or
Literal, the object is used directly. If it is a prefixed name String with a known
prefix, it is mapped to an IRI. Otherwise a typed Literal is created out of the supplied
object, mapping the runtime type of the object to the appropriate XML Schema type. If no mapping
is available, the method creates a literal with the string representation of the supplied object
as the value, and XSD.STRING as the datatype. Recognized types are Boolean ,
Byte, Double, Float, Integer, Long, Short,
XMLGregorianCalendar , and Date.ModelBuilderModelException - if the current subject is not set using subject(Resource) or
subject(String).Copyright © 2015-2021 Eclipse Foundation. All Rights Reserved.