01: ////////////////////////////////////////////////////////////////////////////////
02: // checkstyle: Checks Java source code for adherence to a set of rules.
03: // Copyright (C) 2001-2007 Oliver Burn
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU Lesser General Public
07: // License as published by the Free Software Foundation; either
08: // version 2.1 of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: // Lesser General Public License for more details.
14: //
15: // You should have received a copy of the GNU Lesser General Public
16: // License along with this library; if not, write to the Free Software
17: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: ////////////////////////////////////////////////////////////////////////////////
19: package com.puppycrawl.tools.checkstyle.checks;
20:
21: import org.apache.commons.beanutils.ConversionException;
22:
23: import com.puppycrawl.tools.checkstyle.api.Check;
24:
25: /**
26: * Abstract class for checks with options.
27: * @author Rick Giles
28: */
29: public abstract class AbstractOptionCheck extends Check {
30: /** the policy to enforce */
31: private AbstractOption mOption;
32:
33: /**
34: * Creates a new <code>AbstractOptionCheck</code> instance.
35: * @param aDefault the default option.
36: */
37: public AbstractOptionCheck(AbstractOption aDefault) {
38: mOption = aDefault;
39: }
40:
41: /**
42: * Set the option to enforce.
43: * @param aOption string to decode option from
44: * @throws ConversionException if unable to decode
45: */
46: public void setOption(String aOption) throws ConversionException {
47: mOption = mOption.decode(aOption);
48: if (mOption == null) {
49: throw new ConversionException("unable to parse " + aOption);
50: }
51: }
52:
53: /**
54: * @return the <code>AbstractOption</code> set
55: */
56: public AbstractOption getAbstractOption() {
57: // WARNING!! Do not rename this method to getOption(). It breaks
58: // BeanUtils, which will silently not call setOption. Very annoying!
59: return mOption;
60: }
61: }
|