de.fuberlin.wiwiss.d2rq.map
Class TranslationTable

java.lang.Object
  extended byde.fuberlin.wiwiss.d2rq.map.TranslationTable
All Implemented Interfaces:
Translator

public class TranslationTable
extends java.lang.Object
implements Translator

Translation table that maps a set of database values to a set of RDF literals or URIs. The getTranslatingValueSource(de.fuberlin.wiwiss.d2rq.map.ValueSource) method creates a TranslationTable.TranslatingValueSource that can be chained with other ValueSources. The RDF values can be either literals or URIs. The type of the node that is actually generated is determined by a NodeMaker that should sit on top of the translator. Mappings can be explicitly provided, or a Translator instance can be used to map values. TODO: The two cases (addTranslation calls and setTranslator) should probalby be in separate classes.

History:
08-03-2004: Initial version.

Version:
V0.2
Author:
Richard Cyganiak

Nested Class Summary
private  class TranslationTable.TranslatingValueSource
           
 
Field Summary
private  java.util.Map db2rdf
           
private  java.util.Map rdf2db
           
private  Translator translatorInstance
           
 
Constructor Summary
TranslationTable()
           
 
Method Summary
 void addAll(java.util.Map translationMap)
          Adds multiple translation mappings.
 void addTranslation(java.lang.String dbValue, java.lang.String rdfValue)
          Adds a translation mapping.
 ValueSource getTranslatingValueSource(ValueSource valueSource)
          Creates a new ValueSource that translates values from the argument ValueSource according to the mappings in this TranslationTable.
private  boolean hasConstructorWithArg(java.lang.Class aClass)
           
private  boolean hasConstructorWithoutArg(java.lang.Class aClass)
           
private  boolean implementsTranslator(java.lang.Class aClass)
           
private  Translator invokeConstructorWithArg(java.lang.Class aClass, com.hp.hpl.jena.rdf.model.Resource r)
           
private  Translator invokeConstructorWithoutArg(java.lang.Class aClass)
           
 void setTranslator(Translator translator)
          Sets a Translator.
 void setTranslatorClass(java.lang.String className, com.hp.hpl.jena.rdf.model.Resource resource)
          Sets a translation class.
 int size()
          Returns the number of defined mappings.
 java.lang.String toDBValue(java.lang.String rdfValue)
          Translates an RDF value to a database value.
 java.lang.String toRDFValue(java.lang.String dbValue)
          Translates a database value to a RDF value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

db2rdf

private java.util.Map db2rdf

rdf2db

private java.util.Map rdf2db

translatorInstance

private Translator translatorInstance
Constructor Detail

TranslationTable

public TranslationTable()
Method Detail

size

public int size()
Returns the number of defined mappings.


addTranslation

public void addTranslation(java.lang.String dbValue,
                           java.lang.String rdfValue)
Adds a translation mapping.

Parameters:
dbValue - the value on the database side (usually coming from a DB column)
rdfValue - the value on the RDF side (a string or URI)

setTranslatorClass

public void setTranslatorClass(java.lang.String className,
                               com.hp.hpl.jena.rdf.model.Resource resource)
Sets a translation class. The translation class must implement the Translator interface. This method will take care of generating an instance of the class.

Parameters:
className - name of a class implementing Translator
resource - the node in the D2RQ map where the d2rq:javaClass statement was found

setTranslator

public void setTranslator(Translator translator)
Sets a Translator.


implementsTranslator

private boolean implementsTranslator(java.lang.Class aClass)

hasConstructorWithArg

private boolean hasConstructorWithArg(java.lang.Class aClass)

invokeConstructorWithArg

private Translator invokeConstructorWithArg(java.lang.Class aClass,
                                            com.hp.hpl.jena.rdf.model.Resource r)

hasConstructorWithoutArg

private boolean hasConstructorWithoutArg(java.lang.Class aClass)

invokeConstructorWithoutArg

private Translator invokeConstructorWithoutArg(java.lang.Class aClass)

addAll

public void addAll(java.util.Map translationMap)
Adds multiple translation mappings.

Parameters:
translationMap - a map of DB => RDF mappings (both strings)

toDBValue

public java.lang.String toDBValue(java.lang.String rdfValue)
Translates an RDF value to a database value.

Specified by:
toDBValue in interface Translator
Parameters:
rdfValue - a value coming from an RDF source
Returns:
the corresponding database value, or null if the RDF value cannot be mapped to a database value

toRDFValue

public java.lang.String toRDFValue(java.lang.String dbValue)
Translates a database value to a RDF value. The RDF value is returned as a String. A NodeMaker should be used to create an RDF node from it.

Specified by:
toRDFValue in interface Translator
Parameters:
dbValue - a value coming from the database
Returns:
the corresponding RDF value, or null if no RDF statements should be created from the database value

getTranslatingValueSource

public ValueSource getTranslatingValueSource(ValueSource valueSource)
Creates a new ValueSource that translates values from the argument ValueSource according to the mappings in this TranslationTable.

Parameters:
valueSource - the ValueSource whose values should be translated
Returns:
a new ValueSource that delivers the mapped values