01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.meta.impl;
10:
11: import com.completex.objective.components.persistency.MetaTable;
12: import com.completex.objective.components.persistency.PersistentObject;
13: import com.completex.objective.components.persistency.meta.MetaModelAssembly;
14:
15: import java.util.Collection;
16: import java.util.LinkedHashMap;
17:
18: /**
19: * @author Gennady Krizhevsky
20: */
21: public class BasicMetaModelAssemblyImpl implements MetaModelAssembly {
22:
23: private LinkedHashMap metaTableMap = new LinkedHashMap();
24:
25: public void registgerAll(MetaModelAssembly modelAssembly) {
26: if (modelAssembly != null) {
27: MetaTable[] metaTables = modelAssembly.getMetaTables();
28: for (int i = 0; i < metaTables.length; i++) {
29: registerObject(metaTables[i]);
30: }
31: }
32: }
33:
34: public void unregistgerAll(MetaModelAssembly modelAssembly) {
35: if (modelAssembly != null) {
36: MetaTable[] metaTables = modelAssembly.getMetaTables();
37: for (int i = 0; i < metaTables.length; i++) {
38: unregisterObject(metaTables[i]);
39: }
40: }
41: }
42:
43: public MetaTable registerObject(MetaTable metaTable) {
44: return (MetaTable) metaTableMap.put(metaTable.getTableName(),
45: metaTable);
46: }
47:
48: public MetaTable unregisterObject(MetaTable metaTable) {
49: return (MetaTable) metaTableMap
50: .remove(metaTable.getTableName());
51: }
52:
53: public MetaTable getMetaTable(String key) {
54: PersistentObject persistentObject = (PersistentObject) metaTableMap
55: .get(key);
56: return extractMetaTable(persistentObject);
57: }
58:
59: public MetaTable[] getMetaTables() {
60: Collection collection = metaTableMap.values();
61: return (MetaTable[]) collection
62: .toArray(new MetaTable[collection.size()]);
63: }
64:
65: private MetaTable extractMetaTable(PersistentObject persistentObject) {
66: if (persistentObject != null
67: && persistentObject.record() != null) {
68: return persistentObject.record().getTable();
69: } else {
70: return null;
71: }
72: }
73:
74: }
|