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 2004/04/23 13:42:58 UTC
cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel AggregateField.java
mpo 2004/04/23 04:42:58
Modified: src/blocks/forms/java/org/apache/cocoon/forms/binding
CustomJXPathBinding.java
SimpleRepeaterJXPathBinding.java
TempRepeaterJXPathBinding.java
JavaScriptJXPathBinding.java JXPathBindingBase.java
RepeaterJXPathBinding.java ValueJXPathBinding.java
UnionJXPathBinding.java
MultiValueJXPathBinding.java
AggregateJXPathBinding.java
StructJXPathBinding.java
src/blocks/forms/java/org/apache/cocoon/forms/formmodel
AggregateField.java
Log:
Preparing widgets and binding for moving the signature getWidget(id) to the context of ContainerWidget.
Revision Changes Path
1.5 +3 -21 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/CustomJXPathBinding.java
Index: CustomJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/CustomJXPathBinding.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- CustomJXPathBinding.java 6 Apr 2004 08:51:24 -0000 1.4
+++ CustomJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.5
@@ -64,7 +64,7 @@
* @throws BindingException when the wrapped CustomBinding fails
*/
public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Widget selectedWidget = selectWidget(frmModel);
+ Widget selectedWidget = selectWidget(frmModel, this.widgetId);
JXPathContext context = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
this.wrappedBinding.doLoad(selectedWidget, context);
@@ -79,29 +79,11 @@
* @throws BindingException when the wrapped CustomBinding fails
*/
public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Widget selectedWidget = selectWidget(frmModel);
+ Widget selectedWidget = selectWidget(frmModel, this.widgetId);
JXPathContext context = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
this.wrappedBinding.doSave(selectedWidget, context);
}
-
- /**
- * Helper method which selects down the identified widget from the formModel.
- * If no 'widgetId' is set the formModel will just be returned.
- *
- * @param frmModel
- * @return
- * @throws BindingException
- */
- private Widget selectWidget(Widget frmModel) throws BindingException {
- if (this.widgetId == null) return frmModel;
-
- Widget selectedWidget = frmModel.getWidget(this.widgetId);
- if (selectedWidget == null) {
- throw new BindingException("The widget with the ID [" + this.widgetId
- + "] referenced in the binding does not exist in the form definition.");
- }
- return selectedWidget;
- }
+
}
1.3 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/SimpleRepeaterJXPathBinding.java
Index: SimpleRepeaterJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/SimpleRepeaterJXPathBinding.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SimpleRepeaterJXPathBinding.java 9 Mar 2004 11:31:12 -0000 1.2
+++ SimpleRepeaterJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.3
@@ -59,7 +59,7 @@
public void doLoad(Widget frmModel, JXPathContext jctx)
throws BindingException {
// Find the repeater and clear it
- Repeater repeater = (Repeater)frmModel.getWidget(this.repeaterId);
+ Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);
if (this.clearOnLoad) {
repeater.removeRows();
@@ -101,7 +101,7 @@
public void doSave(Widget frmModel, JXPathContext jctx)
throws BindingException {
// Find the repeater
- Repeater repeater = (Repeater)frmModel.getWidget(this.repeaterId);
+ Repeater repeater = (Repeater)selectWidget(frmModel, this.repeaterId);
if (repeater.getSize() == 0 && this.deleteIfEmpty) {
// Repeater is empty : erase all
1.4 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/TempRepeaterJXPathBinding.java
Index: TempRepeaterJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/TempRepeaterJXPathBinding.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TempRepeaterJXPathBinding.java 12 Apr 2004 14:05:08 -0000 1.3
+++ TempRepeaterJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.4
@@ -71,7 +71,7 @@
// (There should be a general widget type checker for all the bindings to use,
// coupled with a general informative exception class to throw if the widget is
// of the wrong type or null.)
- Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
+ Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);
if (repeater == null) {
String fullId = frmModel.getFullyQualifiedId();
if (fullId == null || fullId.length() == 0) {
@@ -150,7 +150,7 @@
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException {
// (See comment in doLoad about type checking and throwing a meaningful exception.)
- Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
+ Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);
// Perform shortcut binding if the repeater is empty
// and the deleteIfEmpty config option is selected.
1.3 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBinding.java
Index: JavaScriptJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/JavaScriptJXPathBinding.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavaScriptJXPathBinding.java 24 Mar 2004 01:32:45 -0000 1.2
+++ JavaScriptJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.3
@@ -52,7 +52,7 @@
public void doLoad(Widget frmModel, JXPathContext jctx) {
if (this.loadScript != null) {
- Widget widget = frmModel.getWidget(this.id);
+ Widget widget = selectWidget(frmModel,this.id);
// Move to widget context
Pointer pointer = jctx.getPointer(this.path);
@@ -86,7 +86,7 @@
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException {
if (this.saveScript != null) {
- Widget widget = frmModel.getWidget(this.id);
+ Widget widget = selectWidget(frmModel,this.id);
// Move to widget context and create the path if needed
Pointer pointer = jctx.createPath(this.path);
1.2 +26 -8 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java
Index: JXPathBindingBase.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JXPathBindingBase.java 9 Mar 2004 10:33:55 -0000 1.1
+++ JXPathBindingBase.java 23 Apr 2004 11:42:58 -0000 1.2
@@ -20,6 +20,7 @@
import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.logger.Logger;
+import org.apache.cocoon.forms.formmodel.ContainerWidget;
import org.apache.cocoon.forms.formmodel.Widget;
import org.apache.cocoon.util.jxpath.DOMFactory;
import org.apache.commons.jxpath.JXPathContext;
@@ -100,16 +101,33 @@
return classBinding;
}
- protected Widget getWidget(Widget widget, String id) {
- Widget childWidget = widget.getWidget(id);
- if (childWidget != null) {
- return childWidget;
- } else {
+ /**
+ * Helper method that selects a child-widget with a given id from a parent.
+ *
+ * @param parent co9ntaining the child-widget to return.
+ * @param id of the childWidget to find, if this is <code>null</code> then the parent is returned.
+ * @return the selected widget
+ *
+ * @throws a {@link RuntimeException} if the id is not null and points to a
+ * child-widget that cannot be found.
+ */
+ protected Widget selectWidget(Widget parent, String id) {
+ if (id == null) return parent;
+
+ Widget childWidget = null;
+
+ if (parent instanceof ContainerWidget) {
+ childWidget = ((ContainerWidget) parent).getWidget(id);
+ }
+
+ if (childWidget == null) {
throw new RuntimeException(getClass().getName() + ": Widget \"" +
id + "\" does not exist in container \"" +
- widget.getFullyQualifiedId() + "\" (" +
- widget.getLocation() + ").");
+ parent.getFullyQualifiedId() + "\" (" +
+ parent.getLocation() + ").");
}
+
+ return childWidget;
}
/**
1.5 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java
Index: RepeaterJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathBinding.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- RepeaterJXPathBinding.java 31 Mar 2004 20:34:11 -0000 1.4
+++ RepeaterJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.5
@@ -96,7 +96,7 @@
public void doLoad(Widget frmModel, JXPathContext jxpc)
throws BindingException {
// Find the repeater
- Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
+ Repeater repeater = (Repeater) (Repeater) selectWidget(frmModel, this.repeaterId);
if (repeater == null) {
throw new BindingException("The repeater with the ID [" + this.repeaterId
+ "] referenced in the binding does not exist in the form definition.");
@@ -136,7 +136,7 @@
public void doSave(Widget frmModel, JXPathContext jxpc)
throws BindingException {
// Find the repeater
- Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId);
+ Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId);
// and his context
JXPathContext repeaterContext =
jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath));
1.4 +5 -5 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/ValueJXPathBinding.java
Index: ValueJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/ValueJXPathBinding.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ValueJXPathBinding.java 12 Mar 2004 03:31:39 -0000 1.3
+++ ValueJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.4
@@ -15,14 +15,14 @@
*/
package org.apache.cocoon.forms.binding;
+import java.util.Locale;
+
import org.apache.avalon.framework.logger.Logger;
import org.apache.cocoon.forms.datatype.convertor.Convertor;
import org.apache.cocoon.forms.formmodel.Widget;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
-import java.util.Locale;
-
/**
* ValueJXPathBinding provides an implementation of a {@link Binding}
* that loads and saves the information behind a specific xpath expresion
@@ -80,7 +80,7 @@
* context to the CForms-form-widget specified in this object.
*/
public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Widget widget = frmModel.getWidget(this.fieldId);
+ Widget widget = selectWidget(frmModel, this.fieldId);
if (widget == null) {
throw new BindingException("The widget with the ID [" + this.fieldId
+ "] referenced in the binding does not exist in the form definition.");
@@ -106,7 +106,7 @@
* wrapped in a jxpath context
*/
public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Widget widget = frmModel.getWidget(this.fieldId);
+ Widget widget = selectWidget(frmModel, this.fieldId);
Object value = widget.getValue();
if (value != null && convertor != null) {
value = convertor.convertToString(value, convertorLocale, null);
1.3 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/UnionJXPathBinding.java
Index: UnionJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/UnionJXPathBinding.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UnionJXPathBinding.java 12 Apr 2004 14:05:08 -0000 1.2
+++ UnionJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.3
@@ -55,7 +55,7 @@
* before continuing the binding over the child-bindings.
*/
public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Widget widget = frmModel.getWidget(this.widgetId);
+ Widget widget = selectWidget(frmModel, this.widgetId);
JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
if (!(widget instanceof Union))
throw new RuntimeException("Binding: Expected Union widget, but received class: \"" +
@@ -79,7 +79,7 @@
* before continuing the binding over the child-bindings.
*/
public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Union unionWidget = (Union)frmModel.getWidget(this.widgetId);
+ Union unionWidget = (Union)selectWidget(frmModel, this.widgetId);
JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
Binding[] subBindings = getChildBindings();
if (subBindings != null) {
1.2 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java
Index: MultiValueJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/MultiValueJXPathBinding.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MultiValueJXPathBinding.java 9 Mar 2004 10:33:55 -0000 1.1
+++ MultiValueJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.2
@@ -54,7 +54,7 @@
}
public void doLoad(Widget frmModel, JXPathContext jctx) throws BindingException {
- Widget widget = frmModel.getWidget(this.multiValueId);
+ Widget widget = selectWidget(frmModel,this.multiValueId);
if (widget == null) {
throw new BindingException("The widget with the ID [" + this.multiValueId
+ "] referenced in the binding does not exist in the form definition.");
@@ -93,7 +93,7 @@
}
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException {
- Widget widget = frmModel.getWidget(this.multiValueId);
+ Widget widget = selectWidget(frmModel,this.multiValueId);
Object[] values = (Object[])widget.getValue();
JXPathContext multiValueContext = jctx.getRelativeContext(jctx.createPath(this.multiValuePath));
1.2 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java
Index: AggregateJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/AggregateJXPathBinding.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AggregateJXPathBinding.java 9 Mar 2004 10:33:55 -0000 1.1
+++ AggregateJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.2
@@ -58,7 +58,7 @@
public void doLoad(Widget frmModel,
JXPathContext jxpc) throws BindingException {
AggregateField aggregate =
- (AggregateField)frmModel.getWidget(this.widgetId);
+ (AggregateField)selectWidget(frmModel, this.widgetId);
JXPathContext subContext =
jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
super.doLoad(aggregate, subContext);
@@ -76,7 +76,7 @@
public void doSave(Widget frmModel,
JXPathContext jxpc) throws BindingException {
AggregateField aggregate =
- (AggregateField) frmModel.getWidget(this.widgetId);
+ (AggregateField)selectWidget(frmModel, this.widgetId);
JXPathContext subContext =
jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
super.doSave(aggregate, subContext);
1.3 +3 -3 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java
Index: StructJXPathBinding.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/binding/StructJXPathBinding.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StructJXPathBinding.java 12 Apr 2004 14:05:08 -0000 1.2
+++ StructJXPathBinding.java 23 Apr 2004 11:42:58 -0000 1.3
@@ -54,7 +54,7 @@
* before continuing the binding over the child-bindings.
*/
public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Struct structWidget = (Struct)getWidget(frmModel, this.widgetId);
+ Struct structWidget = (Struct)selectWidget(frmModel, this.widgetId);
JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
super.doLoad(structWidget, subContext);
if (getLogger().isDebugEnabled()) {
@@ -68,7 +68,7 @@
* before continuing the binding over the child-bindings.
*/
public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
- Struct structWidget = (Struct)frmModel.getWidget(this.widgetId);
+ Struct structWidget = (Struct)selectWidget(frmModel, this.widgetId);
JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
super.doSave(structWidget, subContext);
if (getLogger().isDebugEnabled()) {
1.6 +13 -2 cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java
Index: AggregateField.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateField.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AggregateField.java 22 Apr 2004 14:26:48 -0000 1.5
+++ AggregateField.java 23 Apr 2004 11:42:58 -0000 1.6
@@ -51,7 +51,7 @@
*
* @version CVS $Id$
*/
-public class AggregateField extends Field {
+public class AggregateField extends Field implements ContainerWidget {
/**
* List of nested fields
@@ -72,10 +72,21 @@
return (AggregateFieldDefinition)getDefinition();
}
+ public void addWidget(Widget widget) {
+ if (!(widget instanceof Field))
+ throw new IllegalArgumentException("AggregateField can only contain fields.");
+ addField((Field)widget);
+ }
+
protected void addField(Field field) {
field.setParent(this);
fields.add(field);
fieldsById.put(field.getId(), field);
+ }
+
+
+ public boolean hasWidget(String id) {
+ return this.fieldsById.containsKey(id);
}
public Iterator getChildren() {