Jostraca Example: Simple Data Container
example index
www.jostraca.org
info@jostraca.org

Description:

A simple data container with get and set methods. The meta data is hard coded into the template. < code > main.CodeWriter < /code > is used to specify the name of the code writer explicitly.

Generate Command:

> jostraca Simple_java.jtm
(you can also use generate.bat or generate.sh)

Generated Files:

Person.java
Point.java
.jostraca/SimpleWriter.java
.jostraca/SimpleWriter.class

Experiments:

Try adding new entities: "Person", "Point", "Address", etc
Try changing the properties: "FirstName", "SecondName", "Title", etc

Template Contents:

<% @conf 
main.JostracaVersion = 0.4
main.CodeWriter      = SimpleWriter 
%>

<% init!

  _setFileNameRoots( new String[] {"Person", "Point"} );
  _setFileNameSuffix( ".java" );

  // create meta data

  String[][] allProps = {  
     { "FirstName", "SecondName" } // for Person
    ,{ "X", "Y" }                  // for Point
  };
 
  String[][] allTypes = { 
     { "String", "String" }        // for Person
    ,{ "int", "int"       }        // for Point
  };
%>

<%
  // get meta data for the current file
  int      fileIndex = _getFileIndex();
  String[] props     = allProps[ fileIndex ];
  String[] types     = allTypes[ fileIndex ]; 
%>

public class <%=_getFileNameRoot()%> {

  <% for( int propI = 0; propI < props.length; propI++ ) { %>
  private <%=types[propI]%> i<%=props[propI]%>;
  <% } %>


  <% for( int propI = 0; propI < props.length; propI++ ) { %>

  public <%=types[propI]%> get<%=props[propI]%>() {
    return i<%=props[propI]%>;
  }

  public void set<%=props[propI]%>( <%=types[propI]%> r<%=props[propI]%> ) {
    i<%=props[propI]%> = r<%=props[propI]%>;
  }

  <% } %>

}
 

Generated File Contents:

Note: only one generated file is shown





public class Person {

  
  private String iFirstName;
  
  private String iSecondName;
  


  

  public String getFirstName() {
    return iFirstName;
  }

  public void setFirstName( String rFirstName ) {
    iFirstName = rFirstName;
  }

  

  public String getSecondName() {
    return iSecondName;
  }

  public void setSecondName( String rSecondName ) {
    iSecondName = rSecondName;
  }

  

}
 

   example index
   Copyright © 2000-2002 Richard Rodger License.