You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2006/10/04 07:15:34 UTC
svn commit: r452738 - in
/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl:
codegen/ codegen/emitter/ codegen/writer/ template/java/
Author: dims
Date: Tue Oct 3 22:15:33 2006
New Revision: 452738
URL: http://svn.apache.org/viewvc?view=rev&rev=452738
Log:
Fix for AXIS2-1266 - Wsdl2Java should generate wsdl faults as separate class files
Added:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ExceptionWriter.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl
Modified:
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonInterfaceTemplate.xsl
webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties?view=diff&rev=452738&r1=452737&r2=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/codegen-config.properties Tue Oct 3 22:15:33 2006
@@ -84,6 +84,7 @@
java.interface.impl.template=org.apache.axis2.wsdl.codegen.writer.InterfaceImplementationWriter,/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
java.bean.template=org.apache.axis2.wsdl.codegen.writer.BeanWriter,/org/apache/axis2/wsdl/template/java/BeanTemplate.xsl
java.callback.template=org.apache.axis2.wsdl.codegen.writer.CallbackHandlerWriter,/org/apache/axis2/wsdl/template/java/CallbackHandlerTemplate.xsl
+java.exception.template=org.apache.axis2.wsdl.codegen.writer.ExceptionWriter,/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl
java.skeleton.template=org.apache.axis2.wsdl.codegen.writer.SkeletonWriter,/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl
java.skeleton.interface.template=org.apache.axis2.wsdl.codegen.writer.SkeletonInterfaceWriter,/org/apache/axis2/wsdl/template/java/SkeletonInterfaceTemplate.xsl
java.testclass.template=org.apache.axis2.wsdl.codegen.writer.TestClassWriter,/org/apache/axis2/wsdl/template/java/TestClassTemplate.xsl
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java?view=diff&rev=452738&r1=452737&r2=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java Tue Oct 3 22:15:33 2006
@@ -136,7 +136,6 @@
//a map to keep the fault classNames
protected Map fullyQualifiedFaultClassNameMap = new HashMap();
- protected Map InstantiatableFaultClassNameMap = new HashMap();
protected Map faultClassNameMap = new HashMap();
protected Map instantiatableMessageClassNames = new HashMap();
@@ -225,10 +224,6 @@
fullyQualifiedFaultClassNameMap.put(
faultMessage.getElementQName(),
className);
- //this needs to be kept seperate and updated later
- InstantiatableFaultClassNameMap.put(
- faultMessage.getElementQName(),
- className);
//we've to keep track of the fault base names seperately
faultClassNameMap.put(faultMessage.getElementQName(),
className);
@@ -271,6 +266,9 @@
// write the call back handlers
writeCallBackHandlers();
+ // write the Exceptions
+ writeExceptions();
+
// write interface implementations
writeInterfaceImplementation();
@@ -500,9 +498,6 @@
addAttribute(doc, "name",
(String) fullyQualifiedFaultClassNameMap.get(key),
faultElement);
- addAttribute(doc, "intantiatiableName",
- (String) InstantiatableFaultClassNameMap.get(key),
- faultElement);
addAttribute(doc, "shortName",
(String) faultClassNameMap.get(key),
faultElement);
@@ -582,6 +577,80 @@
}
+ /**
+ * Writes the exceptions.
+ */
+ protected void writeExceptions() throws Exception {
+ Element faultElement;
+ QName key;
+ Iterator iterator = fullyQualifiedFaultClassNameMap.keySet().iterator();
+ while (iterator.hasNext()) {
+ Document doc = getEmptyDocument();
+
+ faultElement = doc.createElement("fault");
+
+ addAttribute(doc, "package", codeGenConfiguration.getPackageName(), faultElement);
+
+ key = (QName) iterator.next();
+
+ //as for the name of a fault, we generate an exception
+ addAttribute(doc, "name",
+ (String) faultClassNameMap.get(key),
+ faultElement);
+ addAttribute(doc, "shortName",
+ (String) faultClassNameMap.get(key),
+ faultElement);
+
+ //the type represents the type that will be wrapped by this
+ //name
+ String typeMapping =
+ this.mapper.getTypeMappingName(key);
+ addAttribute(doc, "type", (typeMapping == null)
+ ? ""
+ : typeMapping, faultElement);
+ String attribValue = (String) instantiatableMessageClassNames.
+ get(key);
+ addAttribute(doc, "instantiatableType",
+ attribValue == null ? "" : attribValue,
+ faultElement);
+
+ // add an extra attribute to say whether the type mapping is
+ // the default
+ if (mapper.getDefaultMappingName().equals(typeMapping)) {
+ addAttribute(doc, "default", "yes", faultElement);
+ }
+ addAttribute(doc, "value", getParamInitializer(typeMapping),
+ faultElement);
+ ExceptionWriter exceptionWriter =
+ new ExceptionWriter(
+ codeGenConfiguration.isFlattenFiles() ?
+ getOutputDirectory(codeGenConfiguration.getOutputLocation(), null) :
+ getOutputDirectory(codeGenConfiguration.getOutputLocation(),
+ codeGenConfiguration.getSourceLocation()),
+ codeGenConfiguration.getOutputLanguage());
+
+ doc.appendChild(faultElement);
+ writeClass(doc, exceptionWriter);
+ }
+ }
+
+ /**
+ * Generates the model for the callbacks.
+ */
+ protected Document createDOMDocumentForException() {
+ Document doc = getEmptyDocument();
+ Element rootElement = doc.createElement("callback");
+
+ addAttribute(doc, "package", codeGenConfiguration.getPackageName(), rootElement);
+ addAttribute(doc, "name", makeJavaClassName(axisService.getName()) + CALL_BACK_HANDLER_SUFFIX, rootElement);
+
+ // TODO JAXRPC mapping support should be considered here ??
+ this.loadOperations(doc, rootElement, null);
+
+ doc.appendChild(rootElement);
+ return doc;
+ }
+
/**
* Writes the callback handlers.
@@ -727,7 +796,6 @@
//handle faults
generateAndPopulateFaultNames();
- updateFaultPackageForSkeleton(codeGenConfiguration.isServerSideInterface());
//
if (codeGenConfiguration.isServerSideInterface()) {
@@ -749,6 +817,9 @@
// write a MessageReceiver for this particular service.
writeMessageReceiver();
+ // write the Exceptions
+ writeExceptions();
+
// write service xml
// if asked
if (codeGenConfiguration.isGenerateDeployementDescriptor()) {
@@ -854,33 +925,7 @@
String className = (String) fullyQualifiedFaultClassNameMap.get(key);
//append the skelton name
String fullyQualifiedStubName = getFullyQualifiedStubName();
- fullyQualifiedFaultClassNameMap.put(key, fullyQualifiedStubName + "."
- + className);
- InstantiatableFaultClassNameMap.put(key, fullyQualifiedStubName + "$"
- + className);
- }
- }
-
- /**
- * Change the fault classnames to go with the package & class of the
- * skeleton
- * the faults are always generated as inner types
- */
- protected void updateFaultPackageForSkeleton(boolean isInterface) {
- Iterator faultClassNameKeys = fullyQualifiedFaultClassNameMap.keySet().iterator();
- while (faultClassNameKeys.hasNext()) {
- Object key = faultClassNameKeys.next();
- String className = (String) fullyQualifiedFaultClassNameMap.get(key);
- //append the skelton name
- String fullyQualifiedSkeletonName = null;
- if (isInterface){
- fullyQualifiedSkeletonName = getFullyQualifiedSkeletonInterfaceName();
- }else{
- fullyQualifiedSkeletonName = getFullyQualifiedSkeletonName();
- }
- fullyQualifiedFaultClassNameMap.put(key, fullyQualifiedSkeletonName + "."
- + className);
- InstantiatableFaultClassNameMap.put(key, fullyQualifiedSkeletonName + "$"
+ fullyQualifiedFaultClassNameMap.put(key, codeGenConfiguration.getPackageName() + "."
+ className);
}
}
@@ -1767,9 +1812,6 @@
//as for the name of a fault, we generate an exception
addAttribute(doc, "name",
(String) fullyQualifiedFaultClassNameMap.get(msg.getElementQName()),
- paramElement);
- addAttribute(doc, "intantiatiableName",
- (String) InstantiatableFaultClassNameMap.get(msg.getElementQName()),
paramElement);
addAttribute(doc, "shortName",
(String) faultClassNameMap.get(msg.getElementQName()),
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ExceptionWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ExceptionWriter.java?view=auto&rev=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ExceptionWriter.java (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/writer/ExceptionWriter.java Tue Oct 3 22:15:33 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.axis2.wsdl.codegen.writer;
+
+import java.io.File;
+
+public class ExceptionWriter extends ClassWriter {
+
+ public ExceptionWriter(String outputFileLocation) {
+ this.outputFileLocation = new File(outputFileLocation);
+ }
+
+ public ExceptionWriter(File outputFileLocation, String language) {
+ this.outputFileLocation = outputFileLocation;
+ this.language = language;
+ }
+
+
+}
Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl?view=auto&rev=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl (added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl Tue Oct 3 22:15:33 2006
@@ -0,0 +1,37 @@
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="text"/>
+ <xsl:template match="/fault">
+/**
+ * <xsl:value-of select="@name"/>.java
+ *
+ * This file was auto-generated from WSDL
+ * by the Apache Axis2 version: #axisVersion# #today#
+ */
+package <xsl:value-of select="@package"/>;
+
+public class <xsl:value-of select="@shortName"/> extends java.lang.Exception{
+
+ private <xsl:value-of select="@type"/> faultMessage;
+
+ public <xsl:value-of select="@shortName"/>() {
+ super("<xsl:value-of select="@shortName"/>");
+ }
+
+ public <xsl:value-of select="@shortName"/>(java.lang.String s) {
+ super(s);
+ }
+
+ public <xsl:value-of select="@shortName"/>(java.lang.String s, java.lang.Throwable ex) {
+ super(s, ex);
+ }
+
+ public void setFaultMessage(<xsl:value-of select="@type"/> msg){
+ faultMessage = msg;
+ }
+
+ public <xsl:value-of select="@type"/> getFaultMessage(){
+ return faultMessage;
+ }
+}
+ </xsl:template>
+</xsl:stylesheet>
\ No newline at end of file
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?view=diff&rev=452738&r1=452737&r2=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl Tue Oct 3 22:15:33 2006
@@ -116,7 +116,7 @@
faultExeptionClassNameMap.put(new javax.xml.namespace.QName(
"<xsl:value-of select="@namespace"/>",
"<xsl:value-of select="@localname"/>"),
- "<xsl:value-of select="@intantiatiableName"/>");
+ "<xsl:value-of select="@name"/>");
faultMessageMap.put( new javax.xml.namespace.QName(
"<xsl:value-of select="@namespace"/>",
"<xsl:value-of select="@localname"/>"),
@@ -731,7 +731,7 @@
}
- <!-- write the classes for the exceptions if there are any present -->
+ <!-- write the classes for the exceptions if there are any present
<xsl:for-each select="fault-list/fault">
public static class <xsl:value-of select="@shortName"/> extends java.lang.Exception{
@@ -761,7 +761,7 @@
}
</xsl:for-each>
-
+ -->
//<xsl:apply-templates/>
}
</xsl:template>
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonInterfaceTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonInterfaceTemplate.xsl?view=diff&rev=452738&r1=452737&r2=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonInterfaceTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonInterfaceTemplate.xsl Tue Oct 3 22:15:33 2006
@@ -50,7 +50,7 @@
</xsl:for-each>
- <!-- write the classes for the exceptions if there are any present -->
+ <!-- write the classes for the exceptions if there are any present
<xsl:for-each select="fault-list/fault">
public static class <xsl:value-of select="@shortName"/> extends java.lang.Exception{
@@ -79,6 +79,7 @@
}
</xsl:for-each>
+ -->
}
</xsl:template>
</xsl:stylesheet>
Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl?view=diff&rev=452738&r1=452737&r2=452738
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl Tue Oct 3 22:15:33 2006
@@ -59,7 +59,8 @@
<!-- we write the faults here only if it is not the interface mode-->
<xsl:if test="not(@skeletonInterfaceName)">
- <!-- write the classes for the exceptions if there are any present -->
+ <!-- write the classes for the exceptions if there are any present
+
<xsl:for-each select="fault-list/fault">
public static class <xsl:value-of select="@shortName"/> extends java.lang.Exception{
@@ -90,6 +91,7 @@
}
</xsl:for-each>
+ -->
</xsl:if>
}
</xsl:template>
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org