KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > AbstractOptionCheck


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
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
30     extends Check
31 {
32     /** the policy to enforce */
33     private AbstractOption mOption;
34
35     /**
36      * Creates a new <code>AbstractOptionCheck</code> instance.
37      * @param aDefault the default option.
38      */

39     public AbstractOptionCheck(AbstractOption aDefault)
40     {
41         mOption = aDefault;
42     }
43
44     /**
45      * Set the option to enforce.
46      * @param aOption string to decode option from
47      * @throws ConversionException if unable to decode
48      */

49     public void setOption(String JavaDoc aOption)
50         throws ConversionException
51     {
52         mOption = mOption.decode(aOption);
53         if (mOption == null) {
54             throw new ConversionException("unable to parse " + aOption);
55         }
56     }
57
58     /**
59      * @return the <code>AbstractOption</code> set
60      */

61     public AbstractOption getAbstractOption()
62     {
63         // WARNING!! Do not rename this method to getOption(). It breaks
64
// BeanUtils, which will silently not call setOption. Very annoying!
65
return mOption;
66     }
67 }
68
Popular Tags