KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestJ2EEDTDs


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 // Generated classes
27
import samples.j2ee.web_app_2_2.*;
28 import samples.j2ee.enhydra_service_1_0.*;
29 import samples.j2ee.ejb_jar_2_0.*;
30
31 public class TestJ2EEDTDs {
32
33     public static void main(String JavaDoc[] args) {
34         if (args.length != 3) {
35             System.out.println("Usage: java TestJ2EEDTDs " +
36                 "<web.xml location> <enhydra-service.xml location> " +
37                 "<ejb-jar.xml location>");
38             return;
39         }
40
41         try {
42             WebAppUnmarshaller.setErrorHandler(new CommandLineErrorHandler());
43             WebApp webApp =
44                 WebAppUnmarshaller.unmarshal(new File JavaDoc(args[0]), false);
45             System.out.println("\n\nProcessed Web XML...");
46
47             // Set a DTD
48
webApp.setDocType(null, null, null);
49             //webApp.setDocType("web-app", "", "DTD/web-app.dtd");
50

51             // Set encoding
52
webApp.setOutputEncoding("ISO-8859-1");
53
54             // New way of marshalling
55
webApp.marshal(new File JavaDoc("outputWeb.xml"));
56         } catch (Exception JavaDoc e) {
57             e.printStackTrace();
58             return;
59         }
60
61         try {
62             EnhydraServiceUnmarshaller.setErrorHandler(
63                 new CommandLineErrorHandler());
64             EnhydraService enhydraService =
65                 EnhydraServiceUnmarshaller.unmarshal(new File JavaDoc(args[1]));
66             System.out.println("\n\nProcessed Enhydra Service XML...");
67
68
69             List JavaDoc services = enhydraService.getServiceList();
70
71             for (Iterator JavaDoc i = services.iterator(); i.hasNext(); ) {
72                 Service service = (Service)i.next();
73                 System.out.print(" Found service");
74                 if (service.getDisplayName() != null) {
75                     System.out.print(" named " +
76                         service.getDisplayName().getValue());
77                 }
78                 System.out.println();
79
80                 ServiceDesc serviceDesc = service.getServiceDesc();
81                 if (serviceDesc != null) {
82                     System.out.println(" + Service Name: " +
83                         serviceDesc.getServiceName().getValue());
84                     System.out.println(" + Service Class Name: " +
85                         serviceDesc.getServiceClassName().getValue());
86                     System.out.println(" + M-Bean Name: " +
87                         serviceDesc.getMbeanName());
88
89                     List JavaDoc exportJars = serviceDesc.getExportJarList();
90                     for (Iterator JavaDoc j = exportJars.iterator(); j.hasNext(); ) {
91                         ExportJar exportJar = (ExportJar)j.next();
92                         System.out.println(" + Exported Jar: " +
93                             exportJar.getValue());
94                     }
95                 }
96             }
97
98             // New way of marshalling
99
enhydraService.marshal(new File JavaDoc("outputEnhydraService.xml"));
100         } catch (Exception JavaDoc e) {
101             e.printStackTrace();
102             return;
103         }
104
105         try {
106             EjbJarUnmarshaller.setErrorHandler(new CommandLineErrorHandler());
107             EjbJar ejbJar =
108                 EjbJarUnmarshaller.unmarshal(new File JavaDoc(args[2]));
109             System.out.println("\n\nProcessed EJB Jar XML...");
110
111             // New way of marshalling
112
ejbJar.marshal(new File JavaDoc("outputEJBJar.xml"));
113         } catch (Exception JavaDoc e) {
114             e.printStackTrace();
115             return;
116         }
117     }
118 }
119
120
121
Popular Tags