/** * * Copyright (c) 2001 ebXMLsoft Inc. All rights reserved. * */ import javax.sql.*; import java.util.*; import java.io.*; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.DriverManager; import org.xml.sax.ContentHandler; import org.exolab.castor.jdo.*; import org.exolab.castor.util.*; import org.exolab.castor.xml.*; import org.exolab.castor.mapping.Mapping; import org.apache.xml.serialize.*; import asn.*; public class Asn { // database configuration file public static final String DatabaseFile = "database.xml"; // mapping file public static final String MarshalMappingFile = "marshalmap.xml"; private Mapping _marshalmap; private JDO _jdo; public void Prepenv( PrintWriter writer ) throws Exception { _jdo = new JDO(); _jdo.setLogWriter( writer ); _jdo.setConfiguration( getClass().getResource( DatabaseFile ).toString() ); _jdo.setDatabaseName( "ebdb" ); } public void run( PrintWriter writer ) throws Exception { Database db; Container container; Product product; QueryResults results; QueryResults resultsContainer; QueryResults resultsShippedProduct; db = _jdo.getDatabase(); // Marshalling Serializer ser; Marshaller marshal; ContentHandler handler; OQLQuery advanceShippingNoticeOql; OQLQuery containerOql; OQLQuery productOql; boolean asDocument = true; // Load the mapping file _marshalmap = new Mapping( getClass().getClassLoader() ); _marshalmap.setLogWriter( writer ); _marshalmap.loadMapping( getClass().getResource( MarshalMappingFile ) ); FileWriter writer1 = new FileWriter("output.xml"); ser = new XMLSerializer( new OutputFormat( "Method.XML", null, true ) ); ser.setOutputCharStream( writer1 ); handler = ser.asContentHandler(); marshal = new Marshaller( ser.asDocumentHandler() ); marshal.setMapping( _marshalmap ); db.begin(); advanceShippingNoticeOql = db.getOQLQuery( "SELECT p FROM asn.AdvanceShippingNotice p" ); results = advanceShippingNoticeOql.execute(); while( results.hasMore() ) marshal.marshal( results.next() ); db.commit(); db.close(); } public static void main( String[] args ) { PrintWriter writer; Asn asn = new Asn(); writer = new Logger( System.out ).setPrefix( "asn" ); try { asn.Prepenv( writer ); asn.run( writer ); } catch ( Exception except ) { writer.println( except ); except.printStackTrace( writer ); } } }