mpo 2004/04/20 15:19:27
Modified: src/blocks/forms/java/org/apache/cocoon/forms/formmodel
Struct.java Messages.java Repeater.java
MultiValueField.java AbstractContainerWidget.java
Output.java Upload.java Action.java Form.java
ContainerDelegate.java AbstractWidget.java
Field.java Union.java BooleanField.java Widget.java
Log:
Another sweap in the cforms refactoring.
- Added javadoc here and there
- Realized that Repeater is not a container widget (it's rows are):
we should split the aspect of containing multiple values (like multivalue)
(these are 'repeating' or 'iterating'
from the aspect of containing child-widgets (being 'composed' seems more
appropriate)
- Removed confusing overloaded versions of generateSAXFragment from the
Abstract(Container)Widget
--> this introduced getXMLElementName on all subclasses, and needs
additional cleanup
(that should remove quite some load of copy-paste)
- left quite some TODO markers for next sweaps
Revision Changes Path
1.4 +9 -9
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java
Index: Struct.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Struct.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Struct.java 12 Apr 2004 14:05:09 -0000 1.3
+++ Struct.java 20 Apr 2004 22:19:27 -0000 1.4
@@ -15,10 +15,6 @@
*/
package org.apache.cocoon.forms.formmodel;
-import java.util.Locale;
-
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
/**
* A container [EMAIL PROTECTED] Widget} which can hold zero or more child
widgets.
@@ -26,7 +22,7 @@
* @version $Id$
*/
public class Struct extends AbstractContainerWidget {
- private static final String ELEMENT = "struct";
+ private static final String STRUCT_EL = "struct";
private final StructDefinition definition;
@@ -37,8 +33,12 @@
protected WidgetDefinition getDefinition() {
return this.definition;
}
-
- public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
- generateSaxFragment(contentHandler, locale, ELEMENT);
+
+ /**
+ * @return "struct"
+ */
+ public String getXMLElementName() {
+ return STRUCT_EL;
}
+
}
1.6 +10 -2
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java
Index: Messages.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Messages.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Messages.java 9 Apr 2004 16:43:21 -0000 1.5
+++ Messages.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -76,7 +76,15 @@
public void addMessage(XMLizable message) {
messages.add(message);
}
-
+
+ /**
+ * @return "messages"
+ */
+ public String getXMLElementName() {
+ return MESSAGES_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
contentHandler.startElement(Constants.INSTANCE_NS, MESSAGES_EL,
Constants.INSTANCE_PREFIX_COLON + MESSAGES_EL, XMLUtils.EMPTY_ATTRIBUTES);
1.7 +44 -20
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java
Index: Repeater.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Repeater.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Repeater.java 9 Apr 2004 16:43:21 -0000 1.6
+++ Repeater.java 20 Apr 2004 22:19:27 -0000 1.7
@@ -41,7 +41,9 @@
*
* @version $Id$
*/
-public class Repeater extends AbstractWidget implements ContainerWidget {
+public class Repeater extends AbstractWidget
+//implements ContainerWidget
+{
private final RepeaterDefinition definition;
private final List rows = new ArrayList();
@@ -59,9 +61,9 @@
return rows.size();
}
- public void addWidget(Widget widget) {
- throw new RuntimeException("Repeater.addWidget(): Please use
addRow() instead.");
- }
+// public void addWidget(Widget widget) {
+// throw new RuntimeException("Repeater.addWidget(): Please use
addRow() instead.");
+// }
public RepeaterRow addRow() {
RepeaterRow repeaterRow = new RepeaterRow(definition);
@@ -161,18 +163,20 @@
RepeaterRow row = (RepeaterRow)rows.get(rowIndex);
return row.getWidget(id);
}
+//
+// public boolean hasWidget(String id) {
+// int row;
+// try {
+// row = Integer.parseInt(id);
+// } catch (NumberFormatException e) {
+// // TODO: Use i18n.
+// throw new RuntimeException("Repeater: Row id is not a valid
integer: " + id);
+// }
+// return row >= 0 && row < rows.size();
+// }
- public boolean hasWidget(String id) {
- int row;
- try {
- row = Integer.parseInt(id);
- } catch (NumberFormatException e) {
- // TODO: Use i18n.
- throw new RuntimeException("Repeater: Row id is not a valid
integer: " + id);
- }
- return row >= 0 && row < rows.size();
- }
-
+ //TODO: consider removing when this method is removed
+ // from the Widget interface.
public Widget getWidget(String id) {
int row;
try {
@@ -230,12 +234,22 @@
return valid ? super.validate(formContext) : false;
}
+
private static final String REPEATER_EL = "repeater";
private static final String HEADINGS_EL = "headings";
private static final String HEADING_EL = "heading";
private static final String LABEL_EL = "label";
private static final String REPEATER_SIZE_EL = "repeater-size";
+
+ /**
+ * @return "repeater"
+ */
+ public String getXMLElementName() {
+ return REPEATER_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl repeaterAttrs = new AttributesImpl();
repeaterAttrs.addCDATAAttribute("id", getFullyQualifiedId());
@@ -343,6 +357,16 @@
// this widget has no label
}
+
+
+ /**
+ * @return "repeater-row"
+ */
+ public String getXMLElementName() {
+ return ROW_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler,
Locale locale) throws SAXException {
AttributesImpl rowAttrs = new AttributesImpl();
rowAttrs.addCDATAAttribute("id", getFullyQualifiedId());
@@ -363,10 +387,10 @@
/* (non-Javadoc)
* @see org.apache.cocoon.forms.formmodel.ContainerWidget#getChildren()
*/
- public Iterator getChildren() {
- // TODO Auto-generated method stub to make this compile again
- return null;
- }
+// public Iterator getChildren() {
+// // TODO Auto-generated method stub to make this compile again
+// return null;
+// }
}
1.6 +10 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java
Index: MultiValueField.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/MultiValueField.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MultiValueField.java 9 Apr 2004 16:43:21 -0000 1.5
+++ MultiValueField.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -109,6 +109,15 @@
private static final String VALUE_EL = "value";
private static final String VALIDATION_MSG_EL = "validation-message";
+
+ /**
+ * @return "multivaluefield"
+ */
+ public String getXMLElementName() {
+ return MULTIVALUEFIELD_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl attrs = new AttributesImpl();
attrs.addCDATAAttribute("id", getFullyQualifiedId());
1.6 +53 -5
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java
Index: AbstractContainerWidget.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerWidget.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractContainerWidget.java 12 Apr 2004 14:05:09 -0000 1.5
+++ AbstractContainerWidget.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -32,10 +32,15 @@
*/
public abstract class AbstractContainerWidget extends AbstractWidget
implements ContainerWidget {
+ /**
+ * List of contained widgets.
+ */
protected ContainerDelegate widgets;
+ /**
+ * Constructs AbstractContainerWidget
+ */
public AbstractContainerWidget() {
-// public AbstractContainerWidget(AbstractWidgetDefinition definition) {
widgets = new ContainerDelegate();
}
@@ -56,12 +61,38 @@
return widgets.iterator();
}
+ /**
+ * Delegates the readFromRequest() down to the contained child-widgets.
+ *
+ * When overriding one should call <code>super.readFromRequest()</code>
+ * to allow child-widgets to process the request.
+ *
+ * Overide only to add possible request-reading statements on the
containment level.
+ *
+ * @param formContext to be passed to the [EMAIL PROTECTED]
Widget#readFromRequest(FormContext)}
+ * of the contained widgets.
+ */
public void readFromRequest(FormContext formContext) {
widgets.readFromRequest(formContext);
}
+ /**
+ * Delegates the validate() down to the contained child-widgets,
+ * and only validates the extra rules on this containment level if all
+ * child-widgets are valid.
+ *
+ * When overriding one should call <code>super.validate()</code> as the
first
+ * statement to keep in sync with this behaviour.
+ *
+ * @param formContext to be passed to the [EMAIL PROTECTED]
Widget#validate(FormContext)}
+ * of the contained widgets.
+ * @return <code>true</code> only if all contained widgets are valid and
the
+ * extra validation rules on this containment level are ok.
+ */
public boolean validate(FormContext formContext) {
// Validate self only if child widgets are valid
+ //TODO: check if we should not change this to still validating kids
first
+ // BUT also validating the top level
if (widgets.validate(formContext)) {
return super.validate(formContext);
} else {
@@ -69,14 +100,31 @@
}
}
- public void generateSaxFragment(ContentHandler contentHandler, Locale
locale, String element) throws SAXException {
+
+ /**
+ * Convenience method for subclasses that can just rely on the
generation of
+ * some standard XML consisting of a simple wrapper element (name
provided by
+ * [EMAIL PROTECTED] AbstractWidget#getXMLElementName()}) around the
nested elements generated by the
+ * contained child-widgets.
+ * The wrapper element will automatically have its @id set to the
+ * [EMAIL PROTECTED] Widget#getFullyQualifiedId()} of this widget.
+ *
+ * @param contentHandler where the SAX is sent to via [EMAIL PROTECTED]
Widget#generateSaxFragment(ContentHandler, Locale)
+ * @param locale
+ * @throws SAXException
+ */
+ public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
+ String element = this.getXMLElementName();
+
+ //TODO: check for which beasts it is allowed to be a
container-widget, but not have an id!
+ // if no reason we could just do this with the
AbstractWidget#generateItemSaxFragment(ContentHandler, Locale)
if (getId() == null || getId().equals("")) {
contentHandler.startElement(Constants.INSTANCE_NS, element,
Constants.INSTANCE_PREFIX_COLON + element, XMLUtils.EMPTY_ATTRIBUTES);
} else {
- AttributesImpl attrs = new AttributesImpl();
- attrs.addCDATAAttribute("id", getFullyQualifiedId());
+ AttributesImpl attrs = this.getXMLElementAttributes();
contentHandler.startElement(Constants.INSTANCE_NS, element,
Constants.INSTANCE_PREFIX_COLON + element, attrs);
}
+ //TODO: check for which beasts it is allowed to have no definition!
if (getDefinition() != null)
getDefinition().generateDisplayData(contentHandler);
// The child widgets
1.6 +10 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java
Index: Output.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Output.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Output.java 9 Apr 2004 16:43:21 -0000 1.5
+++ Output.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -66,6 +66,15 @@
private static final String OUTPUT_EL = "output";
private static final String VALUE_EL = "value";
+
+ /**
+ * @return "output"
+ */
+ public String getXMLElementName() {
+ return OUTPUT_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl outputAttrs = new AttributesImpl();
outputAttrs.addCDATAAttribute("id", getFullyQualifiedId());
1.6 +14 -5
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java
Index: Upload.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Upload.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Upload.java 9 Apr 2004 16:43:21 -0000 1.5
+++ Upload.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -134,10 +134,19 @@
this.validationError = error;
}
- private static final String FIELD_EL = "upload";
+
+ private static final String UPLOAD_EL = "upload";
private static final String VALUE_EL = "value";
private static final String VALIDATION_MSG_EL = "validation-message";
-
+
+ /**
+ * @return "upload"
+ */
+ public String getXMLElementName() {
+ return UPLOAD_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl fieldAttrs = new AttributesImpl();
fieldAttrs.addCDATAAttribute("id", getFullyQualifiedId());
@@ -145,7 +154,7 @@
if (uploadDefinition.getMimeTypes() != null) {
fieldAttrs.addCDATAAttribute("mime-types",
uploadDefinition.getMimeTypes());
}
- contentHandler.startElement(Constants.INSTANCE_NS, FIELD_EL,
Constants.INSTANCE_PREFIX_COLON + FIELD_EL, fieldAttrs);
+ contentHandler.startElement(Constants.INSTANCE_NS, UPLOAD_EL,
Constants.INSTANCE_PREFIX_COLON + UPLOAD_EL, fieldAttrs);
if (this.part != null) {
String name = (String)this.part.getHeaders().get("filename");
@@ -164,7 +173,7 @@
// the display data
this.uploadDefinition.generateDisplayData(contentHandler);
- contentHandler.endElement(Constants.INSTANCE_NS, FIELD_EL,
Constants.INSTANCE_PREFIX_COLON + FIELD_EL);
+ contentHandler.endElement(Constants.INSTANCE_NS, UPLOAD_EL,
Constants.INSTANCE_PREFIX_COLON + UPLOAD_EL);
}
public void generateLabel(ContentHandler contentHandler) throws
SAXException {
1.5 +10 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java
Index: Action.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Action.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Action.java 9 Apr 2004 16:43:21 -0000 1.4
+++ Action.java 20 Apr 2004 22:19:27 -0000 1.5
@@ -98,7 +98,15 @@
}
private static final String ACTION_EL = "action";
+
+ /**
+ * @return "action"
+ */
+ public String getXMLElementName() {
+ return ACTION_EL;
+ }
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl buttonAttrs = new AttributesImpl();
buttonAttrs.addCDATAAttribute("id", getFullyQualifiedId());
@@ -115,4 +123,5 @@
public void broadcastEvent(WidgetEvent event) {
this.definition.fireActionEvent((ActionEvent)event);
}
+
}
1.8 +10 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java
Index: Form.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Form.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Form.java 13 Apr 2004 21:29:48 -0000 1.7
+++ Form.java 20 Apr 2004 22:19:27 -0000 1.8
@@ -303,9 +303,18 @@
return super.validate(formContext);
}
+
private static final String FORM_EL = "form";
private static final String CHILDREN_EL = "children";
+ /**
+ * @return
+ */
+ public String getXMLElementName() {
+ return FORM_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl formAttrs = new AttributesImpl();
formAttrs.addCDATAAttribute("id", definition.getId());
1.6 +72 -10
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ContainerDelegate.java
Index: ContainerDelegate.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/ContainerDelegate.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ContainerDelegate.java 12 Apr 2004 14:05:09 -0000 1.5
+++ ContainerDelegate.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -30,39 +30,77 @@
/**
* Helper class for the implementation of widgets containing other widgets.
- *
+ * This implements a type-aware List of Widgets that automatically can
distribute
+ * the common Widget operations over the contained Widgets.
+ *
* @version $Id$
*/
public class ContainerDelegate {
-// private WidgetDefinition definition;
+//TODO: consider renaming the ContainerDelegate to what it is: WidgetList
+// (a type aware collection of widgets?)
+
+ private static final String WIDGETS_EL = "widgets";
+
+ /**
+ * List of the contained widgets.
+ * This maintains the original order of the widgets to garantee order of
+ * validation and generation of SAXFragments
+ */
private List widgets;
+
+ /**
+ * Map of the contained widgets using its id as the lookup key.
+ */
private Map widgetsById;
- private static final String WIDGETS_EL = "widgets";
-// public ContainerDelegate(WidgetDefinition definition) {
+ /**
+ * Constructs ContainerDelegate to store and jointly manage a list of
+ * contained widgets.
+ */
public ContainerDelegate() {
widgets = new ArrayList();
widgetsById = new HashMap();
-// this.definition = definition;
}
+ /**
+ * Adds a widget to the list of contained [EMAIL PROTECTED] Widget}'s
+ *
+ * @param widget
+ */
public void addWidget(Widget widget) {
widgets.add(widget);
widgetsById.put(widget.getId(), widget);
}
+
+ /**
+ * Performs the [EMAIL PROTECTED] Widget#readFromRequest(FormContext)}
on all the
+ * contained widgets.
+ *
+ * @param formContext to pass to the [EMAIL PROTECTED]
Widget#readFromRequest(FormContext)}
+ *
+ * @see Widget#readFromRequest(FormContext)
+ */
public void readFromRequest(FormContext formContext) {
- Iterator widgetIt = widgets.iterator();
+ Iterator widgetIt = iterator();
while (widgetIt.hasNext()) {
Widget widget = (Widget)widgetIt.next();
widget.readFromRequest(formContext);
}
}
+ /**
+ * Validates all contained widgets and returns the combined result.
+ *
+ * @param formContext to pass to the [EMAIL PROTECTED]
Widget#validate(FormContext)
+ * @return <code>false</code> if at least one of the contained widgets
is not valid.
+ *
+ * @see Widget#validate(FormContext)
+ */
public boolean validate(FormContext formContext) {
boolean valid = true;
- Iterator widgetIt = widgets.iterator();
+ Iterator widgetIt = iterator();
while (widgetIt.hasNext()) {
Widget widget = (Widget)widgetIt.next();
valid = valid & widget.validate(formContext);
@@ -70,23 +108,38 @@
return valid;
}
+ /**
+ * Checks if a widget with the provided id is contained in the list.
+ *
+ * @param id of the widget to look for.
+ * @return true if the widget was found
+ */
public boolean hasWidget(String id) {
return widgetsById.containsKey(id);
}
+ /**
+ * Looks for a widget in this list by using the provided id as a lookup
key.
+ *
+ * @param id of the widget to look for
+ * @return the found widget or <code>null</code> if it could not be
found.
+ */
public Widget getWidget(String id) {
return (Widget)widgetsById.get(id);
}
+ /**
+ * @return an iterator over the contained [EMAIL PROTECTED] Widget}'s
+ */
public Iterator iterator() {
return widgets.iterator();
}
/**
- * Returns false if there is at least one field which has no value.
+ * @return <code>false</code> if at least one of the contained widgets
has no value.
*/
public boolean widgetsHaveValues() {
- Iterator widgetsIt = widgets.iterator();
+ Iterator widgetsIt = iterator();
while(widgetsIt.hasNext()) {
Widget widget = (Widget)widgetsIt.next();
if (widget.getValue() == null)
@@ -95,6 +148,15 @@
return true;
}
+ /**
+ * Generates the SAXfragments of the contained widgets
+ *
+ * @param contentHandler
+ * @param locale
+ * @throws SAXException
+ *
+ * @see Widget#generateSaxFragment(ContentHandler, Locale)
+ */
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
contentHandler.startElement(Constants.INSTANCE_NS, WIDGETS_EL,
Constants.INSTANCE_PREFIX_COLON + WIDGETS_EL, XMLUtils.EMPTY_ATTRIBUTES);
Iterator widgetIt = widgets.iterator();
1.7 +96 -23
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java
Index: AbstractWidget.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidget.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractWidget.java 9 Apr 2004 16:43:21 -0000 1.6
+++ AbstractWidget.java 20 Apr 2004 22:19:27 -0000 1.7
@@ -37,21 +37,11 @@
* @version $Id$
*/
public abstract class AbstractWidget implements Widget {
-// private String location;
private Widget parent;
private Form form;
-
-// protected AbstractWidgetDefinition definition;
-
+
private List validators;
private Map attributes;
-
-// /**
-// * Sets the definition of this widget.
-// */
-// protected void setDefinition(AbstractWidgetDefinition definition) {
-// this.definition = definition;
-// }
/**
* Gets the id of this widget.
@@ -59,29 +49,44 @@
public String getId() {
return getDefinition().getId();
}
-
-// /**
-// * Sets the source location of this widget.
-// */
-// protected void setLocation(String location) {
-// this.definition.setLocation(location);
-// }
-
+ /**
+ * Concrete subclasses should allow access to their underlaying
Definition
+ * through this method.
+ *
+ * @return the widgetDefinition from which this widget was instantiated.
+ * (@link WidgetDefinition#createInstance()}
+ */
protected abstract WidgetDefinition getDefinition();
+ /**
+ * @return the location-information (file, line and column) where this
widget was
+ * configured.
+ */
public String getLocation() {
return getDefinition().getLocation();
}
+ /**
+ * @return The parent-widget of this widget.
+ */
public Widget getParent() {
return parent;
}
+ /**
+ * Sets the parent-widget of this widget.
+ * @param widget
+ */
public void setParent(Widget widget) {
+ //TODO: check if we should not make this writable only once
+ // (i.e. allow set only if this.parent == null)
this.parent = widget;
}
+ /**
+ * @return the form where this widget belongs to.
+ */
public Form getForm() {
if (this.form == null) {
if (parent == null) {
@@ -93,7 +98,11 @@
return this.form;
}
- public String getNamespace() {
+
+ //TODO: check why this namespace property exists, it seems to be
+ // deceptively resemblant to the getFullyQualifiedId,
+ // looks like it can be removed, no?
+ public String getNamespace() {
if (getParent() != null && getParent().getNamespace().length() > 0) {
return getParent().getNamespace() + "." + getId();
} else {
@@ -123,10 +132,18 @@
return false;
}
+ // TODO: consider moving this from the Widget interface to the
ContainerWidget
+ // then we could remove it here as well, no?
public Widget getWidget(String id) {
return null;
}
+ /**
+ * @inheritDoc
+ *
+ * Abstract implementation throws a [EMAIL PROTECTED]
UnsupportedOperationException}.
+ * Concrete subclass widgets need to override when supporting event
broadcasting.
+ */
public void broadcastEvent(WidgetEvent event) {
throw new UnsupportedOperationException("Widget " +
this.getFullyQualifiedId() + " doesn't handle events.");
}
@@ -157,6 +174,7 @@
}
}
+
public boolean validate(FormContext context) {
// Test validators from the widget definition
if (!getDefinition().validate(this, context)) {
@@ -188,18 +206,73 @@
}
}
+
+ /**
+ * Generates nested additional content nested inside the main element
for this
+ * widget which is generated by [EMAIL PROTECTED]
#generateSaxFragment(ContentHandler, Locale)}
+ *
+ * The implementation on the AbstractWidget level inserts no additional
XML.
+ *
+ * @param contentHandler to send the SAX events to
+ * @param locale in which context potential content needs to be put.
+ * @throws SAXException
+ */
public void generateItemSaxFragment(ContentHandler contentHandler,
Locale locale) throws SAXException {
// Do nothing
}
- public void generateSaxFragment(ContentHandler contentHandler, Locale
locale, String element, WidgetDefinition definition)
- throws SAXException {
+ /**
+ * The XML element name used in [EMAIL PROTECTED]
#generateSaxFragment(ContentHandler, Locale)}
+ * to produce the wrapping element for all the XML-instance-content of
this Widget.
+ *
+ * @return the main elementname for this widget's sax-fragment.
+ */
+ public abstract String getXMLElementName();
+
+ /**
+ * The XML attributes used in [EMAIL PROTECTED]
#generateSaxFragment(ContentHandler, Locale)}
+ * to be placed on the wrapping element for all the XML-instance-content
of this Widget.
+ *
+ * This automatically adds @[EMAIL PROTECTED] #getFullyQualifiedId()} to
that element.
+ * Concrete subclasses should call super.getXMLElementAttributes and
possibly
+ * add additional attributes.
+ *
+ * @return the attributes for the main element for this widget's
sax-fragment.
+ */
+ public AttributesImpl getXMLElementAttributes() {
AttributesImpl attrs = new AttributesImpl();
attrs.addCDATAAttribute("id", getFullyQualifiedId());
+ return attrs;
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * This will generate some standard XML consisting of a simple wrapper
+ * element (name provided by [EMAIL PROTECTED] #getXMLElementName()})
with attributes
+ * (provided by [EMAIL PROTECTED] #getXMLElementAttributes()} around
anything injected
+ * in by [EMAIL PROTECTED] #generateItemSaxFragment(ContentHandler,
Locale)}.
+ *
+ * @param contentHandler to send the SAX events to
+ * @param locale in which context potential content needs to be put.
+ * @throws SAXException
+ */
+ public void generateSaxFragment(ContentHandler contentHandler, Locale
locale)
+ throws SAXException {
+ //TODO: check why there is no call to
getDefinition().generateDisplayData(contentHandler);
+ // if we can add it, then the subclass AbstractContainerWidget could
be pulled up here
+ // and potentially make this even final?
+
+ String element = this.getXMLElementName();
+
+ AttributesImpl attrs = getXMLElementAttributes();
contentHandler.startElement(Constants.INSTANCE_NS, element,
Constants.INSTANCE_PREFIX_COLON + element, attrs);
+
generateItemSaxFragment(contentHandler, locale);
+
contentHandler.endElement(Constants.INSTANCE_NS, element,
Constants.INSTANCE_PREFIX_COLON + element);
}
+
public Object getAttribute(String name) {
if (this.attributes != null){
1.8 +10 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java
Index: Field.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Field.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Field.java 13 Apr 2004 21:28:24 -0000 1.7
+++ Field.java 20 Apr 2004 22:19:27 -0000 1.8
@@ -217,7 +217,16 @@
private static final String FIELD_EL = "field";
private static final String VALUE_EL = "value";
private static final String VALIDATION_MSG_EL = "validation-message";
+
+ /**
+ * @return "field"
+ */
+ public String getXMLElementName() {
+ return FIELD_EL;
+ }
+
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl fieldAttrs = new AttributesImpl();
fieldAttrs.addCDATAAttribute("id", getFullyQualifiedId());
1.6 +16 -14
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java
Index: Union.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Union.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Union.java 14 Apr 2004 17:51:23 -0000 1.5
+++ Union.java 20 Apr 2004 22:19:27 -0000 1.6
@@ -15,11 +15,7 @@
*/
package org.apache.cocoon.forms.formmodel;
-import java.util.Locale;
-
import org.apache.cocoon.forms.FormContext;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
/**
* A discriminated union that references a discriminant value in another
@@ -31,7 +27,9 @@
* @version $Id$
*/
public class Union extends AbstractContainerWidget {
- private static final String ELEMENT = "field";
+
+ //TODO: check if this element-name shouldn't have been 'union'?
+ private static final String UNION_EL = "field";
private Widget caseWidget;
private final UnionDefinition definition;
@@ -62,8 +60,11 @@
caseWidget = getParent().getWidget(caseWidgetId);
}
- public String getElementName() {
- return ELEMENT;
+ /**
+ * @return "field"
+ */
+ public String getXMLElementName() {
+ return UNION_EL;
}
public Object getValue() {
@@ -103,12 +104,13 @@
return super.getWidget(id);
}
+
+ //TODO: check further: cause the claim in the accompanied comment
doesn't seem
+ // to be completely correct
+
// This method is overridden to suppress output of sub-widget sax
fragments.
- public void generateItemsSaxFragment(ContentHandler contentHandler,
Locale locale) throws SAXException {
- // Do nothing
- }
+// public void generateItemsSaxFragment(ContentHandler contentHandler,
Locale locale) throws SAXException {
+// // Do nothing
+// }
- public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
- generateSaxFragment(contentHandler, locale, ELEMENT);
- }
}
1.5 +10 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java
Index: BooleanField.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/BooleanField.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BooleanField.java 9 Apr 2004 16:43:21 -0000 1.4
+++ BooleanField.java 20 Apr 2004 22:19:27 -0000 1.5
@@ -76,9 +76,18 @@
return true;
}
+
private static final String BOOLEAN_FIELD_EL = "booleanfield";
private static final String VALUE_EL = "value";
+
+ /**
+ * @return "booleanfield"
+ */
+ public String getXMLElementName() {
+ return BOOLEAN_FIELD_EL;
+ }
+ //TODO: reuse available implementation on superclass
public void generateSaxFragment(ContentHandler contentHandler, Locale
locale) throws SAXException {
AttributesImpl fieldAttrs = new AttributesImpl();
fieldAttrs.addCDATAAttribute("id", getFullyQualifiedId());
1.4 +15 -1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java
Index: Widget.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Widget.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Widget.java 25 Mar 2004 16:41:48 -0000 1.3
+++ Widget.java 20 Apr 2004 22:19:27 -0000 1.4
@@ -149,6 +149,9 @@
/**
* Gets the child widget of this widget with the given id, or null if
there isn't such a child.
*/
+ //TODO: this is duplicated on the ContainerWidget interface
+ // and in fact only seems to be reasonable in that scope
+ // should we not remove this?
public Widget getWidget(String id);
/**
@@ -156,6 +159,12 @@
*/
public void broadcastEvent(WidgetEvent event);
+ /**
+ * Retrieves an attribute on this widget
+ *
+ * @param name of the attribute to lookup
+ * @return the found attribute or <code>null</code> if none was found
with that name.
+ */
public Object getAttribute(String name);
/**
@@ -164,5 +173,10 @@
*/
public void setAttribute(String name, Object value);
+ /**
+ * Removes the named attribute from this widget.
+ *
+ * @param name of the attribute
+ */
public void removeAttribute(String name);
}