org.openeai.config
Class EnterpriseTranslator


java.lang.Object

  |

  +--org.openeai.OpenEaiObject

        |

        +--org.openeai.config.EnterpriseTranslator


public class EnterpriseTranslator
extends OpenEaiObject

This object is used to perform translations from application values to Enterprise values and vice versa. It contains a Hashtable of EnterpriseMapping objects and uses those mappings to translate the values. The information in the Mappings is specified in the EnterpriseObjects document and are associated to a specific field.

This object is built by the EnterpriseFields object when that object is initialized and it reads through the EnterpriseObjects XML Document and finds a Field that has a Translation associated with it.

For example, the 'Enterprise Values' as specified in a hypothetical EnterpriseObject document for the Gender Element in the BasicPerson object are 'Male' and 'Female'. This means that those are the only allowable values that can be set on the BasicPerson.gender instance variable. Data is set on the gender field via the BasicPerson.setGender(String) method. When this data is passed through the BasicPerson's EnterpriseFields object in that setter method, it attempts to translate the value being passed in to one of these enterprise values if possible. If the data passed in is not equal to or cannot be translated to an enterprise value, an exception is thrown.

Version:
3.0 beta2 - 28 January 2003
Author:
Tod Jackson (tod@openeai.org), Steve Wheat (steve@openeai.org)
See Also:
Field, EnterpriseMapping, EnterpriseFormatter, EnterpriseFields

Field Summary
 
Fields inherited from class org.openeai.OpenEaiObject
logger
 
Constructor Summary
EnterpriseTranslator()
          Constructor
 
Method Summary
 void addMapping(java.lang.String objectFieldName, java.util.List vMapsForField)
          Adds a list of EnterpriseMapping objects to this translator to the Hashtable of mappings.
 java.lang.String convertToAppValue(java.lang.String appName, java.lang.String objectFieldName, java.lang.String fieldName, java.lang.String enterpriseValue)
          This method converts the enterprise value passed in to the corresponding application specific value and returns that value for the field specified.
 java.lang.String convertToEnterpriseValue(java.lang.String objectFieldName, java.lang.String fieldName, java.lang.String value, boolean isRequired)
          This method converts the value passed in to the enterprise value and returns that value for the field specified.
 java.util.Hashtable getMappings()
          Returns a Hashtable of EnterpriseMapping objects associated to this translator.
 java.lang.String toString()
           
 
Methods inherited from class org.openeai.OpenEaiObject
addLog4jProperty, getAppName, getDebug, getFromAddr, getLog4jProperties, getMailHost, getMailService, getProperties, getToAddr, initializeLog4j, initializeLog4j, initializeLog4j, setAppName, setDebug, setFromAddr, setMailHost, setMailService, setProperties, setToAddr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnterpriseTranslator


public EnterpriseTranslator()
Constructor

Method Detail

getMappings


public final java.util.Hashtable getMappings()
Returns a Hashtable of EnterpriseMapping objects associated to this translator.

Returns:
Hashtable the mappings associated to this translator.

addMapping


public final void addMapping(java.lang.String objectFieldName,
                             java.util.List vMapsForField)
                      throws EnterpriseTranslationException
Adds a list of EnterpriseMapping objects to this translator to the Hashtable of mappings. This the key of this Hashtable is the concatenation of the parent object plus the field name (for uniqueness). For example, the BasicPerson/Gender field contains a list of mappings. The key for that list of mappings would be "BasicPerson/Gender". This way, if Gender is ever used in another object besides BasicPerson, we can distinguish between the two.

EnterpriseTranslationException

convertToEnterpriseValue


public final java.lang.String convertToEnterpriseValue(java.lang.String objectFieldName,
                                                       java.lang.String fieldName,
                                                       java.lang.String value,
                                                       boolean isRequired)
                                                throws EnterpriseTranslationException
This method converts the value passed in to the enterprise value and returns that value for the field specified. It uses it's list of EnterpriseMappings to check and see if it can find an application specific value that matches the value passed in. If it does, it returns the enterprise value associated to the mapping that contains that application value. If the value passed in is empty and the field is not required and there is no mapping that accounts for an empty application value, the method will return an empty string. All other values passed in must result in a successful mapping from applicaiton to enterprise value or an exception will be thrown.

This method is called by the EnterpriseFields.getEnterpriseValue method.

Returns:
String the enterprise value
Throws:
EnterpriseTranslationException - if the application value cannot be successfully mapped to an enterprise value.
See Also:
EnterpriseMapping, EnterpriseFields.getEnterpriseValue(String, String, String)

convertToAppValue


public final java.lang.String convertToAppValue(java.lang.String appName,
                                                java.lang.String objectFieldName,
                                                java.lang.String fieldName,
                                                java.lang.String enterpriseValue)
                                         throws EnterpriseTranslationException
This method converts the enterprise value passed in to the corresponding application specific value and returns that value for the field specified. It uses it's list of EnterpriseMappings to check and see if it can find an enterprise value that matches the value passed in. If it does, it then attempts to find an application specific value that the enterprise value should be mapped to for the application name passed in. If no application specific value can be located, it will simply return the enterprise value passed in.

Note, applications may have multiple application specific values that get translated to one enterprise value but that enterprise value can only be converted back to ONE application value. Therefore, when these mappings are specified in the EnterpriseObjects documents, application specific values that will be used for "reverse translations" must be indicated as such by specifying the "preferred" attribute with a value of "true". This way, if there is more than one application value associated to a field for the same application the foundation will know which application value should be used when a reverse translation is performed.

This method is called by the EnterpriseFields.getApplicationValue method.

Returns:
String the application specific value that maps to the enterprise value passed in or simply the enterprise value passed in if no "reverse" translations exist for the field.
Throws:
EnterpriseTranslationException - if an error occurs attempting to map the enterprise value to an application value.
See Also:
EnterpriseMapping, EnterpriseFields.getApplicationValue(String, String, String, String)

toString


public final java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2002, OpenEAI Software Foundation