01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.compass.core.metadata.impl;
18:
19: import java.util.HashMap;
20: import java.util.Iterator;
21:
22: import org.compass.core.metadata.Alias;
23: import org.compass.core.metadata.CompassMetaData;
24: import org.compass.core.metadata.MetaData;
25: import org.compass.core.metadata.MetaDataGroup;
26:
27: /**
28: *
29: * @author kimchy
30: *
31: */
32:
33: public class DefaultCompassMetaData implements CompassMetaData {
34:
35: private HashMap aliasMap = new HashMap();
36:
37: private HashMap metaDataMap = new HashMap();
38:
39: private HashMap groupMap = new HashMap();
40:
41: public Alias getAlias(String name) {
42: return (Alias) aliasMap.get(name);
43: }
44:
45: public MetaData getMetaData(String name) {
46: return (MetaData) metaDataMap.get(name);
47: }
48:
49: public void addGroup(MetaDataGroup group) {
50: groupMap.put(group.getId(), group);
51: for (Iterator it = ((DefaultMetaDataGroup) group)
52: .aliasIterator(); it.hasNext();) {
53: Alias alias = (Alias) it.next();
54: aliasMap.put(alias.getId(), alias);
55: }
56:
57: for (Iterator it = ((DefaultMetaDataGroup) group)
58: .metaDataIterator(); it.hasNext();) {
59: MetaData metaData = (MetaData) it.next();
60: metaDataMap.put(metaData.getId(), metaData);
61: }
62: }
63:
64: public MetaDataGroup getGroup(String name) {
65: return (MetaDataGroup) groupMap.get(name);
66: }
67:
68: public Iterator groupsIterator() {
69: return groupMap.values().iterator();
70: }
71:
72: public CompassMetaData copy() {
73: DefaultCompassMetaData copyMetaData = new DefaultCompassMetaData();
74: for (Iterator it = groupMap.values().iterator(); it.hasNext();) {
75: DefaultMetaDataGroup group = (DefaultMetaDataGroup) it
76: .next();
77: copyMetaData.addGroup(group.copy());
78: }
79: return copyMetaData;
80: }
81: }
|