Package jestr.examples.example5

This example illustrates more advanced usage of the "standard" predicate.

See:
          Description

Class Summary
RunIt  
TestObject1  
TestObject2  
 

Package jestr.examples.example5 Description

This example illustrates more advanced usage of the "standard" predicate. You can run it with "ant -f runexample5.xml" from the root of the distribution.

The classes in this example are listed below:


    public class TestObject1 {
        public String toString() {
            return Jestr.str(this);
        }

        private Date dt1 = new Date();
        private Date dt2 = new Date();
    }

    public class TestObject2 {
        public String toString() {
            return Jestr.str(this);
        }

        private Date dt1 = new Date();
        private Date dt2 = new Date();
    }

    public class RunIt {
        public static void main(String[] argv) {
            System.out.println( new TestObject1() );
            System.out.println( new TestObject2() );
        }
    }

The classes "TestObject1" and "TestObject2" are identical, but to illustrate some properties of the "standard" predicate, let's suppose we want date "dt1" to print in a special format only if it is an attribute of "TestObject1". The "jestr.properties" file to accomplish this is shown below:


    jestr.predicate.mypred1=clone-of-standard
    jestr.predicate.mypred1.nameIncludes=dt1
    jestr.predicate.mypred1.classes=java.util.Date
    jestr.predicate.mypred1.parentClasses=jestr.examples.example5.TestObject1
    jestr.stringifier.test1=clone-of-date
    jestr.stringifier.test1.predicates=mypred1
    jestr.stringifier.test1.dateFormat=MM/dd/yy@HH:mm

The output is as follows:


    TestObject1(
        Date dt1 = 03/14/04@19:14
        Date dt2 = Sun Mar 14 19:14:30 EST 2004
    )

    TestObject2(
        Date dt1 = Sun Mar 14 19:14:31 EST 2004
        Date dt2 = Sun Mar 14 19:14:31 EST 2004
    )

The dt1 field of TestObject1 printed using our special date format, as shown in red, while the same field of TestObject2 failed to match the predicate and so was printed in the default format.



Copyright (c) 2001-2003 - Apache Software Foundation