This section describes the example of RTF model explanation_model.rtf which you can find into jar rtftemplate-usecase-version into directory /usecases/explanation. This model contains all use cases which you can find when you are designing a RTF model.
This RTF source model display information about Project like project name, list of developpers and list of jar dependencies. The RTF target model display information about Project Jakarta Velocity
This section follow steps described into User Guide :
The context is the java object used and the key used when you are putting the context into Velocity engine. Here RTF model explanation_model.rtf context :
public class Project { private String name; public Project(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
putted into context with key project :
template.put("project", new Project("Jakarta Velocity"));
public class Developer { private String name; private String email; private Collection roles; public Developer(String name, String email) { this.name = name; this.email = email; roles = new ArrayList(); } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Collection getRoles() { return roles; } public void setRoles(Collection roles) { this.roles = roles; } public void addRole(Role role) { roles.add(role); } public void addRole(String roleName) { addRole(new Role(roleName)); } }
putted into context with key developers :
List developers = new ArrayList(); Developer developer = new Developer("Will Glass-Husain", "wglass@apache.org"); developer.addRole("Java Developer"); developer.addRole("Release Manager"); developers.add(developer); developer = new Developer("Geir Magnusson Jr.", "geirm@apache.org"); developer.addRole("Java Developer"); developer.addRole("Release Manager"); developers.add(developer); developer = new Developer("Daniel L. Rall", "dlr@finemaltcoding.comg"); developer.addRole("Java Developer"); developer.addRole("Release Manager"); developers.add(developer); template.put("developers", developers );
public class Dependency { private String artifactID; private String type; private String version; private String url; public Dependency(String artifactID, String type, String version, String url) { this.artifactID = artifactID; this.type = type; this.version = version; this.url = url; } public String getArtifactID() { return artifactID; } public void setArtifactID(String artifactID) { this.artifactID = artifactID; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } }
putted into context with key dependencies :
List dependencies = new ArrayList(); Dependency dependency = new Dependency("commons-collection", "jar", "1.0", "http://jakarta.apache.org/commons/collection/"); dependencies.add(dependency); dependency = new Dependency("logkit", "jar", "1.0.1", "http://logkit"); dependencies.add(dependency); dependency = new Dependency("oro", "jar", "2.0.8", "http://jakarta.apache.org/oro/"); dependencies.add(dependency); template.put("dependencies", dependencies );