package com.evisioner.util.ant;
import java.util.*;
import org.apache.tools.ant.*;
/**
* runs castor's org.exolab.castor.builder application (see the SourceGen.bat file).
* takes the following args:
*
* - package
*
- file — the .xsd
*
- platform — mac | unix | win
*
- verbose — true | false
*
- destination
*
- description
*
- factory — fully qualified class name
*
- marshall — true | false
*
- testable — true | false
*
- sax1 — true | false
*
* @author d.kershaw
*/
public class CastorSourceGenTask extends ProjectComponent {
String mPackage;
String mFile;
String mPlatform;
String mVerbose;
String mDestination;
String mDescription;
String mFactory;
String mMarshall;
String mTestable;
String mSax1;
public String getPackage() {
return mPackage;
}
public void setPackage( String s ) {
mPackage = s;
}
public String getFile() {
return mFile;
}
public void setFile( String s ) {
mFile = s;
}
public String getPlatform() {
return mPlatform;
}
public void setPlatform( String s ) {
mPlatform = s;
}
public String getVerbose() {
return mVerbose;
}
public void setVerbose( String s ) {
mVerbose = s;
}
public String getDestination() {
return mDestination;
}
public void setDestination( String s ) {
mDestination = s;
}
public String getDescription() {
return mDescription;
}
public void setDescription( String s ) {
mDescription = s;
}
public String getFactory() {
return mFactory;
}
public void setFactory( String s ) {
mFactory = s;
}
public String getMarshall() {
return mMarshall;
}
public void setMarshall( String s ) {
mMarshall = s;
}
public String getTestable() {
return mTestable;
}
public void setTestable( String s ) {
mTestable = s;
}
public String getSax1() {
return mSax1;
}
public void setSax1( String s ) {
mSax1 = s;
}
/**
* Called by the project to let the task do it's work. This method may be
* called more than once, if the task is invoked more than once. For example,
* if target1 and target2 both depend on target3, then running
* "ant target1 target2" will run all tasks in target3 twice.
* @throws BuildException if someting goes wrong with the build
*/
public void execute() throws BuildException {
Stack s = new Stack();
if ( getPackage() != null ) {
s.push( "-package" );
s.push( getPackage() );
}
if ( getFile() != null ) {
s.push( "-i" ) ;
s.push( getFile() );
}
if ( getPlatform() != null ) {
s.push( "-line-separator" ) ;
s.push( getPlatform() );
}
if ( getVerbose() != null ) {
s.push( "-verbose" ) ;
}
if ( getDestination() != null ) {
s.push( "-dest" ) ;
s.push( getDestination() );
}
if ( getDescription() != null ) {
if ( getDescription().equalsIgnoreCase("false") ) s.push( "-nodesc" ) ;
}
if ( getFactory() != null ) {
s.push( "-type-factory" ) ;
s.push( getFactory() );
}
if ( getMarshall() != null ) {
if ( getMarshall().equalsIgnoreCase("false") ) s.push( "-nomarshall" ) ;
}
if ( getTestable() != null ) {
if ( getTestable().equalsIgnoreCase("true") ) s.push( "-testable" ) ;
}
if ( getSax1() != null ) {
if ( getSax1().equalsIgnoreCase("true") ) s.push( "-sax1" ) ;
}
System.out.println("Castor args: " + s );
String[] args = new String[s.size()];
for ( int i = 0; i < s.size(); i++ ) args[i] = s.get( i ).toString();
System.out.println("Generating...");
try {
org.exolab.castor.builder.SourceGenerator.main( args );
} catch (Exception ex) {
ex.printStackTrace();
}
}
}