KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > wsdl > toJava > JavaBeanFaultWriter


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.wsdl.toJava;
17
18 import org.apache.axis.wsdl.symbolTable.TypeEntry;
19
20 import java.io.IOException JavaDoc;
21 import java.io.PrintWriter JavaDoc;
22 import java.util.Vector JavaDoc;
23 import java.util.Set JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.HashSet JavaDoc;
26
27 /**
28  * This is Wsdl2java's Complex Fault Writer.
29  * It generates bean-like class for complexTypes used
30  * in an operation fault message.
31  */

32 public class JavaBeanFaultWriter extends JavaBeanWriter {
33     /**
34      * All server specific exception classes have {@link Throwable} as an
35      * indirect superclass. <code>Throwable</code> defines a set of properties
36      * that may potentially conflict with those that would be generated by
37      * this class for an XSD complex type used as a fault. The following
38      * immutable object contains all property names that must be excluded
39      * when generating a service specific exception. <i>Note:</t>
40      * {@link org.apache.axis.encoding.ser.BeanSerializer} always excludes
41      * <code>Throwable</code>'s and <code>AxisFault</code>'s properties
42      * when marshalling a service Java exception.
43      */

44     public static final Set JavaDoc RESERVED_PROPERTY_NAMES;
45     static {
46         Set JavaDoc temp = new HashSet JavaDoc();
47         // Throwable's properties.
48
temp.add("cause");
49         temp.add("message");
50         temp.add("localizedMessage");
51         temp.add("stackTrace");
52         // AxisFault's properties.
53
temp.add("faultActor");
54         temp.add("faultCode");
55         temp.add("faultDetails");
56         temp.add("faultNode");
57         temp.add("faultReason");
58         temp.add("faultRole");
59         temp.add("faultString");
60         temp.add("faultSubCodes");
61         temp.add("headers");
62         RESERVED_PROPERTY_NAMES = Collections.unmodifiableSet(temp);
63     }
64
65
66     /**
67      * Constructor.
68      *
69      * @param emitter
70      * @param type The type representing this class
71      * @param elements Vector containing the Type and name of each property
72      * @param extendType The type representing the extended class (or null)
73      * @param attributes Vector containing the attribute types and names
74      * @param helper Helper class writer
75      */

76     protected JavaBeanFaultWriter(Emitter emitter, TypeEntry type,
77                                   Vector JavaDoc elements, TypeEntry extendType,
78                                   Vector JavaDoc attributes, JavaWriter helper) {
79
80         super(emitter, type, elements, extendType, attributes, helper);
81
82         // The Default Constructor is not JSR 101 v1.0 compliant, but
83
// is the only way that Axis can get something back over the wire.
84
// This will need to be changed when fault contents are supported
85
// over the wire.
86
enableDefaultConstructor = true;
87
88         // JSR 101 v1.0 requires a full constructor
89
enableFullConstructor = true;
90
91         // JSR 101 v1.0 does not support write access methods
92
enableSetters = true;
93     } // ctor
94

95     /**
96      * Returns the appropriate extends text
97      *
98      * @return "" or " extends <class> "
99      */

100     protected String JavaDoc getExtendsText() {
101
102         // See if this class extends another class
103
String JavaDoc extendsText = super.getExtendsText();
104
105         if (extendsText.equals("")) {
106
107             // JSR 101 compliant code should extend java.lang.Exception!
108
// extendsText = " extends java.lang.Exception ";
109
extendsText = " extends org.apache.axis.AxisFault ";
110         }
111
112         return extendsText;
113     }
114
115     /**
116      * Write the Exception serialization code
117      * <p/>
118      * NOTE: This function is written in JavaFaultWriter.java also.
119      *
120      * @param pw
121      * @throws IOException
122      */

123     protected void writeFileFooter(PrintWriter JavaDoc pw) throws IOException JavaDoc {
124
125         // We need to have the Exception class serialize itself
126
// with the correct namespace, which can change depending on which
127
// operation the exception is thrown from. We therefore have the
128
// framework call this generated routine with the correct QName,
129
// and allow it to serialize itself.
130
// method that serializes this exception (writeDetail)
131
pw.println();
132         pw.println(" /**");
133         pw.println(" * Writes the exception data to the faultDetails");
134         pw.println(" */");
135         pw.println(
136                 " public void writeDetails(javax.xml.namespace.QName qname, org.apache.axis.encoding.SerializationContext context) throws java.io.IOException {");
137         pw.println(" context.serialize(qname, null, this);");
138         pw.println(" }");
139         super.writeFileFooter(pw);
140     } // writeFileFooter
141
} // class JavaBeanFaultWriter
142
Popular Tags