KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestSongsXSD


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.File JavaDoc;
21 import java.io.FileInputStream JavaDoc;
22 import java.io.FileOutputStream JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 // Zeus imports
27
import org.enhydra.zeus.Source;
28 import org.enhydra.zeus.Marshaller;
29 import org.enhydra.zeus.Unmarshaller;
30 import org.enhydra.zeus.result.StreamResult;
31 import org.enhydra.zeus.source.StreamSource;
32
33 // Generated classes
34
import samples.xsd.ARTIST;
35 import samples.xsd.SONGS;
36 import samples.xsd.SONG;
37 import samples.xsd.TITLE;
38
39 public class TestSongsXSD {
40
41     public static void main(String JavaDoc[] args) {
42         if (args.length != 1) {
43             System.out.println("Usage: java TestSongsXSD " +
44                 "[songs.xml location]");
45             return;
46         }
47
48         try {
49             Source source = new StreamSource(
50                 new FileInputStream JavaDoc(new File JavaDoc(args[0])));
51             Unmarshaller unmarshaller = new Unmarshaller();
52             Object JavaDoc o = unmarshaller.unmarshal(source).getObject();
53
54             // Uncomment the following for the real test. This is just commented
55
// out during the period that the XML schema binder is not working.
56
// SONGS songs = (SONGS)o;
57
// List songList = songs.getSONGList();
58
// for (Iterator i = songList.iterator(); i.hasNext(); ) {
59
// SONG song = (SONG)i.next();
60
// System.out.println("Song title: " +
61
// song.getTITLE().getValue());
62
// List artists = song.getARTISTList();
63
// for (Iterator j = artists.iterator(); j.hasNext(); ) {
64
// ARTIST artist = (ARTIST)j.next();
65
// System.out.println("Artist: " + artist.getValue());
66
// }
67
// System.out.println("-------------------------");
68
// }
69

70             Marshaller marshaller = new Marshaller();
71             marshaller.marshal(o, new StreamResult(
72                 new FileOutputStream JavaDoc(new File JavaDoc("output.xml"))));
73         } catch (Exception JavaDoc e) {
74             e.printStackTrace();
75         }
76     }
77 }
78
Popular Tags