org.barracudamvc.core.comp
Class AbstractBComponent

java.lang.Object
  extended byorg.barracudamvc.core.comp.AbstractBComponent
All Implemented Interfaces:
Attrs, BContainer, StateMap
Direct Known Subclasses:
BComponent

public abstract class AbstractBComponent
extends Object
implements BContainer, StateMap, Attrs

This class provides the abstract implementation for BComponent. NOTE: You should never extend from this class. This class is primarily implemented as an abstract class for code-hiding purposes. ALL BARRACUDA COMPONENTS MUST EXTEND FROM BComponent. If that causes you problems, ask Christian why this must be the case.


Field Summary
protected  Map attrs
           
protected  List children
           
protected  Object dvc
           
protected  boolean isStepChild
           
protected static org.apache.log4j.Logger logger
           
protected  BContainer parent
           
protected  StateMap statemap
           
protected  List stepChildren
           
protected  List tempViews
           
protected  boolean validated
           
protected  List views
           
 
Constructor Summary
AbstractBComponent()
           
 
Method Summary
 BContainer addChild(BContainer child)
          Add a child container to this one
 BComponent addStepChild(BContainer child)
          Add a step child; step children are automatically removed after each render.
 BComponent addStepChild(BContainer child, boolean inheritParentAttrs)
          Add a step child; step children are automatically removed after each render.
 BComponent addTempView(View tview)
          Add a temporary view; temp views are automatically removed after each render
abstract  BComponent addView(View view)
           
 void clearState()
          clear all state information
 void destroyCycle()
          Destroy cycle.
protected  Map findComponentMap(Class cl)
          Look for a factory that can render either this class or its parent class.
protected  RendererFactory findRendererFactory(Class cl, Map domMap)
          Look for a factory that can render either this class or its parent class.
 Object getAttr(Object attr)
          get an attribute associated with this particular component.
 Map getAttrMap()
          return a reference to the underlying component attribute Map
 BContainer getChild(int index)
          Get a child container at a given index
 List getChildren()
          Gets a list of all child BContainers.
 ViewContext getDefaultViewContext()
          Get the default ViewContext.
abstract  String getName()
           
 BContainer getParent()
          Get the parent container.
 Renderer getRenderer(Class domCl)
           
 Renderer getRenderer(View view)
          This method allows a component to get a reference to the appropriate renderer.
 AbstractBComponent getRootComponent()
           
 Object getState(Object key)
          get a property in this StateMap
 Set getStateKeys()
          get a keyset for this StateMap (whether or not the set is backed by the data store depends on the implementation)
 Map getStateStore()
          get a copy of the underlying Map
abstract  List getViews()
           
 boolean hasChildren()
          Determine whether this container has any children
 boolean hasViews()
          Determine whether the component has any views (either regular or temp)
 void initCycle()
          Initialize cycle.
static void installRendererFactory(RendererFactory rf, Class compCl, Class domCl)
          This allows developers to install custom renderers for specific classes of components.
 BContainer invalidate()
          Invalidates the container and all parent containers above it.
abstract  boolean isEnabled()
           
 boolean isStepChild()
          Determine whether this component is a step child
abstract  boolean isVisible()
           
 void printStackTrace(int depth, org.apache.log4j.Logger logger)
           
protected  void printStackTrace(int depth, org.apache.log4j.Logger logger, OutputStream out)
          For debugging purposes.
 void printStackTrace(int depth, OutputStream out)
           
 void putState(Object key, Object val)
          set a property in this StateMap
 BContainer removeAll()
          Remove all child containers from this one
 BComponent removeAllStepChildren()
          Remove all step children
abstract  BComponent removeAllViews()
           
 BContainer removeChild(BContainer child)
          Remove a child container from this one
 BContainer removeChild(int index)
          Remove a child container for a given index
 Object removeState(Object key)
          remove a property in this StateMap
abstract  boolean removeView(View view)
           
abstract  BComponent render(ViewContext vc)
           
 Attrs setAttr(Object attr, Object val)
          set an attribute for this particular component.
 BComponent setDefaultViewContext(ViewContext idvc)
          Set the default ViewContext.
abstract  BComponent setEnabled(boolean val)
           
abstract  BComponent setEnabled(boolean val, boolean recurse)
           
abstract  BContainer setName(String iname)
           
 BContainer setParent(BContainer iparent)
          Set the parent container.
abstract  BComponent setView(View view)
           
abstract  BComponent setVisible(boolean val)
           
abstract  BComponent setVisible(boolean val, boolean recurse)
           
abstract  boolean supports(ViewContext vc)
           
 String toRef()
          Get the component reference
 String toString()
          Get a String representation of the component
 String toString(ViewContext vc)
          Provide a String representation of the component.
 BContainer validate()
          Invalidates the container and all child containers below it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger

parent

protected BContainer parent

children

protected List children

stepChildren

protected List stepChildren

isStepChild

protected boolean isStepChild

views

protected List views

tempViews

protected List tempViews

dvc

protected Object dvc

validated

protected boolean validated

statemap

protected StateMap statemap

attrs

protected Map attrs
Constructor Detail

AbstractBComponent

public AbstractBComponent()
Method Detail

setName

public abstract BContainer setName(String iname)
Specified by:
setName in interface BContainer

getName

public abstract String getName()
Specified by:
getName in interface BContainer

setVisible

public abstract BComponent setVisible(boolean val)

setVisible

public abstract BComponent setVisible(boolean val,
                                      boolean recurse)

isVisible

public abstract boolean isVisible()

setEnabled

public abstract BComponent setEnabled(boolean val)

setEnabled

public abstract BComponent setEnabled(boolean val,
                                      boolean recurse)

isEnabled

public abstract boolean isEnabled()

setView

public abstract BComponent setView(View view)

addView

public abstract BComponent addView(View view)

removeView

public abstract boolean removeView(View view)

removeAllViews

public abstract BComponent removeAllViews()

getViews

public abstract List getViews()

render

public abstract BComponent render(ViewContext vc)
                           throws RenderException
Throws:
RenderException

supports

public abstract boolean supports(ViewContext vc)

setDefaultViewContext

public BComponent setDefaultViewContext(ViewContext idvc)
Set the default ViewContext.

Parameters:
idvc - the default ViewContext

getDefaultViewContext

public ViewContext getDefaultViewContext()
Get the default ViewContext.

Returns:
the default ViewContext

getRootComponent

public AbstractBComponent getRootComponent()

installRendererFactory

public static void installRendererFactory(RendererFactory rf,
                                          Class compCl,
                                          Class domCl)
This allows developers to install custom renderers for specific classes of components. This should generally be done at startup.

Parameters:
rf - the RendererFactory to be registered
compCl - the target document class
domCl - the target dom class

getRenderer

public Renderer getRenderer(View view)
                     throws NoSuitableRendererException
This method allows a component to get a reference to the appropriate renderer. If an exact match does not exist, it will automatically look for renderers registered on parent classes.

Throws:
NoSuitableRendererException

getRenderer

public Renderer getRenderer(Class domCl)
                     throws NoSuitableRendererException
Throws:
NoSuitableRendererException

findComponentMap

protected Map findComponentMap(Class cl)
Look for a factory that can render either this class or its parent class.


findRendererFactory

protected RendererFactory findRendererFactory(Class cl,
                                              Map domMap)
Look for a factory that can render either this class or its parent class.


initCycle

public void initCycle()
Initialize cycle. The component should use this to perform any initialization. Note that the component should be added to the overall component hierarchy before you invoke this method.


destroyCycle

public void destroyCycle()
Destroy cycle. The component should use this cycle to perform any special cleanup.


setParent

public BContainer setParent(BContainer iparent)
Set the parent container. Null indicates its the root.

Specified by:
setParent in interface BContainer
Parameters:
iparent - the parent container

getParent

public BContainer getParent()
Get the parent container. Returns null if it's the root.

Specified by:
getParent in interface BContainer
Returns:
the parent container

addChild

public BContainer addChild(BContainer child)
Add a child container to this one

Specified by:
addChild in interface BContainer
Parameters:
child - the child container to be added

getChild

public BContainer getChild(int index)
Get a child container at a given index

Specified by:
getChild in interface BContainer
Parameters:
index - the index of the child container

removeChild

public BContainer removeChild(BContainer child)
Remove a child container from this one

Specified by:
removeChild in interface BContainer
Parameters:
child - the a child container to be removed
Returns:
the child container that was removed

removeChild

public BContainer removeChild(int index)
Remove a child container for a given index

Specified by:
removeChild in interface BContainer
Parameters:
index - of the child container to be removed
Returns:
the child container that was removed

removeAll

public BContainer removeAll()
Remove all child containers from this one

Specified by:
removeAll in interface BContainer

hasChildren

public boolean hasChildren()
Determine whether this container has any children

Specified by:
hasChildren in interface BContainer
Returns:
true if the container has child containers

getChildren

public List getChildren()
Gets a list of all child BContainers. Note, this method returns a copy of the underlying child list

Specified by:
getChildren in interface BContainer
Returns:
a list of all child components.

isStepChild

public boolean isStepChild()
Determine whether this component is a step child

Returns:
true if this component is a step child

addStepChild

public BComponent addStepChild(BContainer child)
Add a step child; step children are automatically removed after each render.

Parameters:
child - the step child container to be added

addStepChild

public BComponent addStepChild(BContainer child,
                               boolean inheritParentAttrs)
Add a step child; step children are automatically removed after each render.

Parameters:
child - the step child container to be added
inheritParentAttrs - true if we want the step child to inherit the parent's settings for visibility/enabled

removeAllStepChildren

public BComponent removeAllStepChildren()
Remove all step children


addTempView

public BComponent addTempView(View tview)
Add a temporary view; temp views are automatically removed after each render

Parameters:
tview - the temp view to be added

hasViews

public boolean hasViews()
Determine whether the component has any views (either regular or temp)

Returns:
true if the component has any views

invalidate

public BContainer invalidate()
Invalidates the container and all parent containers above it. This essentially indicates the components need to be laid out (in the server side world, this is equivalent to rendering) again. After a component has been rendered, it will be marked valid again.

Specified by:
invalidate in interface BContainer

validate

public BContainer validate()
Invalidates the container and all child containers below it. Calling validate on the root of a tree effectively invalidates the entire tree, forcing the whole tree to be revalidated the next time it is rendered. This call is more expensive than an invalidate because it has to hit every node in the hierarchy.

Specified by:
validate in interface BContainer

putState

public void putState(Object key,
                     Object val)
set a property in this StateMap

Specified by:
putState in interface StateMap
Parameters:
key - the state key object
val - the state value object

getState

public Object getState(Object key)
get a property in this StateMap

Specified by:
getState in interface StateMap
Parameters:
key - the state key object
Returns:
the value for the given key

removeState

public Object removeState(Object key)
remove a property in this StateMap

Specified by:
removeState in interface StateMap
Parameters:
key - the key object
Returns:
the object which was removed

getStateKeys

public Set getStateKeys()
get a keyset for this StateMap (whether or not the set is backed by the data store depends on the implementation)

Specified by:
getStateKeys in interface StateMap
Returns:
a Set of keys for this StateMap

getStateStore

public Map getStateStore()
get a copy of the underlying Map

Specified by:
getStateStore in interface StateMap
Returns:
a copy of the underlying state Map

clearState

public void clearState()
clear all state information

Specified by:
clearState in interface StateMap

setAttr

public Attrs setAttr(Object attr,
                     Object val)
set an attribute for this particular component. When the component is rendered, component attributes will be shown as element attributes in the elements that back each of the views associated with this component. This means that if you set an attribute for the component, it will affect all views associated with the component.If you wish to set an attribute for a specific view alone, then you should get the view, find the node that backs it, and then set the attribute manually that way.

Specified by:
setAttr in interface Attrs
Parameters:
attr - the attribute name
val - the attribute value

getAttr

public Object getAttr(Object attr)
get an attribute associated with this particular component. Note that the attribute map that backs this method only keeps tracks of specific attributes you have added to the component. It does not look at attributes that are physically associated with the underlying elements that back each of the views associated with this component. What this means is that if the template that backs a view has some attribute "foo" and you try to see the value of that attribute using this method, you will not be able to find it unless you have actually associated an attribute named "foo" with the specific component.

Specified by:
getAttr in interface Attrs
Parameters:
attr - the attribute name
Returns:
the value for the given attribute (may be null)

getAttrMap

public Map getAttrMap()
return a reference to the underlying component attribute Map

Specified by:
getAttrMap in interface Attrs
Returns:
a copy of the underlying component attribute Map

toRef

public String toRef()
Get the component reference

Returns:
a String representation of the component reference

toString

public String toString()
Get a String representation of the component

Returns:
a String representation of the component

toString

public String toString(ViewContext vc)
Provide a String representation of the component. This will attempt to render the link as markup, which allows you to inline components along with text (a very useful feature!).

Returns:
a String representation of the component

printStackTrace

public void printStackTrace(int depth,
                            org.apache.log4j.Logger logger)

printStackTrace

public void printStackTrace(int depth,
                            OutputStream out)

printStackTrace

protected void printStackTrace(int depth,
                               org.apache.log4j.Logger logger,
                               OutputStream out)
For debugging purposes. Print the basic structure of the gateway.



Copyright © 2004 BarracudaMVC.org All Rights Reserved.