| java.lang.Object org.ontoware.rdf2go.RDF2Go
RDF2Go | public class RDF2Go (Code) | | Convenience class that allows registering and finding ModelFactories If you
use one adaptor in your application, you should always use the default
instance. If you use multiple frameworks, then you should instantiate the
ModelFactory implementations directly.
Usage
This is the main entry point to use RDF2Go, and in particular to create
Models. You have to register an adaptor once to use this. Example:
// register adapter of implementation XYZ, could be Jena or Sesame or anything.
RDF2Go.register( new org.ontoware.rdf2go.impl.XYZ.ModelFactoryImpl() );
// start using RDF2Go
Model m = RDF2Go.getModelFactory().createModel();
m.addTriple(...)
For each RDF2Go adapter, an ModelFactoy implementation is needed.
User can call the
RDF2Go.register() method to do that.
As a fall-back, when a user calls getModelFactory() but no adapter has been
registered yet, RDF2Go looks for a class named
org.ontoware.rdf2go.impl.StaticBinding and tries to call a method named
"getModelFactory" to get a model factory. This approach has been inspired by
SL4Js static bindign approach. When multiple adapters are found, the first in
the class path is used. This fall-back allows one to simply pack together a
bunch of JARs an be ready to used RDF2Go without any configuration and
without any OSGi.
The expected class looks like this:
package org.ontoware.rdf2go.impl;
import org.ontoware.rdf2go.ModelFactory;
public class StaticBinding {
public static ModelFactory getModelFactory() {
return new org.ontoware.rdf2go.impl.XXXX.ModelFactoryImpl();
}
}
author: sauermann author: voelkel |
modelFactory | protected static ModelFactory modelFactory(Code) | | the default factory for RDF2Go. This is a singleton. The field is
protected by design, JUnit tests inside RDF2Go may want to reset it.
|
getModelFactory | final public static ModelFactory getModelFactory()(Code) | | get the currently registered RDF2Go factory. Usually, you will use one
adaptor in your application, register this adaptor using the .register()
method and it is available here. If none is registered, this throws a
RuntimeException.
the default RDF2Go instance. |
register | final public static void register(ModelFactory modelFactory)(Code) | | register an implementation of the RDF2Go framework. you can only register
one framework inside one Java application, it will throw an Exception if
you register more than one.
Parameters: modelFactory - the factory to register. You can pass null tounregister a modelFactory. Unregistering is restricted toframeworks, you will not need it in simple applications. throws: RuntimeException - if registered already. See the cause of this exception for astacktrace where you first registered. |
|
|