Author: jleroux
Date: Fri Sep 21 15:16:27 2007
New Revision: 578288

URL: http://svn.apache.org/viewvc?rev=578288&view=rev
Log:
Applied fix from trunk for revision: 573140

Modified:
    ofbiz/branches/release4.0/framework/service/dtd/services.xsd
    
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelParam.java
    
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelService.java
    
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelServiceReader.java
    
ofbiz/branches/release4.0/framework/webtools/webapp/webtools/service/availableservices.ftl

Modified: ofbiz/branches/release4.0/framework/service/dtd/services.xsd
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/service/dtd/services.xsd?rev=578288&r1=578287&r2=578288&view=diff
==============================================================================
--- ofbiz/branches/release4.0/framework/service/dtd/services.xsd (original)
+++ ofbiz/branches/release4.0/framework/service/dtd/services.xsd Fri Sep 21 
15:16:27 2007
@@ -295,7 +295,7 @@
             </xs:simpleType>
         </xs:attribute>
         <xs:attribute type="xs:string" name="default-value">
-            <xs:annotation><xs:documentation>The value specified will be used 
for the attribute if no value is passed in. This will only happen if it is okay 
to not pass a value in, ie if optional=true. If optional=false a value must be 
passed in so this attribute would be ignored.</xs:documentation></xs:annotation>
+            <xs:annotation><xs:documentation>The value specified will be used 
for the attribute if no value is passed in. This will only happen if it is okay 
to not pass a value in, so if this is set then optional will be set to true. If 
optional=false and this is set then the value will be overridden and with a 
value in default-value is will set optional=true 
anyway.</xs:documentation></xs:annotation>
         </xs:attribute>
         <xs:attribute type="xs:string" name="form-label"/>
         <xs:attribute type="xs:string" name="entity-name"/>

Modified: 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelParam.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelParam.java?rev=578288&r1=578287&r2=578288&view=diff
==============================================================================
--- 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelParam.java
 (original)
+++ 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelParam.java
 Fri Sep 21 15:16:27 2007
@@ -18,23 +18,26 @@
  
*******************************************************************************/
 package org.ofbiz.service;
 
+import java.io.Serializable;
 import java.util.List;
 import java.util.Locale;
-import java.io.Serializable;
 
-import javax.wsdl.WSDLException;
-import javax.wsdl.Part;
 import javax.wsdl.Definition;
+import javax.wsdl.Part;
+import javax.wsdl.WSDLException;
 import javax.xml.namespace.QName;
 
-import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.ObjectType;
+import org.ofbiz.base.util.UtilProperties;
 
 /**
  * Generic Service Model Parameter
  */
 public class ModelParam implements Serializable {
 
+    public static final String module = ModelParam.class.getName();
+
     /** Parameter name */
     public String name;
 
@@ -63,8 +66,7 @@
     public List validators;
 
     /** Default value */
-    public String defaultValue;    
-    public Object defaultValueObj;
+    private String defaultValue = null;    
 
     /** Is this Parameter required or optional? Default to false, or required 
*/
     public boolean optional = false;
@@ -89,7 +91,7 @@
         this.stringMapPrefix = param.stringMapPrefix;
         this.stringListSuffix = param.stringListSuffix;
         this.validators = param.validators;
-        this.defaultValue = param.defaultValue;
+        if (param.defaultValue != null) 
this.setDefaultValue(param.defaultValue);
         this.optional = param.optional;
         this.overrideOptional = param.overrideOptional;
         this.formDisplay = param.formDisplay;
@@ -111,6 +113,34 @@
         } else {
             return null;
         }
+    }
+    
+    public Object getDefaultValue() {
+        Object defaultValueObj = null;
+        if (this.type != null) {
+            try {
+                defaultValueObj = 
ObjectType.simpleTypeConvert(this.defaultValue, this.type, null, null, false);
+            } catch (Exception e) {
+                Debug.logWarning(e, "Service attribute [" + name + "] default 
value could not be converted to type [" + type + "]: " + e.toString(), module);
+            }
+            if (defaultValueObj == null) {
+                // uh-oh, conversion failed, set the String and see what 
happens
+                defaultValueObj = this.defaultValue;
+            }
+        } else {
+            defaultValueObj = this.defaultValue;
+        }
+        return defaultValueObj;
+    }
+    public void setDefaultValue(String defaultValue) {
+        this.defaultValue = defaultValue;
+        if (this.defaultValue != null) {
+            this.optional = true;
+        }
+        if (Debug.verboseOn()) Debug.logVerbose("Default value for attribute 
[" + this.name + "] set to [" + this.defaultValue + "]", module);
+    }
+    public void copyDefaultValue(ModelParam param) {
+        this.setDefaultValue(param.defaultValue);
     }
 
     public boolean equals(ModelParam model) {

Modified: 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelService.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelService.java?rev=578288&r1=578287&r2=578288&view=diff
==============================================================================
--- 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelService.java
 (original)
+++ 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelService.java
 Fri Sep 21 15:16:27 2007
@@ -369,9 +369,10 @@
             while (i.hasNext()) {
                 ModelParam param = (ModelParam) i.next();
                 if ("INOUT".equals(param.mode) || mode.equals(param.mode)) {
-                    if (param.defaultValue != null && context.get(param.name) 
== null) {
-                        context.put(param.name, param.defaultValueObj);
-                        Debug.log("Set default value for parameter: " + 
param.name, module);
+                    Object defaultValueObj = param.getDefaultValue();
+                    if (defaultValueObj != null && context.get(param.name) == 
null) {
+                        context.put(param.name, defaultValueObj);
+                        Debug.logInfo("Set default value [" + defaultValueObj 
+ "] for parameter [" + param.name + "]", module);
                     }
                 }
             }
@@ -1057,15 +1058,8 @@
                         if (UtilValidate.isNotEmpty(overrideParam.formLabel)) {
                             existingParam.formLabel = overrideParam.formLabel;
                         }
-                        if (overrideParam.defaultValue != null) {
-                            existingParam.defaultValue = 
overrideParam.defaultValue;
-                            existingParam.optional = true;
-                            if (overrideParam.defaultValueObj == null) {
-                                existingParam.defaultValueObj = 
this.convertDefaultValue(this.name, overrideParam.name,
-                                        existingParam.type, 
overrideParam.defaultValue);
-                            } else {
-                                existingParam.defaultValueObj = 
overrideParam.defaultValueObj;
-                            }
+                        if (overrideParam.getDefaultValue() != null) {
+                            existingParam.copyDefaultValue(overrideParam);
                         }
                         if (overrideParam.overrideFormDisplay) {
                             existingParam.formDisplay = 
overrideParam.formDisplay;
@@ -1083,18 +1077,6 @@
             // set the flag so we don't do this again
             this.inheritedParameters = true;
         }
-    }
-
-    protected Object convertDefaultValue(String serviceName, String name, 
String type, String value) {
-        Object converted;
-        try {
-            converted = ObjectType.simpleTypeConvert(value, type, null, null, 
false);
-        } catch (Exception e) {
-            Debug.logWarning("Service [" + serviceName + "] attribute [" + 
name + "] default value could not be converted to type [" + type + "]", module);
-            return value;
-        }
-
-        return converted;
     }
 
     public Document toWSDL(String locationURI) throws WSDLException {

Modified: 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelServiceReader.java
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelServiceReader.java?rev=578288&r1=578287&r2=578288&view=diff
==============================================================================
--- 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelServiceReader.java
 (original)
+++ 
ofbiz/branches/release4.0/framework/service/src/org/ofbiz/service/ModelServiceReader.java
 Fri Sep 21 15:16:27 2007
@@ -552,11 +552,8 @@
             // default value
             String defValue = attribute.getAttribute("default-value");
             if (UtilValidate.isNotEmpty(defValue)) {
-                param.defaultValue = defValue;
-                if (param.type != null) {
-                    param.defaultValueObj = 
service.convertDefaultValue(service.name, param.name, param.type, defValue);
-                }
-                param.optional = true;
+                Debug.logInfo("Got a default-value [" + defValue + "] for 
service attribute [" + service.name + "." + param.name + "]", module);
+                param.setDefaultValue(defValue);
             }
             
             // set the entity name to the default if not specified
@@ -685,11 +682,7 @@
                 // default value
                 String defValue = attribute.getAttribute("default-value");
                 if (UtilValidate.isNotEmpty(defValue)) {
-                    param.defaultValue = defValue;
-                    if (param.type != null) {
-                        param.defaultValueObj = 
service.convertDefaultValue(service.name, param.name, param.type, defValue);
-                    }                    
-                    param.optional = true;
+                    param.setDefaultValue(defValue);
                 }
 
                 // override validators

Modified: 
ofbiz/branches/release4.0/framework/webtools/webapp/webtools/service/availableservices.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/branches/release4.0/framework/webtools/webapp/webtools/service/availableservices.ftl?rev=578288&r1=578287&r2=578288&view=diff
==============================================================================
--- 
ofbiz/branches/release4.0/framework/webtools/webapp/webtools/service/availableservices.ftl
 (original)
+++ 
ofbiz/branches/release4.0/framework/webtools/webapp/webtools/service/availableservices.ftl
 Fri Sep 21 15:16:27 2007
@@ -222,24 +222,26 @@
                 <td>${uiLabelMap.WebtoolsParameterName}</td>
                 <td>${uiLabelMap.WebtoolsOptional}</td>
                 <td>${uiLabelMap.CommonType}</td>
+                <#-- <td>Default Value</td> -->
                 <td>${uiLabelMap.WebtoolsMode}</td>
                 <td>${uiLabelMap.WebtoolsIsSetInternally}</td>
                 <td>${uiLabelMap.WebtoolsEntityName}</td>
                 <td>${uiLabelMap.WebtoolsFieldName}</td>
               </tr>
-              <#list paramList.paramList as params>
+              <#list paramList.paramList as modelParam>
                 <tr>
-                  <td>${params.name?if_exists}</td>
-                  <td>${params.optional?if_exists}</td>
-                  <td>${params.type?if_exists}</td>
-                  <td>${params.mode?if_exists}</td>
-                  <td>${params.internal?if_exists}</td>
+                  <td>${modelParam.name?if_exists}</td>
+                  <td>${modelParam.optional?if_exists}</td>
+                  <td>${modelParam.type?if_exists}</td>
+                  <#-- <td>[${modelParam.defaultValue?if_exists}]</td> -->
+                  <td>${modelParam.mode?if_exists}</td>
+                  <td>${modelParam.internal?if_exists}</td>
                   <td>
-                    <#if params.entityName?exists>
-                      <a href='<@ofbizUrl>[EMAIL 
PROTECTED]</@ofbizUrl>'>${params.entityName?if_exists}</a>
+                    <#if modelParam.entityName?exists>
+                      <a href='<@ofbizUrl>[EMAIL 
PROTECTED]</@ofbizUrl>'>${modelParam.entityName?if_exists}</a>
                     </#if>
                   </td>
-                  <td>${params.fieldName?if_exists}</td>
+                  <td>${modelParam.fieldName?if_exists}</td>
                 </tr>
               </#list>
           </table>


Reply via email to