|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.cocoon.forms.formmodel.AbstractWidget
public abstract class AbstractWidget
Abstract base class for Widget implementations. Provides functionality common to many widgets.
Field Summary | |
---|---|
protected boolean |
wasValid
The result of the last call to validate() . |
Fields inherited from interface org.apache.cocoon.forms.formmodel.Widget |
---|
PATH_SEPARATOR |
Constructor Summary | |
---|---|
protected |
AbstractWidget(AbstractWidgetDefinition definition)
|
Method Summary | |
---|---|
void |
addValidator(WidgetValidator validator)
Add a validator to this widget instance. |
void |
broadcastEvent(WidgetEvent event)
Broadcast an event previously queued by this widget to its event listeners. |
protected void |
generateDisplayData(ContentHandler contentHandler)
Delegates to the getDefinition() of this widget to generate a common
set of 'display' data. |
protected void |
generateItemSaxFragment(ContentHandler contentHandler,
Locale locale)
Generates nested additional content nested inside the main element for this widget which is generated by generateSaxFragment(ContentHandler, Locale)
The implementation on the AbstractWidget level inserts no additional XML. |
void |
generateLabel(ContentHandler contentHandler)
Generates SAX events for the label of this widget. |
void |
generateSaxFragment(ContentHandler contentHandler,
Locale locale)
Generates an XML representation of this widget. |
Object |
getAttribute(String name)
Retrieves an attribute on this widget. |
protected Widget |
getChild(String id)
Concrete widgets that contain actual child widgets should override to return the actual child-widget. |
WidgetState |
getCombinedState()
Get the widget's combined state, which is the strictest of its own state and parent state. |
abstract WidgetDefinition |
getDefinition()
Concrete subclasses should allow access to their underlaying Definition through this method. |
Form |
getForm()
|
String |
getFullName()
|
String |
getId()
Gets the id of this widget. |
Location |
getLocation()
Get the location of this object |
String |
getName()
|
Widget |
getParent()
|
String |
getRequestParameterName()
|
WidgetState |
getState()
Get the widget's own state. |
Object |
getValue()
Get the value of a widget. |
Widget |
getWidget(String id)
|
protected AttributesImpl |
getXMLElementAttributes()
The XML attributes used in generateSaxFragment(ContentHandler, Locale)
to be placed on the wrapping element for all the XML-instance-content of this Widget. |
protected abstract String |
getXMLElementName()
The XML element name used in generateSaxFragment(ContentHandler, Locale)
to produce the wrapping element for all the XML-instance-content of this Widget. |
void |
initialize()
Called after widget's environment has been setup, to allow for any contextual initalization, such as looking up case widgets for union widgets. |
boolean |
isRequired()
|
boolean |
isValid()
Return the current validation state. |
Widget |
lookupWidget(String path)
Finds a widget relative to this one based on a path-like string (/-delimted) into the widget-tree structure. |
void |
removeAttribute(String name)
Removes the named attribute from this widget. |
boolean |
removeValidator(WidgetValidator validator)
Remove a validator from this widget instance |
void |
setAttribute(String name,
Object value)
Sets an attribute on this widget. |
void |
setParent(Widget widget)
Sets the parent-widget of this widget. |
void |
setState(WidgetState state)
Set the widget's own state. |
void |
setValue(Object object)
Sets the value of this widget. |
String |
toString()
|
boolean |
validate()
Validates this widget and returns the outcome. |
protected void |
widgetNameChanged()
Should be called when a widget's own name has changed, in order to clear internal caches used to compute request parameters. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.apache.cocoon.forms.formmodel.Widget |
---|
readFromRequest |
Field Detail |
---|
protected boolean wasValid
validate()
.
Constructor Detail |
---|
protected AbstractWidget(AbstractWidgetDefinition definition)
Method Detail |
---|
public void initialize()
initialize
in interface Widget
public String getId()
getId
in interface Widget
null
Top-level container widgets (like 'form') should return ""
public String getName()
getName
in interface Widget
null
Top-level container widgets (like 'form') should return ""
public abstract WidgetDefinition getDefinition()
null
they should also organize
own implementations of getId()
, getLocation()
,
validate()
, generateLabel(ContentHandler)
and
generateDisplayData(ContentHandler)
to avoid NPE's.
getDefinition
in interface Widget
WidgetDefinition.createInstance()
)public Location getLocation()
Locatable
getLocation
in interface Widget
getLocation
in interface Locatable
public final Widget getParent()
getParent
in interface Widget
public void setParent(Widget widget)
setParent
in interface Widget
widget
- the parent-widget of this one.
IllegalStateException
- when the parent had already been set.public Form getForm()
getForm
in interface Widget
public WidgetState getState()
Widget
getState
in interface Widget
Widget.getCombinedState()
public void setState(WidgetState state)
Widget
setState
in interface Widget
state
- the new wiget statepublic WidgetState getCombinedState()
Widget
getCombinedState
in interface Widget
WidgetState.strictest(WidgetState, WidgetState)
protected void widgetNameChanged()
public String getFullName()
getFullName
in interface Widget
public String getRequestParameterName()
getRequestParameterName
in interface Widget
public Widget lookupWidget(String path)
Widget
lookupWidget
in interface Widget
null
if allong the traversal
of the path an invalid section was encountered.protected Widget getChild(String id)
id
- of the child-widget
null
if not overriden.public Widget getWidget(String id)
getWidget
in interface Widget
public Object getValue()
Widget
Not all widgets do have a value (notably ContainerWidget
s,
but this method is provided here as a convenience to ease writing and avoiding casts.
getValue
in interface Widget
public void setValue(Object object)
Widget
Not all widgets do have a value (notably ContainerWidget
s,
but this method is provided here as a convenience to ease writing and avoiding casts.
setValue
in interface Widget
object
- the new widget's value.public boolean isRequired()
isRequired
in interface Widget
Widget.getValue()
,
for some widgets this may not make sense, those should return false here.public void broadcastEvent(WidgetEvent event)
UnsupportedOperationException
.
Concrete subclass widgets need to override when supporting event broadcasting.
broadcastEvent
in interface Widget
public void addValidator(WidgetValidator validator)
addValidator
in interface Widget
validator
- public boolean removeValidator(WidgetValidator validator)
removeValidator
in interface Widget
validator
-
true
if the validator was found.public boolean validate()
Widget
Widget.generateSaxFragment(ContentHandler, Locale)
method.
validate
in interface Widget
true
to indicate all validations were ok,
false
otherwiseWidget.validate()
public boolean isValid()
Widget
Widget.validate()
.
The validation process is not started again. If the value of this widget has
changed since the latest call to Widget.validate()
, the result of this method
is out of date.
isValid
in interface Widget
Widget.validate()
.Widget.isValid()
public void generateLabel(ContentHandler contentHandler) throws SAXException
getDefinition()
to generate the 'label' part of
the display-data of this widget.
Subclasses should override if the getDefinition can return null
to avoid NPE's
generateLabel
in interface Widget
contentHandler
-
SAXException
protected void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException
generateSaxFragment(ContentHandler, Locale)
The implementation on the AbstractWidget level inserts no additional XML.
Subclasses need to override to insert widget specific content.
contentHandler
- to send the SAX events tolocale
- in which context potential content needs to be put.
SAXException
protected abstract String getXMLElementName()
generateSaxFragment(ContentHandler, Locale)
to produce the wrapping element for all the XML-instance-content of this Widget.
protected AttributesImpl getXMLElementAttributes()
generateSaxFragment(ContentHandler, Locale)
to be placed on the wrapping element for all the XML-instance-content of this Widget.
This automatically adds @id=getRequestParameterName()
to that element.
Concrete subclasses should call super.getXMLElementAttributes and possibly
add additional attributes.
Note: the @id is not added for those widgets who's getId() returns null
(e.g. top-level container widgets like 'form'). The contract of returning a non-null
AttributesImpl
is however maintained.
protected void generateDisplayData(ContentHandler contentHandler) throws SAXException
getDefinition()
of this widget to generate a common
set of 'display' data. (i.e. help, label, hint,...)
Subclasses should override if the getDefinition can return null
to avoid NPE's.
contentHandler
- where to send the SAX events to.
SAXException
WidgetDefinition.generateDisplayData(ContentHandler)
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException
getXMLElementName()
) with attributes
(provided by getXMLElementAttributes()
around anything injected
in by both generateDisplayData(ContentHandler)
and
generateItemSaxFragment(ContentHandler, Locale)
.
<fi:getXMLElementName()
getXMLElementAttributes()
>generateDisplayData(ContentHandler)
(i.e. help, label, ...)generateItemSaxFragment(ContentHandler, Locale)
</fi:getXMLElementName()
>
generateSaxFragment
in interface Widget
contentHandler
- to send the SAX events tolocale
- in which context potential content needs to be put.
SAXException
public Object getAttribute(String name)
Widget
getAttribute
in interface Widget
name
- of the attribute to lookup
null
if none was found with that name.public void setAttribute(String name, Object value)
Widget
setAttribute
in interface Widget
public void removeAttribute(String name)
Widget
removeAttribute
in interface Widget
name
- of the attributepublic String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |