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 00024 package org.dbview.addons.output.table.dotFull; 00025 00026 import java.util.ArrayList; 00027 import org.jdom.Element; 00028 import org.dbview.adapter.AbstractCli; 00029 import org.dbview.adapter.CliException; 00030 import org.dbview.adapter.CliParameter; 00031 import org.dbview.adapter.CliParameterTypes; 00032 import org.dbview.addons.output.table.utils.dot.CliOptions; 00033 import org.dbview.addons.output.table.utils.dot.XML; 00034 import org.dbview.utils.args4j.*; 00035 import org.kohsuke.args4j.CmdLineException; 00036 import org.kohsuke.args4j.CmdLineParser; 00037 00038 /** 00039 * @class Cli 00040 * This class implements the CLI adapter for the add-on that produces detailed DOT (GraphViz) representations. 00041 * @author Denis BEURIVE 00042 */ 00043 public class Cli extends AbstractCli 00044 { 00045 /** 00046 * This attribute represents the <i>command line options' container</i> used to parse the command line that applies to the add-on. 00047 * @remark See Args4j. The command line options are declared in a class. We call this class the <i>command line options container</i> 00048 */ 00049 private CliOptions __options = new CliOptions(); 00050 00051 /** 00052 * Return the command line options container. 00053 * 00054 * @note The returned container is mainly used to detect unexpected arguments in the command line. 00055 * @return The method returns the command line options container. 00056 */ 00057 public OptionContainer getOptionsContainer() { return this.__options; } 00058 00059 /** 00060 * This method returns the information extracted from the command line. 00061 * 00062 * @param in_vargs 00063 * The command line arguments. 00064 * @param in_strict 00065 * This parameter indicates whether the CLI parser should check 00066 * the presence of mandatory options, or not. 00067 * <ul> 00068 * <li>TRUE: Check the presence of mandatory options.</li> 00069 * <li>FALSE: Does not check the presence of mandatory options.</li> 00070 * </ul> 00071 * @param in_set_default 00072 * This parameter indicates whether the method should set default 00073 * values or not. 00074 * <ul> 00075 * <li>TRUE: Set default values. When adding a new profile, you should activate the assignment of default values.</li> 00076 * <li>FALSE: Does not set default values. When updating a profile, you should deactivate the assignment of default values.</li> 00077 * </ul> 00078 * @return The method returns the information extracted from the command 00079 * line. The configuration is represented by a list of 00080 * XML elements. Each element of the returned list will be included 00081 * in the XML representation of the configuration. 00082 */ 00083 protected ArrayList<Element> _getConf_(String[] in_vargs, 00084 Boolean in_strict, 00085 Boolean in_set_default) throws CliException 00086 { 00087 ArrayList<Element> conf = new ArrayList<Element>(); 00088 CmdLineParser parser = new CmdLineParser(this.__options); 00089 00090 try 00091 { 00092 parser.parseArgument(this.__options.extractArgvForThisSet(in_vargs)); 00093 } 00094 catch (CmdLineException e) 00095 { 00096 throw new CliException(e.getMessage()); 00097 } 00098 00099 // Add the layout. 00100 try 00101 { 00102 conf.add(new Element(XML.LAYOUT).addContent(this.__options.getLayout() == org.dbview.addons.output.table.utils.dot.CliOptions.LAYOUT_HORIZONTAL ? "LR" : "TB")); 00103 } 00104 catch (Exception e) 00105 { 00106 throw new CliException(e.getMessage()); 00107 } 00108 00109 // Add the output path. 00110 conf.add(new Element(XML.PATH).addContent(null == this.__options.getPath() ? "" : this.__options.getPath())); 00111 00112 return conf; 00113 } 00114 00115 /** 00116 * This method returns the description of the command line expected by this adaptor. 00117 * 00118 * @return The method returns an array of command line parameter's 00119 * descriptions. 00120 */ 00121 public ArrayList<CliParameter> getOptions() 00122 { 00123 ArrayList<CliParameter> params = new ArrayList<CliParameter>(); 00124 00125 CliParameter p1 = new CliParameter(); 00126 p1.parameter = CliOptions.LAYOUT; 00127 p1.type = CliParameterTypes.STRING; 00128 p1.mandatory = Boolean.FALSE; 00129 p1.description = "The graph's layout. Values can be: \"horizontal\" (or \"h\"), \"vertical\" (or \"v\")."; 00130 params.add(p1); 00131 00132 CliParameter p2 = new CliParameter(); 00133 p2.parameter = CliOptions.PATH; 00134 p2.type = CliParameterTypes.STRING; 00135 p2.mandatory = Boolean.FALSE; 00136 p2.description = "Path to the output file (default is STDOUT)."; 00137 params.add(p2); 00138 00139 return params; 00140 } 00141 }