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