KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestZeusRoundTrip


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  */

19
20 import java.io.FileInputStream JavaDoc;
21
22 // Zeus imports
23
import org.enhydra.zeus.Marshaller;
24 import org.enhydra.zeus.Result;
25 import org.enhydra.zeus.Source;
26 import org.enhydra.zeus.Unmarshaller;
27 import org.enhydra.zeus.source.StreamSource;
28 import org.enhydra.zeus.result.StreamResult;
29
30 /**
31  * <p>
32  * This tests round-tripping of marshalling and unmarshalling.
33  * </p>
34  *
35  * @author Ryan Smith
36  */

37 public class TestZeusRoundTrip {
38
39     /**
40     * @param args the command line arguments
41     */

42     public static void main (String JavaDoc args[]) {
43         String JavaDoc javaPackage = "";
44         if (args.length < 1) {
45             System.out.println("Please specify an XML file.");
46             System.exit(1);
47         } else if (args.length >= 2) {
48             javaPackage = args[1];
49         }
50         
51         try {
52             Source source = new StreamSource(new FileInputStream JavaDoc(args[0]));
53             Unmarshaller unmarshaller = new Unmarshaller();
54             unmarshaller.setJavaPackage(javaPackage);
55             Object JavaDoc obj = unmarshaller.unmarshal(source);
56             System.out.println("Unmarshalled object = " + obj);
57             
58             Marshaller marshaller = new Marshaller();
59             Result result = new StreamResult(System.out);
60             marshaller.marshal(obj, result);
61             
62         } catch (Exception JavaDoc e) {
63             e.printStackTrace();
64         }
65     }
66
67 }
68
Popular Tags