org.semwebcentral.sweetrules.sweetcr
Class SweetCR33TranslationWrapper

java.lang.Object
  extended byorg.semwebcentral.sweetrules.sweetcr.SweetCR33TranslationWrapper

public class SweetCR33TranslationWrapper
extends java.lang.Object

Modification time-stamp: Aug 25, 2004, 1:52:18 PM Title : SweetCR33TranslationWrapper Descritption : This is top level wrapper for CommonRules33 Translator This knows all the details about CR33 and it's APIs and switches

TODO: 1) Enhance getFormatSwitchPrefix for other formats like kif 2) Implement isSupportedTranslation 3) Think about handling options particularly in prepareArgsForMain

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

Field Summary
private static java.lang.String inSuffix
          The suffix for the "in" option of CR33 e.g. xmlin, xsbin etc
private static java.lang.String NO_DISPLAY_OPTION
          The nodisplay option for commonrules
private static java.lang.String outSuffix
          The suffix for the "out" option of CR33 e.g. xmlout, xsbout etc
private static java.lang.String tempFilePattern
          Temporary file pattern
 
Constructor Summary
SweetCR33TranslationWrapper()
           
 
Method Summary
private  java.lang.String getCR33PreferredExtension(ISweetKRDescriptor descriptor)
          If the input is BRML, common rules wants a .xml extension otherwise it throws an exception.
private  java.lang.String getFormatInSwitch(ISweetKRDescriptor sourceDescriptor)
          Returns the format switch appended with "in"
private  java.lang.String getFormatOutSwitch(ISweetKRDescriptor targetDescriptor)
          Returns the format switch appended with "out"
private  java.lang.String getFormatSwitchPrefix(ISweetKRDescriptor descriptor)
          Returns the format switch depending on the descriptor
private  java.lang.String invokeCRMain(ISweetTranslator translator)
          Invoke common rules main function.
private  boolean isSupportedTranslation(ISweetTranslator translator)
          Checks if the specified translation is acceptable to CommonRules
private  boolean needToInvokeCourteousCompiler(ISweetTranslator translator)
          Determines if the courteous compiler needs to be invoked for the specified translator
 java.lang.String translateRequestHandler(ISweetTranslator translator)
          Top level method given a translator object the request is processed
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inSuffix

private static final java.lang.String inSuffix
The suffix for the "in" option of CR33 e.g. xmlin, xsbin etc

See Also:
Constant Field Values

outSuffix

private static final java.lang.String outSuffix
The suffix for the "out" option of CR33 e.g. xmlout, xsbout etc

See Also:
Constant Field Values

NO_DISPLAY_OPTION

private static final java.lang.String NO_DISPLAY_OPTION
The nodisplay option for commonrules

See Also:
Constant Field Values

tempFilePattern

private static final java.lang.String tempFilePattern
Temporary file pattern

See Also:
Constant Field Values
Constructor Detail

SweetCR33TranslationWrapper

public SweetCR33TranslationWrapper()
Method Detail

translateRequestHandler

public java.lang.String translateRequestHandler(ISweetTranslator translator)
                                         throws SweetTranslatorException
Top level method given a translator object the request is processed

Parameters:
translator - The translator which needs to be processed
Returns:
The transformed string
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

invokeCRMain

private java.lang.String invokeCRMain(ISweetTranslator translator)
                               throws SweetTranslatorException
Invoke common rules main function. This is because the API does not seem to work properly

Parameters:
translator - The translator to be processed
Returns:
Translated string
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

needToInvokeCourteousCompiler

private boolean needToInvokeCourteousCompiler(ISweetTranslator translator)
Determines if the courteous compiler needs to be invoked for the specified translator

Parameters:
translator - The translator to check
Returns:
true if courteous compiler should be invoked (e.g. will be true for XSB)

getCR33PreferredExtension

private java.lang.String getCR33PreferredExtension(ISweetKRDescriptor descriptor)
                                            throws SweetTranslatorException
If the input is BRML, common rules wants a .xml extension otherwise it throws an exception. To be safe depending on the krType this function returns the "working" extension

Parameters:
descriptor - The descriptor which needs to be mapped to an acceptable extension
Returns:
The preferrred extension
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

isSupportedTranslation

private boolean isSupportedTranslation(ISweetTranslator translator)
Checks if the specified translation is acceptable to CommonRules

Parameters:
translator - The translator with the specification of translation
Returns:
true if translation is supported, false otherwise

getFormatInSwitch

private java.lang.String getFormatInSwitch(ISweetKRDescriptor sourceDescriptor)
                                    throws SweetTranslatorException
Returns the format switch appended with "in"

Parameters:
sourceDescriptor - The KR descriptor for which the format switch is needed
Returns:
format Switch appended with in
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

getFormatOutSwitch

private java.lang.String getFormatOutSwitch(ISweetKRDescriptor targetDescriptor)
                                     throws SweetTranslatorException
Returns the format switch appended with "out"

Parameters:
targetDescriptor - The KR descriptor for which the format switch is needed
Returns:
format Switch appended with out
Throws:
TranslatorException - if an error occurs
SweetTranslatorException

getFormatSwitchPrefix

private java.lang.String getFormatSwitchPrefix(ISweetKRDescriptor descriptor)
                                        throws SweetTranslatorException
Returns the format switch depending on the descriptor

Parameters:
descriptor - The KR descriptor for which the format switch is needed
Returns:
format Switch
Throws:
TranslatorException - if an error occurs
SweetTranslatorException