KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestSchemaBinder


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.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24
25 // Zeus imports
26
import org.enhydra.zeus.Binder;
27 import org.enhydra.zeus.Binding;
28 import org.enhydra.zeus.Generator;
29 import org.enhydra.zeus.Result;
30 import org.enhydra.zeus.Source;
31 import org.enhydra.zeus.binder.SchemaBinder;
32 import org.enhydra.zeus.binding.Container;
33 import org.enhydra.zeus.binding.Property;
34 import org.enhydra.zeus.generator.SimpleGenerator;
35 import org.enhydra.zeus.result.StreamResult;
36 import org.enhydra.zeus.source.StreamSource;
37 import org.enhydra.zeus.util.Arguments;
38
39 public class TestSchemaBinder {
40
41     public static void main(String JavaDoc[] args) {
42         Arguments theArguments = new Arguments(args);
43
44         // Using Arguments, parameters can be sent in any order
45
if (!theArguments.hasValue("file")) {
46             System.out.println(
47                 "Usage: java samples.TestSchemaBinder -file=<file name> " +
48                     "[-package=<package>] [-quiet=true/false]");
49             return;
50         }
51
52         try {
53             String JavaDoc thePackage = null;
54             if (theArguments.hasValue("package")) {
55                 thePackage = theArguments.getValue("package");
56             } else {
57
58                 // Set the package to the default package if not specified.
59
thePackage = "";
60             }
61
62             // This is to match the original default action
63
boolean isQuiet = false;
64             if (theArguments.hasValue("quiet")) {
65                 isQuiet =
66                     theArguments.getValue("quiet")
67                                 .trim()
68                                 .equalsIgnoreCase("true");
69             }
70
71             // Get handle to the schema
72
File JavaDoc schema = new File JavaDoc(theArguments.getValue("file"));
73             Source source = new StreamSource(new FileInputStream JavaDoc(schema));
74
75             if (!isQuiet) {
76                 System.out.println("Generating bindings...");
77             }
78
79             // Get the Zeus Bindings
80
Binder schemaBinder = new SchemaBinder(source);
81             List JavaDoc bindings = schemaBinder.getBindings();
82
83             if (!isQuiet) {
84                 System.out.println("Bindings generated...\n\n");
85             }
86
87             // Do some printing
88
if (!isQuiet) {
89                 for (Iterator JavaDoc i = bindings.iterator(); i.hasNext();) {
90                     Binding binding = (Binding) i.next();
91                     System.out.println("Binding");
92                     System.out.println(" Type: " +
93                         binding.getClass().getName());
94                     System.out.println(" Name: " + binding.getJavaName());
95                     System.out.println(" Properties");
96
97                     try {
98                         Container container = (Container) binding;
99                         List JavaDoc properties = container.getProperties();
100                         if (properties.size() > 0) {
101                             for (Iterator JavaDoc j = properties.iterator();
102                                  j.hasNext(); ) {
103                                 Property property = (Property) j.next();
104                                 System.out.println(" Name: " +
105                                     property.getJavaName());
106                                 System.out.println(" Type: " +
107                                     property.getJavaType());
108                             }
109                         } else {
110                             System.out.println(" (None)");
111                         }
112                     } catch (ClassCastException JavaDoc e) {
113                         System.out.println(" (None)");
114                     }
115                     System.out.println();
116                 }
117                 System.out.println("--------------------------------------");
118                 System.out.println(
119                     "Finished testing Binding Generation...\n\n");
120                 System.out.println("--------------------------------------");
121                 System.out.println("Going to test Class Generation...\n");
122             }
123
124             Generator generator = new SimpleGenerator();
125             generator.setOutputDirectory(new File JavaDoc("output"));
126             //generator.setImplementationPackage(thePackage);
127
for (Iterator JavaDoc i = bindings.iterator(); i.hasNext();) {
128
129                 if (!isQuiet) {
130                     System.out.println("--------------------------------");
131                 }
132
133                 Binding binding = (Binding) i.next();
134                 generator.generate(binding);
135
136                 if (!isQuiet) {
137                     System.out.println("--------------------------------");
138                 }
139             }
140
141         } catch (Exception JavaDoc e) {
142             e.printStackTrace();
143         }
144     }
145 }
146
Popular Tags