mpo 2003/08/26 06:10:12
Modified: src/blocks/woody/java/org/apache/cocoon/woody/binding RepeaterJXPathBindingBuilder.java RepeaterJXPathBinding.java Log: Making sure the RepeaterBinding can be used without <on-insert-row> and <on-delete-row> Revision Changes Path 1.4 +13 -6 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBindingBuilder.java Index: RepeaterJXPathBindingBuilder.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBindingBuilder.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- RepeaterJXPathBindingBuilder.java 30 Jul 2003 15:17:43 -0000 1.3 +++ RepeaterJXPathBindingBuilder.java 26 Aug 2003 13:10:12 -0000 1.4 @@ -111,24 +111,31 @@ bindingElm, BindingManager.NAMESPACE, "on-bind"); - JXPathBindingBase[] childBindings = - assistant.makeChildBindings(childWrapElement); + + if (childWrapElement == null) throw new BindingException("RepeaterBinding misses '<on-bind>' child definition. " + DomHelper.getLocation(bindingElm)); + + JXPathBindingBase[] childBindings = assistant.makeChildBindings(childWrapElement); Element deleteWrapElement = DomHelper.getChildElement( bindingElm, BindingManager.NAMESPACE, "on-delete-row"); - JXPathBindingBase[] deleteBindings = - assistant.makeChildBindings(deleteWrapElement); + JXPathBindingBase[] deleteBindings = null; + if(deleteWrapElement != null) { + deleteBindings = assistant.makeChildBindings(deleteWrapElement); + } Element insertWrapElement = DomHelper.getChildElement( bindingElm, BindingManager.NAMESPACE, "on-insert-row"); - JXPathBindingBase insertBinding = - assistant.makeChildBindings(insertWrapElement)[0]; + JXPathBindingBase insertBinding = null; + if (insertWrapElement != null) { + insertBinding = assistant.makeChildBindings(insertWrapElement)[0]; + + } RepeaterJXPathBinding repeaterBinding = new RepeaterJXPathBinding( 1.4 +34 -17 cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBinding.java Index: RepeaterJXPathBinding.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/binding/RepeaterJXPathBinding.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- RepeaterJXPathBinding.java 12 Aug 2003 12:56:32 -0000 1.3 +++ RepeaterJXPathBinding.java 26 Aug 2003 13:10:12 -0000 1.4 @@ -192,7 +192,12 @@ // check if matchPath was in list of updates, if not --> bind for delete if (!updatedRowIds.contains(matchId)) { - this.deleteRowBinding.saveFormToModel(frmModel, rowContext); + if (this.deleteRowBinding != null) { + this.deleteRowBinding.saveFormToModel(frmModel, rowContext); + } else { + getLogger().warn("RepeaterBinding has detected rows to delete, " + + "but misses the <on-delete-row> binding to do it."); + } } } @@ -205,21 +210,29 @@ } // end with rows to insert (to make sure they don't get deleted!) - Iterator rowIterator = rowsToInsert.iterator(); - //register the factory! - this.insertRowBinding.saveFormToModel(repeater, repeaterContext); - while (rowIterator.hasNext()) { - Repeater.RepeaterRow thisRow = (Repeater.RepeaterRow) rowIterator.next(); - // --> create the path to let the context be created - Pointer newRowContextPointer = repeaterContext.createPath(this.rowPath + "[" + indexCount + "]"); - JXPathContext newRowContext = repeaterContext.getRelativeContext(newRowContextPointer); - if (getLogger().isDebugEnabled()) - getLogger().debug("inserted row at " + newRowContextPointer.asPath()); - // + rebind to children for update - this.rowBinding.saveFormToModel(thisRow, newRowContext); - getLogger().debug("bound new row"); - indexCount++; + if(rowsToInsert.size() > 0) { + if (this.insertRowBinding != null) { + Iterator rowIterator = rowsToInsert.iterator(); + //register the factory! + this.insertRowBinding.saveFormToModel(repeater, repeaterContext); + while (rowIterator.hasNext()) { + Repeater.RepeaterRow thisRow = (Repeater.RepeaterRow) rowIterator.next(); + // --> create the path to let the context be created + Pointer newRowContextPointer = repeaterContext.createPath(this.rowPath + "[" + indexCount + "]"); + JXPathContext newRowContext = repeaterContext.getRelativeContext(newRowContextPointer); + if (getLogger().isDebugEnabled()) + getLogger().debug("inserted row at " + newRowContextPointer.asPath()); + // + rebind to children for update + this.rowBinding.saveFormToModel(thisRow, newRowContext); + getLogger().debug("bound new row"); + indexCount++; + } + } else { + getLogger().warn("RepeaterBinding has detected rows to insert, " + + "but misses the <on-insert-row> binding to do it."); + } } + if (getLogger().isDebugEnabled()) getLogger().debug("done saving rows " + toString()); @@ -232,8 +245,12 @@ public void enableLogging(Logger logger) { super.enableLogging(logger); this.uniqueFieldBinding.enableLogging(logger); - this.deleteRowBinding.enableLogging(logger); - this.insertRowBinding.enableLogging(logger); + if (this.deleteRowBinding != null) { + this.deleteRowBinding.enableLogging(logger); + } + if (this.insertRowBinding != null) { + this.insertRowBinding.enableLogging(logger); + } this.rowBinding.enableLogging(logger); } }