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.adapter; 00024 00025 import java.util.ArrayList; 00026 import org.jdom.Element; 00027 import org.dbview.utils.args4j.*; 00028 00029 /** 00030 * @class AbstractCli 00031 * 00032 * This class is a base class for all command line interface (CLI) adaptors. 00033 * A command line interface adaptor parses the command line and returns an XML document. 00034 * The returned XML document is provided to all adaptors that need configuration 00035 * Please note that the returned XML representation is independent from the user interface (CLI, GUI...) used to get the configuration. 00036 * 00037 * @author Denis BEURIVE 00038 */ 00039 public abstract class AbstractCli 00040 { 00041 /** 00042 * Return the <i>command line options container</i>. 00043 * @remark See Args4j. The command line options are declared in a class. We call this class the <i>command line options container</i> 00044 * @note The returned container is mainly used to detect unexpected arguments in the command line. 00045 * @return The method returns the command line options container. 00046 */ 00047 public abstract OptionContainer getOptionsContainer(); 00048 00049 /** 00050 * This method returns the description of the command line expected by this adaptor. 00051 * @remark This method is only used when the user requires to print the help. 00052 * @return The method returns an array of command line parameter's 00053 * descriptions. 00054 */ 00055 public abstract ArrayList<CliParameter> getOptions(); 00056 00057 /** 00058 * This method returns an XML document that represents the command line. 00059 * 00060 * @param in_vargs 00061 * The command line arguments. 00062 * @param in_strict 00063 * This parameter indicates whether the CLI parser should check 00064 * the presence of mandatory options, or not. 00065 * <ul> 00066 * <li>TRUE: Check the presence of mandatory options.</li> 00067 * <li>FALSE: Does not check the presence of mandatory options.</li> 00068 * </ul> 00069 * @param in_set_default 00070 * This parameter indicates whether the method should set default 00071 * values or not. 00072 * <ul> 00073 * <li>TRUE: Set default values. When adding a new profile, you should activate the assignment of default values.</li> 00074 * <li>FALSE: Does not set default values. When updating a profile, you should deactivate the assignment of default values.</li> 00075 * </ul> 00076 * @return The method returns the extracted information. The returned 00077 * structure is a XML element identified by the tag "data". Example: 00078 * <code> 00079 * <data><login>...</login><password>...</password></data> 00080 * </code> 00081 */ 00082 public Element getConf(String[] in_vargs, 00083 Boolean in_strict, 00084 Boolean in_set_default) throws CliException 00085 { 00086 ArrayList<Element> values = null; 00087 Element conf = new Element("data"); 00088 00089 try 00090 { 00091 // We get the configuration. 00092 values = this._getConf_(in_vargs, in_strict, in_set_default); 00093 } 00094 catch (CliException e) 00095 { 00096 throw new CliException("The target's configuration is not valid: " + e.getMessage()); 00097 } 00098 00099 // We wrap the configuration into a CML container. 00100 for (int i = 0; i < values.size(); i++) 00101 { 00102 conf.addContent(values.get(i)); 00103 } 00104 00105 // DEBUG 00106 // System.out.println("getConf done"); 00107 return conf; 00108 } 00109 00110 /** 00111 * This method returns the information extracted from the command line. 00112 * 00113 * @param in_vargs 00114 * The command line arguments. 00115 * @param in_strict 00116 * This parameter indicates whether the CLI parser should check 00117 * the presence of mandatory options, or not. 00118 * <ul> 00119 * <li>TRUE: Check the presence of mandatory options.</li> 00120 * <li>FALSE: Does not check the presence of mandatory options.</li> 00121 * </ul> 00122 * @param in_set_default 00123 * This parameter indicates whether the method should set default 00124 * values or not. 00125 * <ul> 00126 * <li>TRUE: Set default values. When adding a new profile, you should activate the assignment of default values.</li> 00127 * <li>FALSE: Does not set default values. When updating a profile, you should deactivate the assignment of default values.</li> 00128 * </ul> 00129 * @return The method returns the information extracted from the command 00130 * line. The configuration is represented by a list of 00131 * XML elements. Each element of the returned list will be included 00132 * in the XML representation of the configuration. 00133 */ 00134 protected abstract ArrayList<Element> _getConf_(String[] in_vargs, 00135 Boolean in_strict, 00136 Boolean in_set_default) throws CliException; 00137 00138 00139 }