KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > ojbmetatreemodel > OjbMetaCollectionDescriptorNode


1 package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
2
3 import org.apache.ojb.broker.metadata.ClassDescriptor;
4 import org.apache.ojb.broker.metadata.CollectionDescriptor;
5 import org.apache.ojb.broker.metadata.DescriptorRepository;
6 import org.apache.commons.collections.iterators.ArrayIterator;
7
8 public class OjbMetaCollectionDescriptorNode extends OjbMetaTreeNode
9 {
10     private static java.util.ArrayList JavaDoc supportedActions = new java.util.ArrayList JavaDoc();
11     
12
13     private CollectionDescriptor collectionDescriptor;
14 /* Copyright 2002-2005 The Apache Software Foundation
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License");
17  * you may not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS,
24  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  */

28     public OjbMetaCollectionDescriptorNode(
29         DescriptorRepository pRepository,
30         OjbMetaDataTreeModel pTreeModel,
31         OjbMetaTreeNode pparent,
32         CollectionDescriptor pCollectionDescriptor)
33     {
34         super(pRepository, pTreeModel, pparent);
35         this.collectionDescriptor = pCollectionDescriptor;
36     }
37
38     /**
39      * @see OjbMetaTreeNode#_load()
40      */

41     protected boolean _load()
42     {
43         java.util.ArrayList JavaDoc newChildren = new java.util.ArrayList JavaDoc();
44         ClassDescriptor itemClass = this.getRepository().getDescriptorFor(this.collectionDescriptor.getItemClassName());
45         newChildren.add(getOjbMetaTreeModel().getClassDescriptorNodeForClassDescriptor(itemClass));
46         
47         // Foreign Key fields retrieved here map to FieldDescriptors of the table in the collection
48
System.err.println(toString());
49         java.util.Iterator JavaDoc it;
50         try
51         {
52             it = new ArrayIterator(collectionDescriptor.getFksToThisClass());
53             while (it.hasNext())
54                 newChildren.add(new javax.swing.tree.DefaultMutableTreeNode JavaDoc("FksToThisClass: " + it.next().toString()));
55             it = new ArrayIterator(collectionDescriptor.getFksToItemClass());
56             while (it.hasNext())
57                 newChildren.add(new javax.swing.tree.DefaultMutableTreeNode JavaDoc("FksToItemClass: " + it.next().toString()));
58             
59         }
60         catch (NullPointerException JavaDoc npe)
61         {
62         }
63         try
64         {
65         
66             it = collectionDescriptor.getForeignKeyFields().iterator();
67             while (it.hasNext())
68                 newChildren.add(new javax.swing.tree.DefaultMutableTreeNode JavaDoc("FkFields: " + it.next().toString()));
69         }
70         catch (NullPointerException JavaDoc npe)
71         {
72             npe.printStackTrace();
73         }
74         this.alChildren = newChildren;
75         this.getOjbMetaTreeModel().nodeStructureChanged(this);
76         return true;
77     }
78     
79     /**
80      * Override load() of superClass to prevent recursive loading which would lead to an endless recursion
81      * because of OjbClassDescriptorNodes being children of this node
82      */

83     public boolean load()
84     {
85         return _load();
86     }
87
88     /**
89      * @see OjbMetaTreeNode#isLeaf()
90      */

91     public boolean isLeaf()
92     {
93         return false;
94     }
95
96     /**
97      * @see OjbMetaTreeNode#getAllowsChildren()
98      */

99     public boolean getAllowsChildren()
100     {
101         return false;
102     }
103
104     /**
105      * @see OjbMetaTreeNode#setAttribute(String, Object)
106      */

107     public void setAttribute(String JavaDoc strKey, Object JavaDoc value)
108     {
109     }
110
111     /**
112      * @see OjbMetaTreeNode#getAttribute(String)
113      */

114     public Object JavaDoc getAttribute(String JavaDoc strKey)
115     {
116         return null;
117     }
118
119     /**
120      * @see org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditorTarget#getPropertyEditorClass()
121      */

122     public Class JavaDoc getPropertyEditorClass()
123     {
124         return null;
125     }
126     
127     public String JavaDoc toString()
128     {
129 // System.out.println(collectionDescriptor.toXML());
130
if (collectionDescriptor.getItemClassName() == null)
131             return "CollectionDescriptor.getItemClass() == null";
132         else return "CollectionDescriptor: " + collectionDescriptor.getItemClassName();
133     }
134     
135     /**
136      * @see org.apache.ojb.tools.mapping.reversedb2.ActionTarget#getActions()
137      */

138     public java.util.Iterator JavaDoc getActions()
139     {
140         return supportedActions.iterator();
141     }
142     
143     /**
144      * @see org.apache.ojb.tools.mapping.reversedb2.ActionTarget#actionListCachable()
145      */

146     public boolean actionListCachable()
147     {
148         return true;
149     }
150     
151     public boolean actionListStatic()
152     {
153         return true;
154     }
155     
156     /**
157      * Return the descriptor object this node is associated with. E.g. if the
158      * node displays a class descriptor, the ClassDescriptor describing the class
159      * should be returned. Used for creating a Transferable.
160      */

161     public Object JavaDoc getAssociatedDescriptor()
162     {
163         return collectionDescriptor;
164     }
165     
166 }
167
168
Popular Tags