01: package com.bm.introspectors.relations;
02:
03: import org.apache.log4j.Logger;
04:
05: import com.bm.introspectors.EntityBeanIntrospector;
06: import com.bm.introspectors.Property;
07:
08: /**
09: * Helper class to find properties wich are inwolved in releations.
10: *
11: * @author Daniel Wiese
12: *
13: */
14: public final class RelationPropertyResolver {
15:
16: private static final Logger log = Logger
17: .getLogger(RelationPropertyResolver.class);
18:
19: private RelationPropertyResolver() {
20: // empty to avoid contructions
21: }
22:
23: /**
24: * Search the attribute representing the releation on the !other side!
25: *
26: * @param declaredInClass -
27: * the other side class holding the mappedBy attribute
28: * @param mappedBy -
29: * the attribute name mapping the property (on the other side)
30: * @return - the property (if found)
31: */
32: public static Property findAttributeForRelationAtOtherSide(
33: Class<Object> declaredInClass, String mappedBy) {
34: // now look for the other if exist at the global store
35: Property relProp = GlobalRelationStore.getStore().getProperty(
36: declaredInClass, mappedBy);
37: if (relProp == null) {
38: // use a new instrospector to put the relation to the global
39: // store
40: final EntityBeanIntrospector<Object> tmpIn = new EntityBeanIntrospector<Object>(
41: declaredInClass);
42: log.debug("Dependend class: " + tmpIn.getTableName());
43: // now it should be in theglobal store
44:
45: relProp = GlobalRelationStore.getStore().getProperty(
46: declaredInClass, mappedBy);
47: if (relProp == null) {
48: log
49: .debug("The relation is unidirectional. Cant´t resolve releations for property ("
50: + mappedBy
51: + ") decared in class ("
52: + declaredInClass.getName() + ")");
53: }
54: }
55: return relProp;
56: }
57:
58: /**
59: * Search the attribute representing the relation on the !other side!
60: *
61: * @param aktProperty -
62: * the current property representing this side
63: * @return - the property (if found)
64: */
65: @SuppressWarnings("unchecked")
66: public static Property findAttributeForRelationAtOtherSide(
67: Property aktProperty) {
68: // now look for the other if exist at the global store
69: // WIR MÜSSEN DIE N SEITE FINDEN: die als target uns hat (aktProperty)
70: // TODO WIR MÜSSEN DIE N SEITE FINDEN:
71: Property relProp = GlobalRelationStore.getStore().getProperty(
72: aktProperty.getType(), aktProperty.getDeclaringClass());
73: if (relProp == null) {
74: // use a new instrospector to put the relation to the global
75: // store
76: final EntityBeanIntrospector<Object> tmpIn = new EntityBeanIntrospector<Object>(
77: aktProperty.getType());
78: log.debug("Dependend class: " + tmpIn.getTableName());
79: // now it should be in theglobal store
80: relProp = GlobalRelationStore.getStore().getProperty(
81: aktProperty.getType(),
82: aktProperty.getDeclaringClass());
83: if (relProp == null) {
84: throw new RuntimeException(
85: "Cant´t resolve releations for property ("
86: + aktProperty.getName()
87: + ") in class ("
88: + aktProperty.getDeclaringClass() + ")");
89: }
90: }
91: return relProp;
92: }
93:
94: }
|