net.esper.view
Class ViewServiceHelper

java.lang.Object
  extended by net.esper.view.ViewServiceHelper

public class ViewServiceHelper
extends Object

Utility methods to deal with chains of views, and for merge/group-by views.


Constructor Summary
ViewServiceHelper()
           
 
Method Summary
protected static void addMergeViews(List<ViewSpec> specifications)
          Add merge views for any views in the chain requiring a merge (group view).
protected static List<View> instantiateChain(Viewable parentViewable, List<ViewFactory> viewFactories, StatementContext context)
          Instantiate a chain of views.
static List<ViewFactory> instantiateFactories(int streamNum, List<ViewSpec> viewSpecList, StatementContext statementContext)
          Given a list of view specifications obtained from by parsing this method instantiates a list of view factories.
protected static Pair<Viewable,List<View>> matchExistingViews(Viewable rootViewable, List<ViewFactory> viewFactories)
          Match the views under the stream to the list of view specications passed in.
protected static List<View> removeChainLeafView(Viewable parentViewable, Viewable viewToRemove)
          Removes a view from a parent view returning the orphaned parent views in a list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViewServiceHelper

public ViewServiceHelper()
Method Detail

addMergeViews

protected static void addMergeViews(List<ViewSpec> specifications)
Add merge views for any views in the chain requiring a merge (group view). Appends to the list of view specifications passed in one ore more new view specifications that represent merge views. Merge views have the same parameter list as the (group) view they merge data for.

Parameters:
specifications - is a list of view definitions defining the chain of views.

instantiateChain

protected static List<View> instantiateChain(Viewable parentViewable,
                                             List<ViewFactory> viewFactories,
                                             StatementContext context)
Instantiate a chain of views.

Parameters:
parentViewable - - parent view to add the chain to
viewFactories - - is the view factories to use to make each view, or reuse and existing view
context - - dependent services
Returns:
chain of views instantiated

removeChainLeafView

protected static List<View> removeChainLeafView(Viewable parentViewable,
                                                Viewable viewToRemove)
Removes a view from a parent view returning the orphaned parent views in a list.

Parameters:
parentViewable - - parent to remove view from
viewToRemove - - view to remove
Returns:
chain of orphaned views

matchExistingViews

protected static Pair<Viewable,List<View>> matchExistingViews(Viewable rootViewable,
                                                              List<ViewFactory> viewFactories)
Match the views under the stream to the list of view specications passed in. The method changes the view specifications list passed in and removes those specifications for which matcing views have been found. If none of the views under the stream matches the first view specification passed in, the method returns the stream itself and leaves the view specification list unchanged. If one view under the stream matches, the view's specification is removed from the list. The method will then attempt to determine if any child views of that view also match specifications.

Parameters:
rootViewable - is the top rootViewable event stream to which all views are attached as child views This parameter is changed by this method, ie. specifications are removed if they match existing views.
viewFactories - is the view specifications for making views
Returns:
a pair of (A) the stream if no views matched, or the last child view that matched (B) the full list of parent views

instantiateFactories

public static List<ViewFactory> instantiateFactories(int streamNum,
                                                     List<ViewSpec> viewSpecList,
                                                     StatementContext statementContext)
                                              throws ViewProcessingException
Given a list of view specifications obtained from by parsing this method instantiates a list of view factories. The view factories are not yet aware of each other after leaving this method (so not yet chained logically). They are simply instantiated and assigned view parameters.

Parameters:
streamNum - is the stream number
viewSpecList - is the view definition
statementContext - is statement service context and statement info
Returns:
list of view factories
Throws:
ViewProcessingException - if the factory cannot be creates such as for invalid view spec