001: package org.apache.ojb.broker;
002:
003: /* Copyright 2003-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import org.apache.ojb.broker.core.proxy.ProxyHelper;
019: import org.apache.ojb.broker.metadata.CollectionDescriptor;
020:
021: /**
022: * Helper class to handle single m:n relation entries (m:n indirection table entries).
023: * <br/>
024: * The "left / right" notation is only used to differ both sides of the relation.
025: *
026: * @author Leandro Rodrigo Saad Cruz
027: * @version $Id: MtoNImplementor.java,v 1.7.2.4 2005/12/21 22:22:08 tomdz Exp $
028: */
029: public class MtoNImplementor {
030: private Object leftObject;
031: private Object rightObject;
032: private Class leftClass;
033: private Class rightClass;
034: private CollectionDescriptor leftDescriptor;
035:
036: /**
037: * Creates a new instance.
038: *
039: * @param pb The currently used {@link PersistenceBroker} instance
040: * @param leftDescriptor The collection descriptor for the left side
041: * @param left The left side object
042: * @param right The right side object
043: * @deprecated
044: */
045: public MtoNImplementor(PersistenceBroker pb,
046: CollectionDescriptor leftDescriptor, Object left,
047: Object right) {
048: init(leftDescriptor, left, right);
049: }
050:
051: /**
052: * Creates a new instance.
053: *
054: * @param pb The currently used {@link PersistenceBroker} instance
055: * @param leftFieldName Field name of the left m:n reference
056: * @param left The left side object
057: * @param right The right side object
058: */
059: public MtoNImplementor(PersistenceBroker pb, String leftFieldName,
060: Object left, Object right) {
061: if (left == null || right == null) {
062: throw new IllegalArgumentException(
063: "both objects must exist");
064: }
065: CollectionDescriptor cod = pb.getClassDescriptor(
066: ProxyHelper.getRealClass(left))
067: .getCollectionDescriptorByName(leftFieldName);
068: init(cod, left, right);
069: }
070:
071: /**
072: * Creates a new instance.
073: *
074: * @param leftDescriptor The collection descriptor for the left side
075: * @param left The left side object
076: * @param right The right side object
077: * @deprecated
078: */
079: public MtoNImplementor(CollectionDescriptor leftDescriptor,
080: Object left, Object right) {
081: init(leftDescriptor, left, right);
082: }
083:
084: private void init(CollectionDescriptor leftDescriptor, Object left,
085: Object right) {
086: if (left == null || right == null) {
087: throw new IllegalArgumentException(
088: "both objects must exist");
089: }
090: this .leftDescriptor = leftDescriptor;
091: leftObject = left;
092: rightObject = right;
093: leftClass = ProxyHelper.getRealClass(leftObject);
094: rightClass = ProxyHelper.getRealClass(rightObject);
095: }
096:
097: /**
098: * Returns the collection descriptor for the left side of the m:n collection.
099: *
100: * @return The collection descriptor
101: */
102: public CollectionDescriptor getLeftDescriptor() {
103: return leftDescriptor;
104: }
105:
106: /**
107: * Returns the class of the left side of the m:n collection.
108: *
109: * @return The class of the left side
110: */
111: public Class getLeftClass() {
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: return rightClass;
122: }
123:
124: /**
125: * Returns the object for the left side of the m:n collection.
126: *
127: * @return The object for the left side
128: */
129: public Object getLeftObject() {
130: return leftObject;
131: }
132:
133: /**
134: * Returns the object for the right side of the m:n collection.
135: *
136: * @return The object for the right side
137: */
138: public Object getRightObject() {
139: return rightObject;
140: }
141: }
|