001: package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
002:
003: /* Copyright 2002-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * This represents the root of the repository.xml tree model. It contains
020: * the ClassDescriptor objects for this repository and the default JDBC
021: * connection.
022: *
023: * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
024: * @version $Id: OjbMetaRootNode.java,v 1.1.2.1 2005/12/21 22:32:38 tomdz Exp $
025: */
026: public class OjbMetaRootNode extends OjbMetaTreeNode {
027: private java.util.ArrayList supportedActions = new java.util.ArrayList();
028:
029: java.util.HashMap cldToNodes = new java.util.HashMap();
030:
031: /** Creates a new instance of OjbMetaRootNode */
032: public OjbMetaRootNode(
033: org.apache.ojb.broker.metadata.DescriptorRepository pRepository,
034: OjbMetaDataTreeModel model) {
035: super (pRepository, model, null);
036: supportedActions
037: .add(new org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel.actions.ActionAddClassDescriptor(
038: this ));
039: }
040:
041: public boolean getAllowsChildren() {
042: return true;
043: }
044:
045: public Class getPropertyEditorClass() {
046: return null;
047: }
048:
049: public boolean isLeaf() {
050: return false;
051: }
052:
053: /** Get an attribute of this node as Object.
054: */
055: public Object getAttribute(String strKey) {
056: return null;
057: }
058:
059: /** Set an attribute of this node as Object.
060: */
061: public void setAttribute(String strKey, Object value) {
062: }
063:
064: public OjbMetaClassDescriptorNode getClassDescriptorNodeForClassDescriptor(
065: org.apache.ojb.broker.metadata.ClassDescriptor cld) {
066: return (OjbMetaClassDescriptorNode) this .cldToNodes.get(cld);
067: }
068:
069: /** Purpose of this method is to fill the children of the node. It should
070: * replace all children in alChildren (the arraylist containing the children)
071: * of this node and notify the TreeModel that a change has occurred.
072: */
073: protected boolean _load() {
074: java.util.Iterator it = this .getOjbMetaTreeModel()
075: .getRepository().iterator();
076: java.util.ArrayList newChildren = new java.util.ArrayList();
077:
078: /* @todo make this work */
079:
080: // newChildren.add(new OjbMetaJdbcConnectionDescriptorNode(
081: // this.getOjbMetaTreeModel ().getRepository(),
082: // this.getOjbMetaTreeModel (),
083: // this,
084: // this.getOjbMetaTreeModel ().getRepository().getDefaultJdbcConnection()));
085: while (it.hasNext()) {
086: org.apache.ojb.broker.metadata.ClassDescriptor cld = (org.apache.ojb.broker.metadata.ClassDescriptor) it
087: .next();
088: OjbMetaClassDescriptorNode cldNode = new OjbMetaClassDescriptorNode(
089: this .getOjbMetaTreeModel().getRepository(), this
090: .getOjbMetaTreeModel(), this , cld);
091: cldToNodes.put(cld, cldNode);
092: newChildren.add(cldNode);
093: }
094: java.util.Collections.sort(newChildren);
095: this .alChildren = newChildren;
096: this .getOjbMetaTreeModel().nodeStructureChanged(this );
097: return true;
098: }
099:
100: public void addClassDescriptor(
101: org.apache.ojb.broker.metadata.ClassDescriptor cld) {
102: OjbMetaClassDescriptorNode cldNode = new OjbMetaClassDescriptorNode(
103: this .getOjbMetaTreeModel().getRepository(), this
104: .getOjbMetaTreeModel(), this , cld);
105: cldToNodes.put(cld, cldNode);
106: this .alChildren.add(cldNode);
107: this .getOjbMetaTreeModel().nodesWereInserted(this ,
108: new int[] { this .alChildren.size() - 1 });
109: }
110:
111: /**
112: * @see ActionTarget#getActions()
113: */
114: public java.util.Iterator getActions() {
115: return supportedActions.iterator();
116: }
117:
118: /**
119: * @see ActionTarget#actionListCacheable()
120: */
121: public boolean actionListCachable() {
122: return true;
123: }
124:
125: /**
126: * @see ActionTarget
127: */
128: public boolean actionListStatic() {
129: return false;
130: }
131:
132: /**
133: * Return the descriptor object this node is associated with. E.g. if the
134: * node displays a class descriptor, the ClassDescriptor describing the class
135: * should be returned. Used for creating a Transferable. Null in this case
136: * because the root doesn't have any associated objects.
137: */
138: public Object getAssociatedDescriptor() {
139: return null;
140: }
141:
142: }
|