axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r392522 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl: codegen/emitter/ template/java/
Date Sat, 08 Apr 2006 13:26:47 GMT
Author: ajith
Date: Sat Apr  8 06:26:44 2006
New Revision: 392522

URL: http://svn.apache.org/viewcvs?rev=392522&view=rev
Log:
Adding fault binding support for axis2
1. Changed the templates to incorporate correct code
2. Added the necessary extraction points to the AxisServiceBasedMultiLanguageEmitter.java

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/InterfaceImplementationTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.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/emitter/AxisServiceBasedMultiLanguageEmitter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/codegen/emitter/AxisServiceBasedMultiLanguageEmitter.java?rev=392522&r1=392521&r2=392522&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
Sat Apr  8 06:26:44 2006
@@ -139,8 +139,11 @@
 
     //a map to keep the fault classNames
     private Map fullyQualifiedFaultClassNameMap = new HashMap();
+    private Map InstantiatableFaultClassNameMap = new HashMap();
     private Map faultClassNameMap = new HashMap();
 
+    private Map instantiatableMessageClassNames = new HashMap();;
+
 
     public AxisServiceBasedMultiLanguageEmitter() {
         infoHolder = new HashMap();
@@ -173,7 +176,7 @@
      * Update mapper for the stub
      */
     private void updateMapperForStub() {
-        updateMapperClassnames(getFullyQualifiedStubName() + ".");
+        updateMapperClassnames(getFullyQualifiedStubName());
     }
 
     private String getFullyQualifiedStubName(){
@@ -181,6 +184,14 @@
         String localPart = makeJavaClassName(axisService.getName());
         return packageName + "." + localPart + STUB_SUFFIX;
     }
+
+    /**
+     *
+     */
+    private void resetFaultNames(){
+        fullyQualifiedFaultClassNameMap.clear();
+        faultClassNameMap.clear();
+    }
     /**
      * Populate a map of fault class names
      */
@@ -207,7 +218,10 @@
                     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);
@@ -229,11 +243,16 @@
         // calling this method
         if (mapper.isObjectMappingPresent()) {
             updateMapperForStub();
+        }else{
+            copyToFaultMap();
         }
 
         //generate and populate the fault names before hand. We need that for
         //the smooth opration of the thing
+        //first reset the fault names and recreate it
+        resetFaultNames();
         generateAndPopulateFaultNames();
+        updateFaultPackageForStub();
 
         // write the inteface
         // feed the binding information also
@@ -575,7 +594,7 @@
      * Update mapper for message receiver
      */
     private void updateMapperForMessageReceiver() {
-        updateMapperClassnames(getFullyQualifiedMessageReceiverName() + ".");
+        updateMapperClassnames(getFullyQualifiedMessageReceiverName());
     }
 
     /**
@@ -607,6 +626,8 @@
         // calling this method
         if (mapper.isObjectMappingPresent()) {
             updateMapperForMessageReceiver();
+        }else{
+            copyToFaultMap();
         }
 
         //handle faults
@@ -629,6 +650,33 @@
         log.info(CodegenMessages.getMessage("emitter.logEntryInterface2"));
     }
 
+    private void copyToFaultMap() {
+        Map classNameMap = mapper.getAllMappedNames();
+        Iterator keys = classNameMap.keySet().iterator();
+        while (keys.hasNext()) {
+            Object key = keys.next();
+            instantiatableMessageClassNames.put(key,
+                    classNameMap.get(key));
+        }
+    }
+
+    /**
+     *
+     */
+    private void updateFaultPackageForStub() {
+        Iterator faultClassNameKeys = fullyQualifiedFaultClassNameMap.keySet().iterator();
+        while (faultClassNameKeys.hasNext()) {
+            Object key =  faultClassNameKeys.next();
+            String className = (String)fullyQualifiedFaultClassNameMap.get(key);
+            //append the skelton name
+            String fullyQualifiedStubName = getFullyQualifiedStubName();
+            fullyQualifiedFaultClassNameMap.put(key,fullyQualifiedStubName + "."
+                    + className);
+            InstantiatableFaultClassNameMap.put(key,fullyQualifiedStubName + "$"
+                    + className);
+        }
+    }
+
     /**
      *
      */
@@ -638,9 +686,11 @@
             Object key =  faultClassNameKeys.next();
             String className = (String)fullyQualifiedFaultClassNameMap.get(key);
             //append the skelton name
-            className = getFullyQualifiedSkeletonName() + "."
-                           + className;
-            fullyQualifiedFaultClassNameMap.put(key,className);
+            String fullyQualifiedSkeletonName = getFullyQualifiedSkeletonName();
+            fullyQualifiedFaultClassNameMap.put(key,fullyQualifiedSkeletonName + "."
+                    + className);
+            InstantiatableFaultClassNameMap.put(key,fullyQualifiedSkeletonName + "$"
+                    + className);
         }
     }
 
@@ -702,7 +752,7 @@
         doc.appendChild(rootElement);
 
         //////////////////////////////////
-        System.out.println(DOM2Writer.nodeToString(rootElement));
+        //System.out.println(DOM2Writer.nodeToString(rootElement));
         ////////////////////////////////
         return doc;
     }
@@ -849,7 +899,10 @@
 
         while (keys.hasNext()) {
             Object key = keys.next();
-            classNameMap.put(key, fullyQulifiedIncludingClassNamePrefix + classNameMap.get(key));
+            String className = (String)classNameMap.get(key);
+            classNameMap.put(key, fullyQulifiedIncludingClassNamePrefix +"."+ className);
+            instantiatableMessageClassNames.put(key,
+                    fullyQulifiedIncludingClassNamePrefix +"$"+ className);
         }
     }
 
@@ -1279,9 +1332,20 @@
                 addAttribute(doc, "name",
                         (String)fullyQualifiedFaultClassNameMap.get(msg.getElementQName()),
                         paramElement);
-                 addAttribute(doc, "shortName",
+                addAttribute(doc, "intantiatiableName",
+                        (String)InstantiatableFaultClassNameMap.get(msg.getElementQName()),
+                        paramElement);
+                addAttribute(doc, "shortName",
                         (String)faultClassNameMap.get(msg.getElementQName()),
                         paramElement);
+
+                // attach the namespace and the localName
+                addAttribute(doc, "namespace",
+                        msg.getElementQName().getNamespaceURI(),
+                        paramElement);
+                addAttribute(doc, "localname",
+                        msg.getElementQName().getLocalPart(),
+                        paramElement);
                 //the type represents the type that will be wrapped by this
                 //name
                 String typeMapping =
@@ -1289,6 +1353,12 @@
                 addAttribute(doc, "type", (typeMapping == null)
                         ? ""
                         : typeMapping, paramElement);
+                String attribValue = (String) instantiatableMessageClassNames.
+                        get(msg.getElementQName());
+
+                addAttribute(doc, "instantiatableType",
+                        attribValue==null?"":attribValue,
+                        paramElement);
 
                 // add an extra attribute to say whether the type mapping is
                 // the default
@@ -1301,11 +1371,7 @@
                 Iterator iter = msg.getExtensibilityAttributes().iterator();
                 while (iter.hasNext()) {
                     //TODO : implement this
-//                    WSDLExtensibilityAttribute att =
-//                            (WSDLExtensibilityAttribute) iter.next();
-//                    addAttribute(doc, att.getKey().getLocalPart(),
-//                            att.getValue().toString(),
-//                            paramElement);
+//
                 }
                 params.add(paramElement);
             }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/InterfaceImplementationTemplate.xsl?rev=392522&r1=392521&r2=392522&view=diff
==============================================================================
--- 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
Sat Apr  8 06:26:44 2006
@@ -33,13 +33,20 @@
         *  <xsl:value-of select="@name"/> java implementation
         */
 
+        <xsl:variable name="fullyQualifiedClassName"><xsl:value-of select="$package"/>.<xsl:value-of
select="@name"/></xsl:variable>
         public class <xsl:value-of select="@name"/> extends org.apache.axis2.client.Stub
         <xsl:if test="not(@wrapped)">implements <xsl:value-of select="$interfaceName"/></xsl:if>{
         //default axis home being null forces the system to pick up the mars from the axis2
library
         public static final java.lang.String AXIS2_HOME = null;
         protected static org.apache.axis2.description.AxisOperation[] _operations;
+
+        //hashmaps to keep the fault mapping
+        private java.util.HashMap faultExeptionNameMap = new java.util.HashMap();
+        private java.util.HashMap faultExeptionClassNameMap = new java.util.HashMap();
+        private java.util.HashMap faultMessageMap = new java.util.HashMap();
+
 	
-	private void populateAxisService(){
+    private void populateAxisService(){
 
         //creating the Service
         _service = new org.apache.axis2.description.AxisService("<xsl:value-of select="@servicename"/>");
@@ -91,13 +98,36 @@
         </xsl:for-each>
         }
 
+    //populates the faults
+    private void populateFaults(){
+         <xsl:for-each select="method">
+           <xsl:for-each select="fault/param">
+              faultExeptionNameMap.put( new javax.xml.namespace.QName(
+                 "<xsl:value-of select="@namespace"/>",
+                 "<xsl:value-of select="@localname"/>"),
+                 "<xsl:value-of select="@name"/>"
+               );
+              faultExeptionClassNameMap.put(new javax.xml.namespace.QName(
+                "<xsl:value-of select="@namespace"/>",
+                "<xsl:value-of select="@localname"/>"),
+                "<xsl:value-of select="@intantiatiableName"/>");
+               faultMessageMap.put( new javax.xml.namespace.QName(
+                 "<xsl:value-of select="@namespace"/>",
+                 "<xsl:value-of select="@localname"/>"),
+                 "<xsl:value-of select="@instantiatableType"/>"
+               );
+           </xsl:for-each>
+        </xsl:for-each>
 
 
+    }
+
      public <xsl:value-of select="@name"/>(org.apache.axis2.context.ConfigurationContext
configurationContext,
         java.lang.String targetEndpoint)
         throws java.lang.Exception {
-       //To populate AxisService
-       populateAxisService();
+         //To populate AxisService
+         populateAxisService();
+         populateFaults();
 	<xsl:if test="//@policy">
 	
 	////////////////////////////////////////////////////////////////////////
@@ -200,7 +230,7 @@
                     <xsl:for-each select="fault/param[@type!='']">
                         ,<xsl:value-of select="@name"/>
                     </xsl:for-each>{
-
+              try{
                org.apache.axis2.client.OperationClient _operationClient = _serviceClient.createClient(_operations[<xsl:value-of
select="position()-1"/>].getName());
               _operationClient.getOptions().setAction("<xsl:value-of select="$soapAction"/>");
               _operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(true);
@@ -282,9 +312,7 @@
                 <xsl:choose>
                     <xsl:when test="$style='document' or $style='rpc'">
                            java.lang.Object object = fromOM(getElement(_returnEnv,"<xsl:value-of
select="$style"/>"),<xsl:value-of select="$outputtype"/>.class);
-                          
                            _messageContext.getTransportOut().getSender().cleanUp(_messageContext);
-
                            return (<xsl:value-of select="$outputtype"/>)object;
                     </xsl:when>
                     <xsl:otherwise>
@@ -294,7 +322,56 @@
                 </xsl:choose>
             </xsl:otherwise>
         </xsl:choose>
-
+         }catch(org.apache.axis2.AxisFault f){
+            org.apache.axiom.om.OMElement faultElt = f.getDetail();
+            if (faultElt!=null){
+                if (faultExeptionNameMap.containsKey(faultElt.getQName())){
+                    //make the fault by reflection
+                    try{
+                        java.lang.String exceptionClassName = (java.lang.String)faultExeptionClassNameMap.get(faultElt.getQName());
+                        java.lang.Class exceptionClass = java.lang.Class.forName(exceptionClassName);
+                        java.rmi.RemoteException ex=
+                                (java.rmi.RemoteException)exceptionClass.newInstance();
+                        //message class
+                        java.lang.String messageClassName = (java.lang.String)faultMessageMap.get(faultElt.getQName());
+                        java.lang.Class messageClass = java.lang.Class.forName(messageClassName);
+                        java.lang.Object messageObject = fromOM(faultElt,messageClass);
+                        java.lang.reflect.Method m = exceptionClass.getMethod("setFaultMessage",
+                                   new java.lang.Class[]{messageClass});
+                        m.invoke(ex,new java.lang.Object[]{messageObject});
+                        <xsl:for-each select="fault/param">
+                        if (ex instanceof <xsl:value-of select="@name"/>){
+                          throw (<xsl:value-of select="@name"/>)ex;
+                        }
+                        </xsl:for-each>
+
+                        throw ex;
+                    }catch(java.lang.ClassCastException e){
+                       // we cannot intantiate the class - throw the original Axis fault
+                        throw f;
+                    } catch (java.lang.ClassNotFoundException e) {
+                        // we cannot intantiate the class - throw the original Axis fault
+                        throw f;
+                    }catch (java.lang.NoSuchMethodException e) {
+                        // we cannot intantiate the class - throw the original Axis fault
+                        throw f;
+                    } catch (java.lang.reflect.InvocationTargetException e) {
+                        // we cannot intantiate the class - throw the original Axis fault
+                        throw f;
+                    }  catch (java.lang.IllegalAccessException e) {
+                        // we cannot intantiate the class - throw the original Axis fault
+                        throw f;
+                    }   catch (java.lang.InstantiationException e) {
+                        // we cannot intantiate the class - throw the original Axis fault
+                        throw f;
+                    }
+                }else{
+                    throw f;
+                }
+            }else{
+                throw f;
+            }
+        }
         }
             </xsl:if>
             <!-- Async method generation -->
@@ -578,7 +655,7 @@
      <!-- write the classes for the exceptions if there are any present -->
    <xsl:for-each select="method">
        <xsl:for-each select="fault/param">
-         public static class <xsl:value-of select="@shortName"/> extends Exception{
+         public static class <xsl:value-of select="@shortName"/> extends java.rmi.RemoteException{
 
             private <xsl:value-of select="@type"/> faultMessage;
 

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl?rev=392522&r1=392521&r2=392522&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/MessageReceiverTemplate.xsl
Sat Apr  8 06:26:44 2006
@@ -111,20 +111,19 @@
         </xsl:for-each>
 
         newMsgContext.setEnvelope(envelope);
-        }
-
+       }
         <xsl:for-each select="method">
         <xsl:choose>
            <xsl:when test="fault/param">
                <xsl:for-each select="fault/param">
-                   <xsl:if test="position()>1">}</xsl:if> catch (<xsl:value-of
select="@name"/> e) {
+                    <xsl:if test="position()=1">}</xsl:if>catch (<xsl:value-of
select="@name"/> e) {
                         org.apache.axis2.AxisFault f =
                             new org.apache.axis2.AxisFault("<xsl:value-of select="@shortName"/>");
                         f.setDetail(toOM(e.getFaultMessage(),false));
                         throw f;
-                   }
+                    }
                </xsl:for-each>
-           </xsl:when>
+            </xsl:when>
             <xsl:otherwise>
                     <!-- put a single bracket for the catch-->
                     }

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/wsdl/template/java/SkeletonTemplate.xsl?rev=392522&r1=392521&r2=392522&view=diff
==============================================================================
--- 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
Sat Apr  8 06:26:44 2006
@@ -41,7 +41,7 @@
     <!-- write the classes for the exceptions if there are any present -->
    <xsl:for-each select="method">
        <xsl:for-each select="fault/param">
-         public static class <xsl:value-of select="@shortName"/> extends Exception{
+         public static class <xsl:value-of select="@shortName"/> extends java.rmi.RemoteException{
 
             private <xsl:value-of select="@type"/> faultMessage;
 



Mime
View raw message