001/*-----------------------------------------------------------------------+ 002 | com.teamscale.checks 003 | | 004 $Id$ 005 | | 006 | Copyright (c) 2009-2015 CQSE GmbH | 007 +-----------------------------------------------------------------------*/ 008package eu.cqse.check.framework.core.xpath.functions; 009 010import java.util.List; 011 012import org.jaxen.FunctionCallException; 013 014import eu.cqse.check.framework.shallowparser.framework.ShallowEntity; 015 016/** 017 * Base class for functions that compare an attribute of a node to a given input 018 * string. 019 */ 020public abstract class AttributeEqualSelectionFunctionBase extends FunctionBase<String> { 021 022 /** {@inheritDoc} */ 023 @Override 024 protected String parseArguments(List<?> args) throws FunctionCallException { 025 if (args.size() != 1) { 026 throw new FunctionCallException(getArgumentSizeInvalidErrorMessage()); 027 } 028 return args.get(0).toString(); 029 } 030 031 /** {@inheritDoc} */ 032 @Override 033 protected boolean checkNode(ShallowEntity node, String arguments) { 034 return getComparisonAttributeValue(node).equals(arguments); 035 } 036 037 /** Returns the value of the attribute that is used for comparison. */ 038 protected abstract String getComparisonAttributeValue(ShallowEntity node); 039 040 /** 041 * Returns the error message that is displayed if the number of arguments 042 * does not match. 043 */ 044 protected abstract String getArgumentSizeInvalidErrorMessage(); 045}