axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r376581 - in /webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema: template/ADBBeanTemplate.xsl util/PrimitiveTypeFinder.java writer/JavaBeanWriter.java
Date Fri, 10 Feb 2006 06:52:30 GMT
Author: ajith
Date: Thu Feb  9 22:52:29 2006
New Revision: 376581

URL: http://svn.apache.org/viewcvs?rev=376581&view=rev
Log:
Added a fix for null handling with xml primitive types.

Added:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/util/PrimitiveTypeFinder.java
Modified:
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
    webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl?rev=376581&r1=376580&r2=376581&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/template/ADBBeanTemplate.xsl
Thu Feb  9 22:52:29 2006
@@ -172,29 +172,32 @@
                             elementList.add(new javax.xml.namespace.QName("<xsl:value-of
select="$namespace"/>",
                                                                       "<xsl:value-of select="$propertyName"/>"));
                             <!-- Arraylist can handle null's -->
-                                 <xsl:choose>
-                                    <xsl:when test="@nillable">
-                                     elementList.add(<xsl:value-of select="$varName"/>==null?null:
-                                     <xsl:value-of select="$varName"/>);
-                                     </xsl:when>
-                                     <xsl:otherwise>
-                                      if (<xsl:value-of select="$varName"/>==null){
-                                         throw new RuntimeException("<xsl:value-of select="$propertyName"/>
cannot be null!!");
-                                      }
-                                      elementList.add(<xsl:value-of select="$varName"/>);
-                                     </xsl:otherwise>
-                                   </xsl:choose>
+                            <xsl:choose>
+                                <xsl:when test="@nillable">
+                                    elementList.add(<xsl:value-of select="$varName"/>==null?null:
+                                    <xsl:value-of select="$varName"/>);
+                                </xsl:when>
+                                <xsl:otherwise>
+                                    if (<xsl:value-of select="$varName"/>==null){
+                                    throw new RuntimeException("<xsl:value-of select="$propertyName"/>
cannot be null!!");
+                                    }
+                                    elementList.add(<xsl:value-of select="$varName"/>);
+                                </xsl:otherwise>
+                            </xsl:choose>
                         </xsl:when>
                         <xsl:otherwise>
                              elementList.add(new javax.xml.namespace.QName("<xsl:value-of
select="$namespace"/>",
                                                                       "<xsl:value-of select="$propertyName"/>"));
-                             <!-- for some primitive types - there's no concept of a null,
say for int. hence we
-                                  are unbale to test for null unless a supporting parameter
is supplied to say
-                                  whether a type is primitive or not -->
-
-                            elementList.add(
-                            org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>));
-
+                            <xsl:choose>
+                                <xsl:when test="@nillable and not(@primitive)">
+                                    elementList.add(<xsl:value-of select="$varName"/>==null?null:
+                                     org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>));
+                                </xsl:when>
+                                <xsl:otherwise>
+                                elementList.add(
+                                   org.apache.axis2.databinding.utils.ConverterUtil.convertToString(<xsl:value-of
select="$varName"/>));
+                                </xsl:otherwise>
+                            </xsl:choose>
                         </xsl:otherwise>
                     </xsl:choose>
                     <xsl:if test="$min=0 or $choice">}</xsl:if>

Added: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/util/PrimitiveTypeFinder.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/util/PrimitiveTypeFinder.java?rev=376581&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/util/PrimitiveTypeFinder.java
(added)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/util/PrimitiveTypeFinder.java
Thu Feb  9 22:52:29 2006
@@ -0,0 +1,51 @@
+package org.apache.axis2.schema.util;
+
+import java.util.List;
+import java.util.ArrayList;
+/*
+ * 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.
+ */
+
+/**
+ * A simple utiliy to find whether a given class name is
+ * primitive or not
+ */
+public class PrimitiveTypeFinder {
+
+    private static List primitiveClassNameList;
+
+    static{
+        primitiveClassNameList =  new ArrayList();
+        //add the java primitive class names
+        primitiveClassNameList.add(int.class.getName());
+        primitiveClassNameList.add(long.class.getName());
+        primitiveClassNameList.add(byte.class.getName());
+        primitiveClassNameList.add(double.class.getName());
+        primitiveClassNameList.add(boolean.class.getName());
+        primitiveClassNameList.add(float.class.getName());
+        primitiveClassNameList.add(short.class.getName());
+        primitiveClassNameList.add(char.class.getName());
+
+    }
+
+    /**
+     *
+     * @param className
+     * @return
+     */
+    public static boolean isPrimitive(String className){
+        return primitiveClassNameList.contains(className);
+    }
+}

Modified: webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java?rev=376581&r1=376580&r2=376581&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
(original)
+++ webservices/axis2/trunk/java/modules/codegen/src/org/apache/axis2/schema/writer/JavaBeanWriter.java
Thu Feb  9 22:52:29 2006
@@ -7,6 +7,7 @@
 import org.apache.axis2.schema.typemap.JavaTypeMap;
 import org.apache.axis2.schema.i18n.SchemaCompilerMessages;
 import org.apache.axis2.schema.util.SchemaPropertyLoader;
+import org.apache.axis2.schema.util.PrimitiveTypeFinder;
 import org.apache.axis2.util.JavaUtils;
 import org.apache.axis2.util.URLProcessor;
 import org.apache.axis2.util.XSLTTemplateProcessor;
@@ -427,6 +428,9 @@
 
             XSLTUtils.addAttribute(model, "type", javaClassNameForElement, property);
 
+            if (PrimitiveTypeFinder.isPrimitive(javaClassNameForElement)){
+                XSLTUtils.addAttribute(model, "primitive", "yes", property);
+            }
             //add an attribute that says the type is default
             if (isDefault(javaClassNameForElement)){
                 XSLTUtils.addAttribute(model, "default", "yes", property);



Mime
View raw message