dfki.util.rdf
Class RDF

java.lang.Object
  |
  +--dfki.util.rdf.RDF

public final class RDF
extends java.lang.Object

Class to support RDF handling. Main entry points are the two methods for creating an RDFFactory. These are factory() and factory(String). New models, RDF parsers and RDF serializers can be created via this factory class.
The RDF class also provides a number of static convenience methods that make life with RDF a little bit easier.
A speacial RDF.Syntax class offers standard resource instances for given namespaces. These instances can be useful for search and compare operations on the triples of a model. The Syntax instance can be obtained via the methods syntax() and syntax(String).

Properties of the RDF class are:

RDF_FACTORY_IMPL_CLASSNAME: (default: Util.RDF.RDFFactoryImplClassName)
Name of the class implementing the RDFFactory interface
DEFAULT_SYNTAX_NAMESPACE: (default: Util.RDF.DefaultSyntaxNamespace)
Default namespace for identifiers that are related to the RDF specification.

Have a look at dfki.util.examples.rdf to see how to use the RDF class.


Inner Class Summary
static class RDF.Exception
           
static class RDF.Import
           
static class RDF.Property
          Defines the Properties of the RDF class.
static class RDF.Setup
          Class managing the Setup of the RDF class.
static class RDF.Syntax
           
 
Field Summary
static java.lang.String DEFAULT_IMPORT_IMPL_CLASSNAME
           
static java.lang.String DEFAULT_RDF_FACTORY_CLASSNAME
           
static java.lang.String DEFAULT_SYNTAX_NAMESPACE
           
static java.lang.String MODULE_NAME
           
 
Method Summary
static void add(org.w3c.rdf.model.Model m, org.w3c.rdf.model.Resource subject, org.w3c.rdf.model.Resource predicate, org.w3c.rdf.model.RDFNode object)
           
static void collectNamespaces(org.w3c.rdf.model.Model m, java.util.Collection target)
           
static void collectNamespaces(org.w3c.rdf.model.Resource r, java.util.Collection target)
           
static void collectNamespaces(org.w3c.rdf.model.Statement st, java.util.Collection target)
           
static void dumpModel(org.w3c.rdf.model.Model m, java.io.PrintStream ps, org.w3c.rdf.syntax.RDFSerializer s)
          Dumps the model in a serialized form.
static java.lang.String dumpModel(org.w3c.rdf.model.Model m, org.w3c.rdf.syntax.RDFSerializer s)
          Dumps the model in a serialized form in a string
static java.lang.String dumpModel(org.w3c.rdf.model.Model m, java.io.Writer w, org.w3c.rdf.syntax.RDFSerializer s)
          Dumps the model in a serialized form in a string
static org.w3c.rdf.util.RDFFactory factory()
          Create a RDFFactory.
static org.w3c.rdf.util.RDFFactory factory(java.lang.String factoryImplClassName)
          Create a RDFFactory.
static org.w3c.rdf.model.Statement get1(org.w3c.rdf.model.Model m)
          Returns the first triple of the model
static java.lang.String getLocalName(org.w3c.rdf.model.Resource r)
          Delivers the name out of the URI (without the namespace prefix).
static java.lang.String getNamespace(org.w3c.rdf.model.Resource r)
          Extracts the namespace prefix out of a URI.
static java.util.Hashtable getNodes(org.w3c.rdf.model.Model m)
           
static org.w3c.rdf.model.RDFNode getObject(org.w3c.rdf.model.Model r, org.w3c.rdf.model.Resource subject, org.w3c.rdf.model.Resource predicate)
           
static java.lang.String getObjectLiteral(org.w3c.rdf.model.Model r, org.w3c.rdf.model.Resource subject, org.w3c.rdf.model.Resource predicate)
          returns the literal value of the node reachable from subject via predicate
static org.w3c.rdf.model.Resource getObjectResource(org.w3c.rdf.model.Model r, org.w3c.rdf.model.Resource subject, org.w3c.rdf.model.Resource predicate)
           
static int getOrd(org.w3c.rdf.model.Resource r)
          Converts an ordinal property to an integer.
static org.w3c.rdf.model.Model getReachable(org.w3c.rdf.model.Resource r, org.w3c.rdf.model.Model m)
          returns a subgraph of "m" containing "r" and all nodes reachable from "r" via directed edges.
static java.util.Hashtable getResources(org.w3c.rdf.model.Model m)
           
static org.w3c.rdf.model.Statement[] getStatementArray(org.w3c.rdf.model.Model m)
          Collects the triples of a model into an array.
static java.util.Vector getStatementVector(org.w3c.rdf.model.Model m)
          Collects the triples of a model in a vector.
static org.w3c.rdf.model.Resource getSubject(org.w3c.rdf.model.Model r, org.w3c.rdf.model.Resource predicate, org.w3c.rdf.model.RDFNode object)
           
static java.lang.String guessName(java.lang.String uri)
          Delivers the name out of the URI (without the namespace prefix).
static java.lang.String guessNamespace(java.lang.String uri)
          Extracts the namespace prefix out of a URI.
static RDF.Import importer(java.lang.String namespace, java.lang.String packageName)
           
static RDF.Import importer(java.lang.String importerImplClassName, java.lang.String namespace, java.lang.String packageName)
           
static boolean isInstanceOf(org.w3c.rdf.model.Model r, org.w3c.rdf.model.Resource i, org.w3c.rdf.model.Resource cls)
           
static boolean isQualified(java.lang.String s)
          Tests if the URI is qualified, i.e.
static boolean isRDF(org.w3c.rdf.model.Resource r)
          Tests if the resource belongs to the RDF syntax/model namespace.
static boolean isRDF(java.lang.String uri)
          Tests if the URI belongs to the RDF syntax/model namespace.
static org.w3c.rdf.model.Resource noname(org.w3c.rdf.model.Model m)
          Creates a new unique unnamed resource.
static java.lang.String normalizeURI(java.lang.String uri)
           
static void parse(java.lang.String fileNameOrURL, org.w3c.rdf.syntax.RDFParser parser, org.w3c.rdf.model.Model model)
           
static void parse(java.lang.String uri, java.io.Reader reader, org.w3c.rdf.util.RDFFactory factory)
           
static void parse(java.lang.String uri, java.io.Reader reader, org.w3c.rdf.syntax.RDFParser parser, org.w3c.rdf.model.Model model)
           
static void printStatements(org.w3c.rdf.model.Model m, java.io.PrintStream ps)
          Prints the triples of a model to the given PrintStream.
static org.w3c.rdf.model.Model removeNamespace(java.lang.String ns, org.w3c.rdf.model.Model m)
          Removes all triples which have something to do with the given namespace
static void saveModel(org.w3c.rdf.model.Model m, org.w3c.rdf.syntax.RDFSerializer s)
          tries to determine the file name from getSourceURI
static void saveModel(org.w3c.rdf.model.Model m, java.lang.String fileName, org.w3c.rdf.syntax.RDFSerializer s)
           
static boolean setUniqueObject(org.w3c.rdf.model.Model r, org.w3c.rdf.model.Resource subject, org.w3c.rdf.model.Resource predicate, org.w3c.rdf.model.RDFNode object)
          returns true if old triples from r were removed
static RDF.Syntax syntax()
           
static RDF.Syntax syntax(java.lang.String namespace)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODULE_NAME

public static final java.lang.String MODULE_NAME

DEFAULT_RDF_FACTORY_CLASSNAME

public static final java.lang.String DEFAULT_RDF_FACTORY_CLASSNAME

DEFAULT_SYNTAX_NAMESPACE

public static final java.lang.String DEFAULT_SYNTAX_NAMESPACE

DEFAULT_IMPORT_IMPL_CLASSNAME

public static final java.lang.String DEFAULT_IMPORT_IMPL_CLASSNAME
Method Detail

syntax

public static RDF.Syntax syntax()
                         throws RDF.Exception

syntax

public static RDF.Syntax syntax(java.lang.String namespace)
                         throws RDF.Exception

factory

public static org.w3c.rdf.util.RDFFactory factory()
                                           throws RDF.Exception
Create a RDFFactory. The default factory implementation is used.
See Also:
RDF.Property.RDF_FACTORY_IMPL_CLASSNAME

factory

public static org.w3c.rdf.util.RDFFactory factory(java.lang.String factoryImplClassName)
                                           throws RDF.Exception
Create a RDFFactory.
Parameters:
factoryImplClassName - The class name of a RDFFactory implementation.

importer

public static RDF.Import importer(java.lang.String namespace,
                                  java.lang.String packageName)
                           throws RDF.Import.Exception

importer

public static RDF.Import importer(java.lang.String importerImplClassName,
                                  java.lang.String namespace,
                                  java.lang.String packageName)
                           throws RDF.Import.Exception

parse

public static void parse(java.lang.String uri,
                         java.io.Reader reader,
                         org.w3c.rdf.syntax.RDFParser parser,
                         org.w3c.rdf.model.Model model)
                  throws java.io.IOException,
                         org.xml.sax.SAXException,
                         org.w3c.rdf.model.ModelException

parse

public static void parse(java.lang.String uri,
                         java.io.Reader reader,
                         org.w3c.rdf.util.RDFFactory factory)
                  throws java.io.IOException,
                         org.xml.sax.SAXException,
                         org.w3c.rdf.model.ModelException

noname

public static org.w3c.rdf.model.Resource noname(org.w3c.rdf.model.Model m)
                                         throws org.w3c.rdf.model.ModelException
Creates a new unique unnamed resource.

getOrd

public static int getOrd(org.w3c.rdf.model.Resource r)
                  throws org.w3c.rdf.model.ModelException
Converts an ordinal property to an integer.

isQualified

public static boolean isQualified(java.lang.String s)
Tests if the URI is qualified, i.e. has a namespace prefix.

guessNamespace

public static java.lang.String guessNamespace(java.lang.String uri)
Extracts the namespace prefix out of a URI.

guessName

public static java.lang.String guessName(java.lang.String uri)
Delivers the name out of the URI (without the namespace prefix).

getNamespace

public static java.lang.String getNamespace(org.w3c.rdf.model.Resource r)
                                     throws org.w3c.rdf.model.ModelException
Extracts the namespace prefix out of a URI.

getLocalName

public static java.lang.String getLocalName(org.w3c.rdf.model.Resource r)
                                     throws org.w3c.rdf.model.ModelException
Delivers the name out of the URI (without the namespace prefix).

isRDF

public static boolean isRDF(java.lang.String uri)
Tests if the URI belongs to the RDF syntax/model namespace.

isRDF

public static boolean isRDF(org.w3c.rdf.model.Resource r)
                     throws org.w3c.rdf.model.ModelException
Tests if the resource belongs to the RDF syntax/model namespace.

get1

public static org.w3c.rdf.model.Statement get1(org.w3c.rdf.model.Model m)
                                        throws org.w3c.rdf.model.ModelException
Returns the first triple of the model

add

public static void add(org.w3c.rdf.model.Model m,
                       org.w3c.rdf.model.Resource subject,
                       org.w3c.rdf.model.Resource predicate,
                       org.w3c.rdf.model.RDFNode object)
                throws org.w3c.rdf.model.ModelException

setUniqueObject

public static boolean setUniqueObject(org.w3c.rdf.model.Model r,
                                      org.w3c.rdf.model.Resource subject,
                                      org.w3c.rdf.model.Resource predicate,
                                      org.w3c.rdf.model.RDFNode object)
                               throws org.w3c.rdf.model.ModelException
returns true if old triples from r were removed

getObjectLiteral

public static java.lang.String getObjectLiteral(org.w3c.rdf.model.Model r,
                                                org.w3c.rdf.model.Resource subject,
                                                org.w3c.rdf.model.Resource predicate)
                                         throws org.w3c.rdf.model.ModelException
returns the literal value of the node reachable from subject via predicate

getObjectResource

public static org.w3c.rdf.model.Resource getObjectResource(org.w3c.rdf.model.Model r,
                                                           org.w3c.rdf.model.Resource subject,
                                                           org.w3c.rdf.model.Resource predicate)
                                                    throws org.w3c.rdf.model.ModelException

isInstanceOf

public static boolean isInstanceOf(org.w3c.rdf.model.Model r,
                                   org.w3c.rdf.model.Resource i,
                                   org.w3c.rdf.model.Resource cls)
                            throws org.w3c.rdf.model.ModelException

getObject

public static org.w3c.rdf.model.RDFNode getObject(org.w3c.rdf.model.Model r,
                                                  org.w3c.rdf.model.Resource subject,
                                                  org.w3c.rdf.model.Resource predicate)
                                           throws org.w3c.rdf.model.ModelException

getSubject

public static org.w3c.rdf.model.Resource getSubject(org.w3c.rdf.model.Model r,
                                                    org.w3c.rdf.model.Resource predicate,
                                                    org.w3c.rdf.model.RDFNode object)
                                             throws org.w3c.rdf.model.ModelException

printStatements

public static void printStatements(org.w3c.rdf.model.Model m,
                                   java.io.PrintStream ps)
                            throws org.w3c.rdf.model.ModelException
Prints the triples of a model to the given PrintStream.

dumpModel

public static void dumpModel(org.w3c.rdf.model.Model m,
                             java.io.PrintStream ps,
                             org.w3c.rdf.syntax.RDFSerializer s)
                      throws org.w3c.rdf.model.ModelException,
                             java.io.IOException,
                             org.w3c.rdf.syntax.SerializationException
Dumps the model in a serialized form.

dumpModel

public static java.lang.String dumpModel(org.w3c.rdf.model.Model m,
                                         org.w3c.rdf.syntax.RDFSerializer s)
                                  throws org.w3c.rdf.model.ModelException,
                                         java.io.IOException,
                                         org.w3c.rdf.syntax.SerializationException
Dumps the model in a serialized form in a string

dumpModel

public static java.lang.String dumpModel(org.w3c.rdf.model.Model m,
                                         java.io.Writer w,
                                         org.w3c.rdf.syntax.RDFSerializer s)
                                  throws org.w3c.rdf.model.ModelException,
                                         java.io.IOException,
                                         org.w3c.rdf.syntax.SerializationException
Dumps the model in a serialized form in a string

getStatementVector

public static java.util.Vector getStatementVector(org.w3c.rdf.model.Model m)
                                           throws org.w3c.rdf.model.ModelException
Collects the triples of a model in a vector.

getStatementArray

public static org.w3c.rdf.model.Statement[] getStatementArray(org.w3c.rdf.model.Model m)
                                                       throws org.w3c.rdf.model.ModelException
Collects the triples of a model into an array.

removeNamespace

public static org.w3c.rdf.model.Model removeNamespace(java.lang.String ns,
                                                      org.w3c.rdf.model.Model m)
                                               throws org.w3c.rdf.model.ModelException
Removes all triples which have something to do with the given namespace

getReachable

public static org.w3c.rdf.model.Model getReachable(org.w3c.rdf.model.Resource r,
                                                   org.w3c.rdf.model.Model m)
                                            throws org.w3c.rdf.model.ModelException
returns a subgraph of "m" containing "r" and all nodes reachable from "r" via directed edges. These edges are also included in the resulting model.

parse

public static void parse(java.lang.String fileNameOrURL,
                         org.w3c.rdf.syntax.RDFParser parser,
                         org.w3c.rdf.model.Model model)
                  throws java.io.IOException,
                         org.xml.sax.SAXException,
                         java.net.MalformedURLException,
                         org.w3c.rdf.model.ModelException

normalizeURI

public static java.lang.String normalizeURI(java.lang.String uri)

getResources

public static java.util.Hashtable getResources(org.w3c.rdf.model.Model m)
                                        throws org.w3c.rdf.model.ModelException

getNodes

public static java.util.Hashtable getNodes(org.w3c.rdf.model.Model m)
                                    throws org.w3c.rdf.model.ModelException

saveModel

public static void saveModel(org.w3c.rdf.model.Model m,
                             java.lang.String fileName,
                             org.w3c.rdf.syntax.RDFSerializer s)
                      throws java.io.FileNotFoundException,
                             java.io.IOException,
                             org.w3c.rdf.model.ModelException,
                             org.w3c.rdf.syntax.SerializationException

saveModel

public static void saveModel(org.w3c.rdf.model.Model m,
                             org.w3c.rdf.syntax.RDFSerializer s)
                      throws java.io.FileNotFoundException,
                             java.io.IOException,
                             org.w3c.rdf.model.ModelException,
                             org.w3c.rdf.syntax.SerializationException
tries to determine the file name from getSourceURI

collectNamespaces

public static void collectNamespaces(org.w3c.rdf.model.Resource r,
                                     java.util.Collection target)
                              throws org.w3c.rdf.model.ModelException

collectNamespaces

public static void collectNamespaces(org.w3c.rdf.model.Statement st,
                                     java.util.Collection target)
                              throws org.w3c.rdf.model.ModelException

collectNamespaces

public static void collectNamespaces(org.w3c.rdf.model.Model m,
                                     java.util.Collection target)
                              throws org.w3c.rdf.model.ModelException