/*	convert_file.java -
		Sample java program that uses the XmlConvert class to 
		convert a flat file into XML. The names of the flat file, 
		the XFlat schema file and the XML output file are passed
		to the application as command line arguments.

    Copyright (C) 1999 Unidex Inc. All rights reserved.
*/
import java.io.FileReader ;
import java.io.FileWriter ;
import com.unidex.xflat.XmlConvert ;
import com.unidex.xflat.XflatException ;

public class convert_file {
	private final static int NUM_ARGS = 3 ;
	private final static String usage_info =
		"Usage: convert_file schema_file flat_file xml_output_file" ;

	public static void main( String args[] ) throws Exception {
		// Validate the number of command line arguments.
		if ( args.length != NUM_ARGS ) {
			System.err.println( usage_info ) ;
			System.exit( 1 ) ; // Error.
		}

		String schema_file = args[0] ;
		String flat_file = args[1] ;
		String xml_file = args[2] ;
		final boolean suppress_startup_message = true ;

		try {
			// Create an XmlConvert instance.
			XmlConvert xml_convert =
				new XmlConvert( new FileReader( schema_file ),
						suppress_startup_message ) ;

			// Use the flatToXml method of the XmlConvert object
			// to convert the flat file into XML.
			xml_convert.flatToXml(	new FileReader( flat_file ),
						new FileWriter( xml_file ) ) ;
		} catch( Exception e ) {
			if ( e instanceof XflatException ) {
				System.err.println( e.getMessage() ) ;
			} else {
				System.err.println( e.toString() ) ;
			}
			System.exit( 1 ) ; // Error.
		}
		System.exit( 0 ) ; // Success.
	}
}