KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > DefaultConfiguration


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;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Set JavaDoc;
25
26 import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
27 import com.puppycrawl.tools.checkstyle.api.Configuration;
28
29 /**
30  * Default implementation of the Configuration interface.
31  * @author lkuehne
32  */

33 public final class DefaultConfiguration implements Configuration
34 {
35     /** The name of this configuration */
36     private final String JavaDoc mName;
37
38     /** the list of child Configurations */
39     private final ArrayList JavaDoc mChildren = new ArrayList JavaDoc();
40
41     /** the map from attribute names to attribute values */
42     private final Map JavaDoc mAttributeMap = new HashMap JavaDoc();
43
44     /**
45      * Instantiates a DefaultConfiguration.
46      * @param aName the name for this DefaultConfiguration.
47      */

48     public DefaultConfiguration(String JavaDoc aName)
49     {
50         mName = aName;
51     }
52
53     /** {@inheritDoc} */
54     public String JavaDoc[] getAttributeNames()
55     {
56         final Set JavaDoc keySet = mAttributeMap.keySet();
57         return (String JavaDoc[]) keySet.toArray(new String JavaDoc[keySet.size()]);
58     }
59
60     /** {@inheritDoc} */
61     public String JavaDoc getAttribute(String JavaDoc aName) throws CheckstyleException
62     {
63         if (!mAttributeMap.containsKey(aName)) {
64             // TODO: i18n
65
throw new CheckstyleException(
66                     "missing key '" + aName + "' in " + getName());
67         }
68         return (String JavaDoc) mAttributeMap.get(aName);
69     }
70
71     /** {@inheritDoc} */
72     public Configuration[] getChildren()
73     {
74         return (Configuration[]) mChildren.toArray(
75             new Configuration[mChildren.size()]);
76     }
77
78     /** {@inheritDoc} */
79     public String JavaDoc getName()
80     {
81         return mName;
82     }
83
84     /**
85      * Makes a configuration a child of this configuration.
86      * @param aConfiguration the child configuration.
87      */

88     public void addChild(Configuration aConfiguration)
89     {
90         mChildren.add(aConfiguration);
91     }
92
93     /**
94      * Removes a child of this configuration.
95      * @param aConfiguration the child configuration to remove.
96      */

97     public void removeChild(final Configuration aConfiguration)
98     {
99         mChildren.remove(aConfiguration);
100     }
101
102     /**
103      * Adds an attribute to this configuration.
104      * @param aName the name of the attribute.
105      * @param aValue the value of the attribute.
106      */

107     public void addAttribute(String JavaDoc aName, String JavaDoc aValue)
108     {
109         mAttributeMap.put(aName, aValue);
110     }
111
112 }
113
Popular Tags