01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.metadata;
19:
20: import java.util.HashMap;
21: import java.util.Map;
22: import java.util.Set;
23:
24: import org.apache.avalon.framework.logger.AbstractLogEnabled;
25: import org.apache.avalon.framework.thread.ThreadSafe;
26:
27: /**
28: * Meta data registry implementation.
29: */
30: public class MetaDataRegistryImpl extends AbstractLogEnabled implements
31: MetaDataRegistry, ThreadSafe {
32:
33: public ElementSet getElementSet(String namespaceUri)
34: throws MetaDataException {
35: if (!isRegistered(namespaceUri)) {
36: throw new MetaDataException("The namespace URI ["
37: + namespaceUri + "] is not registered.");
38: }
39: return (ElementSet) this .namespace2set.get(namespaceUri);
40: }
41:
42: public boolean isRegistered(String namespaceUri)
43: throws MetaDataException {
44: return this .namespace2set.containsKey(namespaceUri);
45: }
46:
47: private Map namespace2set = new HashMap();
48:
49: public void register(String namespaceUri, ElementSet elementSet)
50: throws MetaDataException {
51: if (this .namespace2set.containsKey(namespaceUri)) {
52: throw new MetaDataException("The namespace ["
53: + namespaceUri + "] is already registered.");
54: }
55: this .namespace2set.put(namespaceUri, elementSet);
56: }
57:
58: public String[] getNamespaceUris() throws MetaDataException {
59: Set keys = this .namespace2set.keySet();
60: return (String[]) keys.toArray(new String[keys.size()]);
61: }
62:
63: }
|