org.semwebcentral.sweetrules.infrastructure
Class SweetTranslatorRepository

java.lang.Object
  extended byorg.semwebcentral.sweetrules.infrastructure.SweetTranslatorRepository
All Implemented Interfaces:
ISweetTranslatorRepository

public class SweetTranslatorRepository
extends java.lang.Object
implements ISweetTranslatorRepository

This is the implementation of ISweetTranslatorRepository interface

TODO: 1) Think about implications of equals method for adding elements to to the hash set. The point is when do we say 2 kr descriptors are equal

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

Field Summary
private static Logger logger
           
private  java.util.Hashtable sourceIndexedTranslatorDescriptorTable
          Hashtable of known translator descriptors indexed by source krtype
private  java.util.Hashtable targetIndexedTranslatorDescriptorTable
          Hashtable of known translator descriptors indexed by target krtype
 
Constructor Summary
SweetTranslatorRepository()
          Constructor for the Sweet translator repository
 
Method Summary
private  void addToHashtable(ISweetTranslator translator, java.lang.String krType, java.util.Hashtable hashTable)
          Adds the specified translator to the hashtable
 void addTranslator(ISweetTranslator translator)
          Add a translator to the repository
private  boolean causesCycle(ISweetTranslator trans, java.util.Vector pathToSource)
          Utility function that checks if adding a translator to a current list of translators causes a cycle
private  void computeAllPaths(ISweetInvocationDescriptor translatorOptions, java.util.Vector compositeTranslatorCollection)
          This computes all the possible translators from all the sources
private  void dfsEnumerateAllPaths(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetInvocationDescriptor translatorOptions, java.util.Vector pathToSource, java.util.Vector compositeTranslatorCollection)
          Enumerates all the paths from the source to the target
private  void filterNonTargetPaths(ISweetKRDescriptor target, java.util.Vector compositeTranslatorCollection)
          Utility function to filter paths (which have been enumerated by dfsEnumerateAllPaths) which do not have the last element matching with target
 ISweetCompositeTranslator getCompositeTranslator(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetInvocationDescriptor translatorOptions)
          Returns a composite (may involve multiple steps) translator by computing the transitive closure of the required translators.
 java.lang.String getMostPreferredTranslatorClassName(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetCanonicalVersionNumber translatorVersionNumber, ISweetInvocationDescriptor translatorOptions)
          Based on the source, target and the translatorOptions parameters this returns the current most preferred translator class name If no direct translator exists null is returned
 ISweetTranslator getSimpleTranslator(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetInvocationDescriptor translatorOptions)
          Returns a simple(i.e. direct one step) translator if one exists without bothering about transitive closure.
private  boolean needToInvokeCourteousCompiler(ISweetTranslator translator)
          Method to indicate that courteous compiler is to be invoked when performing the translation
 ISweetCompositeTranslator[] searchCompositeTranslators(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetInvocationDescriptor translatorOptions)
          Searches for the repository for translators depending on source, target and options.
 ISweetTranslator[] searchSimpleTranslators(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetInvocationDescriptor translatorOptions)
          Searches for the repository for translators depending on source, target and options.
private  void setDefaultCompositeTranslatorOptions(ISweetCompositeTranslator compositeTranslator, ISweetInvocationDescriptor invocationDescriptor)
          Propagates the options to the composite translator
private  void setDefaultTranslatorOptions(ISweetTranslator translator)
          Sets the default relevant translator options
 void setMostPreferredTranslatorClassName(ISweetKRDescriptor source, ISweetKRDescriptor target, ISweetCanonicalVersionNumber translatorVersionNumber, ISweetInvocationDescriptor translatorOptions, java.lang.String className)
          Based on the source, target, translator version and the translatorOptions parameters this sets the current most preferred translator class name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sourceIndexedTranslatorDescriptorTable

private java.util.Hashtable sourceIndexedTranslatorDescriptorTable
Hashtable of known translator descriptors indexed by source krtype


targetIndexedTranslatorDescriptorTable

private java.util.Hashtable targetIndexedTranslatorDescriptorTable
Hashtable of known translator descriptors indexed by target krtype


logger

private static Logger logger
Constructor Detail

SweetTranslatorRepository

public SweetTranslatorRepository()
Constructor for the Sweet translator repository

Method Detail

addTranslator

public void addTranslator(ISweetTranslator translator)
                   throws SweetTranslatorException
Add a translator to the repository

Specified by:
addTranslator in interface ISweetTranslatorRepository
Parameters:
translator - the translator to be stored in the repository as a "known" translator
Throws:
TranslatorException - if the translator already exists
SweetTranslatorException

getSimpleTranslator

public ISweetTranslator getSimpleTranslator(ISweetKRDescriptor source,
                                            ISweetKRDescriptor target,
                                            ISweetInvocationDescriptor translatorOptions)
                                     throws SweetTranslatorException
Returns a simple(i.e. direct one step) translator if one exists without bothering about transitive closure. If there is no such translator it returns null. If there are multiple translators available then most preferred translator is returned

Specified by:
getSimpleTranslator in interface ISweetTranslatorRepository
Parameters:
source - the source KR format
target - the target KR format
translatorOptions - the options for "complete" translation, i.e. including options for all intermediate translations
Returns:
A translator(simple) instance.
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

setDefaultTranslatorOptions

private void setDefaultTranslatorOptions(ISweetTranslator translator)
                                  throws SweetTranslatorException
Sets the default relevant translator options

Parameters:
translator - The translator to process
Throws:
SweetTranslatorException - if an error occurs

setDefaultCompositeTranslatorOptions

private void setDefaultCompositeTranslatorOptions(ISweetCompositeTranslator compositeTranslator,
                                                  ISweetInvocationDescriptor invocationDescriptor)
                                           throws SweetTranslatorException
Propagates the options to the composite translator

Parameters:
compositeTranslator - The composite translator
invocationDescriptor - The invocation descriptor
Throws:
SweetTranslatorException - if an error occurs

needToInvokeCourteousCompiler

private boolean needToInvokeCourteousCompiler(ISweetTranslator translator)
Method to indicate that courteous compiler is to be invoked when performing the translation

Parameters:
translator - The translator whose options are being set
Returns:
true if courteous compiler *must* be invoked

getCompositeTranslator

public ISweetCompositeTranslator getCompositeTranslator(ISweetKRDescriptor source,
                                                        ISweetKRDescriptor target,
                                                        ISweetInvocationDescriptor translatorOptions)
                                                 throws SweetTranslatorException
Returns a composite (may involve multiple steps) translator by computing the transitive closure of the required translators. If there is no such translator then null is returned

Specified by:
getCompositeTranslator in interface ISweetTranslatorRepository
Parameters:
source - the source KR format
target - the target KR format
translatorOptions - the options for "complete" translation, i.e. including options for all intermediate translations
Returns:
A translator (composite) instance
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

searchCompositeTranslators

public ISweetCompositeTranslator[] searchCompositeTranslators(ISweetKRDescriptor source,
                                                              ISweetKRDescriptor target,
                                                              ISweetInvocationDescriptor translatorOptions)
                                                       throws SweetTranslatorException
Searches for the repository for translators depending on source, target and options. This returns composite translators and considering transitivity and is **very** expensive operation

Specified by:
searchCompositeTranslators in interface ISweetTranslatorRepository
Parameters:
source - The source KR format, if it is null the target is matched
target - The target KR format, if it is null the source is matched Note: if both source and target are null then all combinations are returned
translatorOptions - Options to the translator
Returns:
The translators which match the search criteria
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

computeAllPaths

private void computeAllPaths(ISweetInvocationDescriptor translatorOptions,
                             java.util.Vector compositeTranslatorCollection)
This computes all the possible translators from all the sources

Parameters:
translatorOptions - The options for search currently ignored
compositeTranslatorCollection - The collection to hold the results

dfsEnumerateAllPaths

private void dfsEnumerateAllPaths(ISweetKRDescriptor source,
                                  ISweetKRDescriptor target,
                                  ISweetInvocationDescriptor translatorOptions,
                                  java.util.Vector pathToSource,
                                  java.util.Vector compositeTranslatorCollection)
Enumerates all the paths from the source to the target


filterNonTargetPaths

private void filterNonTargetPaths(ISweetKRDescriptor target,
                                  java.util.Vector compositeTranslatorCollection)
Utility function to filter paths (which have been enumerated by dfsEnumerateAllPaths) which do not have the last element matching with target


causesCycle

private boolean causesCycle(ISweetTranslator trans,
                            java.util.Vector pathToSource)
Utility function that checks if adding a translator to a current list of translators causes a cycle


searchSimpleTranslators

public ISweetTranslator[] searchSimpleTranslators(ISweetKRDescriptor source,
                                                  ISweetKRDescriptor target,
                                                  ISweetInvocationDescriptor translatorOptions)
                                           throws SweetTranslatorException
Searches for the repository for translators depending on source, target and options. This returns only direct translators and does not consider transitivity

Specified by:
searchSimpleTranslators in interface ISweetTranslatorRepository
Parameters:
source - The source KR format, if it is null the target is matched
target - The target KR format, if it is null the source is matched Note: if both source and target are null then null is returned
translatorOptions - Options to the translator
Returns:
The translators which match the search criteria
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

getMostPreferredTranslatorClassName

public java.lang.String getMostPreferredTranslatorClassName(ISweetKRDescriptor source,
                                                            ISweetKRDescriptor target,
                                                            ISweetCanonicalVersionNumber translatorVersionNumber,
                                                            ISweetInvocationDescriptor translatorOptions)
                                                     throws SweetTranslatorException
Based on the source, target and the translatorOptions parameters this returns the current most preferred translator class name If no direct translator exists null is returned

Specified by:
getMostPreferredTranslatorClassName in interface ISweetTranslatorRepository
Parameters:
source - The source KR format
target - The target KR format
translatorVersionNumber - The version number of the translator
translatorOptions - Options to the translator
Returns:
The current most preferred direct translator or null if no such translator exists
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

setMostPreferredTranslatorClassName

public void setMostPreferredTranslatorClassName(ISweetKRDescriptor source,
                                                ISweetKRDescriptor target,
                                                ISweetCanonicalVersionNumber translatorVersionNumber,
                                                ISweetInvocationDescriptor translatorOptions,
                                                java.lang.String className)
                                         throws SweetTranslatorException
Based on the source, target, translator version and the translatorOptions parameters this sets the current most preferred translator class name

Specified by:
setMostPreferredTranslatorClassName in interface ISweetTranslatorRepository
Parameters:
source - The source KR format
target - The target KR format
translatorVersionNumber - The version number of the translator
translatorOptions - Options to the translator
className - The class name of the most preferred direct translator
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

addToHashtable

private void addToHashtable(ISweetTranslator translator,
                            java.lang.String krType,
                            java.util.Hashtable hashTable)
Adds the specified translator to the hashtable

Parameters:
translator - The descriptor of the translator to be added
krType - The key KR type
hashTable - The hashtable which needs to hold the translator