001/*-----------------------------------------------------------------------+
002 | com.teamscale.checks
003 |                                                                       |
004   $Id$            
005 |                                                                       |
006 | Copyright (c)  2009-2015 CQSE GmbH                                 |
007 +-----------------------------------------------------------------------*/
008package eu.cqse.check.base;
009
010import java.util.List;
011
012import eu.cqse.check.framework.core.CheckException;
013import eu.cqse.check.framework.core.CheckImplementationBase;
014import eu.cqse.check.framework.core.ECheckParameter;
015import eu.cqse.check.framework.shallowparser.framework.ShallowEntity;
016
017/**
018 * Base class for checks, that select a set of entities via xPath and inspect
019 * each of these. Subclasses must use the
020 * {@link ECheckParameter#ABSTRACT_SYNTAX_TREE} parameter.
021 */
022public abstract class EntityCheckBase extends CheckImplementationBase {
023
024        /** {@inheritDoc} */
025        @Override
026        public void execute() throws CheckException {
027                for (ShallowEntity entity : filterEntities(select(getXPathSelectionString()))) {
028                        processEntity(entity);
029                }
030        }
031
032        /**
033         * Filters the selected entities. The default implementation returns all
034         * selected entities.
035         */
036        protected List<ShallowEntity> filterEntities(List<ShallowEntity> entities) {
037                return entities;
038        }
039
040        /** Returns the xPath string for selecting entities. */
041        protected abstract String getXPathSelectionString();
042
043        /** Processes a single selected entity. */
044        protected abstract void processEntity(ShallowEntity entity) throws CheckException;
045
046}