KickJava   Java API By Example, From Geeks To Geeks.

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


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.DescriptorRepository;
5 import org.apache.ojb.tools.mapping.reversedb2.events.StatusMessageListener;
6
7 /* Copyright 2002-2005 The Apache Software Foundation
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 /**
23  * TreeModel representing the metadata of the database. Root element of this
24  * model is a DBMetaRootNode.
25  *
26  *
27  * @author <a HREF="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
28  * @version $Id: OjbMetaDataTreeModel.java,v 1.1.2.1 2005/12/21 22:32:38 tomdz Exp $
29  */

30
31 public class OjbMetaDataTreeModel extends javax.swing.tree.DefaultTreeModel JavaDoc
32 {
33     private DescriptorRepository ojbMetaData;
34     
35     /** Creates a new instance of DatabaseMetaDataTreeModel. The
36      * model represents the metadata specified by pdbMetadata
37      * @param pdbMetadata the metadata this model represents.
38      * @param pStatusBar a JTextComponent that takes status messages
39      * of this model. This model sometimes needs
40      * some time to finish a request, the status
41      * bar indicates what the model is doing.
42      */

43     public OjbMetaDataTreeModel (DescriptorRepository pOjbMetaData)
44     {
45         super(new javax.swing.tree.DefaultMutableTreeNode JavaDoc("dummy"));
46         this.ojbMetaData = pOjbMetaData;
47         OjbMetaRootNode rootNode = new OjbMetaRootNode(ojbMetaData, this);
48         super.setRoot(rootNode);
49         rootNode.load();
50     }
51     
52     public DescriptorRepository getRepository()
53     {
54         return ojbMetaData;
55     }
56     
57     
58     /** Set a status message in the JTextComponent passed to this
59      * model.
60      * @param message The message that should be displayed.
61      */

62     public void setStatusBarMessage(final String JavaDoc message)
63     {
64         // Guaranteed to return a non-null array
65
Object JavaDoc[] listeners = listenerList.getListenerList();
66         // Process the listeners last to first, notifying
67
// those that are interested in this event
68
for (int i = listeners.length-2; i>=0; i-=2) {
69             if (listeners[i]==StatusMessageListener.class)
70             {
71                 ((StatusMessageListener)listeners[i+1]).statusMessageReceived(message);
72             }
73         }
74     }
75     
76     /** Add a listener that receives status messages from
77      * this model.
78      * @param listener The listener that should receive the status messsages
79      */

80     public void addStatusMessageListener(StatusMessageListener listener)
81     {
82         listenerList.add(StatusMessageListener.class, listener);
83     }
84     
85     /** Remove a listener that receives status messages from
86      * this model.
87      * @param listener The listener that shall be removed
88      */

89     public void removeStatusMessageListener(StatusMessageListener listener)
90     {
91         listenerList.remove(StatusMessageListener.class, listener);
92     }
93     
94     /** Method for reporting SQLException. This is used by
95      * the treenodes if retrieving information for a node
96      * is not successful.
97      * @param message The message describing where the error occurred
98      * @param sqlEx The exception to be reported.
99      */

100     public void reportSqlError(String JavaDoc message, java.sql.SQLException JavaDoc sqlEx)
101     {
102         StringBuffer JavaDoc strBufMessages = new StringBuffer JavaDoc();
103         java.sql.SQLException JavaDoc currentSqlEx = sqlEx;
104         do
105         {
106             strBufMessages.append("\n" + sqlEx.getErrorCode() + ":" + sqlEx.getMessage());
107             currentSqlEx = currentSqlEx.getNextException();
108         } while (currentSqlEx != null);
109         System.err.println(message + strBufMessages.toString());
110         sqlEx.printStackTrace();
111     }
112     
113     public OjbMetaClassDescriptorNode getClassDescriptorNodeForClassDescriptor(ClassDescriptor cld)
114     {
115         return ((OjbMetaRootNode)this.getRoot()).getClassDescriptorNodeForClassDescriptor(cld);
116     }
117 }
118
Popular Tags