joerg 2004/03/03 11:47:35
Modified: src/blocks/woody/java/org/apache/cocoon/woody/binding
RepeaterJXPathBinding.java
Log:
clean up: removed unused code (for reverting changes we have CVS, so please
remove old stuff always), JavaDoc added, comments fixed;
changed isNullAllListElements() => isAnyListElementNotNull(): the duplicate
negation at usage time breaks my brain ;-)
Revision Changes Path
1.23 +47 -75
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.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- RepeaterJXPathBinding.java 3 Mar 2004 12:30:18 -0000 1.22
+++ RepeaterJXPathBinding.java 3 Mar 2004 19:47:35 -0000 1.23
@@ -78,11 +78,6 @@
private final String repeaterPath;
private final String rowPath;
private final String rowPathForInsert;
- //private final String uniqueRowId;
- //private final String uniqueRowIdPath;
- //private final Convertor uniqueRowIdConvertor;
- //private final Locale uniqueRowIdConvertorLocale;
- //private final ValueJXPathBinding uniqueFieldBinding;
private final JXPathBindingBase rowBinding;
private final JXPathBindingBase insertRowBinding;
private final JXPathBindingBase deleteRowBinding;
@@ -118,13 +113,6 @@
this.repeaterPath = repeaterPath;
this.rowPath = rowPath;
this.rowPathForInsert = rowPathForInsert;
- //this.uniqueRowId = uniqueRowId;
- //this.uniqueRowIdPath = uniqueRowPath;
- /*this.uniqueFieldBinding = new ValueJXPathBinding(
- JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
uniqueRowId,
- uniqueRowPath, null, convertor, convertorLocale);*/
- //this.uniqueRowIdConvertor = convertor;
- //this.uniqueRowIdConvertorLocale = convertorLocale;
this.rowBinding = new ComposedJXPathBindingBase(
JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
childBindings);
@@ -139,9 +127,9 @@
if (this.deleteRowBinding != null) {
this.deleteRowBinding.setParent(this);
}
- /* New unique key management */
+ // New unique key management
uniqueRowBinding = new ArrayList();
- // Create a UniqueFieldJXPAthBining for the unique define in
old-style
+ // Create a UniqueFieldJXPathBining for the unique define in
old-style
if (uniqueRowId != null && uniqueRowPath != null) {
uniqueRowBinding.add(new UniqueFieldJXPathBinding(
JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
@@ -152,12 +140,6 @@
uniqueRowBinding.add(uniqueBindings[i]);
}
}
- /*this.uniqueRowBinding = new ComposedJXPathBindingBase(
- JXPathBindingBuilderBase.CommonAttributes.DEFAULT,
- uniqueBindings);
- if (this.uniqueRowBinding != null) {
- this.uniqueRowBinding.setParent(this);
- }*/
}
/**
@@ -193,7 +175,6 @@
while (iter.hasNext()) {
((UniqueFieldJXPathBinding)iter.next()).loadFormFromModel(thisRow, rowContext);
}
- //this.uniqueFieldBinding.loadFormFromModel(thisRow, rowContext);
this.rowBinding.loadFormFromModel(thisRow, rowContext);
}
if (getLogger().isDebugEnabled())
@@ -225,18 +206,15 @@
// Get the key values
List rowIdValues = getUniqueRowValues(thisRow);
- /*Widget rowIdWidget = thisRow.getWidget(this.uniqueRowId);
- Object rowIdValue = rowIdWidget.getValue();*/
- if (!isNullAllListElements(rowIdValues)) {
- // if (rowIdValue != null) {
- //if rowIdValue != null --> iterate nodes to find match
+ if (isAnyListElementNotNull(rowIdValues)) {
+ // iterate nodes to find match
Iterator rowPointers =
repeaterContext.iteratePointers(this.rowPath);
boolean found = false;
while (rowPointers.hasNext()) {
Pointer jxp = (Pointer) rowPointers.next();
JXPathContext rowContext =
repeaterContext.getRelativeContext(jxp);
- List matchIds = getMatchIdList(rowContext);
+ List matchIds = getMatchIds(rowContext);
if (ListUtils.isEqualList(rowIdValues, matchIds)) {
// match! --> bind to children
this.rowBinding.saveFormToModel(thisRow, rowContext);
@@ -253,7 +231,7 @@
updatedRowIds.add(rowIdValues);
}
} else {
- //if rowId == null --> remember to insert this one later
+ // if all rowIdValues == null --> this is a new row
rowsToInsert.add(thisRow);
}
}
@@ -263,9 +241,9 @@
while (rowPointers.hasNext()) {
Pointer jxp = (Pointer)rowPointers.next();
JXPathContext rowContext =
repeaterContext.getRelativeContext((Pointer)jxp.clone());
- List matchIds = getMatchIdList(rowContext);
+ List matchIds = getMatchIds(rowContext);
// check if matchPath was in list of updates, if not --> bind
for delete
- if (!isInUpdatedRowSet(updatedRowIds, matchIds)) {
+ if (!isListInSet(updatedRowIds, matchIds)) {
rowsToDelete.add(rowContext);
}
}
@@ -298,7 +276,6 @@
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();
// Perform the insert row binding.
@@ -328,18 +305,45 @@
}
}
- private boolean isInUpdatedRowSet(Set updatedRowIdsSet, List matchIds) {
- Iterator iter = updatedRowIdsSet.iterator();
+ /**
+ * Tests if a List is already contained in a Set of Lists.
+ * @param set the Set of Lists.
+ * @param list the list that is tested if it is already in the Set.
+ * @return true if the Set contains the List, false otherwise.
+ */
+ private boolean isListInSet(Set set, List list) {
+ Iterator iter = set.iterator();
+ while (iter.hasNext()) {
+ List listFromSet = (List)iter.next();
+ if (ListUtils.isEqualList(listFromSet, list)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Tests if any of the elements in a List is not null.
+ * @param list
+ * @return
+ */
+ private boolean isAnyListElementNotNull(List list) {
+ Iterator iter = list.iterator();
while (iter.hasNext()) {
- List updatedRowId = (List)iter.next();
- if (ListUtils.isEqualList(updatedRowId, matchIds)) {
+ if (iter.next() != null) {
return true;
}
}
return false;
}
- private List getMatchIdList(JXPathContext rowContext) {
- List matchIdList = new ArrayList();
+
+ /**
+ *
+ * @param rowContext
+ * @return
+ */
+ private List getMatchIds(JXPathContext rowContext) {
+ List matchIds = new ArrayList();
Iterator iter = this.uniqueRowBinding.iterator();
while (iter.hasNext()) {
UniqueFieldJXPathBinding key =
(UniqueFieldJXPathBinding)iter.next();
@@ -355,42 +359,11 @@
}
}
}
- matchIdList.add(matchId);
- }
- return matchIdList;
- }
- /*
- private Object getMatchId(JXPathContext rowContext) {
- Object matchId;
- matchId = rowContext.getValue(this.uniqueRowIdPath);
- if (matchId != null && this.uniqueRowIdConvertor != null) {
- if (matchId instanceof String) {
- matchId = this.uniqueRowIdConvertor.convertFromString(
- (String)matchId,
- this.uniqueRowIdConvertorLocale, null);
- } else {
- if (getLogger().isWarnEnabled()) {
- getLogger().warn("Convertor ignored on backend-value " +
- "which isn't of type String.");
- }
- }
- }
- return matchId;
- }
-*/
- private boolean isNullAllListElements(List list) {
- Iterator iter = list.iterator();
- while (iter.hasNext()) {
- if (iter.next() != null) {
- return false;
- }
- }
- if (list.size() > 0) {
- return true;
- } else {
- return false;
+ matchIds.add(matchId);
}
+ return matchIds;
}
+
/**
* Get the values of the unique-fields of the given row in the formModel
* @param thisRow
@@ -405,17 +378,16 @@
Object rowIdValue = rowIdWidget.getValue();
values.add(rowIdValue);
}
- return values;
+ return values;
}
public String toString() {
return "RepeaterJXPathBinding [widget=" + this.repeaterId +
- ", xpath=" + this.repeaterPath + "]";
+ ", xpath=" + this.repeaterPath + "]";
}
public void enableLogging(Logger logger) {
super.enableLogging(logger);
- //this.uniqueFieldBinding.enableLogging(logger);
if (this.deleteRowBinding != null) {
this.deleteRowBinding.enableLogging(logger);
}