KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > chain > impl > CatalogFactoryBase


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.chain.impl;
18
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import org.apache.commons.chain.Catalog;
23 import org.apache.commons.chain.CatalogFactory;
24
25 /**
26  * <p>A simple implementation of {@link CatalogFactory}.</p>
27  *
28  * @author Sean Schofield
29  * @version $Revision: 1.4 $ $Date: 2004/11/30 05:52:23 $
30  */

31
32 public class CatalogFactoryBase extends CatalogFactory {
33
34
35     // ----------------------------------------------------------- Constructors
36

37
38     /**
39      * <p>Construct an empty instance of {@link CatalogFactoryBase}. This
40      * constructor is intended solely for use by {@link CatalogFactory}.</p>
41      */

42     public CatalogFactoryBase() { }
43
44
45     // ----------------------------------------------------- Instance Variables
46

47
48     /**
49      * <p>The default {@link Catalog} for this {@link CatalogFactory).</p>
50      */

51     private Catalog catalog = null;
52
53
54     /**
55      * <p>Map of named {@link Catalog}s, keyed by catalog name.</p>
56      */

57     private Map JavaDoc catalogs = new HashMap JavaDoc();
58
59
60     // --------------------------------------------------------- Public Methods
61

62
63     // Documented in CatalogFactory interface
64
public Catalog getCatalog() {
65
66         return catalog;
67
68     }
69
70
71     // Documented in CatalogFactory interface
72
public void setCatalog(Catalog catalog) {
73
74         this.catalog = catalog;
75
76     }
77
78
79     // Documented in CatalogFactory interface
80
public Catalog getCatalog(String JavaDoc name) {
81
82         synchronized (catalogs) {
83             return (Catalog) catalogs.get(name);
84         }
85
86     }
87
88
89     // Documented in CatalogFactory interface
90
public void addCatalog(String JavaDoc name, Catalog catalog) {
91
92         synchronized (catalogs) {
93             catalogs.put(name, catalog);
94         }
95
96     }
97
98
99     // Documented in CatalogFactory interface
100
public Iterator JavaDoc getNames() {
101
102         synchronized (catalogs) {
103             return catalogs.keySet().iterator();
104         }
105
106     }
107
108
109 }
110
Popular Tags