DBVIEW
src/org/dbview/addons/output/table/dotLight/Cli.java
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.dotLight;
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 light 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         // DEBUG
00113         // System.out.println("Cli done");
00114         return conf;
00115     }
00116 
00117     /**
00118      * This method returns the description of the command line expected by this adaptor.
00119      *
00120      * @return The method returns an array of command line parameter's
00121      *         descriptions.
00122      */
00123     public ArrayList<CliParameter> getOptions()
00124     {
00125         ArrayList<CliParameter> params = new ArrayList<CliParameter>();
00126 
00127         CliParameter p1 = new CliParameter();
00128         p1.parameter    = CliOptions.LAYOUT;
00129         p1.type         = CliParameterTypes.STRING;
00130         p1.mandatory    = Boolean.FALSE;
00131         p1.description  = "The graph's layout. Values can be: \"horizontal\" (or \"h\"), \"vertical\" (or \"v\").";
00132         params.add(p1);
00133 
00134         CliParameter p2 = new CliParameter();
00135         p2.parameter    = CliOptions.PATH;
00136         p2.type         = CliParameterTypes.STRING;
00137         p2.mandatory    = Boolean.FALSE;
00138         p2.description  = "Path to the output file (default is STDOUT).";
00139         params.add(p2);
00140 
00141         return params;
00142     }
00143 }