KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > modules > ojb > model > CollectionDescriptorDef


1 package xdoclet.modules.ojb.model;
2
3 import java.util.Iterator JavaDoc;
4
5 import xdoclet.modules.ojb.CommaListIterator;
6
7 /* Copyright 2004-2005 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 /**
23  * A collection descriptor for the ojb repository file.
24  *
25  * @author <a HREF="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
26  */

27 public class CollectionDescriptorDef extends FeatureDescriptorDef
28 {
29     /**
30      * Creates a new collection descriptor object.
31      *
32      * @param name The name of the collection field
33      */

34     public CollectionDescriptorDef(String JavaDoc name)
35     {
36         super(name);
37     }
38
39     /**
40      * Creates copy of the given collection descriptor object. Note that the copy has no owner initially.
41      *
42      * @param src The original collection descriptor
43      * @param prefix A prefix for the name
44      */

45     public CollectionDescriptorDef(CollectionDescriptorDef src, String JavaDoc prefix)
46     {
47         super(src, prefix);
48     }
49
50     /**
51      * Tries to find the corresponding remote collection for this m:n collection.
52      *
53      * @return The corresponding remote collection
54      */

55     public CollectionDescriptorDef getRemoteCollection()
56     {
57         if (!hasProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE))
58         {
59             return null;
60         }
61         ModelDef modelDef = (ModelDef)getOwner().getOwner();
62         String JavaDoc elementClassName = getProperty(PropertyHelper.OJB_PROPERTY_ELEMENT_CLASS_REF);
63         ClassDescriptorDef elementClass = modelDef.getClass(elementClassName);
64         String JavaDoc indirTable = getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE);
65         boolean hasRemoteKey = hasProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
66         String JavaDoc remoteKey = getProperty(PropertyHelper.OJB_PROPERTY_REMOTE_FOREIGNKEY);
67         CollectionDescriptorDef remoteCollDef = null;
68
69         // find the collection in the element class that has the same indirection table
70
for (Iterator JavaDoc it = elementClass.getCollections(); it.hasNext();)
71         {
72             remoteCollDef = (CollectionDescriptorDef)it.next();
73             if (indirTable.equals(remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE)) &&
74                 (this != remoteCollDef) &&
75                 (!hasRemoteKey || CommaListIterator.sameLists(remoteKey, remoteCollDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY))))
76             {
77                 return remoteCollDef;
78             }
79         }
80         return null;
81     }
82 }
83
Popular Tags