mpo 2004/04/21 13:30:49
Modified: src/blocks/forms/java/org/apache/cocoon/forms/formmodel
AggregateFieldDefinition.java
AbstractContainerWidget.java
AbstractContainerDefinition.java
Added: src/blocks/forms/java/org/apache/cocoon/forms/formmodel
WidgetDefinitionList.java WidgetList.java
Removed: src/blocks/forms/java/org/apache/cocoon/forms/formmodel
ContainerDelegate.java
ContainerDefinitionDelegate.java
Log:
Renaming Container(Definition)Delegate to Widget(Definition)List.
Revision Changes Path
1.2 +2 -2
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java
Index: AggregateFieldDefinition.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AggregateFieldDefinition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AggregateFieldDefinition.java 9 Mar 2004 10:33:50 -0000 1.1
+++ AggregateFieldDefinition.java 21 Apr 2004 20:30:49 -0000 1.2
@@ -62,7 +62,7 @@
/**
*
*/
- private ContainerDefinitionDelegate container = new
ContainerDefinitionDelegate(this);
+ private WidgetDefinitionList container = new WidgetDefinitionList(this);
public void addWidgetDefinition(WidgetDefinition widgetDefinition)
throws DuplicateIdException {
1.7 +3 -3
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.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractContainerWidget.java 20 Apr 2004 22:19:27 -0000 1.6
+++ AbstractContainerWidget.java 21 Apr 2004 20:30:49 -0000 1.7
@@ -35,13 +35,13 @@
/**
* List of contained widgets.
*/
- protected ContainerDelegate widgets;
+ protected WidgetList widgets;
/**
* Constructs AbstractContainerWidget
*/
public AbstractContainerWidget() {
- widgets = new ContainerDelegate();
+ widgets = new WidgetList();
}
public void addWidget(Widget widget) {
1.3 +3 -3
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java
Index: AbstractContainerDefinition.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/AbstractContainerDefinition.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractContainerDefinition.java 12 Apr 2004 14:05:09 -0000 1.2
+++ AbstractContainerDefinition.java 21 Apr 2004 20:30:49 -0000 1.3
@@ -25,10 +25,10 @@
*/
public abstract class AbstractContainerDefinition
extends AbstractWidgetDefinition implements ContainerDefinition {
- protected ContainerDefinitionDelegate definitions;
+ protected WidgetDefinitionList definitions;
public AbstractContainerDefinition() {
- definitions = new ContainerDefinitionDelegate(this);
+ definitions = new WidgetDefinitionList(this);
}
public void createWidget(Widget parent, String id) {
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetDefinitionList.java
Index: WidgetDefinitionList.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.forms.formmodel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
// TODO: Refine and i18n the exception messages.
/**
* Helper class for the Definition implementation of widgets containing
* other widgets.
*
* @version $Id: WidgetDefinitionList.java,v 1.1 2004/04/21 20:30:49 mpo Exp $
*/
public class WidgetDefinitionList {
private List widgetDefinitions = new ArrayList();
private Map widgetDefinitionsById = new HashMap();
private WidgetDefinition definition;
private boolean resolving;
private ListIterator definitionsIt = widgetDefinitions.listIterator();
/**
* @param definition the widget definition to which this container
delegate belongs
*/
public WidgetDefinitionList(WidgetDefinition definition) {
this.definition = definition;
resolving = false;
}
public void addWidgetDefinition(WidgetDefinition widgetDefinition) throws
DuplicateIdException {
String id = widgetDefinition.getId();
// Do not add NewDefinition id's hash.
if (!(widgetDefinition instanceof NewDefinition)) {
if (widgetDefinitionsById.containsKey(id)) {
String duplicateLocation = widgetDefinition.getLocation();
String containerLocation = definition.getLocation();
String firstLocation = getWidgetDefinition(id).getLocation();
throw new DuplicateIdException(
"Duplicate widget id \"" + id + "\" detected at " +
duplicateLocation + ".\n" +
"Container widget \"" + definition.getId() + "\" at " +
containerLocation + "\n" +
"already contains a widget with id \"" + id + "\" at " +
firstLocation + ".");
}
widgetDefinitionsById.put(widgetDefinition.getId(),
widgetDefinition);
}
this.definitionsIt.add(widgetDefinition);
}
public List getWidgetDefinitions() {
return widgetDefinitions;
}
public boolean hasWidget(String id) {
return widgetDefinitionsById.containsKey(id);
}
public WidgetDefinition getWidgetDefinition(String id) {
return (WidgetDefinition)widgetDefinitionsById.get(id);
}
public boolean isResolving() {
return resolving;
}
public void resolve(List parents, WidgetDefinition parent) throws
Exception {
if (!resolving) {
resolving = true;
this.definitionsIt = widgetDefinitions.listIterator();
parents.add(definition);
while (this.definitionsIt.hasNext()) {
WidgetDefinition widgetDefinition =
(WidgetDefinition)this.definitionsIt.next();
// ClassDefinition's get resolved by NewDefinition rather
than here.
if (!(widgetDefinition instanceof ClassDefinition)) {
if (widgetDefinition instanceof NewDefinition) {
// Remove NewDefinition in preparation for its
referenced class of widget definitions to be added.
this.definitionsIt.remove();
((NewDefinition)widgetDefinition).resolve(parents,
definition);
} else {
if (widgetDefinition instanceof ContainerDefinition)
((ContainerDefinition)widgetDefinition).resolve(parents, definition);
}
}
}
parents.remove(parents.size()-1);
resolving = false;
} else {
// Non-terminating recursion detection
if (resolving == true) {
// Search up parent list in hopes of finding a "Union" before
finding previous "New" for this "Class".
ListIterator parentsIt = parents.listIterator(parents.size());
while(parentsIt.hasPrevious()) {
WidgetDefinition widgetDefinition =
(WidgetDefinition)parentsIt.previous();
if (widgetDefinition instanceof UnionDefinition) break;
if (widgetDefinition == definition) {
String location = definition.getLocation();
if (parent instanceof FormDefinition) {
throw new Exception("Container: Non-terminating
recursion detected in form definition (" + location + ")");
} else {
throw new Exception("Container: Non-terminating
recursion detected in widget definition: "
+ parent.getId() + " (" + location + ")");
}
}
}
}
}
}
public void createWidget(Widget parent, String id) {
WidgetDefinition widgetDefinition =
(WidgetDefinition)widgetDefinitionsById.get(id);
if (widgetDefinition == null) {
throw new RuntimeException(definition.getId() + ":
WidgetDefinition \"" + id +
"\" does not exist (" + definition.getLocation() + ")");
}
Widget widget = widgetDefinition.createInstance();
if (widget != null)
((ContainerWidget)parent).addWidget(widget);
}
public void createWidgets(Widget parent) {
Iterator definitionsIt = widgetDefinitions.iterator();
while (definitionsIt.hasNext()) {
WidgetDefinition widgetDefinition =
(WidgetDefinition)definitionsIt.next();
Widget widget = widgetDefinition.createInstance();
if (widget != null)
((ContainerWidget)parent).addWidget(widget);
}
}
}
1.1
cocoon-2.1/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/WidgetList.java
Index: WidgetList.java
===================================================================
/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cocoon.forms.formmodel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.cocoon.forms.Constants;
import org.apache.cocoon.forms.FormContext;
import org.apache.cocoon.xml.XMLUtils;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/**
* 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: WidgetList.java,v 1.1 2004/04/21 20:30:49 mpo Exp $
*/
public class WidgetList {
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;
/**
* Constructs ContainerDelegate to store and jointly manage a list of
* contained widgets.
*/
public WidgetList() {
widgets = new ArrayList();
widgetsById = new HashMap();
}
/**
* 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 = 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 = iterator();
while (widgetIt.hasNext()) {
Widget widget = (Widget)widgetIt.next();
valid = valid & widget.validate(formContext);
}
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();
}
/**
* @return <code>false</code> if at least one of the contained widgets
has no value.
*/
public boolean widgetsHaveValues() {
Iterator widgetsIt = iterator();
while(widgetsIt.hasNext()) {
Widget widget = (Widget)widgetsIt.next();
if (widget.getValue() == null)
return false;
}
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();
while (widgetIt.hasNext()) {
Widget widget = (Widget)widgetIt.next();
widget.generateSaxFragment(contentHandler, locale);
}
contentHandler.endElement(Constants.INSTANCE_NS, WIDGETS_EL,
Constants.INSTANCE_PREFIX_COLON + WIDGETS_EL);
}
}