You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/12/14 18:47:46 UTC
svn commit: r356817 -
/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
Author: sylvain
Date: Wed Dec 14 09:46:05 2005
New Revision: 356817
URL: http://svn.apache.org/viewcvs?rev=356817&view=rev
Log:
Make some methods public, fix indentation
Modified:
cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
Modified: cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java?rev=356817&r1=356816&r2=356817&view=diff
==============================================================================
--- cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java (original)
+++ cocoon/blocks/forms/trunk/java/org/apache/cocoon/forms/formmodel/AbstractWidgetDefinition.java Wed Dec 14 09:46:05 2005
@@ -40,7 +40,7 @@
public abstract class AbstractWidgetDefinition implements WidgetDefinition {
private FormDefinition formDefinition;
protected WidgetDefinition parent;
-
+
//TODO consider final on these
private Location location = Location.UNKNOWN;
private String id;
@@ -51,9 +51,9 @@
private Map displayData;
private List validators;
private WidgetState state = WidgetState.ACTIVE;
-
+
protected CreateListener createListener;
-
+
public FormDefinition getFormDefinition() {
if (this.formDefinition == null) {
if (this instanceof FormDefinition) {
@@ -69,46 +69,31 @@
* initialize this definition with the other, sort of like a copy constructor
*/
public void initializeFrom(WidgetDefinition definition) throws Exception {
- if(definition instanceof AbstractWidgetDefinition) {
- AbstractWidgetDefinition other = (AbstractWidgetDefinition)definition;
-
- this.state = other.state;
- this.createListener = other.createListener; // this works, we don't really remove listeners, right?
-
- this.validators = new ArrayList();
- if(other.validators!=null) {
- for(int i=0; i<other.validators.size(); i++)
- this.validators.add(other.validators.get(i));
- }
-
- if(other.attributes!=null) {
- if(attributes==null)
- attributes = new HashMap();
- copyMap(attributes,other.attributes);
- }
- if(other.displayData!=null) {
- if(displayData==null)
- displayData = new HashMap();
- copyMap(displayData,other.displayData);
- }
- } else {
- throw new Exception("Definition to inherit from is not of the right type! (at "+getLocation()+")");
- }
- }
-
- /**
- * helper to copy a map
- *
- * @param dest destination map
- * @param src source map
- */
- protected void copyMap(Map dest, Map src) {
- dest.clear();
- Iterator it = src.entrySet().iterator();
- while(it.hasNext()) {
- Map.Entry entry = (Map.Entry)it.next();
- dest.put(entry.getKey(),entry.getValue());
- }
+ if(definition instanceof AbstractWidgetDefinition) {
+ AbstractWidgetDefinition other = (AbstractWidgetDefinition)definition;
+
+ this.state = other.state;
+ this.createListener = other.createListener; // this works, we don't really remove listeners, right?
+
+ this.validators = new ArrayList();
+ if(other.validators!=null) {
+ for(int i=0; i<other.validators.size(); i++)
+ this.validators.add(other.validators.get(i));
+ }
+
+ if(other.attributes!=null) {
+ if(attributes==null)
+ attributes = new HashMap();
+ attributes.putAll(other.attributes);
+ }
+ if(other.displayData!=null) {
+ if(displayData==null)
+ displayData = new HashMap();
+ attributes.putAll(other.displayData);
+ }
+ } else {
+ throw new Exception("Definition to inherit from is not of the right type! (at "+getLocation()+")");
+ }
}
/**
@@ -116,12 +101,12 @@
*/
public void checkCompleteness() throws IncompletenessException
{
- // FormDefinition is the only one allowed not to have an ID
- if( (id==null || "".equals(id) && !(this instanceof FormDefinition) ))
- throw new IncompletenessException("Widget found without an ID! "+this,this);
-
-
- // TODO: don't know what else to check now
+ // FormDefinition is the only one allowed not to have an ID
+ if( (id==null || "".equals(id) && !(this instanceof FormDefinition) ))
+ throw new IncompletenessException("Widget found without an ID! "+this,this);
+
+
+ // TODO: don't know what else to check now
}
@@ -140,7 +125,7 @@
throw new IllegalStateException("Attempt to modify an immutable WidgetDefinition");
}
}
-
+
/**
* Sets the parent of this definition
*/
@@ -149,7 +134,7 @@
//reorganization of the definition tree
this.parent = definition;
}
-
+
/**
* Gets the parent of this definition.
* This method returns null for the root definition.
@@ -157,52 +142,46 @@
public WidgetDefinition getParent() {
return this.parent;
}
-
+
public WidgetState getState() {
return this.state;
}
-
+
public void setState(WidgetState state) {
checkMutable();
this.state = state;
}
-
+
public void setLocation(Location location) {
checkMutable();
this.location = location;
}
-
+
public Location getLocation() {
return location;
}
-
+
public String getId() {
return id;
}
-
- protected void setId(String id) {
+
+ public void setId(String id) {
checkMutable();
this.id = id;
}
-
- protected void setAttributes(Map attributes) {
+
+ public void setAttributes(Map attributes) {
checkMutable();
//this.attributes = attributes;
if(this.attributes==null) {
- this.attributes = attributes;
- return;
+ this.attributes = attributes;
+ return;
}
if(attributes==null)
- return;
+ return;
// merge attribute lists
- Iterator entries = attributes.entrySet().iterator();
- while(entries.hasNext()) {
- Map.Entry entry = (Map.Entry)entries.next();
- Object key = entry.getKey();
- Object value = entry.getValue();
- this.attributes.put(key,value);
- }
+ this.attributes.putAll(attributes);
}
public Object getAttribute(String name) {
@@ -211,8 +190,8 @@
}
return null;
}
-
- protected void addCreateListener(CreateListener listener) {
+
+ public void addCreateListener(CreateListener listener) {
checkMutable();
// Event listener daisy-chain
this.createListener = WidgetEventMulticaster.add(this.createListener, listener);
@@ -223,7 +202,7 @@
widget.getForm().addWidgetEvent(new CreateEvent(widget));
}
}
-
+
public void fireCreateEvent(CreateEvent event) {
// Check that this widget was created by the current definition
if (event.getSourceWidget().getDefinition() != this) {
@@ -233,11 +212,11 @@
this.createListener.widgetCreated(event);
}
}
-
+
public void generateLabel(ContentHandler contentHandler) throws SAXException {
generateDisplayData("label", contentHandler);
}
-
+
/**
* Sets the various display data for this widget. This includes the label, hint and help.
* They must all be objects implementing the XMLizable interface. This approach
@@ -250,32 +229,32 @@
//this.displayData = displayData;
if(this.displayData==null) {
- this.displayData = displayData;
- return;
+ this.displayData = displayData;
+ return;
}
if(displayData==null)
- return;
+ return;
// merge displayData lists
Iterator entries = displayData.entrySet().iterator();
while(entries.hasNext()) {
- Map.Entry entry = (Map.Entry)entries.next();
- Object key = entry.getKey();
- Object value = entry.getValue();
- if(value!=null || !this.displayData.containsKey(key))
- this.displayData.put(key,value);
+ Map.Entry entry = (Map.Entry)entries.next();
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ if(value!=null || !this.displayData.containsKey(key))
+ this.displayData.put(key,value);
}
}
-
+
public void addValidator(WidgetValidator validator) {
checkMutable();
if (this.validators == null) {
this.validators = new ArrayList();
}
-
+
this.validators.add(validator);
}
-
+
public void generateDisplayData(String name, ContentHandler contentHandler) throws SAXException {
Object data = this.displayData.get(name);
if (data != null) {
@@ -284,7 +263,7 @@
throw new IllegalArgumentException("Unknown display data name '" + name + "'");
}
}
-
+
public void generateDisplayData(ContentHandler contentHandler) throws SAXException {
// Output all non-null display data
Iterator iter = this.displayData.entrySet().iterator();
@@ -292,22 +271,22 @@
Map.Entry entry = (Map.Entry)iter.next();
if (entry.getValue() != null) {
String name = (String)entry.getKey();
-
+
// Enclose the data into a "wi:{name}" element
contentHandler.startElement(FormsConstants.INSTANCE_NS, name, FormsConstants.INSTANCE_PREFIX_COLON + name, XMLUtils.EMPTY_ATTRIBUTES);
-
+
((XMLizable)entry.getValue()).toSAX(contentHandler);
-
+
contentHandler.endElement(FormsConstants.INSTANCE_NS, name, FormsConstants.INSTANCE_PREFIX_COLON + name);
}
}
}
-
+
public boolean validate(Widget widget) {
if (this.validators == null) {
// No validators
return true;
-
+
}
Iterator iter = this.validators.iterator();
while(iter.hasNext()) {