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.tools.mapping.reversedb2.events.StatusMessageListener;
006:
007: /* Copyright 2002-2005 The Apache Software Foundation
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: /**
023: * TreeModel representing the metadata of the database. Root element of this
024: * model is a DBMetaRootNode.
025: *
026: *
027: * @author <a href="mailto:bfl@florianbruckner.com">Florian Bruckner</a>
028: * @version $Id: OjbMetaDataTreeModel.java,v 1.1.2.1 2005/12/21 22:32:38 tomdz Exp $
029: */
030:
031: public class OjbMetaDataTreeModel extends
032: javax.swing.tree.DefaultTreeModel {
033: private DescriptorRepository ojbMetaData;
034:
035: /** Creates a new instance of DatabaseMetaDataTreeModel. The
036: * model represents the metadata specified by pdbMetadata
037: * @param pdbMetadata the metadata this model represents.
038: * @param pStatusBar a JTextComponent that takes status messages
039: * of this model. This model sometimes needs
040: * some time to finish a request, the status
041: * bar indicates what the model is doing.
042: */
043: public OjbMetaDataTreeModel(DescriptorRepository pOjbMetaData) {
044: super (new javax.swing.tree.DefaultMutableTreeNode("dummy"));
045: this .ojbMetaData = pOjbMetaData;
046: OjbMetaRootNode rootNode = new OjbMetaRootNode(ojbMetaData,
047: this );
048: super .setRoot(rootNode);
049: rootNode.load();
050: }
051:
052: public DescriptorRepository getRepository() {
053: return ojbMetaData;
054: }
055:
056: /** Set a status message in the JTextComponent passed to this
057: * model.
058: * @param message The message that should be displayed.
059: */
060: public void setStatusBarMessage(final String message) {
061: // Guaranteed to return a non-null array
062: Object[] listeners = listenerList.getListenerList();
063: // Process the listeners last to first, notifying
064: // those that are interested in this event
065: for (int i = listeners.length - 2; i >= 0; i -= 2) {
066: if (listeners[i] == StatusMessageListener.class) {
067: ((StatusMessageListener) listeners[i + 1])
068: .statusMessageReceived(message);
069: }
070: }
071: }
072:
073: /** Add a listener that receives status messages from
074: * this model.
075: * @param listener The listener that should receive the status messsages
076: */
077: public void addStatusMessageListener(StatusMessageListener listener) {
078: listenerList.add(StatusMessageListener.class, listener);
079: }
080:
081: /** Remove a listener that receives status messages from
082: * this model.
083: * @param listener The listener that shall be removed
084: */
085: public void removeStatusMessageListener(
086: StatusMessageListener listener) {
087: listenerList.remove(StatusMessageListener.class, listener);
088: }
089:
090: /** Method for reporting SQLException. This is used by
091: * the treenodes if retrieving information for a node
092: * is not successful.
093: * @param message The message describing where the error occurred
094: * @param sqlEx The exception to be reported.
095: */
096: public void reportSqlError(String message,
097: java.sql.SQLException sqlEx) {
098: StringBuffer strBufMessages = new StringBuffer();
099: java.sql.SQLException currentSqlEx = sqlEx;
100: do {
101: strBufMessages.append("\n" + sqlEx.getErrorCode() + ":"
102: + sqlEx.getMessage());
103: currentSqlEx = currentSqlEx.getNextException();
104: } while (currentSqlEx != null);
105: System.err.println(message + strBufMessages.toString());
106: sqlEx.printStackTrace();
107: }
108:
109: public OjbMetaClassDescriptorNode getClassDescriptorNodeForClassDescriptor(
110: ClassDescriptor cld) {
111: return ((OjbMetaRootNode) this.getRoot())
112: .getClassDescriptorNodeForClassDescriptor(cld);
113: }
114: }
|