Java Virtal Machine.net

[ News ] rss

February 01, 2011

Mark Wielaard: New GPG key. Finally created a new GPG key using gnupg. The old one was a DSA/1024 bits one and 8 years old. The new one is a RSA/2048 bits one. I will use the new one in the future to sign any release tarballs I might create. pub 2048R/57816A6A 2011-01-29 Key f...

More »

February 01, 2011

Andrew Hughes: [SECURITY] IcedTea6 1.7.8, 1.8.5, 1.9.5 Released!. We are pleased to announce a new set of security releases, IcedTea6 1.7.8, IcedTea6 1.8.5 and IcedTea6 1.9.5. This update contains the following security updates: The IcedTea project provides a harness to build the source code from OpenJDK6 u...

More »

December/2024
SunMonTueWedThuFriSat
1234567
891011121314
15161718192021
22232425 262728
293031    

[ Archives News
for 'Java Technology' ]

home > news > java technology > stringtemplate part 3: complex data types and renderers

StringTemplate Part 3: Complex Data Types and Renderers

In Part 1 and Part 2 we dealt with simple data types who's string representation is well known. Complex data types may not have a string representation that meets the needs of a particular template. // Example 1: Some objects don't have a useful toString() Object objectParamater = new Object(); StringTemplate template = new StringTemplate("Hello $param$ !"); template.setAttribute("param", objectParamater); System.out.println(template); Output: Hello java.lang.Object@18eb9e6 ! Your output will very but I think it's safe to say that in most cases this output is undesirable. Here is another example of a well intentioned toString() that just won't do for our purposes. //Example 2: Even a well intentioned toString() methods may not be useful. Planet mars = createMars(); template = new StringTemplate("Hello $param$ !"); template.setAttribute("param", mars); System.out.println("Example 2:"); System.out.println(template); Output: Example 2: Hello Planet [atmosphere=CO2 N2, diameter=0.532, inclinationToSunsEquator=5.65, mass=0.11, moons=[Phobos, Deimos], name=Mars, orbitalEccentricity=0.093, orbitalPeriod=1.88, orbitalRadius=1.52, rings=false, rotationPeriod=1.03] ! For object that follow the JavaBean specification (getters and setters) StringTemplate provides property access via the “.” notation. This allows you to access properties from within your template. //Example 3: Dot notati...


Date: June, 07 2010
Url: http://www.java.net/blog/aberrant/archive/2010/06/07/stringtemplate-part-3-complex-data-types-and-renderers


Others News

©2002-2019Java-Virtual-Machine.net es | bootstrap navbar examples | bootstrap modal popup | wowslider.com | free bootstrap templates