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 am...@apache.org on 2008/12/17 13:32:32 UTC
svn commit: r727356 - in
/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl:
codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java
template/java/ExceptionTemplate.xsl
Author: amilas
Date: Wed Dec 17 04:32:32 2008
New Revision: 727356
URL: http://svn.apache.org/viewvc?rev=727356&view=rev
Log:
populate the constructor details when an exception base class is given. Here the exception base class
should be in the class path.
Modified:
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/ExceptionTemplate.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?rev=727356&r1=727355&r2=727356&view=diff
==============================================================================
--- 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 Wed Dec 17 04:32:32 2008
@@ -75,8 +75,6 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLStreamException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
@@ -94,7 +92,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-
+import java.lang.reflect.Constructor;
public class AxisServiceBasedMultiLanguageEmitter implements Emitter {
@@ -275,7 +273,7 @@
}
protected Policy getBindingPolicyFromMessage(AxisBindingOperation axisBindingOperation,
- String key) {
+ String key) {
AxisBindingMessage axisBindingMessage = null;
if (axisBindingOperation != null) {
@@ -1056,6 +1054,11 @@
if (this.codeGenConfiguration.getExceptionBaseClassName() != null) {
addAttribute(doc, "exceptionBaseClass",
this.codeGenConfiguration.getExceptionBaseClassName(), faultElement);
+ try {
+ addConstructorDetails(doc, faultElement, this.codeGenConfiguration.getExceptionBaseClassName());
+ } catch (ClassNotFoundException e) {
+ log.warn("Can not load the Exception base class");
+ }
} else {
addAttribute(doc, "exceptionBaseClass", Exception.class.getName(), faultElement);
}
@@ -1098,6 +1101,34 @@
}
}
+ private void addConstructorDetails(Document doc,
+ Element faultElement,
+ String exceptionClassName) throws ClassNotFoundException {
+ Class exceptionClass = Class.forName(exceptionClassName);
+ Constructor[] constructors = exceptionClass.getConstructors();
+ for (int i = 0; i < constructors.length; i++) {
+ Element constructorElement = doc.createElement("constructor");
+ faultElement.appendChild(constructorElement);
+ Class[] parameters = constructors[i].getParameterTypes();
+ for (int j = 0; j < parameters.length; j++){
+ Element parameterElement = doc.createElement("param");
+ constructorElement.appendChild(parameterElement);
+ addAttribute(doc, "type",
+ parameters[j].getName(), parameterElement);
+ addAttribute(doc, "name",
+ getParameterName(parameters[j].getName()), parameterElement);
+
+ }
+ }
+ }
+
+ private String getParameterName(String className){
+ if (className.lastIndexOf(".") > 0){
+ className = className.substring(className.lastIndexOf(".") + 1);
+ }
+ return JavaUtils.xmlNameToJavaIdentifier(className);
+ }
+
/**
* Generates the model for the callbacks.
*/
Modified: 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?rev=727356&r1=727355&r2=727356&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl (original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/ExceptionTemplate.xsl Wed Dec 17 04:32:32 2008
@@ -32,19 +32,33 @@
public class <xsl:value-of select="@shortName"/> extends <xsl:value-of select="@exceptionBaseClass"/>{
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);
- }
-
+
+ <xsl:variable name="classShortName" select="@shortName"/>
+ <xsl:if test="count(constructor) > 0">
+ <xsl:for-each select="constructor">
+ public <xsl:value-of select="$classShortName"/>(<xsl:for-each select="param"><xsl:if test="position() > 1">,</xsl:if><xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/></xsl:for-each>) {
+ super(<xsl:for-each select="param"><xsl:if test="position() > 1">,</xsl:if><xsl:value-of select="@name"/></xsl:for-each>);
+ }
+ </xsl:for-each>
+ </xsl:if>
+ <xsl:if test="count(constructor) = 0">
+ 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 <xsl:value-of select="@shortName"/>(java.lang.Throwable cause) {
+ super(cause);
+ }
+ </xsl:if>
+
public void setFaultMessage(<xsl:value-of select="@type"/> msg){
faultMessage = msg;
}