com.sun.rave.web.ui.component.util.descriptors
Class LayoutElementBase

java.lang.Object
  extended by com.sun.rave.web.ui.component.util.descriptors.LayoutElementBase
All Implemented Interfaces:
LayoutElement, java.io.Serializable
Direct Known Subclasses:
LayoutAttribute, LayoutComponent, LayoutDefinition, LayoutFacet, LayoutForEach, LayoutIf, LayoutMarkup, LayoutStaticText

public abstract class LayoutElementBase
extends java.lang.Object
implements LayoutElement

This class provides some common functionality between the various types of LayoutElements. It is the base class of most implementations (perhaps all).

See Also:
Serialized Form

Field Summary
static java.lang.String AFTER_ENCODE
           This is the "type" for handlers to be invoked after the encoding of this element.
static java.lang.String BEFORE_ENCODE
           This is the "type" for handlers to be invoked before the encoding of this element.
static java.lang.String ENCODE
           This is the "type" for handlers to be invoked during the encoding of this element.
 
Constructor Summary
protected LayoutElementBase(LayoutElement parent, java.lang.String id)
          Constructor
 
Method Summary
 void addChildLayoutElement(LayoutElement element)
          This method is used to add a LayoutElement.
protected  HandlerContext createHandlerContext(javax.faces.context.FacesContext context, java.util.EventObject event, java.lang.String eventType)
           This method is responsible for creating a new HandlerContext.
 java.lang.Object dispatchHandlers(javax.faces.context.FacesContext context, java.lang.String eventType, java.util.EventObject event)
           This method iterates over the handlers and executes each one.
 java.lang.Object dispatchHandlers(HandlerContext handlerCtx, java.util.List handlers)
           As currently implemented, this method is essentially a utility method.
 void encode(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
           This is the base implementation for encode.
static void encodeChild(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
           This method is a convenience method for encoding the given UIComponent.
protected abstract  boolean encodeThis(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
           This method allows each LayoutElement to provide it's own encode functionality.
 java.util.List getChildLayoutElements()
          This method returns the LayoutElements as a List.
 java.util.List getHandlers(java.lang.String type)
           This method retrieves the Handlers for the requested type.
 java.util.List getHandlers(java.lang.String type, javax.faces.component.UIComponent comp)
           This method retrieves the Handlers for the requested type.
 java.util.Map getHandlersByTypeMap()
           This method provides access to the "handlersByType" Map.
 java.lang.String getId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent parent)
           Accessor method for id.
 LayoutDefinition getLayoutDefinition()
          This method walks to the top-most LayoutElement, which should be a LayoutDefinition.
 LayoutElement getParent()
          This method returns the parent LayoutElement.
 java.lang.String getUnevaluatedId()
           This method generally should not be used.
 java.lang.Object resolveValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent parent, java.lang.String value)
           This method will attempt to resolve EL strings in the given value.
 void setHandlers(java.lang.String type, java.util.List handlers)
           This method associates 'type' with the given list of Handlers.
 void setHandlersByTypeMap(java.util.Map map)
           This method provides a means to set the "handlersByType" Map.
protected  void setParent(LayoutElement parent)
          This method sets the parent LayoutElement.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AFTER_ENCODE

public static final java.lang.String AFTER_ENCODE

This is the "type" for handlers to be invoked after the encoding of this element.

See Also:
Constant Field Values

BEFORE_ENCODE

public static final java.lang.String BEFORE_ENCODE

This is the "type" for handlers to be invoked before the encoding of this element.

See Also:
Constant Field Values

ENCODE

public static final java.lang.String ENCODE

This is the "type" for handlers to be invoked during the encoding of this element. This occurs before any child LayoutElements are invoked and only if child Elements are to be invoked.

See Also:
Constant Field Values
Constructor Detail

LayoutElementBase

protected LayoutElementBase(LayoutElement parent,
                            java.lang.String id)
Constructor

Parameters:
parent - The parent LayoutElement
id - Identifier for this LayoutElement
Method Detail

addChildLayoutElement

public void addChildLayoutElement(LayoutElement element)
This method is used to add a LayoutElement. LayoutElements should be added sequentially in the order in which they are to be rendered.

Specified by:
addChildLayoutElement in interface LayoutElement
Parameters:
element - The LayoutElement to add as a child

getChildLayoutElements

public java.util.List getChildLayoutElements()
This method returns the LayoutElements as a List.

Specified by:
getChildLayoutElements in interface LayoutElement
Returns:
List of LayoutElements

getLayoutDefinition

public LayoutDefinition getLayoutDefinition()
This method walks to the top-most LayoutElement, which should be a LayoutDefinition. If not, it will throw an Exception.

Specified by:
getLayoutDefinition in interface LayoutElement
Returns:
The LayoutDefinition

getParent

public LayoutElement getParent()
This method returns the parent LayoutElement.

Specified by:
getParent in interface LayoutElement
Returns:
parent LayoutElement

setParent

protected void setParent(LayoutElement parent)
This method sets the parent LayoutElement.

Parameters:
parent - Parent LayoutElement

getUnevaluatedId

public java.lang.String getUnevaluatedId()

This method generally should not be used. It does not resolve expressions. Instead use getId(FacesContext, UIComponent).

Specified by:
getUnevaluatedId in interface LayoutElement
Returns:
The unevaluated id.

getId

public java.lang.String getId(javax.faces.context.FacesContext context,
                              javax.faces.component.UIComponent parent)

Accessor method for id. This returns a non-null value, it may return "" if id is not set or does not apply.

This method will also attempt to resolve EL strings.

Specified by:
getId in interface LayoutElement
Parameters:
context - The FacesContext
parent - The parent UIComponent. This is used because the current UIComponent is typically unknown (or not even created yet).
Returns:
a non-null id

resolveValue

public java.lang.Object resolveValue(javax.faces.context.FacesContext context,
                                     javax.faces.component.UIComponent parent,
                                     java.lang.String value)

This method will attempt to resolve EL strings in the given value.

Parameters:
context - The FacesContext
parent - The parent UIComponent. This is used because the current UIComponent is typically unknown (or not even created yet).
value - The String to resolve
Returns:
The evaluated value (may be null).

encodeThis

protected abstract boolean encodeThis(javax.faces.context.FacesContext context,
                                      javax.faces.component.UIComponent component)
                               throws java.io.IOException

This method allows each LayoutElement to provide it's own encode functionality. If the LayoutElement should render its children, this method should return true. Otherwise, this method should return false.

Parameters:
context - The FacesContext
component - The UIComponent
Returns:
true if children are to be rendered, false otherwise.
Throws:
java.io.IOException

encode

public void encode(javax.faces.context.FacesContext context,
                   javax.faces.component.UIComponent component)
            throws java.io.IOException

This is the base implementation for encode. Typically each type of LayoutElement wants to do something specific then conditionally have its children rendered. This method invokes the abstract method "encodeThis" to do specific functionality, it the walks the children and renders them, if encodeThis returns true. It skips the children if encodeThis returns false.

Specified by:
encode in interface LayoutElement
Parameters:
context - The FacesContext
component - The UIComponent
Throws:
java.io.IOException

dispatchHandlers

public java.lang.Object dispatchHandlers(javax.faces.context.FacesContext context,
                                         java.lang.String eventType,
                                         java.util.EventObject event)

This method iterates over the handlers and executes each one. A HandlerContext will be created to pass to each Handler. The HandlerContext object is reused across all Handlers that are invoked; the setHandler(Handler) method is invoked with the correct Handler descriptor before the handler is executed.

Specified by:
dispatchHandlers in interface LayoutElement
Parameters:
context - The FacesContext
eventType - The event type which is being fired
event - An optional EventObject providing more detail
Returns:
By default, (null) is returned. However, if any of the handlers produce a non-null return value, then the value from the last handler to produces a non-null return value is returned.

dispatchHandlers

public java.lang.Object dispatchHandlers(HandlerContext handlerCtx,
                                         java.util.List handlers)

As currently implemented, this method is essentially a utility method. May want to rethink this.

Specified by:
dispatchHandlers in interface LayoutElement

createHandlerContext

protected HandlerContext createHandlerContext(javax.faces.context.FacesContext context,
                                              java.util.EventObject event,
                                              java.lang.String eventType)

This method is responsible for creating a new HandlerContext. It does not set the Handler descriptor. This is done right before a Handler is invoked. This allows the HandlerContext object to be reused.

Parameters:
context - The FacesContext

getHandlers

public java.util.List getHandlers(java.lang.String type)

This method retrieves the Handlers for the requested type.

Specified by:
getHandlers in interface LayoutElement
Parameters:
type - The type of Handlers to retrieve.
Returns:
A List of Handlers.

getHandlersByTypeMap

public java.util.Map getHandlersByTypeMap()

This method provides access to the "handlersByType" Map.


setHandlersByTypeMap

public void setHandlersByTypeMap(java.util.Map map)

This method provides a means to set the "handlersByType" Map. Normally this is done for each type individually via setHandlers(String, List). This Map may not be null (null will be ignored) and should contain entries that map to Lists of Handlers.


getHandlers

public java.util.List getHandlers(java.lang.String type,
                                  javax.faces.component.UIComponent comp)

This method retrieves the Handlers for the requested type. But also includes any handlers that are associated with the instance (i.e. the UIComponent).

Parameters:
type - The type of Handlers to retrieve.
event - The associated UIComponent (or null).
Returns:
A List of Handlers.

setHandlers

public void setHandlers(java.lang.String type,
                        java.util.List handlers)

This method associates 'type' with the given list of Handlers.

Specified by:
setHandlers in interface LayoutElement
Parameters:
type - The String type for the List of Handlers
handlers - The List of Handlers

encodeChild

public static void encodeChild(javax.faces.context.FacesContext context,
                               javax.faces.component.UIComponent component)
                        throws java.io.IOException

This method is a convenience method for encoding the given UIComponent. It calls the appropriate encoding methods on the component and calls itself recursively for all UIComponent children that do not render their own children.

Parameters:
context - FacesContext
component - UIComponent to encode
Throws:
java.io.IOException