FileDocCategorySizeDatePackage
XPathPredicate.javaAPI DocExample2199Wed May 18 09:39:00 BST 2005com.discursive.jccook.collections.predicate

XPathPredicate

public class XPathPredicate extends Object implements org.apache.commons.collections.Predicate

Fields Summary
private String
path
private Map
variables
Constructors Summary
public XPathPredicate(String path)


	   
		this.path = path;
	
public XPathPredicate(String path, Map variables)

		this.path = path;
		this.variables.putAll( variables );
	
Methods Summary
public booleanevaluate(java.lang.Object object)

		boolean matches = false;
		JXPathContext context = JXPathContext.newContext(object);
		if( variables != null ) {
			populateVariables( context );
		}
		try {
			Object value = context.getValue( path );
			if( value != null ) {
				matches = true;
			}
		} catch( JXPathException e ) {
			// If this happens there is no match
		}
		return matches;
	
private voidpopulateVariables(org.apache.commons.jxpath.JXPathContext context)

		Set keys = variables.keySet();
		Iterator keyIter = keys.iterator();
		while( keyIter.hasNext() ) {
			String key = (String) keyIter.next();
			context.getVariables().declareVariable( key, variables.get( key ) );
		}