1 package org.apache.ojb.broker;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * 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 import org.apache.ojb.broker.core.proxy.ProxyHelper;
19 import org.apache.ojb.broker.metadata.CollectionDescriptor;
20
21 /**
22 * Helper class to handle single m:n relation entries (m:n indirection table entries).
23 * <br/>
24 * The "left / right" notation is only used to differ both sides of the relation.
25 *
26 * @author Leandro Rodrigo Saad Cruz
27 * @version $Id: MtoNImplementor.java,v 1.1 2007-08-24 22:17:36 ewestfal Exp $
28 */
29 public class MtoNImplementor
30 {
31 private Object leftObject;
32 private Object rightObject;
33 private Class leftClass;
34 private Class rightClass;
35 private CollectionDescriptor leftDescriptor;
36
37 /**
38 * Creates a new instance.
39 *
40 * @param pb The currently used {@link PersistenceBroker} instance
41 * @param leftDescriptor The collection descriptor for the left side
42 * @param left The left side object
43 * @param right The right side object
44 * @deprecated
45 */
46 public MtoNImplementor(PersistenceBroker pb, CollectionDescriptor leftDescriptor, Object left, Object right)
47 {
48 init(leftDescriptor, left, right);
49 }
50
51 /**
52 * Creates a new instance.
53 *
54 * @param pb The currently used {@link PersistenceBroker} instance
55 * @param leftFieldName Field name of the left m:n reference
56 * @param left The left side object
57 * @param right The right side object
58 */
59 public MtoNImplementor(PersistenceBroker pb, String leftFieldName, Object left, Object right)
60 {
61 if(left == null || right == null)
62 {
63 throw new IllegalArgumentException("both objects must exist");
64 }
65 CollectionDescriptor cod = pb.getClassDescriptor(ProxyHelper.getRealClass(left)).getCollectionDescriptorByName(leftFieldName);
66 init(cod, left, right);
67 }
68
69 /**
70 * Creates a new instance.
71 *
72 * @param leftDescriptor The collection descriptor for the left side
73 * @param left The left side object
74 * @param right The right side object
75 * @deprecated
76 */
77 public MtoNImplementor(CollectionDescriptor leftDescriptor, Object left, Object right)
78 {
79 init(leftDescriptor, left, right);
80 }
81
82 private void init(CollectionDescriptor leftDescriptor, Object left, Object right)
83 {
84 if(left == null || right == null)
85 {
86 throw new IllegalArgumentException("both objects must exist");
87 }
88 this.leftDescriptor = leftDescriptor;
89 leftObject = left;
90 rightObject = right;
91 leftClass = ProxyHelper.getRealClass(leftObject);
92 rightClass = ProxyHelper.getRealClass(rightObject);
93 }
94
95 /**
96 * Returns the collection descriptor for the left side of the m:n collection.
97 *
98 * @return The collection descriptor
99 */
100 public CollectionDescriptor getLeftDescriptor()
101 {
102 return leftDescriptor;
103 }
104
105 /**
106 * Returns the class of the left side of the m:n collection.
107 *
108 * @return The class of the left side
109 */
110 public Class getLeftClass()
111 {
112 return leftClass;
113 }
114
115 /**
116 * Returns the class of the right side of the m:n collection.
117 *
118 * @return The class of the right side
119 */
120 public Class getRightClass()
121 {
122 return rightClass;
123 }
124
125 /**
126 * Returns the object for the left side of the m:n collection.
127 *
128 * @return The object for the left side
129 */
130 public Object getLeftObject()
131 {
132 return leftObject;
133 }
134
135 /**
136 * Returns the object for the right side of the m:n collection.
137 *
138 * @return The object for the right side
139 */
140 public Object getRightObject()
141 {
142 return rightObject;
143 }
144 }