KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > mlw > vlh > Configuration


1 /**
2  * Copyright (c) 2003 held jointly by the individual authors.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; with out even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * > http://www.gnu.org/copyleft/lesser.html
19  * > http://www.opensource.org/licenses/lgpl-license.php
20  */

21 package net.mlw.vlh;
22
23 import java.util.Map JavaDoc;
24
25 /**
26  * Holds the configuration for the value list handler.
27  *
28  * @author Matthew L. Wilson
29  * @version $Revision: 1.4 $ $Date: 2005/11/23 14:18:53 $
30  */

31 public class Configuration
32 {
33    /** Commons logger. */
34    // private static final Log LOGGER = LogFactory.getLog(Configuration.class);
35

36    /** Holds all the adapters. The name of the adapter is the key. */
37    private Map JavaDoc adapters = null;
38
39    /** The default adapter to pass back if none are found. **/
40    private ValueListAdapter defaultAdapter = null;
41
42    /** Gets the adapter with the given name. Returns the defaultAdapter
43     * if the given name could not be found.
44     *
45     * @param name The name of the adapter.
46     * @return The adapter with the given name, or the default.
47     */

48    public ValueListAdapter getAdapter(String JavaDoc name)
49    {
50       ValueListAdapter adapter = (ValueListAdapter) adapters.get(name);
51
52       if (adapter == null)
53       {
54          adapter = getDefaultAdapter();
55       }
56
57       if (adapter == null)
58       {
59          throw new NullPointerException JavaDoc("Adapter named: " + name + ", not found, and no default was declared.");
60       }
61       return adapter;
62    }
63
64    /** Sets the Map of adapters.
65     * @param adapters
66     * The adapters to set.
67     */

68    public void setAdapters(Map JavaDoc adapters)
69    {
70       this.adapters = adapters;
71    }
72
73    /** Gets the default adapter to pass back if none are found.
74     * @return Returns the defaultAdapter.
75     */

76    public ValueListAdapter getDefaultAdapter()
77    {
78       return defaultAdapter;
79    }
80
81    /** Sets the default adapter to pass back if none are found.
82     * @param defaultAdapter
83     * The defaultAdapter to set.
84     */

85    public void setDefaultAdapter(ValueListAdapter defaultAdapter)
86    {
87       this.defaultAdapter = defaultAdapter;
88    }
89 }
Popular Tags