org.eclipse.actf.model.locate
Class AbstractNodeLocator

java.lang.Object
  extended by org.eclipse.actf.model.locate.AbstractNodeLocator
All Implemented Interfaces:
INodeLocator
Direct Known Subclasses:
AccessibleNodeLocator, DomNodeLocator, MozillaDomNodeLocator

public abstract class AbstractNodeLocator
extends Object
implements INodeLocator

default base class for element locators. Clients should extend this class rather than attempting to implement INodeLocator directly.

Author:
Mike Squillace

Field Summary
static String CONTAINSSUBSTR_SEARCH
           
protected  String defaultIdPropName
           
static String EXACTMATCH_SEARCH
           
static String IGNORECASE_SEARCH
           
protected  IModel model
           
static String NODELOCATOR_VARIABLE
           
static String NODENAME_CHARCLASS
           
static String NODENAME_KEY
           
static String PREDICATEVAL_CHARCLASS
           
protected  Map propertiesMap
           
static String REGEXP_SEARCH
           
protected static org.apache.commons.jxpath.ri.JXPathContextReferenceImpl ROOT_JXPATH_CONTEXT
           
static Pattern SEGMENT_PATTERN
           
 
Constructor Summary
AbstractNodeLocator(String defaultIdProperty, String modelName, org.apache.commons.jxpath.ri.model.NodePointerFactory factory)
          create a new node locator
 
Method Summary
protected  void addNodePointerFactory(org.apache.commons.jxpath.ri.model.NodePointerFactory factory)
           
 Properties describe(Object element)
          identify or distinguish the given element in the hierarchy.
static String descriptionAsString(Properties properties)
          utility method for converting the set of properties returned by describe to a string.
 Object find(String path, Object startNode)
          finds an object in a model given the specified path.
 Object[] findAll(String path, Object startNode)
          finds all objects in a model that match the specified path.
protected  String getDefaultIdPropertyName()
          return the property used by default for discovering the id string of a component.
protected  IModel getModel()
           
 String getNodeId(org.apache.commons.jxpath.ExpressionContext context)
          used by the JXPath evaluator to find the node ID of the context node by querying the underlying model.
protected  Object invokeGetter(Object element, String propName)
          invoke the getter with the specified method name on the given element.
 String locate(Object element, Object root)
          locate a component within a model from the given root.
 boolean matches(org.apache.commons.jxpath.ExpressionContext context, String property, String input, String searchType)
          used by the JXPath evaluator to perform various comparisons during a find operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NODENAME_KEY

public static final String NODENAME_KEY
See Also:
Constant Field Values

NODELOCATOR_VARIABLE

public static final String NODELOCATOR_VARIABLE
See Also:
Constant Field Values

EXACTMATCH_SEARCH

public static final String EXACTMATCH_SEARCH
See Also:
Constant Field Values

IGNORECASE_SEARCH

public static final String IGNORECASE_SEARCH
See Also:
Constant Field Values

CONTAINSSUBSTR_SEARCH

public static final String CONTAINSSUBSTR_SEARCH
See Also:
Constant Field Values

REGEXP_SEARCH

public static final String REGEXP_SEARCH
See Also:
Constant Field Values

NODENAME_CHARCLASS

public static final String NODENAME_CHARCLASS
See Also:
Constant Field Values

PREDICATEVAL_CHARCLASS

public static final String PREDICATEVAL_CHARCLASS
See Also:
Constant Field Values

SEGMENT_PATTERN

public static final Pattern SEGMENT_PATTERN

ROOT_JXPATH_CONTEXT

protected static final org.apache.commons.jxpath.ri.JXPathContextReferenceImpl ROOT_JXPATH_CONTEXT

defaultIdPropName

protected String defaultIdPropName

model

protected IModel model

propertiesMap

protected Map propertiesMap
Constructor Detail

AbstractNodeLocator

public AbstractNodeLocator(String defaultIdProperty,
                           String modelName,
                           org.apache.commons.jxpath.ri.model.NodePointerFactory factory)
create a new node locator

Parameters:
defaultIdProperty - - name of property to serve as default identification of node
modelName - - name of model for which this locator is being registered
factory -
Method Detail

getModel

protected IModel getModel()

getNodeId

public String getNodeId(org.apache.commons.jxpath.ExpressionContext context)
used by the JXPath evaluator to find the node ID of the context node by querying the underlying model. Every context includes the variable $<NODELOCATOR_VARIABLE>, which can be used to invoke this method.

Parameters:
context - supplied by the JXPath runtime
Returns:
node id as determined by underlying model or an empty string if no id is available

matches

public boolean matches(org.apache.commons.jxpath.ExpressionContext context,
                       String property,
                       String input,
                       String searchType)
used by the JXPath evaluator to perform various comparisons during a find operation. Every context includes the variable $<NODELOCATOR_VARIABLE>, which can be used to invoke this method.

Parameters:
context - supplied by the JXPath runtime
property - property whose value is to be tested
input - against which property value is to be tested
searchType - one of EXACTMATCH_SEARCH, IGNORECASE_SEARCH, CONTAINSSUBSTR_SEARCH, REGEXP_SEARCH
Returns:
true if the given input matches the value of the property for the given node according to the search type, false otherwise

describe

public Properties describe(Object element)
identify or distinguish the given element in the hierarchy. This default implementation first uses the model-specific locator properties. These properties are defined in the IConfiguration.MODEL_LOCATORIDS_POOL symbol pool of a given model type. The returned Properties object contains the names of these properties as keys and their values.

If no getter was defined for the type of the given element, this implementation then uses the property name returned by getDefaultIdPropertyName.

Note: If the model associated with this locator is an instance of IRenderableModel, this locator will invoke this getter on the UI thread.

Specified by:
describe in interface INodeLocator
Parameters:
element - element to be identified
Returns:
set of properties describing or identifying element
See Also:
IRenderableModel

descriptionAsString

public static String descriptionAsString(Properties properties)
utility method for converting the set of properties returned by describe to a string. The returned string will have the form:

key1=val1,key2=val2,...

Parameters:
properties - as returned by describe
Returns:
string of above form representing set of properties of description
See Also:
describe(Object)

invokeGetter

protected Object invokeGetter(Object element,
                              String propName)
invoke the getter with the specified method name on the given element. If this locator defines a model and it is an instance of IRenderableModel, the getter will be invoked on the UI thread.

Parameters:
element -
methName -
Returns:
result of getter invocation

addNodePointerFactory

protected void addNodePointerFactory(org.apache.commons.jxpath.ri.model.NodePointerFactory factory)

getDefaultIdPropertyName

protected String getDefaultIdPropertyName()
return the property used by default for discovering the id string of a component. For this abstract implementation, the default property name is 'id'.

Returns:
default property name used to fetch id string of a component

locate

public String locate(Object element,
                     Object root)
locate a component within a model from the given root. The returned string represents an XPath location path that uniquely determines the component's location within the graph starting with the given root. This method can be used in conjunction with describey to provide a richer description of the component.

Specified by:
locate in interface INodeLocator
Parameters:
element - element within a graph to be located
root - - root from which element is to be located or null if element is to be found from a start node in the graph
Returns:
string that uniquely locates element within the model
See Also:
XPath specification

find

public Object find(String path,
                   Object startNode)
finds an object in a model given the specified path. The path must be a valid XPath expression according to the XPath 1.0 specification. A path that is returned by locate is just such a path.

If a startNode is specified, the path is assumed to have that startNode as its context node. If the startNode is null, the model's start nodes will be used as supplying potential context nodes for the path.

The parameters for searching for a node can be defined in the Configuration.MODEL_ID symbol pool using the public symbolic constants of this interface.

Specified by:
find in interface INodeLocator
Parameters:
path - - path to desired node in the model
startNode - - context for the path (may be null)
Returns:
desired node or null if no object in the model matches the given path
See Also:
XPath 1.0 Specification

findAll

public Object[] findAll(String path,
                        Object startNode)
finds all objects in a model that match the specified path. The path must be a valid XPath expression according to the XPath 1.0 specification. A path that is returned by locate is just such a path.

If a startNode is specified, the path is assumed to have that startNode as its context node. If the startNode is null, the model's start nodes will be used as supplying potential context nodes for the path.

The parameters for searching for a node can be defined in the Configuration.MODEL_ID symbol pool using the public symbolic constants of this interface.

Specified by:
findAll in interface INodeLocator
Parameters:
path - - path to desired nodes in the model
startNode - - context for the path (may be null)
Returns:
desired nodes or an empty array if no objects in the model match the given path
See Also:
XPath 1.0 Specification