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/09 18:43:21 UTC

cvs commit: cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel Struct.java WidgetDefinition.java Messages.java AbstractWidgetDefinition.java Repeater.java MultiValueField.java AbstractContainerWidget.java Output.java RepeaterAction.java Upload.java Action.java Form.java ContainerDelegate.java AbstractWidget.java Field.java Union.java BooleanField.java Submit.java AggregateField.java

mpo         2004/04/09 09:43:21

  Modified:    src/blocks/forms/java/org/apache/cocoon/forms/formmodel
                        Struct.java WidgetDefinition.java Messages.java
                        AbstractWidgetDefinition.java Repeater.java
                        MultiValueField.java AbstractContainerWidget.java
                        Output.java RepeaterAction.java Upload.java
                        Action.java Form.java ContainerDelegate.java
                        AbstractWidget.java Field.java Union.java
                        BooleanField.java Submit.java AggregateField.java
  Log:
  Some refactoring on the structure of the widget formmodel.
  The definition clearly is an immutable, that doesn't need to be set on any of the Abstract levels.
  Location is a property of the definition, not the widget-instance.
  
  Revision  Changes    Path
  1.2       +8 -2      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Struct.java	9 Mar 2004 10:33:50 -0000	1.1
  +++ Struct.java	9 Apr 2004 16:43:21 -0000	1.2
  @@ -28,9 +28,15 @@
    */
   public class Struct extends AbstractContainerWidget {
       private static final String ELEMENT = "struct";
  +    
  +    private final StructDefinition definition; 
   
       public Struct(StructDefinition definition) {
  -        super(definition);
  +        this.definition = definition;
  +    }
  +    
  +    protected WidgetDefinition getDefinition() {
  +        return this.definition;
       }
   
       public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException {
  
  
  
  1.3       +13 -1     cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java
  
  Index: WidgetDefinition.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinition.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- WidgetDefinition.java	11 Mar 2004 02:56:33 -0000	1.2
  +++ WidgetDefinition.java	9 Apr 2004 16:43:21 -0000	1.3
  @@ -15,6 +15,7 @@
    */
   package org.apache.cocoon.forms.formmodel;
   
  +import org.apache.cocoon.forms.FormContext;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  @@ -47,6 +48,17 @@
        * Gets id of this widget definition.
        */
       public String getId();
  +    
  +    /**
  +     * Validate a widget using the validators that were defined in its definition. If validation
  +     * fails, the validator has set a validation error on the widget or one of its children.
  +     * 
  +     * @param widget the widget
  +     * @param context the form context
  +     * @return <code>true</code> if validation was successful.
  +     */
  +    public boolean validate(Widget widget, FormContext context);
  +    
   
       /**
        * Creates and returns a widget based on this widget definition.
  
  
  
  1.5       +4 -5      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Messages.java	9 Mar 2004 13:17:26 -0000	1.4
  +++ Messages.java	9 Apr 2004 16:43:21 -0000	1.5
  @@ -38,18 +38,17 @@
    */
   public class Messages extends AbstractWidget {
       private ArrayList messages = new ArrayList();
  -    private MessagesDefinition definition;
  +    private final MessagesDefinition definition;
   
       private static final String MESSAGES_EL = "messages";
       private static final String MESSAGE_EL = "message";
   
       protected Messages(MessagesDefinition definition) {
           this.definition = definition;
  -        setLocation(definition.getLocation());
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return this.definition;
       }
   
       public void readFromRequest(FormContext formContext) {
  
  
  
  1.4       +3 -9      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
  
  Index: AbstractWidgetDefinition.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractWidgetDefinition.java	9 Mar 2004 13:17:26 -0000	1.3
  +++ AbstractWidgetDefinition.java	9 Apr 2004 16:43:21 -0000	1.4
  @@ -36,6 +36,8 @@
   public abstract class AbstractWidgetDefinition implements WidgetDefinition {
       private FormDefinition formDefinition;
       protected WidgetDefinition parent;
  +    
  +    //TODO consider final on these
       private String location = null;
       private String id;
       private Map displayData;
  @@ -133,14 +135,6 @@
           }   
       }
       
  -    /**
  -     * Validate a widget using the validators that were defined in its definition. If validation
  -     * fails, the validator has set a validation error on the widget or one of its children.
  -     * 
  -     * @param widget the widget
  -     * @param context the form context
  -     * @return <code>true</code> if validation was successful.
  -     */
       public boolean validate(Widget widget, FormContext context) {
           if (this.validators == null) {
               // No validators
  
  
  
  1.6       +15 -14    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Repeater.java	15 Mar 2004 21:50:08 -0000	1.5
  +++ Repeater.java	9 Apr 2004 16:43:21 -0000	1.6
  @@ -42,19 +42,17 @@
    * @version $Id$
    */
   public class Repeater extends AbstractWidget implements ContainerWidget {
  -    private RepeaterDefinition repeaterDefinition;
  -    private List rows = new ArrayList();
  +    private final RepeaterDefinition definition;
  +    private final List rows = new ArrayList();
   
       public Repeater(RepeaterDefinition repeaterDefinition) {
  -        this.repeaterDefinition = repeaterDefinition;
  -        super.setDefinition(repeaterDefinition);
  -        setLocation(definition.getLocation());
  +        this.definition = repeaterDefinition;
           // setup initial size
           removeRows();
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return definition;
       }
   
       public int getSize() {
  @@ -148,7 +146,7 @@
           rows.clear();
           
           // and reset to initial size
  -        for (int i = 0; i < this.repeaterDefinition.getInitialSize(); i++) {
  +        for (int i = 0; i < this.definition.getInitialSize(); i++) {
               addRow();
           }
       }
  @@ -251,7 +249,7 @@
   
           // heading element -- currently contains the labels of each widget in the repeater
           contentHandler.startElement(Constants.INSTANCE_NS, HEADINGS_EL, Constants.INSTANCE_PREFIX_COLON + HEADINGS_EL, XMLUtils.EMPTY_ATTRIBUTES);
  -        Iterator widgetDefinitionIt = repeaterDefinition.getWidgetDefinitions().iterator();
  +        Iterator widgetDefinitionIt = definition.getWidgetDefinitions().iterator();
           while (widgetDefinitionIt.hasNext()) {
               WidgetDefinition widgetDefinition = (WidgetDefinition)widgetDefinitionIt.next();
               contentHandler.startElement(Constants.INSTANCE_NS, HEADING_EL, Constants.INSTANCE_PREFIX_COLON + HEADING_EL, XMLUtils.EMPTY_ATTRIBUTES);
  @@ -277,7 +275,7 @@
        * Generates the label of a certain widget in this repeater.
        */
       public void generateWidgetLabel(String widgetId, ContentHandler contentHandler) throws SAXException {
  -        WidgetDefinition widgetDefinition = repeaterDefinition.getWidgetDefinition(widgetId);
  +        WidgetDefinition widgetDefinition = definition.getWidgetDefinition(widgetId);
           if (widgetDefinition == null)
               throw new SAXException("Repeater \"" + getFullyQualifiedId() + "\" at " + this.getLocation()
                                      + " contains no widget with id \"" + widgetId + "\".");
  @@ -298,12 +296,15 @@
       public class RepeaterRow extends AbstractContainerWidget {
   
           public RepeaterRow(AbstractWidgetDefinition definition) {
  -            super(definition);
               ((ContainerDefinition)definition).createWidgets(this);
           }
   
  -        public String getLocation() {
  -            return Repeater.this.getLocation();
  +//        public String getLocation() {
  +//            return Repeater.this.getLocation();
  +//        }
  +//        
  +        protected WidgetDefinition getDefinition() {
  +            return Repeater.this.definition;
           }
   
           public String getId() {
  
  
  
  1.5       +16 -17    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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MultiValueField.java	9 Mar 2004 13:17:26 -0000	1.4
  +++ MultiValueField.java	9 Apr 2004 16:43:21 -0000	1.5
  @@ -48,20 +48,19 @@
    * @version $Id$
    */
   public class MultiValueField extends AbstractWidget implements ValidationErrorAware, SelectableWidget {
  +    private final MultiValueFieldDefinition definition;
  +    
       private SelectionList selectionList;
  -    private MultiValueFieldDefinition fieldDefinition;
       private String[] enteredValues;
       private Object[] values;
       private ValidationError validationError;
   
       public MultiValueField(MultiValueFieldDefinition definition) {
  -        super.setDefinition(definition);
  -        this.fieldDefinition = definition;
  -        setLocation(definition.getLocation());
  +        this.definition = definition;
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return definition;
       }
   
       public void readFromRequest(FormContext formContext) {
  @@ -79,7 +78,7 @@
               Object[] tempValues = new Object[enteredValues.length];
               for (int i = 0; i < enteredValues.length; i++) {
                   String param = enteredValues[i];
  -                tempValues[i] = fieldDefinition.getDatatype().convertFromString(param, formContext.getLocale());
  +                tempValues[i] = definition.getDatatype().convertFromString(param, formContext.getLocale());
                   if (tempValues[i] == null) {
                       conversionFailed = true;
                       break;
  @@ -97,7 +96,7 @@
   
       public boolean validate(FormContext formContext) {
           if (values != null)
  -            validationError = fieldDefinition.getDatatype().validate(values, new ExpressionContextImpl(this));
  +            validationError = definition.getDatatype().validate(values, new ExpressionContextImpl(this));
           else
               validationError = new ValidationError(new I18nMessage("multivaluefield.conversionfailed", Constants.I18N_CATALOGUE));
   
  @@ -119,14 +118,14 @@
           if (values != null) {
               for (int i = 0; i < values.length; i++) {
                   contentHandler.startElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES);
  -                String value = fieldDefinition.getDatatype().getPlainConvertor().convertToString(values[i], locale, null);
  +                String value = definition.getDatatype().getPlainConvertor().convertToString(values[i], locale, null);
                   contentHandler.characters(value.toCharArray(), 0, value.length());
                   contentHandler.endElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON + VALUE_EL);
               }
           } else if (enteredValues != null) {
               for (int i = 0; i < enteredValues.length; i++) {
                   contentHandler.startElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES);
  -                String value = fieldDefinition.getDatatype().getPlainConvertor().convertToString(enteredValues[i], locale, null);
  +                String value = definition.getDatatype().getPlainConvertor().convertToString(enteredValues[i], locale, null);
                   contentHandler.characters(value.toCharArray(), 0, value.length());
                   contentHandler.endElement(Constants.INSTANCE_NS, VALUE_EL, Constants.INSTANCE_PREFIX_COLON + VALUE_EL);
               }
  @@ -140,7 +139,7 @@
           if (this.selectionList != null) {
               this.selectionList.generateSaxFragment(contentHandler, locale);
           } else {
  -            fieldDefinition.getSelectionList().generateSaxFragment(contentHandler, locale);
  +            definition.getSelectionList().generateSaxFragment(contentHandler, locale);
           }
   
           // validation message element
  @@ -174,7 +173,7 @@
       public void setValues(Object[] values) {
           // check that all the objects in the array correspond to the datatype
           for (int i = 0; i < values.length; i++) {
  -            if (!fieldDefinition.getDatatype().getTypeClass().isAssignableFrom(values[i].getClass()))
  +            if (!definition.getDatatype().getTypeClass().isAssignableFrom(values[i].getClass()))
                   throw new RuntimeException("Cannot set value of field \"" + getFullyQualifiedId() + "\" with an object of type " + values[i].getClass().getName());
           }
           this.values = values;
  @@ -187,7 +186,7 @@
       public void setSelectionList(SelectionList selectionList) {
           if (selectionList != null &&
               selectionList.getDatatype() != null &&
  -            selectionList.getDatatype() != fieldDefinition.getDatatype()) {
  +            selectionList.getDatatype() != definition.getDatatype()) {
   
               throw new RuntimeException("Tried to assign a SelectionList that is not associated with this widget's datatype.");
           }
  @@ -204,7 +203,7 @@
        * @param uri The URI of the source.
        */
       public void setSelectionList(String uri) {
  -        setSelectionList(this.fieldDefinition.buildSelectionList(uri));
  +        setSelectionList(this.definition.buildSelectionList(uri));
       }
   
       /**
  @@ -224,11 +223,11 @@
        * to populate the labels of the list's items.
        */
       public void setSelectionList(Object model, String valuePath, String labelPath) {
  -        setSelectionList(this.fieldDefinition.buildSelectionListFromModel(model, valuePath, labelPath));
  +        setSelectionList(this.definition.buildSelectionListFromModel(model, valuePath, labelPath));
       }
   
       public void broadcastEvent(WidgetEvent event) {
  -        this.fieldDefinition.fireValueChangedEvent((ValueChangedEvent)event);
  +        this.definition.fireValueChangedEvent((ValueChangedEvent)event);
       }
   
       public ValidationError getValidationError() {
  
  
  
  1.4       +7 -7      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractContainerWidget.java	9 Mar 2004 13:17:26 -0000	1.3
  +++ AbstractContainerWidget.java	9 Apr 2004 16:43:21 -0000	1.4
  @@ -32,12 +32,12 @@
    * @version $Id$
    */
   public abstract class AbstractContainerWidget extends AbstractWidget implements ContainerWidget {
  +    
       protected ContainerDelegate widgets;
   
  -    public AbstractContainerWidget(AbstractWidgetDefinition definition) {
  -        setDefinition(definition);
  -        setLocation(definition.getLocation());
  -        widgets = new ContainerDelegate(definition);
  +    public AbstractContainerWidget() {
  +//    public AbstractContainerWidget(AbstractWidgetDefinition definition) {
  +        widgets = new ContainerDelegate();
       }
   
       public void addWidget(Widget widget) {
  @@ -78,8 +78,8 @@
               attrs.addCDATAAttribute("id", getFullyQualifiedId());
               contentHandler.startElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element, attrs);
           }
  -        if (definition != null)
  -            definition.generateDisplayData(contentHandler);
  +        if (getDefinition() != null)
  +            getDefinition().generateDisplayData(contentHandler);
           // The child widgets
           widgets.generateSaxFragment(contentHandler, locale);
           contentHandler.endElement(Constants.INSTANCE_NS, element, Constants.INSTANCE_PREFIX_COLON + element);
  
  
  
  1.5       +5 -5      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Output.java	9 Mar 2004 13:17:26 -0000	1.4
  +++ Output.java	9 Apr 2004 16:43:21 -0000	1.5
  @@ -35,7 +35,8 @@
    * @version $Id$
    */
   public class Output extends AbstractWidget implements DataWidget {
  -    private OutputDefinition definition;
  +    
  +    private final OutputDefinition definition;
       private Object value;
   
       public OutputDefinition getOutputDefinition() {
  @@ -48,11 +49,10 @@
   
       protected Output(OutputDefinition definition) {
           this.definition = definition;
  -        setLocation(definition.getLocation());
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return definition;
       }
   
       public void readFromRequest(FormContext formContext) {
  
  
  
  1.2       +3 -3      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterAction.java
  
  Index: RepeaterAction.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterAction.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RepeaterAction.java	9 Mar 2004 10:33:50 -0000	1.1
  +++ RepeaterAction.java	9 Apr 2004 16:43:21 -0000	1.2
  @@ -27,7 +27,7 @@
       private Repeater repeater;
       
   
  -    public RepeaterAction(ActionDefinition definition) {
  +    public RepeaterAction(RepeaterActionDefinition definition) {
           super(definition);
       }
       
  @@ -36,7 +36,7 @@
        */
       public Repeater getRepeater() {
           if (this.repeater == null) {
  -            String name = ((RepeaterActionDefinition)this.definition).getRepeaterName();
  +            String name = ((RepeaterActionDefinition)getDefinition()).getRepeaterName();
               Widget widget;
               if (name != null) {
                   // Get the corresponding sibling
  
  
  
  1.5       +6 -8      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Upload.java	11 Mar 2004 02:56:33 -0000	1.4
  +++ Upload.java	9 Apr 2004 16:43:21 -0000	1.5
  @@ -38,22 +38,20 @@
    * @version CVS $Id$
    */
   public class Upload extends AbstractWidget implements ValidationErrorAware {
  -    private UploadDefinition uploadDefinition;
  +    private final UploadDefinition uploadDefinition;
       private Part part;
       private ValidationError validationError;
   
       public Upload(UploadDefinition uploadDefinition) {
           this.uploadDefinition = uploadDefinition;
  -        this.setDefinition(uploadDefinition);
  -        setLocation(uploadDefinition.getLocation());
       }
   
       public UploadDefinition getUploadDefinition() {
           return this.uploadDefinition;
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return uploadDefinition;
       }
   
       public Object getValue() {
  @@ -164,12 +162,12 @@
           }
   
           // the display data
  -        this.definition.generateDisplayData(contentHandler);
  +        this.uploadDefinition.generateDisplayData(contentHandler);
   
           contentHandler.endElement(Constants.INSTANCE_NS, FIELD_EL, Constants.INSTANCE_PREFIX_COLON + FIELD_EL);
       }
   
       public void generateLabel(ContentHandler contentHandler) throws SAXException {
  -        definition.generateLabel(contentHandler);
  +        this.uploadDefinition.generateLabel(contentHandler);
       }
   }
  
  
  
  1.4       +5 -6      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Action.java	9 Mar 2004 13:08:45 -0000	1.3
  +++ Action.java	9 Apr 2004 16:43:21 -0000	1.4
  @@ -38,17 +38,16 @@
    * @version $Id$
    */
   public class Action extends AbstractWidget {
  -    protected ActionDefinition definition;
  +    private final ActionDefinition definition;
   
       public Action(ActionDefinition definition) {
           this.definition = definition;
  -        setLocation(definition.getLocation());
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return this.definition;
       }
  -
  +    
       public void readFromRequest(final FormContext formContext) {
           Form form = getForm();
           
  
  
  
  1.6       +8 -4      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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Form.java	25 Mar 2004 16:41:48 -0000	1.5
  +++ Form.java	9 Apr 2004 16:43:21 -0000	1.6
  @@ -43,10 +43,11 @@
    */
   public class Form extends AbstractContainerWidget {
       
  +    private final FormDefinition definition;
  +    
       private Boolean endProcessing;
       private Locale locale = Locale.getDefault();
       private CursorableLinkedList events;
  -//    private FormDefinition definition;
       private FormHandler formHandler;
       private Widget submitWidget;
       private ProcessingPhase phase = ProcessingPhase.LOAD_MODEL;
  @@ -54,10 +55,13 @@
       private ProcessingPhaseListener listener;
   
       public Form(FormDefinition definition) {
  -        super(definition);
  -        setLocation(definition.getLocation());
  +        this.definition = definition;
       }
   
  +    protected WidgetDefinition getDefinition() {
  +        return this.definition;
  +    }
  +    
       /**
        * Events produced by child widgets should not be fired immediately, but queued in order to ensure
        * an overall consistency of the widget tree before being handled.
  
  
  
  1.4       +3 -2      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ContainerDelegate.java	9 Mar 2004 13:17:26 -0000	1.3
  +++ ContainerDelegate.java	9 Apr 2004 16:43:21 -0000	1.4
  @@ -41,7 +41,8 @@
   
       private static final String WIDGETS_EL = "widgets";
   
  -    public ContainerDelegate(WidgetDefinition definition) {
  +//    public ContainerDelegate(WidgetDefinition definition) {
  +    public ContainerDelegate() {
           widgets = new ArrayList();
           widgetsById = new HashMap();
   //        this.definition = definition;
  
  
  
  1.6       +26 -25    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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AbstractWidget.java	2 Apr 2004 09:50:35 -0000	1.5
  +++ AbstractWidget.java	9 Apr 2004 16:43:21 -0000	1.6
  @@ -37,40 +37,41 @@
    * @version $Id$
    */
   public abstract class AbstractWidget implements Widget {
  -    private String location;
  +//    private String location;
       private Widget parent;
       private Form form;
  -    protected AbstractWidgetDefinition definition;
  +    
  +//    protected AbstractWidgetDefinition definition;
       
       private List validators;
       private Map attributes;
   
  -    /**
  -     * Sets the definition of this widget.
  -     */
  -    protected void setDefinition(AbstractWidgetDefinition definition) {
  -        this.definition = definition;
  -    }
  -
  +//    /**
  +//     * Sets the definition of this widget.
  +//     */
  +//    protected void setDefinition(AbstractWidgetDefinition definition) {
  +//        this.definition = definition;
  +//    }
  +    
       /**
        * Gets the id of this widget.
        */
       public String getId() {
  -        return definition.getId();
  +        return getDefinition().getId();
       }
   
  -    /**
  -     * Sets the source location of this widget.
  -     */
  -    protected void setLocation(String location) {
  -        this.location = location;
  -    }
  +//    /**
  +//     * Sets the source location of this widget.
  +//     */
  +//    protected void setLocation(String location) {
  +//        this.definition.setLocation(location);
  +//    }
   
  -    /**
  -     * Gets the source location of this widget.
  -     */
  +    
  +    protected abstract WidgetDefinition getDefinition();
  +    
       public String getLocation() {
  -        return this.location;
  +        return getDefinition().getLocation();
       }
   
       public Widget getParent() {
  @@ -158,7 +159,7 @@
       
       public boolean validate(FormContext context) {
           // Test validators from the widget definition
  -        if (!this.definition.validate(this, context)) {
  +        if (!getDefinition().validate(this, context)) {
               // Failed
               return false;
           } else {
  @@ -182,8 +183,8 @@
       }
       
       public void generateLabel(ContentHandler contentHandler) throws SAXException {
  -        if (definition != null) {
  -            definition.generateDisplayData("label", contentHandler);
  +        if (getDefinition() != null) {
  +            getDefinition().generateDisplayData("label", contentHandler);
           }
       }
   
  @@ -205,7 +206,7 @@
               return this.attributes.get(name);
           } else{
               return null;
  -				}
  +        }
       }
   
       public void setAttribute(String name, Object value) {
  
  
  
  1.5       +7 -6      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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Field.java	9 Mar 2004 13:17:26 -0000	1.4
  +++ Field.java	9 Apr 2004 16:43:21 -0000	1.5
  @@ -47,6 +47,8 @@
    */
   public class Field extends AbstractWidget implements ValidationErrorAware, DataWidget, SelectableWidget {
       protected SelectionList selectionList;
  +    
  +    private final FieldDefinition definition;
   
       protected String enteredValue;
       protected Object value;
  @@ -61,16 +63,15 @@
   
   
       public Field(FieldDefinition fieldDefinition) {
  -        setDefinition(fieldDefinition);
  -        setLocation(fieldDefinition.getLocation());
  +        this.definition = fieldDefinition;
       }
   
       public final FieldDefinition getFieldDefinition() {
  -        return (FieldDefinition)super.definition;
  +        return this.definition;
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return this.definition;
       }
   
       public Object getOldValue() {
  
  
  
  1.2       +8 -3      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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Union.java	9 Mar 2004 10:33:50 -0000	1.1
  +++ Union.java	9 Apr 2004 16:43:21 -0000	1.2
  @@ -34,12 +34,17 @@
   public class Union extends AbstractContainerWidget {
       private static final String ELEMENT = "field";
       private Widget caseWidget;
  +    
  +    private final UnionDefinition definition;
   
       public Union(UnionDefinition definition) {
  -        super(definition);
  -        setLocation(definition.getLocation());
  +        this.definition = definition;
           // TODO: Remove after moving logic to Field.
           //item.enteredValue = (String)definition.getDefaultValue();
  +    }
  +    
  +    protected WidgetDefinition getDefinition() {
  +        return definition;
       }
   
       // TODO: This whole union mess is too dependent on undefined sequences of execution.
  
  
  
  1.4       +4 -5      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BooleanField.java	9 Mar 2004 13:17:26 -0000	1.3
  +++ BooleanField.java	9 Apr 2004 16:43:21 -0000	1.4
  @@ -43,15 +43,14 @@
       // FIXME(SW) : should the initial value be false or null ? This would allow
       // event listeners to be triggered at bind time.
       private Boolean value = Boolean.FALSE;
  -    private BooleanFieldDefinition definition;
  +    private final BooleanFieldDefinition definition;
   
       public BooleanField(BooleanFieldDefinition definition) {
           this.definition = definition;
  -        setLocation(definition.getLocation());
       }
   
  -    public String getId() {
  -        return definition.getId();
  +    protected WidgetDefinition getDefinition() {
  +        return this.definition;
       }
   
       public void readFromRequest(FormContext formContext) {
  
  
  
  1.2       +1 -2      cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Submit.java
  
  Index: Submit.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/Submit.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Submit.java	9 Mar 2004 10:33:49 -0000	1.1
  +++ Submit.java	9 Apr 2004 16:43:21 -0000	1.2
  @@ -28,7 +28,6 @@
       
       public Submit(ActionDefinition definition, boolean validateForm) {
           super(definition);
  -        setLocation(definition.getLocation());
           this.validateForm = validateForm;
       }
       
  
  
  
  1.4       +4 -4      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AggregateField.java	9 Mar 2004 13:17:26 -0000	1.3
  +++ AggregateField.java	9 Apr 2004 16:43:21 -0000	1.4
  @@ -75,7 +75,7 @@
       }
   
       public final AggregateFieldDefinition getAggregateFieldDefinition() {
  -        return (AggregateFieldDefinition)super.definition;
  +        return (AggregateFieldDefinition)getDefinition();
       }
   
       protected void addField(Field field) {
  @@ -235,7 +235,7 @@
           }
   
           // generate label, help, hint, etc.
  -        definition.generateDisplayData(contentHandler);
  +        getDefinition().generateDisplayData(contentHandler);
   
           // generate selection list, if any
           if (selectionList != null) {
  @@ -247,7 +247,7 @@
       }
   
       public void generateLabel(ContentHandler contentHandler) throws SAXException {
  -        definition.generateLabel(contentHandler);
  +        getDefinition().generateLabel(contentHandler);
       }
   
       public Widget getWidget(String id) {