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 2008/05/13 12:33:18 UTC

svn commit: r655795 - in /webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema: template/CADBBeanTemplateHeader.xsl template/CADBBeanTemplateSource.xsl writer/CStructWriter.java

Author: dimuthu
Date: Tue May 13 03:33:17 2008
New Revision: 655795

URL: http://svn.apache.org/viewvc?rev=655795&view=rev
Log:
adding c-style enumeration to the wsdl2c code - https://issues.apache.org/jira/browse/AXIS2C-1133 - Thanks Sérgio Gomes for the patch

Modified:
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateSource.xsl
    webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl?rev=655795&r1=655794&r2=655795&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateHeader.xsl Tue May 13 03:33:17 2008
@@ -132,6 +132,26 @@
         #define ADB_DEFAULT_LIST_SEPERATOR " "
         </xsl:if>
 
+        <!-- Check if this type is a supported enum -->
+        <xsl:variable name="isEnum">
+          <xsl:choose>
+            <xsl:when test="count(property)=1 and property/enumFacet and property/@type='axis2_char_t*'">1</xsl:when>
+            <xsl:otherwise>0</xsl:otherwise>
+          </xsl:choose>
+        </xsl:variable>
+
+        <xsl:if test="$isEnum=1">
+          <xsl:variable name="enum">adb_<xsl:value-of select="property/@name"/>_enum_t</xsl:variable>
+          <xsl:variable name="propertyCapsCName" select="property/@caps-cname"/>
+        /* Enumeration for this type */
+        typedef enum {
+            <xsl:for-each select="property/enumFacet">
+                <xsl:text/><xsl:value-of select="$propertyCapsCName"/>_<xsl:value-of select="@id"/>
+                <xsl:if test="position()!=last()">,
+            </xsl:if>
+          </xsl:for-each> } <xsl:value-of select="$enum"/>;
+        </xsl:if>
+
         /******************************* Create and Free functions *********************************/
 
         /**
@@ -537,6 +557,48 @@
    
         </xsl:for-each>
 
+        <xsl:if test="$isEnum=1">
+          <xsl:for-each select="property">
+            <xsl:variable name="propertyName"><xsl:value-of select="@name"></xsl:value-of></xsl:variable>
+            <xsl:variable name="CName"><xsl:value-of select="@cname"></xsl:value-of></xsl:variable>
+            <xsl:variable name="enum">adb_<xsl:value-of select="@name"/>_enum_t</xsl:variable>
+            <xsl:variable name="constValue">
+              <xsl:choose>
+                <xsl:when test="@isarray"></xsl:when>
+                <xsl:when test="@type='axis2_char_t*' or @type='unsigned short' or @type='uint64_t' or @type='unsigned int' or @type='unsigned char' or @type='short' or @type='char' or @type='int' or @type='float' or @type='double' or @type='int64_t'">const </xsl:when>
+              </xsl:choose>
+            </xsl:variable>
+            
+            /************************** Getters and Setters For Enumerations ********************************/
+            /********************* Enumeration Specific Operations: get_enum, set_enum **********************/
+            
+            /**
+            * Enum getter for <xsl:value-of select="$propertyName"/>.
+            * @param <xsl:text> _</xsl:text><xsl:value-of select="$name"/> <xsl:text> </xsl:text><xsl:value-of select="$axis2_name"/>_t object
+            * @param env pointer to environment struct
+            * @return <xsl:value-of select="$enum"/>; -1 on failure
+            */
+            <xsl:value-of select="$enum"/> AXIS2_CALL
+            <xsl:value-of select="$axis2_name"/>_get_<xsl:value-of select="$CName"/>_enum(
+            <xsl:value-of select="$axis2_name"/>_t*<xsl:text> _</xsl:text><xsl:value-of select="$name"/>,
+            const axutil_env_t *env);
+            
+            /**
+            * Enum setter for <xsl:value-of select="$propertyName"/>.
+            * @param <xsl:text> _</xsl:text><xsl:value-of select="$name"/> <xsl:text> </xsl:text><xsl:value-of select="$axis2_name"/>_t object
+            * @param env pointer to environment struct
+            * @param arg_<xsl:value-of select="$CName"/><xsl:text> </xsl:text> <xsl:value-of select="$enum"/>
+            * @return AXIS2_SUCCESS on success, else AXIS2_FAILURE
+            */
+            axis2_status_t AXIS2_CALL
+            <xsl:value-of select="$axis2_name"/>_set_<xsl:value-of select="$CName"/>_enum(
+            <xsl:value-of select="$axis2_name"/>_t*<xsl:text> _</xsl:text><xsl:value-of select="$name"/>,
+            const axutil_env_t *env,
+            <xsl:value-of select="$constValue"/><xsl:value-of select="$enum"/><xsl:text> </xsl:text>arg_<xsl:value-of select="$CName"/>);
+            
+          </xsl:for-each>
+        </xsl:if>
+
 
         /******************************* Checking and Setting NIL values *********************************/
         <xsl:if test="count(property[@array])!=0">/* Use 'Checking and Setting NIL values for Arrays' to check and set nil for individual elements */</xsl:if>

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateSource.xsl
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateSource.xsl?rev=655795&r1=655794&r2=655795&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateSource.xsl (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/template/CADBBeanTemplateSource.xsl Tue May 13 03:33:17 2008
@@ -57,6 +57,14 @@
         <xsl:variable name="simple"><xsl:value-of select="@simple"/></xsl:variable>
         <xsl:variable name="choice"><xsl:value-of select="@choice"/></xsl:variable>
 
+        <!-- Check if this type is a supported enum -->
+        <xsl:variable name="isEnum">
+          <xsl:choose>
+            <xsl:when test="count(property)=1 and property/enumFacet and property/@type='axis2_char_t*'">1</xsl:when>
+            <xsl:otherwise>0</xsl:otherwise>
+          </xsl:choose>
+        </xsl:variable>
+
         /**
          * <xsl:value-of select="$axis2_name"/>.c
          *
@@ -4582,6 +4590,78 @@
                 return AXIS2_SUCCESS;
              }
 
+            <xsl:if test="$isEnum=1">
+               <xsl:variable name="enum">adb_<xsl:value-of select="$propertyName"/>_enum_t</xsl:variable>
+             /**
+             * specialized enum getter for <xsl:value-of select="$propertyName"/>.
+             */
+             <xsl:value-of select="$enum"/> AXIS2_CALL
+             <xsl:value-of select="$axis2_name"/>_get_<xsl:value-of select="$CName"/>_enum(
+                 <xsl:value-of select="$axis2_name"/>_t* <xsl:value-of select="$name"/>,
+                 const axutil_env_t *env)
+             {
+                 AXIS2_ENV_CHECK(env, -1);
+                 AXIS2_PARAM_CHECK(env->error, <xsl:value-of select="$name"/>, -1);
+             
+             <xsl:for-each select="enumFacet">
+                 if (axutil_strcmp(<xsl:value-of select="$name"/>->property_<xsl:value-of select="$CName"/>, "<xsl:value-of select="@value"/>") == 0)
+                    return <xsl:value-of select="parent::node()/@caps-cname"/>_<xsl:value-of select="@id"/>;
+             </xsl:for-each>
+             
+                 /* Error: none of the strings matched; invalid enum value */
+                 return -1;
+             }
+             
+             
+             /**
+             * specialized enum setter for <xsl:value-of select="$propertyName"/>.
+             */
+             axis2_status_t AXIS2_CALL
+            <xsl:value-of select="$axis2_name"/>_set_<xsl:value-of select="$CName"/>_enum(
+                    <xsl:value-of select="$axis2_name"/>_t*<xsl:text> </xsl:text><xsl:value-of select="$name"/>,
+                    const axutil_env_t *env,
+                    <xsl:value-of select="$constValue"/><xsl:value-of select="$enum"/><xsl:text> </xsl:text> arg_<xsl:value-of select="$CName"/>)
+             {
+                <xsl:if test="@isarray">
+                 int size = 0;
+                 int i = 0;
+                 axis2_bool_t non_nil_exists = AXIS2_FALSE;
+                </xsl:if>
+
+                AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+                AXIS2_PARAM_CHECK(env->error, <xsl:value-of select="$name"/>, AXIS2_FAILURE);
+
+                <!-- first reset whatever already in there -->
+                   <xsl:value-of select="$axis2_name"/>_reset_<xsl:value-of select="$CName"/>(<xsl:value-of select="$name"/>, env);
+
+                   
+                   switch (arg_<xsl:value-of select="$CName"/>)
+                   {
+                     <xsl:for-each select="enumFacet">
+                       case <xsl:value-of select="parent::node()/@caps-cname"/>_<xsl:value-of select="@id"/> :
+                          <xsl:value-of select="$name"/>->property_<xsl:value-of select="$CName"/> = (axis2_char_t *)axutil_strdup(env, "<xsl:value-of select="@value"/>");
+                          break;
+                     </xsl:for-each>
+                     
+                       default:
+                          AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error setting <xsl:value-of select="$propertyName"/>: undefined enum value");
+                          return AXIS2_FAILURE;
+                   }
+                
+                   if(NULL == <xsl:value-of select="$name"/>->property_<xsl:value-of select="$CName"/>)
+                   {
+                       AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "Error allocating memory for <xsl:value-of select="$propertyName"/>");
+                       return AXIS2_FAILURE;
+                   }
+                        <xsl:value-of select="$name"/>->is_valid_<xsl:value-of select="$CName"/> = AXIS2_TRUE;
+                        
+                <xsl:if test="$choice">
+                    <xsl:value-of select="$name"/>->current_choice = "<xsl:value-of select="@nsuri"/>:<xsl:value-of select="$propertyName"/>";
+                </xsl:if>
+                return AXIS2_SUCCESS;
+             }
+            </xsl:if>
+
             <xsl:if test="@isarray">
             /**
              * Get ith element of <xsl:value-of select="$propertyName"/>.

Modified: webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java?rev=655795&r1=655794&r2=655795&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java (original)
+++ webservices/axis2/trunk/java/modules/adb-codegen/src/org/apache/axis2/schema/writer/CStructWriter.java Tue May 13 03:33:17 2008
@@ -31,6 +31,7 @@
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.XSLTTemplateProcessor;
 import org.apache.axis2.util.XSLTUtils;
+//import com.ibm.wsdl.util.xml.DOM2Writer;
 import org.apache.axis2.wsdl.databinding.CUtils;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.ws.commons.schema.XmlSchemaSimpleType;
@@ -893,10 +894,12 @@
                     String attribValue = (String) iterator.next();
                     XSLTUtils.addAttribute(model, "value", attribValue, enumFacet);
                     if (validJava) {
-                        XSLTUtils.addAttribute(model, "id", attribValue, enumFacet);
+                        XSLTUtils.addAttribute(model, "id", attribValue.toUpperCase(), enumFacet);
                     } else {
                         id++;
-                        XSLTUtils.addAttribute(model, "id", "value" + id, enumFacet);
+                        // Replace all invalid characters and append an id to avoid collisions
+                        XSLTUtils.addAttribute(model, "id", 
+                                attribValue.toUpperCase().replaceAll("[^A-Z0-9]", "_") + "_" + id, enumFacet);
                     }
                 }
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org