Class ResourceFactory

java.lang.Object
org.apache.jena.rdf.model.ResourceFactory

public class ResourceFactory extends Object
A Factory class for creating resources.

This class creates resources and properties and things of that ilk. These resources are not associated with a user-modifiable model: doing getModel() on them will return null.

It is designed as a singleton. There are static convenience methods on this class itself, so the easy way to create resource is for example to do something like:

   Resource r = ResourceFactory.createResource();
 

If a factory object is needed, then this can be obtained using the getInstance method on the class. The factory object used may be changed using the setInstance method.

  • Method Details

    • getInstance

      public static ResourceFactory.Interface getInstance()
      Get the current factory object.
      Returns:
      the current factory object
    • setInstance

      public static ResourceFactory.Interface setInstance(ResourceFactory.Interface newInstance)
      Set the current factory object.
      Parameters:
      newInstance - the new factory object
      Returns:
      the previous factory object
    • createResource

      public static Resource createResource()
      Create a new anonymous resource.

      Uses the current factory object to create a new anonymous resource.

      Returns:
      a new anonymous resource
    • createResource

      public static Resource createResource(String uriref)
      Create a new resource.

      Uses the current factory object to create a new resource.

      Parameters:
      uriref - URIREF of the resource
      Returns:
      a new resource
    • createStmtResource

      public static Resource createStmtResource(Statement statement)
      Create a new resource representing an RDF-star triple term.
      Parameters:
      statement -
      Returns:
      a new resource
    • createPlainLiteral

      public static Literal createPlainLiteral(String string)
      Answer a string (xsd:string) literal. This is the equivalent of a plain literal with no language from RDF 1.0 (also called a simple literal in SPARQL) Using createStringLiteral(java.lang.String) is preferred; "plain literal" is RDF 1.0 terminology.
      Parameters:
      string - the string which forms the value of the literal
      Returns:
      a Literal node with that string as value
    • createStringLiteral

      public static Literal createStringLiteral(String string)
      Answer a string (xsd:string) literal. This is the equivalent of a plain literal with no language from RDF 1.0 (also called a simple literal in SPARQL)
      Parameters:
      string - the string which forms the value of the literal
      Returns:
      a Literal node with that string as value
    • createLangLiteral

      public static Literal createLangLiteral(String string, String lang)
      Answer a literal with language and the given content. The literal will have datatype rdf:langString.
      Parameters:
      string - the string which forms the value of the literal
      lang - The language tag to be used
      Returns:
      a Literal node with that string as value
    • createTypedLiteral

      public static Literal createTypedLiteral(String string, RDFDatatype dType)
      Answer a typed literal.
      Parameters:
      string - the string which forms the value of the literal
      dType - RDFDatatype of the type literal
      Returns:
      a Literal node with that string as value
    • createTypedLiteral

      public static Literal createTypedLiteral(Object value)
      Answer a typed literal.
      Parameters:
      value - a java Object, the default RDFDatatype for that object will be used
      Returns:
      a Literal node with that value
    • createProperty

      public static Property createProperty(String uriref)
      Create a new property.

      Uses the current factory object to create a new resource.

      Parameters:
      uriref - URIREF of the property
      Returns:
      a new property
    • createProperty

      public static Property createProperty(String namespace, String localName)
      Create a new property.

      Uses the current factory object to create a new property.

      Parameters:
      namespace - URIREF of the namespace of the property
      localName - localname of the property
      Returns:
      a new property
    • createStatement

      public static Statement createStatement(Resource subject, Property predicate, RDFNode object)
      Create a new statement.

      Uses the current factory object to create a new statement.

      Parameters:
      subject - the subject of the new statement
      predicate - the predicate of the new statement
      object - the object of the new statement
      Returns:
      a new resource