Create a Custom Java Translator Class
For custom security labels a custom Java translator class can be used to convert the internal form of the security label value into the external form of the security label value or back again. To do this, the class must extend the wt.access.CustomSecurityLabelValueTranslator class. The internal form is used by Windchill during access evaluations and is stored in the database. The external form is what is displayed in the Windchill interface and what users will enter when specifying a security label value. If no translator class is defined, the external form is the same as the internal form and is what is stored in the database.
There are certain restrictions on what can be included in the internal form. The equals (=) and comma (,) characters cannot be stored in the database. If your user-entered security label values will use either of these characters, you must use a translator class to remove them from the internal name. Similarly, the string NULL cannot be stored in the database. Using a custom Java translator class also allows you to have longer security label value names. The security label attribute is limited to 4000 characters in the database, so having lengthy security label values can cause a storage issue. By specifying a custom translator class, you can have descriptive label values in the Windchill user interface using an external form and less user-friendly values stored in the database using an internal form. A custom translator class can also be used to validate custom security label values, particularly in cases where there is no user interface to validate the user-specified label values.
The wt.access.CustomSecurityLabelValueTranslator class contains two methods:
• getExternalValue - Returns the external value associated with a given internal value.
• getInternalValue - Returns the internal value associated with a given external value.
The following simple example removes the restricted comma character (,) and replaces it with an unrestricted plus character (+). This example assumes that the external value never contains a plus character (+).
public class CustomTranslator implements CustomSecurityLabelValueTranslator {
public String getExternalValue(String label_name, String internal_value)
throws WTException {
return internal_value.replace("+", ",");
}
public String getInternalValue(String label_name, String external_value)
throws WTException {
return external_value.replace(",", "+");
}
}
Each method must always return the same answer when given the same input. If you anticipate the internal value changing over time, consider putting a version number in the string. For example, if a custom security label represents third party companies with whom you work, you may need to add the countries in which each third party has offices at some point in the future. Initially, one external value could be “Company A”, with the internal value of “1:A”. In the future, when office locations of Company A need to be represented, the external value could change to “Company A (US)” and “Company A (UK)”. The corresponding internal values could change to “2:A-US” and “2:A-UK”. The version number can be used to let the custom translator class know how to translate each version individually since the database might have both versions stored.
For more information about working with class files, see
Managing Customizations.