Jostraca Example: Simple Exception Maker
example index
www.jostraca.org
info@jostraca.org

Description:

This template creates a set of simple Exception classes listed in a text file in the following format: FooException; BarException; ... See the < code > org.jostraca.resource.DataObject < /code > class for more details on this format.

Generate Command:

> jostraca SimpleExceptionMaker.jtm exceptionlist.txt my.package
(you can also use generate.bat or generate.sh)

Generated Files:

SimpleExceptionMaker.java
.jostraca/SimpleExceptionMakerWriter.java
.jostraca/SimpleExceptionMakerWriter.class
FooException.java
BarException.java

Experiments:

Try changing the list of exceptions in exceptionlist.txt.

Template Contents:

<% @conf 
main.JostracaVersion = 0.4
%>

<% import!
import org.jostraca.resource.SimpleDataObjectReader;
import org.jostraca.resource.SimpleDataObject;
%>

<% init!
  String exceptionListFile = _getFirstUserArg();
  String exceptionPackage  = _getSecondUserArg();

  SimpleDataObject[]     dos    = SimpleDataObjectReader.read( exceptionListFile, 0 );
  int              numDos = dos.length;
  String[]         doName = new String[ numDos ];

  for( int doI = 0; doI < numDos; doI++ ) {
    doName[ doI ] = dos[ doI ].getName();
  }

   _setFileNameRoots( doName );

%>

<% int fileI = _getFileIndex(); %>

<% if( !"".equals( exceptionPackage ) ) { %>
package <%=exceptionPackage%>;
<% } %>

public class <%=doName[fileI]%> extends Exception {

  public <%=doName[fileI]%>() {
    super();
  }

  public <%=doName[fileI]%>( String rMessage ) {
    super( rMessage );
  }

}
 

Generated File Contents:

Note: only one generated file is shown








package my.package;


public class FooException extends Exception {

  public FooException() {
    super();
  }

  public FooException( String rMessage ) {
    super( rMessage );
  }

}
 

   example index
   Copyright © 2000-2002 Richard Rodger License.