org.semwebcentral.sweetrules.infrastructure
Class AbstractSweetTranslator

java.lang.Object
  extended byorg.semwebcentral.sweetrules.infrastructure.AbstractSweetTranslator
All Implemented Interfaces:
java.lang.Cloneable, ISweetTranslator
Direct Known Subclasses:
AbstractSweetCompositeTranslator, SweetB2CLPTranslator, SweetB2RTranslator, SweetB2XSBTranslator, SweetBRML2KIFTranslator, SweetBRML2SmodelsTranslator, SweetCLP2BRMLTranslator, SweetCLP2XSBTranslator, SweetJess2RuleMLTranslator, SweetKIF2BRMLTranslator, SweetOWL2DLPCompilerTranslator, SweetR2BTranslator, SweetRuleML2JessTranslator, SweetRuleMLFacts2RDFTranslator, SweetSmodels2BRMLTranslator, SweetSWRLRDF2SWRLXMLTranslator, SweetSWRLXML2CLIPSTranslator, SweetSWRLXML2JenaTranslator, SweetSWRLXML2SWRLRDFTranslator, SweetXSB2CLPTranslator

public abstract class AbstractSweetTranslator
extends java.lang.Object
implements ISweetTranslator

An abstract implementation of ISweetTranslator interface providing some default get/set methods and constructor support for code reuse and extensibility. The new translators will mainly need to implement translate () method, the rest have "good" defaults in this class

Author:
Shashidhara K Ganjugunte, Dr. Benjamin Grosof, Dr. Said Tabet, Chitravanu Neogy

Field Summary
protected  Logger logger
          The logger object
protected  ISweetKBDescriptor sourceKBDescriptor
          The source KB descriptor
protected  ISweetKBDescriptor targetKBDescriptor
          The target KB descriptor
protected  ISweetTranslatorDescriptor translatorDescriptor
          The descriptor for the translator
 
Constructor Summary
AbstractSweetTranslator(ISweetTranslatorDescriptor descriptor, ISweetKBDescriptor sourceKBDescriptor, ISweetKBDescriptor targetKBDescriptor)
          Constructor for the abstract class
 
Method Summary
 java.lang.Object clone()
          The clone method to clone this object
 java.lang.String getSourceData()
          Returns the source data which will be translated
 ISweetTranslatorDescriptor getTranslatorDescriptor()
          Retrievs the translator descriptor of this object
protected  void loadAllNamespacesAndEntities()
          Loads all the namespaces and entity declarations from the source XML kb.
 void print()
          Friendly method for printing
 void setSourceData(java.lang.String sourceData)
          Set the source data to be translated
 void setSourceKBDescriptor(ISweetKBDescriptor kbDescriptor)
          Sets the source KB descriptor
 void setTargetKBDescriptor(ISweetKBDescriptor kbDescriptor)
          Sets the target KB descriptor
 void setTranslatorDescriptor(ISweetTranslatorDescriptor translatorDescriptor)
          Sets the translator descriptor for this class
 void trace()
          Trace API to help debugging
protected  void writeToTargetKB(java.lang.String translatedData)
          Writes the result of the translation to the target KB if the descriptor is not null
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.semwebcentral.sweetrules.infrastructure.ISweetTranslator
translate
 

Field Detail

sourceKBDescriptor

protected ISweetKBDescriptor sourceKBDescriptor
The source KB descriptor


targetKBDescriptor

protected ISweetKBDescriptor targetKBDescriptor
The target KB descriptor


translatorDescriptor

protected ISweetTranslatorDescriptor translatorDescriptor
The descriptor for the translator


logger

protected Logger logger
The logger object

Constructor Detail

AbstractSweetTranslator

public AbstractSweetTranslator(ISweetTranslatorDescriptor descriptor,
                               ISweetKBDescriptor sourceKBDescriptor,
                               ISweetKBDescriptor targetKBDescriptor)
Constructor for the abstract class

Parameters:
descriptor - The descriptor of the class which extends this translator
sourceKBDescriptor - The source KB to be translated
targetKBDescriptor - The target KB to store the result of translation
Method Detail

setSourceKBDescriptor

public void setSourceKBDescriptor(ISweetKBDescriptor kbDescriptor)
Sets the source KB descriptor

Specified by:
setSourceKBDescriptor in interface ISweetTranslator
Parameters:
kbDescriptor - The source KB descriptor

setTargetKBDescriptor

public void setTargetKBDescriptor(ISweetKBDescriptor kbDescriptor)
Sets the target KB descriptor

Specified by:
setTargetKBDescriptor in interface ISweetTranslator
Parameters:
kbDescriptor - The target KB descriptor

getSourceData

public java.lang.String getSourceData()
                               throws SweetTranslatorException
Returns the source data which will be translated

Specified by:
getSourceData in interface ISweetTranslator
Returns:
The source data which will be subject to translation
Throws:
SweetTranslatorException - if an error occurs while fetching source data

setSourceData

public void setSourceData(java.lang.String sourceData)
Set the source data to be translated

Specified by:
setSourceData in interface ISweetTranslator
Parameters:
sourceData - The data which needs to be translated

getTranslatorDescriptor

public ISweetTranslatorDescriptor getTranslatorDescriptor()
Retrievs the translator descriptor of this object

Specified by:
getTranslatorDescriptor in interface ISweetTranslator
Returns:
The tranlator describing the translation performed by this object

setTranslatorDescriptor

public void setTranslatorDescriptor(ISweetTranslatorDescriptor translatorDescriptor)
Sets the translator descriptor for this class

Specified by:
setTranslatorDescriptor in interface ISweetTranslator
Parameters:
translatorDescriptor - An instance of class implementing ISweetTranslatorDescriptor which describes the translation performed by this class

print

public void print()
Friendly method for printing

Specified by:
print in interface ISweetTranslator

trace

public void trace()
Trace API to help debugging


writeToTargetKB

protected void writeToTargetKB(java.lang.String translatedData)
                        throws SweetTranslatorException
Writes the result of the translation to the target KB if the descriptor is not null

Parameters:
translatedData - The translated data
Throws:
SweetTranslatorException - if an error occurs

loadAllNamespacesAndEntities

protected void loadAllNamespacesAndEntities()
                                     throws SweetTranslatorException
Loads all the namespaces and entity declarations from the source XML kb. This is a simple wrapper for the corresponding method in SweetEntityAndNamespaceManager

Throws:
SweetTranslatorException - if an error occurs

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
The clone method to clone this object

Specified by:
clone in interface ISweetTranslator
Returns:
The cloned object
Throws:
java.lang.CloneNotSupportedException - if an error occurs