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.mapper.impl;
10:
11: import com.completex.objective.components.persistency.mapper.MapperRegistry;
12:
13: import java.util.HashMap;
14:
15: /**
16: * @author Gennady Krizhevsky
17: */
18: public class MapperRegistryImpl implements MapperRegistry {
19:
20: private HashMap directMap = new HashMap(); /* HashMap<Class poClass, Class beanClass> */
21: private HashMap inversedMap = new HashMap(); /* HashMap<Class beanClass, Class poClass> */
22:
23: public void map(Class poClass, Class beanClass) {
24: if (directMap.containsKey(beanClass)) {
25: throw new IllegalArgumentException("Bean class "
26: + beanClass
27: + " is already mapped to PersistentObject class"
28: + poClass);
29: }
30: if (inversedMap.containsKey(poClass)) {
31: throw new IllegalArgumentException(
32: "PersistentObject class " + poClass
33: + " is already mapped to Bean class"
34: + beanClass);
35: }
36:
37: remap(poClass, beanClass);
38: }
39:
40: protected void remap(Class poClass, Class beanClass) {
41: directMap.put(poClass, beanClass);
42: inversedMap.put(beanClass, poClass);
43: }
44:
45: public boolean mappingExists(Class poClass, Class beanClass) {
46: if (beanClass != null) {
47: return getDirectBeanClass(beanClass) != null;
48: }
49:
50: if (poClass != null) {
51: return getInversetBeanClass(poClass) != null;
52: }
53:
54: return false;
55: }
56:
57: public Class getDirectBeanClass(Class poClass) {
58: return (Class) directMap.get(poClass);
59: }
60:
61: public Class getInversetBeanClass(Class poClass) {
62: return (Class) inversedMap.get(poClass);
63: }
64:
65: }
|