001: package net.sourceforge.squirrel_sql.fw.sql;
002:
003: /*
004: * Copyright (C) 2006 Rob Manning
005: * manningr@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021:
022: import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
023: import net.sourceforge.squirrel_sql.fw.util.StringManager;
024: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
025:
026: import java.io.File;
027: import java.sql.DatabaseMetaData;
028: import java.util.ArrayList;
029: import java.util.Iterator;
030:
031: /**
032: * A simple decorator of MetaDataDataSet which adds two additional properties -
033: * which are not really MetaData, so here I'm cheating just a little - for the
034: * purpose of telling the user which JDBC driver CLASSNAME is in use for this
035: * session and what jar files make up the 'CLASSPATH' for the driver being used
036: * in this session. I call this class a decorator of MetaDataDataSet since it
037: * wraps this class, providing the two aforementioned additional properties.
038: *
039: * @author manningr
040: */
041: public class MetaDataDecoratorDataSet extends MetaDataDataSet {
042:
043: /** Internationalized strings for this class. */
044: private static final StringManager s_stringMgr = StringManagerFactory
045: .getStringManager(MetaDataDecoratorDataSet.class);
046:
047: boolean finishedLocalRows = false;
048:
049: Iterator<Object[]> iter = null;
050: ArrayList<Object[]> data = new ArrayList<Object[]>();
051:
052: Object[] currentRow = null;
053:
054: private static interface i18n {
055: //1i8n[MetaDataDecoratorDataSet.classNameLabel=JDBC Driver CLASSNAME]
056: String CLASS_NAME_LABEL = s_stringMgr
057: .getString("MetaDataDecoratorDataSet.classNameLabel");
058: //1i8n[MetaDataDecoratorDataSet.classPathLabel=JDBC Driver CLASSPATH]
059: String CLASS_PATH_LABEL = s_stringMgr
060: .getString("MetaDataDecoratorDataSet.classPathLabel");
061: //i18n[MetaDataDecoratorDataSet.noJarFiles=No files specified in 'Extra ClassPath' tab for driver]
062: String NO_JAR_FILES = s_stringMgr
063: .getString("MetaDataDecoratorDataSet.noJarFiles");
064: }
065:
066: /**
067: *
068: * @param md
069: * @param driverClassName
070: * @param jarFileNames
071: */
072: public MetaDataDecoratorDataSet(DatabaseMetaData md,
073: String driverClassName, String[] jarFileNames) {
074: super (md, null);
075: Object[] className = new Object[] { i18n.CLASS_NAME_LABEL,
076: driverClassName };
077:
078: data.add(className);
079: String[] classPathFiles = jarFileNames;
080: StringBuffer classPathBuffer = new StringBuffer();
081: if (classPathFiles.length == 0) {
082: classPathBuffer.append(i18n.NO_JAR_FILES);
083: } else {
084: for (int i = 0; i < classPathFiles.length; i++) {
085: classPathBuffer.append(classPathFiles[i]);
086: if (i + 1 < classPathFiles.length) {
087: classPathBuffer.append(File.pathSeparator);
088: }
089: }
090: }
091: Object[] classPath = new Object[] { i18n.CLASS_PATH_LABEL,
092: classPathBuffer.toString() };
093: data.add(classPath);
094: iter = data.iterator();
095: }
096:
097: /* (non-Javadoc)
098: * @see net.sourceforge.squirrel_sql.fw.sql.MetaDataDataSet#get(int)
099: */
100: public synchronized Object get(int columnIndex) {
101: if (finishedLocalRows) {
102: return super .get(columnIndex);
103: } else {
104: return currentRow[columnIndex];
105: }
106: }
107:
108: /* (non-Javadoc)
109: * @see net.sourceforge.squirrel_sql.fw.sql.MetaDataDataSet#next(net.sourceforge.squirrel_sql.fw.util.IMessageHandler)
110: */
111: public synchronized boolean next(IMessageHandler msgHandler) {
112: if (finishedLocalRows) {
113: return super .next(msgHandler);
114: } else {
115: if (iter.hasNext()) {
116: currentRow = iter.next();
117: return true;
118: } else {
119: finishedLocalRows = true;
120: return super.next(msgHandler);
121: }
122: }
123: }
124:
125: }
|