KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > dbmetatreemodel > DatabaseMetaDataTreeModel


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

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

28
29 public class DatabaseMetaDataTreeModel extends javax.swing.tree.DefaultTreeModel JavaDoc
30     implements java.io.Serializable JavaDoc
31 {
32     static final long serialVersionUID = -8045409456918534509L; transient private java.sql.DatabaseMetaData JavaDoc dbMetadata;
33     /** Creates a new instance of DatabaseMetaDataTreeModel. The
34      * model represents the metadata specified by pdbMetadata
35      * @param pdbMetadata the metadata this model represents.
36      * @param pStatusBar a JTextComponent that takes status messages
37      * of this model. This model sometimes needs
38      * some time to finish a request, the status
39      * bar indicates what the model is doing.
40      */

41     public DatabaseMetaDataTreeModel(java.sql.DatabaseMetaData JavaDoc pdbMetadata)
42     {
43         super(new javax.swing.tree.DefaultMutableTreeNode JavaDoc("initializing"));
44         this.dbMetadata = pdbMetadata;
45         DBMetaRootNode rootNode = new DBMetaRootNode(dbMetadata, this);
46         super.setRoot(rootNode);
47         rootNode.loadWait(true, false, true);
48     }
49     
50     
51     /** Set a status message in the JTextComponent passed to this
52      * model.
53      * @param message The message that should be displayed.
54      */

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

73     public void addStatusMessageListener(StatusMessageListener listener)
74     {
75         listenerList.add(StatusMessageListener.class, listener);
76     }
77     
78     /** Remove a listener that receives status messages from
79      * this model.
80      * @param listener The listener that shall be removed
81      */

82     public void removeStatusMessageListener(StatusMessageListener listener)
83     {
84         listenerList.remove(StatusMessageListener.class, listener);
85     }
86     
87     /** Method for reporting SQLException. This is used by
88      * the treenodes if retrieving information for a node
89      * is not successful.
90      * @param message The message describing where the error occurred
91      * @param sqlEx The exception to be reported.
92      */

93     public void reportSqlError(String JavaDoc message, java.sql.SQLException JavaDoc sqlEx)
94     {
95         StringBuffer JavaDoc strBufMessages = new StringBuffer JavaDoc();
96         java.sql.SQLException JavaDoc currentSqlEx = sqlEx;
97         do
98         {
99             strBufMessages.append("\n" + sqlEx.getErrorCode() + ":" + sqlEx.getMessage());
100             currentSqlEx = currentSqlEx.getNextException();
101         } while (currentSqlEx != null);
102         System.err.println(message + strBufMessages.toString());
103         sqlEx.printStackTrace();
104     }
105 }
106
Popular Tags