The previous section discussed using external methods from the package java.lang, which contains public Java API's. It is possible for you to write your own public static methods in your own Java class. As long as all the conditions outlined in the first section are met, a user-written external method can be used in an Connect CDC expression.
In the example that follows, the public static methods “country” and “language” could be coded in the following class TestUser, written to the file TestUser.java:
import java.util.Locale;
/** This is a class to test the calling of an external static
* user method from a user expression. The methods would be
* invoked as follows:
* <p>TestUser.<method_name>()
* <p>where <method_name> is the name of a method in this
* class.
*/
public class TestUser
{/** This is the default locale. */
static private Locale m_myLocale = Locale.getDefault();
/** Dummy c'tor that is never called. */
private TestUser (){}
/** This method returns the string representation
* of the country associated with the default
* "java locale" which is active for the process.
*/
static public String country()
{
// return our country
return m_myLocale. getDisplayCountry();
}
/** This method returns the string representation
* of the language associated
* with the default "java locale" which is active for the
* process.
*
*/
static public String language()
{
// return our language
return m_myLocale. getDisplayLanguage();
}
} // end TestUser
When the above Java file is compiled using javac, the class file, TestUser.class is created. If this class is accessible in the CLASSPATH, then the two methods can be used in an Connect CDC expression.
For example:
concat('My country=',TestUser.country());
yields the result:
My country=United States
And the expression:
concat('My language=',TestUser.language());
yields the result:
My language=English