DBVIEW
|
00001 /* 00002 DbView - Graph Visualization 00003 Copyright (C) 2012 Denis BEURIVE 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 /** 00020 * @author Denis Beurive 00021 */ 00022 00023 package org.dbview.databaseExporters.dot; 00024 00025 import java.util.*; 00026 import org.dbview.db.structure.Database; 00027 import org.dbview.db.structure.Table; 00028 00029 /** 00030 * This class defines the generic interface of a database exporter that relies on Grahviz. 00031 * A database exporter creates a representation of a given list of tables, within a given database. 00032 * @remark Please note that all DOT add-ons use this exporter. 00033 * @author Denis Beurive 00034 */ 00035 public abstract class AbstractDatabaseExporter 00036 { 00037 /** 00038 * List of table to export. Please note that the property's value may be null. 00039 * If the property's value is null, then all tables of the database are exported. 00040 */ 00041 protected ArrayList<Table> _tables = null; 00042 00043 /** 00044 * Database to export. 00045 */ 00046 protected Database _db = null; 00047 00048 /** 00049 * Create the exporter. 00050 * @param in_tables List of tables to export. This parameter can be null. 00051 * If the parameter's value is null, then all tables of the database are exported. 00052 * @param in_db Handle to the database. 00053 */ 00054 public AbstractDatabaseExporter(ArrayList<Table> in_tables, Database in_db) 00055 { 00056 this._db = in_db; 00057 if (null == in_tables) { this._tables = in_db.getTables(); } 00058 else { this._tables = in_tables; } 00059 } 00060 00061 /** 00062 * This method exports the given tables, from the given database. 00063 * @param in_options Options. 00064 * @return The method returns a string that represents the DOT representation. 00065 * @throws Exception 00066 */ 00067 public abstract String export(Hashtable<String, Object> in_options) throws Exception; 00068 00069 /** 00070 * This method returns the color to apply to a given edge, given the type of the table to table relation. 00071 * @param in_table_to_table_relation_type The type of the relation. 00072 * @return The method returns the color to apply to a given edge. 00073 * @throws Exception 00074 */ 00075 protected String _relationColor(int in_table_to_table_relation_type) throws Exception 00076 { 00077 switch (in_table_to_table_relation_type) 00078 { 00079 case Database.HARD_LINK : return org.dbview.addons.output.table.utils.dot.Conf.HARD_EDGE_COLOR; 00080 case Database.SOFT_LINK : return org.dbview.addons.output.table.utils.dot.Conf.SOFT_EDGE_COLOR; 00081 case Database.SOFT_AND_HARD_LINK : return org.dbview.addons.output.table.utils.dot.Conf.SOFT_AND_HARD_EDGE_COLOR; 00082 } 00083 throw new Exception("Unexpected table to table type: " + in_table_to_table_relation_type); 00084 } 00085 }