net.esper.view
Class ViewSupport

java.lang.Object
  extended by net.esper.view.ViewSupport
All Implemented Interfaces:
java.lang.Iterable<EventBean>, EventCollection, View, Viewable
Direct Known Subclasses:
AddPropertyValueView, BaseBivariateStatisticsView, BufferView, ExternallyTimedWindowView, FilterExprView, GroupByView, InternalRouteView, LastElementView, LengthWindowView, MergeView, MultiDimStatsView, OutputProcessView, SizeView, SortWindowView, TimeBatchView, TimeWindowView, UniqueByPropertyView, UnivariateStatisticsView, UpdateDispatchView, WeightedAverageView

public abstract class ViewSupport
extends java.lang.Object
implements View

A helper class for View implementations that provides generic implementation for some of the methods. Methods that contain the actual logic of the view are not implemented in this class. A common implementation normally does not need to override any of the methods implemented here, their implementation is generic and should suffice. The class provides a convenience method for updateing it's children data updateChildren(Object[], Object[]). This method should be called from within the View.update(Object[], Object[]) methods in the subclasses.


Field Summary
protected  Viewable parent
          Parent viewable to this view - directly accessible by subclasses.
 
Constructor Summary
protected ViewSupport()
          Constructor.
 
Method Summary
 View addView(View view)
          Add a view to the viewable object.
static void dumpChildViews(java.lang.String prefix, Viewable parentViewable)
          Convenience method for logging the child views of a Viewable.
static void dumpUpdateParams(java.lang.String prefix, java.lang.Object[] newData, java.lang.Object[] oldData)
          Convenience method for logging the parameters passed to the update method.
static java.util.List<View> findDescendent(Viewable parentView, Viewable descendentView)
          Find the descendent view in the view tree under the parent view returning the list of view nodes between the parent view and the descendent view.
 Viewable getParent()
          Returns the View's parent Viewable.
 java.util.List<View> getViews()
          Returns all added views.
 boolean hasViews()
          Test is there are any views to the Viewable.
 boolean removeView(View view)
          Remove a view.
 void setParent(Viewable parent)
          Called when the View is added to a Viewable object.
static View shallowCopyView(View view)
          Copies the view by copying the bean properties of the view but does not copy the views children, does not copy or set the property for the parent view.
 void updateChildren(EventBean[] newData, EventBean[] oldData)
          Updates all the children with new data.
protected static void updateChildren(java.util.List<View> childViews, EventBean[] newData, EventBean[] oldData)
          Updates all the children with new data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.esper.view.View
attachesTo, update
 

Field Detail

parent

protected Viewable parent
Parent viewable to this view - directly accessible by subclasses.

Constructor Detail

ViewSupport

protected ViewSupport()
Constructor.

Method Detail

getParent

public final Viewable getParent()
Description copied from interface: View
Returns the View's parent Viewable.

Specified by:
getParent in interface View
Returns:
viewable

setParent

public void setParent(Viewable parent)
Description copied from interface: View
Called when the View is added to a Viewable object.

Specified by:
setParent in interface View
Parameters:
parent - is the parent that this view is a child of

addView

public final View addView(View view)
Description copied from interface: Viewable
Add a view to the viewable object.

Specified by:
addView in interface Viewable
Parameters:
view - to add
Returns:
view to add

removeView

public final boolean removeView(View view)
Description copied from interface: Viewable
Remove a view.

Specified by:
removeView in interface Viewable
Parameters:
view - to remove
Returns:
true to indicate that the view to be removed existed within this view, false if the view to remove could not be found

getViews

public final java.util.List<View> getViews()
Description copied from interface: Viewable
Returns all added views.

Specified by:
getViews in interface Viewable
Returns:
list of added views

hasViews

public final boolean hasViews()
Description copied from interface: Viewable
Test is there are any views to the Viewable.

Specified by:
hasViews in interface Viewable
Returns:
true indicating there are child views, false indicating there are no child views

updateChildren

public final void updateChildren(EventBean[] newData,
                                 EventBean[] oldData)
Updates all the children with new data. Views may want to use the hasViews method on the Viewable interface to determine if there are any child views attached at all, and save the work of constructing the arrays and making the call to updateChildren() in case there aren't any children attached.

Parameters:
newData - is the array of new event data
oldData - is the array of old event data

updateChildren

protected static void updateChildren(java.util.List<View> childViews,
                                     EventBean[] newData,
                                     EventBean[] oldData)
Updates all the children with new data. Static convenience method that accepts the list of child views as a parameter.

Parameters:
childViews - is the list of child views to send the data to
newData - is the array of new event data
oldData - is the array of old event data

shallowCopyView

public static View shallowCopyView(View view)
Copies the view by copying the bean properties of the view but does not copy the views children, does not copy or set the property for the parent view.

Parameters:
view - to be copied
Returns:
copy of the view, populated via Java bean property getter and setter methods

dumpUpdateParams

public static void dumpUpdateParams(java.lang.String prefix,
                                    java.lang.Object[] newData,
                                    java.lang.Object[] oldData)
Convenience method for logging the parameters passed to the update method. Only logs if debug is enabled.

Parameters:
prefix - is a prefix text to output for each line
newData - is the new data in an update call
oldData - is the old data in an update call

dumpChildViews

public static void dumpChildViews(java.lang.String prefix,
                                  Viewable parentViewable)
Convenience method for logging the child views of a Viewable. Only logs if debug is enabled. This is a recursive method.

Parameters:
prefix - is a text to print for each view printed
parentViewable - is the parent for which the child views are displayed.

findDescendent

public static java.util.List<View> findDescendent(Viewable parentView,
                                                  Viewable descendentView)
Find the descendent view in the view tree under the parent view returning the list of view nodes between the parent view and the descendent view. Returns null if the descendent view is not found. Returns an empty list if the descendent view is a child view of the parent view.

Parameters:
parentView - is the view to start searching under
descendentView - is the view to find
Returns:
list of Viewable nodes between parent and descendent view.