KickJava   Java API By Example, From Geeks To Geeks.

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


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

15
16 package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
17
18 import org.apache.commons.collections.iterators.ArrayIterator;
19 import org.apache.ojb.broker.metadata.ClassDescriptor;
20 import org.apache.ojb.broker.metadata.CollectionDescriptor;
21 import org.apache.ojb.broker.metadata.DescriptorRepository;
22 import org.apache.ojb.broker.metadata.FieldDescriptor;
23 import org.apache.ojb.broker.metadata.IndexDescriptor;
24 import org.apache.ojb.broker.metadata.ObjectReferenceDescriptor;
25
26
27 /**
28  *
29  * @author Administrator
30  */

31 public class OjbMetaClassDescriptorNode extends OjbMetaTreeNode implements javax.swing.tree.MutableTreeNode JavaDoc
32 {
33
34     private static java.util.ArrayList JavaDoc supportedActions = new java.util.ArrayList JavaDoc();
35
36
37     private ClassDescriptor cld;
38     /** Creates a new instance of OjbMetaClassDescriptorNode */
39     public OjbMetaClassDescriptorNode (DescriptorRepository pRepository,
40                                        OjbMetaDataTreeModel pTreeModel,
41                                        OjbMetaRootNode pparent,
42                                        ClassDescriptor pCld)
43     {
44         super(pRepository, pTreeModel, pparent);
45         this.cld = pCld;
46     }
47
48     public boolean getAllowsChildren ()
49     {
50         return true;
51     }
52
53     public Object JavaDoc getAttribute (String JavaDoc key)
54     {
55         return null;
56     }
57
58     public Class JavaDoc getPropertyEditorClass ()
59     {
60         return null;
61     }
62
63     public boolean isLeaf ()
64     {
65         return false;
66     }
67
68     public void setAttribute (String JavaDoc key, Object JavaDoc value)
69     {
70
71     }
72
73     /** Purpose of this method is to fill the children of the node. It should
74      * replace all children in alChildren (the arraylist containing the children)
75      * of this node and notify the TreeModel that a change has occurred.
76      */

77     protected boolean _load ()
78     {
79         java.util.ArrayList JavaDoc newChildren = new java.util.ArrayList JavaDoc();
80
81         /* @todo make this work */
82 // if (cld.getConnectionDescriptor() != null)
83
// {
84
// newChildren.add(new OjbMetaJdbcConnectionDescriptorNode(
85
// this.getOjbMetaTreeModel().getRepository(),
86
// this.getOjbMetaTreeModel(),
87
// this,
88
// cld.getConnectionDescriptor()));
89
// }
90
//
91
// Add collection descriptors
92
java.util.Iterator JavaDoc it = cld.getCollectionDescriptors().iterator();
93         while (it.hasNext())
94         {
95             CollectionDescriptor collDesc = (CollectionDescriptor)it.next();
96             newChildren.add(new OjbMetaCollectionDescriptorNode(
97                 this.getOjbMetaTreeModel().getRepository(),
98                 this.getOjbMetaTreeModel(),
99                 this,
100                 collDesc));
101
102         }
103
104         // Add extent classes Class
105

106         it = cld.getExtentClassNames().iterator();
107         while (it.hasNext())
108         {
109             String JavaDoc extentClassName = (String JavaDoc)it.next();
110             newChildren.add(new OjbMetaExtentClassNode(
111                 this.getOjbMetaTreeModel().getRepository(),
112                 this.getOjbMetaTreeModel(),
113                 this,
114                 extentClassName));
115
116         }
117
118         // Get Field descriptors FieldDescriptor
119
if (cld.getFieldDescriptions() != null)
120         {
121             it = new ArrayIterator(cld.getFieldDescriptions());
122             while (it.hasNext())
123             {
124                 FieldDescriptor fieldDesc = (FieldDescriptor)it.next();
125                 newChildren.add(new OjbMetaFieldDescriptorNode(
126                         this.getOjbMetaTreeModel().getRepository(),
127                         this.getOjbMetaTreeModel(),
128                         this,
129                         fieldDesc));
130             }
131         }
132         else
133         {
134                 System.out.println(cld.getClassNameOfObject() + " does not have field descriptors");
135         }
136
137         // Get Indices IndexDescriptor
138
it = cld.getIndexes().iterator();
139         while (it.hasNext())
140         {
141             IndexDescriptor indexDesc = (IndexDescriptor)it.next();
142             newChildren.add(new OjbMetaIndexDescriptorNode(
143                 this.getOjbMetaTreeModel().getRepository(),
144                 this.getOjbMetaTreeModel(),
145                 this,
146                 indexDesc));
147
148         }
149
150         // Get references ObjectReferenceDescriptor
151
it = cld.getObjectReferenceDescriptors().iterator();
152         while (it.hasNext())
153         {
154             ObjectReferenceDescriptor objRefDesc = (ObjectReferenceDescriptor)it.next();
155             newChildren.add(new OjbMetaObjectReferenceDescriptorNode(
156                 this.getOjbMetaTreeModel().getRepository(),
157                 this.getOjbMetaTreeModel(),
158                 this,
159                 objRefDesc));
160
161         }
162         // Add
163
this.alChildren = newChildren;
164         this.getOjbMetaTreeModel().nodeStructureChanged(this);
165         return true;
166     }
167
168     public String JavaDoc toString()
169     {
170         return "ClassDescriptor:" + this.cld.getClassNameOfObject();
171         // return "ClassDescriptor:" + this.cld.getClassOfObject().getName();
172
}
173
174     /**
175      * @see org.apache.ojb.tools.mapping.reversedb2.ActionTarget#getActions()
176      */

177     public java.util.Iterator JavaDoc getActions()
178     {
179         return supportedActions.iterator();
180     }
181
182     /**
183      * @see org.apache.ojb.tools.mapping.reversedb2.ActionTarget#actionListCachable()
184      */

185     public boolean actionListCachable()
186     {
187         return true;
188     }
189
190     public boolean actionListStatic()
191     {
192         return true;
193     }
194
195     /** Adds <code>child</code> to the receiver at <code>index</code>.
196      * <code>child</code> will be messaged with <code>setParent</code>.
197      *
198      */

199     public void insert(javax.swing.tree.MutableTreeNode JavaDoc child, int index)
200     {
201     }
202
203     /** Removes <code>node</code> from the receiver. <code>setParent</code>
204      * will be messaged on <code>node</code>.
205      *
206      */

207     public void remove(javax.swing.tree.MutableTreeNode JavaDoc node)
208     {
209     }
210
211     /** Removes the child at <code>index</code> from the receiver.
212      *
213      */

214     public void remove(int index)
215     {
216     }
217
218     /** Removes the receiver from its parent.
219      *
220      */

221     public void removeFromParent()
222     {
223     }
224
225     /** Sets the parent of the receiver to <code>newParent</code>.
226      *
227      */

228     public void setParent(javax.swing.tree.MutableTreeNode JavaDoc newParent)
229     {
230     }
231
232     /** Resets the user object of the receiver to <code>object</code>.
233      *
234      */

235     public void setUserObject(Object JavaDoc object)
236     {
237     }
238
239     /**
240      * Return the descriptor object this node is associated with. E.g. if the
241      * node displays a class descriptor, the ClassDescriptor describing the class
242      * should be returned. Used for creating a Transferable.
243      */

244     public Object JavaDoc getAssociatedDescriptor()
245     {
246         return cld;
247     }
248
249 }
250
Popular Tags