Methods Summary |
---|
private java.lang.String | addEscapeToLiteral(java.lang.String strToAdd)This method adds escape character preceding the '$' character.
The reason for doing this is because match.appendReplacement
will throw an IllegalArgumentException if the literal '$'
does not precede by an escape character.
The java api class Matcher, uses the regular expression
'$' as a group reference. So if it encounters '$
it'll throw an IllegalArgumentException. In order to by pass this
exception, the literal '$' must precede with an escape character.
StringBuffer strbuf = new StringBuffer();
int previousIndex =0;
int index = strToAdd.indexOf('$");
while (index > -1)
{
strbuf.append(strToAdd.substring(previousIndex, index)+"\\$");
previousIndex = index+1;
index = strToAdd.indexOf('$", index+1);
}
strbuf.append(strToAdd.substring(previousIndex));
return strbuf.toString();
|
private java.lang.String | escapeTheEscape(java.lang.String strToEscape)This method adds escape character to each escape chars encounters
the purpose for doing this is is that match.appendReplacement
drops the escape character.
StringBuffer strbuf = new StringBuffer();
int previousIndex =0;
int index =strToEscape.indexOf("\\");
while (index > -1)
{
if (index<strToEscape.length()-1 && strToEscape.charAt(index+1) == '$")
strbuf.append(strToEscape.substring(previousIndex, index));
else
strbuf.append(strToEscape.substring(previousIndex, index)+"\\\\");
previousIndex = index+1;
index = strToEscape.indexOf("\\", index+1);
}
strbuf.append(strToEscape.substring(previousIndex));
return strbuf.toString();
|
private java.lang.String | findPatternStringValue(java.lang.String pattern, java.lang.String key)this method finds the pattern for option and operand
option pattern starts with "$" while operand pattern starts with "#"
once key is determined, the option or operand value is returned
String value = null;
try
{
if (pattern.equals(String.valueOf(OPERAND_START_CHAR)))
{
if (operands.size() > 0)
value = (String)getOperands().get(Integer.parseInt(key)-1);
}
else if (pattern.equals(String.valueOf(VARIABLE_START_CHAR)))
value = getOption(key);
}
catch(Exception e)
{
throw new CommandException(e);
}
// (bug 6363010), temporary fix, return null and make sure this isn't
// propagated into the attributeList to the backend
//return (value==null)?"":value;
return value;
|
protected boolean | getBooleanOption(java.lang.String optionName)Finds the option with the give name
return Boolean.valueOf(getOption(optionName)).booleanValue();
|
public java.lang.String | getCLOption(java.lang.String optionName)Finds the option with the give name
Map<String, String> map = this.optionsMap.getCLOptions();
return map.get(optionName);
|
public java.util.Map | getCLOptions()Gets the list of options read from command line for this Command
return this.optionsMap.getCLOptions();
|
protected int | getDelimeterIndex(java.lang.String searchStr, java.lang.String delimeter, int fromIndex)returns the index of the delimeter string in the search string.
return searchStr.indexOf(delimeter, fromIndex);
|
public java.lang.String | getENVOption(java.lang.String optionName)Finds the option with the give name
Map<String, String> map = this.optionsMap.getEnvOptions();
return map.get(optionName);
|
public java.util.Map | getENVOptions()Gets the list of options read from environment for this Command
return this.optionsMap.getEnvOptions();
|
protected int | getIntegerOption(java.lang.String optionName)Finds the option with the give name
//assert
assert(!optionNameExist(optionName));
return (Integer.valueOf(getOption(optionName)).intValue());
|
protected java.lang.String | getLocalizedString(java.lang.String key)returns the localized string from the properties file as defined in
the CommandProperties element of CLIDescriptor.xml file
Calls the LocalStringsManagerFactory.getCommandLocalStringsManager()
method, returns "Key not found" if it cannot find the key
LocalStringsManager lsm = null;
try
{
lsm = LocalStringsManagerFactory.getCommandLocalStringsManager();
}
catch (CommandValidationException cve)
{
return LocalStringsManager.DEFAULT_STRING_VALUE;
}
return lsm.getString(key);
|
protected java.lang.String | getLocalizedString(java.lang.String key, java.lang.Object[] toInsert)returns the localized string from the properties file as defined in
the CommandProperties element of CLIDescriptor.xml file
Calls the LocalStringsManagerFactory.getCommandLocalStringsManager()
method, returns "Key not found" if it cannot find the key
LocalStringsManager lsm = null;
try
{
lsm = LocalStringsManagerFactory.getCommandLocalStringsManager();
return lsm.getString(key, toInsert);
}
catch (CommandValidationException cve)
{
return LocalStringsManager.DEFAULT_STRING_VALUE;
}
|
public java.lang.String | getName()Gets the name of the command
return name;
|
public java.util.Vector | getOperands()Gets the list of operands of this command
return operands;
|
public java.lang.String | getOption(java.lang.String optionName)Finds the option with the give name
return this.optionsMap.getOption(optionName);
|
public java.util.Map | getOptions()Gets the list of options for this Command
return this.optionsMap.getOptions();
|
public java.lang.String | getOtherOption(java.lang.String optionName)Finds the option with the give name
Options set bo "Other" are usually set by the command module
Map<String, String> map = this.optionsMap.getOtherOptions();
return map.get(optionName);
|
protected java.util.Hashtable | getProperties(java.lang.String key)returns the properties list
return the property
return properties;
|
public java.lang.Object | getProperty(java.lang.String key)Searches for the property with the specified key in this
properties list
return the property
return properties.get(key);
|
public java.lang.String | getUsageText()Gets the Usage text for this command
return usageStr;
|
private boolean | optionNameExist(java.lang.String optionName)returns true if the option name exist in the options list
return this.optionsMap.containsName(optionName);
|
private java.lang.String | prepareStringForAppend(java.lang.String str)this method is a hack
to add escape character to each esacpe chars encounters except
the escape character is follow by a '$'.
match.appendReplacement will throw an IllegalArgumentException
if literal $ does not preceed by an escape char.
the purpose for doing this is for the match.appendReplacement
which drops the escape character.
final String strTmp = escapeTheEscape(str);
return addEscapeToLiteral(strTmp);
|
public java.lang.String | replacePattern(java.lang.String replaceValue)this method replaces pattern with option or operand values
if (replaceValue == null) return null;
final Pattern patt = Pattern.compile(PATTERN_MATCHING);
final Matcher match = patt.matcher(replaceValue);
String outstr = replaceValue;
try
{
if (match.find())
{
StringBuffer strbuf = new StringBuffer();
do
{
String value = findPatternStringValue(match.group(1),
match.group(2));
//value = escapeTheEscape(value);
if (value == null)
return value;
value = prepareStringForAppend(value);
match.appendReplacement(strbuf, value);
CLILogger.getInstance().printDebugMessage("strbuf = " + strbuf);
} while (match.find());
match.appendTail(strbuf);
outstr = strbuf.toString();
}
}
catch (java.lang.IllegalArgumentException iae)
{
try
{
final LocalStringsManager lsm =
LocalStringsManagerFactory.getFrameworkLocalStringsManager();
throw new CommandException(lsm.getString("RequireEscapeChar"), iae);
}
catch (CommandValidationException cve)
{
throw new CommandException(cve);
}
}
catch (Exception e)
{
throw new CommandException(e);
}
return (outstr.length()<1)?null:outstr;
|
public abstract void | runCommand()An abstract method that Executes the command
|
public void | setName(java.lang.String name)Sets the name of the command
this.name = name;
|
public void | setOperands(java.util.Vector operands)Sets the list of operands for this command
this.operands = operands;
|
public void | setOption(java.lang.String optionName, java.lang.String optionValue)Sets the option value for the give name
this.optionsMap.addOptionValue(optionName, optionValue);
|
public void | setOptionsMap(OptionsMap options)Sets OptionsMap
this.optionsMap = options;
|
protected void | setProperties(java.util.Hashtable properties)Sets the properties of the command
this.properties = properties;
|
public void | setProperty(java.lang.String key, java.lang.Object value)Sets the properties of the command
properties.put(key, value);
|
public void | setUsageText(java.lang.String usageText)Sets the Usage text for this command
this.usageStr = usageText;
|
public java.lang.String | toString()Overrides the Object's toString() method
StringBuffer strbuf = new StringBuffer();
strbuf.append(getName());
final Map<String, String> clOptions = this.optionsMap.getOptions();
Iterator optionNames = clOptions.keySet().iterator();
while (optionNames.hasNext())
{
final String optionKey = (String) optionNames.next();
strbuf.append(" --" + optionKey );
final String optionVal = (String)clOptions.get(optionKey);
//check if the value is boolean
if (Boolean.TRUE.toString().equalsIgnoreCase(optionVal) ||
Boolean.FALSE.toString().equalsIgnoreCase(optionVal) )
strbuf.append("=");
else
strbuf.append(" ");
strbuf.append(optionVal);
}
for (int ii=0; ii<operands.size(); ii++)
{
strbuf.append(" "+ operands.get(ii).toString());
}
return strbuf.toString();
|
public abstract boolean | validateOptions()An abstract method that validates the options
on the specification in the xml properties file
This method verifies for the correctness of number of
operands and if all the required options are supplied by the client.
|