View Javadoc

    1   /* DecideRule
    2   *
    3   * $Id: DecideRule.java 5010 2007-03-16 15:50:55Z Gojomo $
    4   *
    5   * Created on Mar 3, 2005
    6   *
    7   * Copyright (C) 2005 Internet Archive.
    8   *
    9   * This file is part of the Heritrix web crawler (crawler.archive.org).
    10  *
    11  * Heritrix is free software; you can redistribute it and/or modify
    12  * it under the terms of the GNU Lesser Public License as published by
    13  * the Free Software Foundation; either version 2.1 of the License, or
    14  * any later version.
    15  *
    16  * Heritrix is distributed in the hope that it will be useful,
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    19  * GNU Lesser Public License for more details.
    20  *
    21  * You should have received a copy of the GNU Lesser Public License
    22  * along with Heritrix; if not, write to the Free Software
    23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    24  */
    25  package org.archive.crawler.deciderules;
    26
    27  import org.archive.crawler.framework.CrawlController;
    28  import org.archive.crawler.settings.ModuleType;
    29
    30
    31  /***
    32   * Interface for rules which, given an object to evaluate,
    33   * respond with a decision: {@link DecideRule#ACCEPT},
    34   * {@link DecideRule#REJECT}, or
    35   * {@link DecideRule#PASS}.
    36   *
    37   * Rules return {@link #PASS} by default.
    38   *
    39   * @author gojomo
    40   * @see org.archive.crawler.deciderules.DecideRuleSequence
    41   */
    42  public class DecideRule extends ModuleType {
    43
    44      private static final long serialVersionUID = 3437522810581532520L;
    45      // enumeration of 'actions'
    46      public static final String ACCEPT = "ACCEPT".intern();
    47      public static final String REJECT = "REJECT".intern();
    48      public static final String PASS = "PASS".intern();
    49
    50      /***
    51       * Constructor.
    52       * @param name Name of this rule.
    53       */
    54      public DecideRule(String name) {
    55          super(name);
    56      }
    57
    58      /***
    59       * Make decision on passed <code>object</code>.
    60       * @param object Object to rule on.
    61       * @return {@link #ACCEPT}, {@link #REJECT}, or {@link #PASS}.
    62       */
    63      public Object decisionFor(Object object) {
    64          return PASS;
    65      }
    66
    67      /***
    68       * If this rule is "one-way" -- can only return a single
    69       * possible decision other than PASS -- return that
    70       * decision. Otherwise return null. Most rules will be
    71       * one-way.
    72       * @param object
    73       *
    74       * @return the one decision other than PASS this rule might
    75       * return, if there is only one
    76       */
    77      public Object singlePossibleNonPassDecision(Object object) {
    78          // by default, don't assume one-way
    79          return null;
    80      }
    81
    82      /***
    83       * Respond to a settings update, refreshing any internal settings-derived
    84       * state.
    85       *
    86       * This method gives implementors a chance to refresh internal state
    87       * after a settings change. Normally new settings are picked up w/o
    88       * the need of work on the part of settings' clients but some facilities
    89       * -- for example, Surt classes need to sort submissions into
    90       * common-prefix-coalesced collection of Surt prefixes, or,
    91       * settings changes that alter external file or seeds/directives
    92       * references -- need to be flagged so they can take
    93       * compensatory action.
    94       */
    95      public void kickUpdate() {
    96          // by default do nothing
    97      }
    98
    99      /***
    100      * Get the controller object.
    101      *
    102      * @return the controller object.
    103      */
    104     public CrawlController getController() {
    105         return getSettingsHandler().getOrder().getController();
    106     }
    107 }