KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestUnmarshaller


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.lang.reflect.Method JavaDoc;
23
24 // Zeus imports
25
import org.enhydra.zeus.Source;
26 import org.enhydra.zeus.Unmarshaller;
27 import org.enhydra.zeus.source.StreamSource;
28
29 public class TestUnmarshaller {
30
31     public static void main(String JavaDoc[] args) {
32         if (args.length < 1) {
33             System.out.println("Usage: java samples.TestUnmarshaller " +
34                 "[XML filename] [package]");
35             return;
36         }
37
38         try {
39             String JavaDoc thePackage = null;
40             if (args.length > 1) {
41                 thePackage = args[1];
42             } else {
43
44                 // Set the package to the default package if not specified.
45
thePackage = "";
46             }
47
48             Source source = new StreamSource(
49                 new FileInputStream JavaDoc(new File JavaDoc(args[0])));
50             Unmarshaller unmarshaller = new Unmarshaller();
51             unmarshaller.setJavaPackage(thePackage);
52             Object JavaDoc o = unmarshaller.unmarshal(source).getObject();
53
54             // Introspect the returned object
55
System.out.println("Generated class of type " +
56                 o.getClass().getName());
57             System.out.println("Methods available:");
58             Method JavaDoc[] methods = o.getClass().getDeclaredMethods();
59             for (int i=0; i<methods.length; i++) {
60                 Method JavaDoc method = methods[i];
61                 System.out.print(" " + method.getReturnType().getName() +
62                     " " + method.getName() + "(");
63                 Class JavaDoc[] params = method.getParameterTypes();
64                 for (int j=0; j<params.length; j++) {
65                     System.out.print(params[j].getName());
66                     if (j+1 < params.length) {
67                         System.out.print(", ");
68                     }
69                 }
70                 System.out.println(");");
71             }
72         } catch (Exception JavaDoc e) {
73             e.printStackTrace();
74         }
75     }
76 }
77
Popular Tags