|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Class Summary | |
Account | |
Balance | |
RunIt |
This example illustrates child filtering.
You can run it with "ant -f runexample4.xml
" from the root of the distribution.
Suppose I have a class that defines an attribute I wish to be excluded from the string representation. It may be an attribute that is especially lengthy, provides redundant information, or perhaps contains sensitive information we wish to keep out of the logs. Then we can define a child filter to exclude this attribute from stringification.
In this example we introduce three attributes to the Account
class that we wish to exclude:
public class Account {
private Balance currentBalance = new Balance(100.00, "USD", new Date());
private Balance endingBalance = new Balance(62.44, "USD", new Date() );
private Balance ledgerBalance = new Balance(89.75, "USD", new Date());
private String id = "123";
private String useless1 = "Useless attribute 1";
private String useless2 = "Useless attribute 2";
private String useless3 = "Useless attribute 3";
}
Child filtering can also be used to change the names of existing children. To illustrate this let's prefix "the
" to each field name.
The "jestr.properties
" file is shown below:
jestr.childFilter.accountChildFilter=clone-of-regex
jestr.childFilter.accountChildFilter.nameExcludes=.*Useless.*
jestr.childFilter.accountChildFilter.substitutions=^(.)=\\U$1\\E,^=the
jestr.stringifier.account=clone-of-default
jestr.stringifier.account.childFilter=accountChildFilter
jestr.category.jestr.examples.example4.Account=account
The output is as follows:
Account(
Balance theCurrentBalance = Balance(100.0 USD as of Sat Mar 20 00:04:07 EST 2004)
Balance theEndingBalance = Balance(62.44 USD as of Sat Mar 20 00:04:07 EST 2004)
Balance theLedgerBalance = Balance(89.75 USD as of Sat Mar 20 00:04:07 EST 2004)
String theId = "123"
)
The three attributes with the word "useless
" in the name were omitted per the ".*Useless.*
" regular expression,
and the names have been changed as dicated by the two substitutions listed.
|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |