001 /* 002 * Copyright 1999-2002,2004 The Apache Software Foundation. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.apache.commons.latka.validators; 018 019 import org.apache.commons.latka.Validator; 020 import org.apache.commons.latka.ValidationException; 021 022 import org.apache.commons.latka.http.Response; 023 024 import org.apache.log4j.Category; 025 026 /** 027 * @author Rodney Waldhoff 028 * @author dIon Gillard 029 * @version $Id: BaseValidator.java 155424 2005-02-26 13:09:29Z dirkv $ 030 */ 031 public abstract class BaseValidator implements Validator { 032 // ----------------------------------------------------- Instance Variables 033 034 /** log4j category for debug output */ 035 protected final Category _log = Category.getInstance(BaseValidator.class); 036 037 // ------------------------------------------------------- Abstract Methods 038 /** 039 * Validate a response 040 * 041 * @param response the response to validate 042 * @throws ValidationException 043 */ 044 public abstract void validate(Response response) throws ValidationException; 045 046 protected String _label = null; 047 048 // ----------------------------------------------------------- Constructors 049 050 public BaseValidator() { 051 this(null); 052 } 053 054 public BaseValidator(String label) { 055 _label = label; 056 } 057 058 // ---------------------------------------------------------------- Methods 059 060 public void setLabel(String label) { 061 _label = label; 062 } 063 064 public String getLabel() { 065 return _label; 066 } 067 068 protected void fail(String reason) throws ValidationException { 069 throw new ValidationException(getLabel(),reason); 070 } 071 072 }