You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jo...@apache.org on 2007/09/06 05:25:30 UTC
svn commit: r573140 - in /ofbiz/trunk/framework: service/dtd/
service/src/org/ofbiz/service/ webtools/webapp/webtools/service/
Author: jonesde
Date: Wed Sep 5 20:25:29 2007
New Revision: 573140
URL: http://svn.apache.org/viewvc?rev=573140&view=rev
Log:
Refactor of service def attribute default-value stuff, fixes the corner case found in OFBIZ-1226; was able to get through test case that previously erred out
Modified:
ofbiz/trunk/framework/service/dtd/services.xsd
ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java
ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java
ofbiz/trunk/framework/webtools/webapp/webtools/service/availableservices.ftl
Modified: ofbiz/trunk/framework/service/dtd/services.xsd
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/dtd/services.xsd?rev=573140&r1=573139&r2=573140&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/dtd/services.xsd (original)
+++ ofbiz/trunk/framework/service/dtd/services.xsd Wed Sep 5 20:25:29 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/trunk/framework/service/src/org/ofbiz/service/ModelParam.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java?rev=573140&r1=573139&r2=573140&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelParam.java Wed Sep 5 20:25:29 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/trunk/framework/service/src/org/ofbiz/service/ModelService.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java?rev=573140&r1=573139&r2=573140&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelService.java Wed Sep 5 20:25:29 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);
}
}
}
@@ -1091,15 +1092,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;
@@ -1117,18 +1111,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/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java?rev=573140&r1=573139&r2=573140&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ModelServiceReader.java Wed Sep 5 20:25:29 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
@@ -693,11 +690,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/trunk/framework/webtools/webapp/webtools/service/availableservices.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/service/availableservices.ftl?rev=573140&r1=573139&r2=573140&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/service/availableservices.ftl (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/service/availableservices.ftl Wed Sep 5 20:25:29 2007
@@ -223,24 +223,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='<@o...@ofbizUrl>'>${params.entityName?if_exists}</a>
+ <#if modelParam.entityName?exists>
+ <a href='<@o...@ofbizUrl>'>${modelParam.entityName?if_exists}</a>
</#if>
</td>
- <td>${params.fieldName?if_exists}</td>
+ <td>${modelParam.fieldName?if_exists}</td>
</tr>
</#list>
</table>