001: package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
002:
003: import org.apache.ojb.broker.metadata.ClassDescriptor;
004: import org.apache.ojb.broker.metadata.CollectionDescriptor;
005: import org.apache.ojb.broker.metadata.DescriptorRepository;
006: import org.apache.commons.collections.iterators.ArrayIterator;
007:
008: public class OjbMetaCollectionDescriptorNode extends OjbMetaTreeNode {
009: private static java.util.ArrayList supportedActions = new java.util.ArrayList();
010:
011: private CollectionDescriptor collectionDescriptor;
012:
013: /* Copyright 2002-2005 The Apache Software Foundation
014: *
015: * Licensed under the Apache License, Version 2.0 (the "License");
016: * you may not use this file except in compliance with the License.
017: * You may obtain a copy of the License at
018: *
019: * http://www.apache.org/licenses/LICENSE-2.0
020: *
021: * Unless required by applicable law or agreed to in writing, software
022: * distributed under the License is distributed on an "AS IS" BASIS,
023: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
024: * See the License for the specific language governing permissions and
025: * limitations under the License.
026: */
027: public OjbMetaCollectionDescriptorNode(
028: DescriptorRepository pRepository,
029: OjbMetaDataTreeModel pTreeModel, OjbMetaTreeNode pparent,
030: CollectionDescriptor pCollectionDescriptor) {
031: super (pRepository, pTreeModel, pparent);
032: this .collectionDescriptor = pCollectionDescriptor;
033: }
034:
035: /**
036: * @see OjbMetaTreeNode#_load()
037: */
038: protected boolean _load() {
039: java.util.ArrayList newChildren = new java.util.ArrayList();
040: ClassDescriptor itemClass = this .getRepository()
041: .getDescriptorFor(
042: this .collectionDescriptor.getItemClassName());
043: newChildren.add(getOjbMetaTreeModel()
044: .getClassDescriptorNodeForClassDescriptor(itemClass));
045:
046: // Foreign Key fields retrieved here map to FieldDescriptors of the table in the collection
047: System.err.println(toString());
048: java.util.Iterator it;
049: try {
050: it = new ArrayIterator(collectionDescriptor
051: .getFksToThisClass());
052: while (it.hasNext())
053: newChildren
054: .add(new javax.swing.tree.DefaultMutableTreeNode(
055: "FksToThisClass: "
056: + it.next().toString()));
057: it = new ArrayIterator(collectionDescriptor
058: .getFksToItemClass());
059: while (it.hasNext())
060: newChildren
061: .add(new javax.swing.tree.DefaultMutableTreeNode(
062: "FksToItemClass: "
063: + it.next().toString()));
064:
065: } catch (NullPointerException npe) {
066: }
067: try {
068:
069: it = collectionDescriptor.getForeignKeyFields().iterator();
070: while (it.hasNext())
071: newChildren
072: .add(new javax.swing.tree.DefaultMutableTreeNode(
073: "FkFields: " + it.next().toString()));
074: } catch (NullPointerException npe) {
075: npe.printStackTrace();
076: }
077: this .alChildren = newChildren;
078: this .getOjbMetaTreeModel().nodeStructureChanged(this );
079: return true;
080: }
081:
082: /**
083: * Override load() of superClass to prevent recursive loading which would lead to an endless recursion
084: * because of OjbClassDescriptorNodes being children of this node
085: */
086: public boolean load() {
087: return _load();
088: }
089:
090: /**
091: * @see OjbMetaTreeNode#isLeaf()
092: */
093: public boolean isLeaf() {
094: return false;
095: }
096:
097: /**
098: * @see OjbMetaTreeNode#getAllowsChildren()
099: */
100: public boolean getAllowsChildren() {
101: return false;
102: }
103:
104: /**
105: * @see OjbMetaTreeNode#setAttribute(String, Object)
106: */
107: public void setAttribute(String strKey, Object value) {
108: }
109:
110: /**
111: * @see OjbMetaTreeNode#getAttribute(String)
112: */
113: public Object getAttribute(String strKey) {
114: return null;
115: }
116:
117: /**
118: * @see org.apache.ojb.tools.mapping.reversedb2.propertyEditors.PropertyEditorTarget#getPropertyEditorClass()
119: */
120: public Class getPropertyEditorClass() {
121: return null;
122: }
123:
124: public String toString() {
125: // System.out.println(collectionDescriptor.toXML());
126: if (collectionDescriptor.getItemClassName() == null)
127: return "CollectionDescriptor.getItemClass() == null";
128: else
129: return "CollectionDescriptor: "
130: + collectionDescriptor.getItemClassName();
131: }
132:
133: /**
134: * @see org.apache.ojb.tools.mapping.reversedb2.ActionTarget#getActions()
135: */
136: public java.util.Iterator getActions() {
137: return supportedActions.iterator();
138: }
139:
140: /**
141: * @see org.apache.ojb.tools.mapping.reversedb2.ActionTarget#actionListCachable()
142: */
143: public boolean actionListCachable() {
144: return true;
145: }
146:
147: public boolean actionListStatic() {
148: return true;
149: }
150:
151: /**
152: * Return the descriptor object this node is associated with. E.g. if the
153: * node displays a class descriptor, the ClassDescriptor describing the class
154: * should be returned. Used for creating a Transferable.
155: */
156: public Object getAssociatedDescriptor() {
157: return collectionDescriptor;
158: }
159:
160: }
|