KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_ws > wsgen > generator > ews > wsdltoj2ee > writer > JOnASTypeWriter


1 /**
2  * JOnAS : Java(TM) OpenSource Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: JOnASTypeWriter.java,v 1.2 2005/05/27 15:01:22 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas_ws.wsgen.generator.ews.wsdltoj2ee.writer;
26
27 import java.io.IOException JavaDoc;
28 import java.util.Vector JavaDoc;
29
30 import javax.xml.namespace.QName JavaDoc;
31
32 import org.w3c.dom.Node JavaDoc;
33
34 import org.apache.axis.wsdl.gen.Generator;
35 import org.apache.axis.wsdl.symbolTable.SchemaUtils;
36 import org.apache.axis.wsdl.symbolTable.SymbolTable;
37 import org.apache.axis.wsdl.symbolTable.Type;
38 import org.apache.axis.wsdl.symbolTable.TypeEntry;
39 import org.apache.axis.wsdl.toJava.Emitter;
40 import org.apache.axis.wsdl.toJava.JavaGeneratorFactory;
41 import org.apache.axis.wsdl.toJava.JavaTypeWriter;
42 import org.apache.axis.wsdl.toJava.Utils;
43
44 /**
45  * This is Wsdl2java's Type Writer. It writes the following files, as appropriate:
46  * <typeName>.java, <typeName>Holder.java.
47  */

48 public class JOnASTypeWriter extends JavaTypeWriter implements Generator {
49
50     /** Field typeWriter */
51     private Generator jonasTypeWriter = null;
52
53     /**
54      * Constructor.
55      *
56      * @param emitter the Emitter
57      * @param type Type to be generated
58      * @param symbolTable SymbolTable containing mapping informations
59      */

60     public JOnASTypeWriter(Emitter emitter, TypeEntry type,
61                           SymbolTable symbolTable) {
62         super(emitter, type, symbolTable);
63         if (type.isReferenced() && !type.isOnlyLiteralReferenced() && type instanceof Type) {
64
65             // Determine what sort of type this is and instantiate
66
// the appropriate Writer.
67
Node JavaDoc node = type.getNode();
68
69             boolean isSimpleList = SchemaUtils.isListWithItemType(node);
70             // If it's an array, don't emit a class
71
if (!type.getName().endsWith("[]") && !isSimpleList) {
72
73                 // Generate the proper class for either "complex" or "enumeration" types
74
Vector JavaDoc v = Utils.getEnumerationBaseAndValues(node, symbolTable);
75
76                 if (v == null) {
77                     // that's not an enumeration
78
TypeEntry base =
79                             SchemaUtils.getComplexElementExtensionBase(node,
80                                     symbolTable);
81
82                     if (base == null) {
83                         base = SchemaUtils.getComplexElementRestrictionBase(
84                                 node, symbolTable);
85                     }
86
87                     if (base == null) {
88                         QName JavaDoc baseQName = SchemaUtils.getSimpleTypeBase(node);
89
90                         if (baseQName != null) {
91                             base = symbolTable.getType(baseQName);
92                         }
93                     }
94                     Vector JavaDoc elements = type.getContainedElements();
95                     Vector JavaDoc attributes = type.getContainedAttributes();
96
97                     // If this complexType is referenced in a
98
// fault context, emit a bean-like exception
99
// class
100
Boolean JavaDoc isComplexFault = (Boolean JavaDoc) type.getDynamicVar(
101                             JavaGeneratorFactory.COMPLEX_TYPE_FAULT);
102
103                     if ((isComplexFault != null) && isComplexFault.booleanValue()) {
104
105                         jonasTypeWriter = getBeanHelperWriter(emitter, type, elements, base, attributes, true);
106                     } else {
107                         jonasTypeWriter = getBeanHelperWriter(emitter, type, elements, base, attributes, false);
108                     }
109                 }
110             }
111         }
112     } // ctor
113

114     /**
115      * Write all the service bindnigs: service and testcase.
116      *
117      * @throws IOException if generation of Helper fails
118      */

119     public void generate() throws IOException JavaDoc {
120
121         if (jonasTypeWriter != null) {
122             jonasTypeWriter.generate();
123         }
124     }
125
126 } // class JavaTypeWriter
127
Popular Tags