You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by mp...@apache.org on 2003/12/31 15:35:49 UTC

cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding ValueJXPathBinding.java

mpo         2003/12/31 06:35:49

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/binding
                        ValueJXPathBinding.java
  Log:
  Establishing consistency between bindings in how they handle 'leniency'.
  More story at: http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=107287810417490&w=2
  
  Revision  Changes    Path
  1.9       +44 -55    cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/ValueJXPathBinding.java
  
  Index: ValueJXPathBinding.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/ValueJXPathBinding.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ValueJXPathBinding.java	18 Dec 2003 07:57:21 -0000	1.8
  +++ ValueJXPathBinding.java	31 Dec 2003 14:35:49 -0000	1.9
  @@ -113,25 +113,21 @@
        * context to the Woody-form-widget specified in this object.
        */
       public void doLoad(Widget frmModel, JXPathContext jxpc) {
  -        try {
  -            Widget widget = frmModel.getWidget(this.fieldId);
  -            Object value = jxpc.getValue(this.xpath);
  -
  -            if (value != null && convertor != null) {
  -                if (value instanceof String) {
  -                    value = convertor.convertFromString((String)value, convertorLocale, null);
  -                } else {
  -                    getLogger().warn("Convertor ignored on backend-value which isn't of type String.");   
  -                }                
  -            }
  -
  -            widget.setValue(value);
  +        Widget widget = frmModel.getWidget(this.fieldId);
  +        Object value = jxpc.getValue(this.xpath);
   
  -            if (getLogger().isDebugEnabled())
  -                getLogger().debug("done loading " + toString() + " -- value= " + value);
  -        } catch (Exception e) {
  -            getLogger().warn("JXPath failed to find value for " + this.xpath, e);
  +        if (value != null && convertor != null) {
  +            if (value instanceof String) {
  +                value = convertor.convertFromString((String)value, convertorLocale, null);
  +            } else {
  +                getLogger().warn("Convertor ignored on backend-value which isn't of type String.");   
  +            }                
           }
  +
  +        widget.setValue(value);
  +
  +        if (getLogger().isDebugEnabled())
  +            getLogger().debug("done loading " + toString() + " -- value= " + value);
       }
   
       /**
  @@ -139,50 +135,43 @@
        * wrapped in a jxpath context
        */
       public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
  -        try {
  -            Widget widget = frmModel.getWidget(this.fieldId);
  -            Object value = widget.getValue();
  -            if (value != null && convertor != null) {
  -                value = convertor.convertToString(value, convertorLocale, null);
  -            }
  +        Widget widget = frmModel.getWidget(this.fieldId);
  +        Object value = widget.getValue();
  +        if (value != null && convertor != null) {
  +            value = convertor.convertToString(value, convertorLocale, null);
  +        }
   
  -            Object oldValue = jxpc.getValue(this.xpath);
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("value= " + value + "-- oldvalue=" + oldValue);
  -            }
  +        Object oldValue = jxpc.getValue(this.xpath);
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("value= " + value + "-- oldvalue=" + oldValue);
  +        }
   
  -            boolean update = false;
  +        boolean update = false;
   
  -            if ((value == null && oldValue != null) || value != null && !value.equals(oldValue)) {
  -                // first update the value itself
  -                jxpc.createPathAndSetValue(this.xpath, value);
  -
  -                // now perform any other bindings that need to be performed when the value is updated
  -                JXPathContext subContext = null;
  -                try {
  -                    subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
  -                } catch (JXPathException e) {
  -                    // if the value has been set to null and the underlying model is a bean, then
  -                    // JXPath will not be able to create a relative context
  -                    if (getLogger().isDebugEnabled()) {
  -                        getLogger().debug("(Ignorable) problem binding field " + widget.getFullyQualifiedId(), e);
  -                    }
  -                }
  -                if (subContext != null) {
  -                    this.updateBinding.saveFormToModel(frmModel, subContext);
  +        if ((value == null && oldValue != null) || value != null && !value.equals(oldValue)) {
  +            // first update the value itself
  +            jxpc.createPathAndSetValue(this.xpath, value);
  +
  +            // now perform any other bindings that need to be performed when the value is updated
  +            JXPathContext subContext = null;
  +            try {
  +                subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
  +            } catch (JXPathException e) {
  +                // if the value has been set to null and the underlying model is a bean, then
  +                // JXPath will not be able to create a relative context
  +                if (getLogger().isDebugEnabled()) {
  +                    getLogger().debug("(Ignorable) problem binding field " + widget.getFullyQualifiedId(), e);
                   }
  -
  -                update = true;
               }
  -
  -            if (getLogger().isDebugEnabled()) {
  -                getLogger().debug("done saving " + toString() + " -- value= " + value + " -- on-update == " + update);
  +            if (subContext != null) {
  +                this.updateBinding.saveFormToModel(frmModel, subContext);
               }
  -        } catch (Exception e) {
  -            throw new BindingException("Problem binding field " + this.fieldId +
  -                                       " (parent = \"" + frmModel.getFullyQualifiedId() + "\") to xpath " +
  -                                       this.xpath + " (context xpath = \"" + jxpc.getContextPointer().asPath() + "\")",
  -                                       e);
  +
  +            update = true;
  +        }
  +
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("done saving " + toString() + " -- value= " + value + " -- on-update == " + update);
           }
       }